Add some more rw lock tests
authorMatthias Clasen <mclasen@redhat.com>
Fri, 23 Sep 2011 10:31:12 +0000 (06:31 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 23 Sep 2011 10:31:59 +0000 (06:31 -0400)
These test some simple mixed reader/writer api usage.

glib/tests/rwlock.c

index 95a1dd1..17869ca 100644 (file)
@@ -63,6 +63,53 @@ test_rwlock3 (void)
   g_rw_lock_clear (&lock);
 }
 
+static void
+test_rwlock4 (void)
+{
+  GRWLock lock = G_RW_LOCK_INIT;
+
+  g_rw_lock_reader_lock (&lock);
+  g_rw_lock_reader_unlock (&lock);
+  g_rw_lock_reader_lock (&lock);
+  g_rw_lock_reader_unlock (&lock);
+  g_rw_lock_clear (&lock);
+}
+
+static void
+test_rwlock5 (void)
+{
+  GRWLock lock = G_RW_LOCK_INIT;
+  gboolean ret;
+
+  ret = g_rw_lock_reader_trylock (&lock);
+  g_assert (ret);
+  ret = g_rw_lock_reader_trylock (&lock);
+  g_assert (ret);
+
+  g_rw_lock_reader_unlock (&lock);
+  g_rw_lock_reader_unlock (&lock);
+
+  g_rw_lock_clear (&lock);
+}
+
+static void
+test_rwlock6 (void)
+{
+  GRWLock lock = G_RW_LOCK_INIT;
+  gboolean ret;
+
+  g_rw_lock_writer_lock (&lock);
+  ret = g_rw_lock_reader_trylock (&lock);
+  g_assert (!ret);
+  g_rw_lock_writer_unlock (&lock);
+
+  g_rw_lock_reader_lock (&lock);
+  ret = g_rw_lock_writer_trylock (&lock);
+  g_assert (!ret);
+  g_rw_lock_reader_unlock (&lock);
+
+  g_rw_lock_clear (&lock);
+}
 
 int
 main (int argc, char *argv[])
@@ -72,6 +119,9 @@ main (int argc, char *argv[])
   g_test_add_func ("/thread/rwlock1", test_rwlock1);
   g_test_add_func ("/thread/rwlock2", test_rwlock2);
   g_test_add_func ("/thread/rwlock3", test_rwlock3);
+  g_test_add_func ("/thread/rwlock4", test_rwlock4);
+  g_test_add_func ("/thread/rwlock5", test_rwlock5);
+  g_test_add_func ("/thread/rwlock6", test_rwlock6);
 
   return g_test_run ();
 }