Add basic tests for GRWLock

Just basic api usage, no functional test cases yet.
This commit is contained in:
Matthias Clasen 2011-09-22 22:43:29 -04:00
parent b2717740a2
commit ff13913537
2 changed files with 80 additions and 0 deletions

View File

@ -206,6 +206,9 @@ mutex_LDADD = $(progs_ldadd)
TEST_PROGS += rec-mutex
rec_mutex_LDADD = $(progs_ldadd)
TEST_PROGS += rwlock
rwlock_LDADD = $(progs_ldadd)
# some testing of gtester funcitonality
XMLLINT=xmllint
gtester-xmllint-check: # check testreport xml with xmllint if present

77
glib/tests/rwlock.c Normal file
View File

@ -0,0 +1,77 @@
/* Unit tests for GRWLock
* Copyright (C) 2011 Red Hat, Inc
* Author: Matthias Clasen
*
* This work is provided "as is"; redistribution and modification
* in whole or in part, in any medium, physical or electronic is
* permitted without restriction.
*
* This work is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* In no event shall the authors or contributors be liable for any
* direct, indirect, incidental, special, exemplary, or consequential
* damages (including, but not limited to, procurement of substitute
* goods or services; loss of use, data, or profits; or business
* interruption) however caused and on any theory of liability, whether
* in contract, strict liability, or tort (including negligence or
* otherwise) arising in any way out of the use of this software, even
* if advised of the possibility of such damage.
*/
#include <glib.h>
static void
test_rwlock1 (void)
{
GRWLock lock;
g_rw_lock_init (&lock);
g_rw_lock_writer_lock (&lock);
g_rw_lock_writer_unlock (&lock);
g_rw_lock_writer_lock (&lock);
g_rw_lock_writer_unlock (&lock);
g_rw_lock_clear (&lock);
}
static void
test_rwlock2 (void)
{
GRWLock lock = G_RW_LOCK_INIT;
g_rw_lock_writer_lock (&lock);
g_rw_lock_writer_unlock (&lock);
g_rw_lock_writer_lock (&lock);
g_rw_lock_writer_unlock (&lock);
g_rw_lock_clear (&lock);
}
static void
test_rwlock3 (void)
{
GRWLock lock = G_RW_LOCK_INIT;
gboolean ret;
ret = g_rw_lock_writer_trylock (&lock);
g_assert (ret);
ret = g_rw_lock_writer_trylock (&lock);
g_assert (!ret);
g_rw_lock_writer_unlock (&lock);
g_rw_lock_clear (&lock);
}
int
main (int argc, char *argv[])
{
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/thread/rwlock1", test_rwlock1);
g_test_add_func ("/thread/rwlock2", test_rwlock2);
g_test_add_func ("/thread/rwlock3", test_rwlock3);
return g_test_run ();
}