X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=tests%2Ftestglib.c;h=b674fa99cd7c0d0b03e577ce1f68dc42821bb7f2;hb=bac4179476d0eee96f8bd73fef760b4289b79c17;hp=1f0a9abea110cc22c57bf947c1bfcca89c2fa604;hpb=1b033919845cef366842373da9f1cfb56f522d01;p=platform%2Fupstream%2Fglib.git diff --git a/tests/testglib.c b/tests/testglib.c index 1f0a9ab..b674fa9 100644 --- a/tests/testglib.c +++ b/tests/testglib.c @@ -448,6 +448,8 @@ binary_tree_test (void) g_tree_foreach (tree, my_traverse, NULL); g_print ("\n"); } + + g_tree_unref (tree); } static gboolean @@ -509,12 +511,13 @@ find_first_that(gpointer key, static void test_g_parse_debug_string (void) { - GDebugKey keys[3] = { + GDebugKey keys[] = { { "foo", 1 }, { "bar", 2 }, - { "baz", 4 } + { "baz", 4 }, + { "weird", 8 }, }; - guint n_keys = 3; + guint n_keys = G_N_ELEMENTS (keys); guint result; result = g_parse_debug_string ("bar:foo:blubb", keys, n_keys); @@ -528,37 +531,51 @@ test_g_parse_debug_string (void) result = g_parse_debug_string (" : ", keys, n_keys); g_assert (result == 0); + + result = g_parse_debug_string ("all", keys, n_keys); + g_assert_cmpuint (result, ==, (1 << n_keys) - 1); + + /* Test subtracting debug flags from "all" */ + result = g_parse_debug_string ("all:foo", keys, n_keys); + g_assert_cmpuint (result, ==, 2 | 4 | 8); + + result = g_parse_debug_string ("foo baz,all", keys, n_keys); + g_assert_cmpuint (result, ==, 2 | 8); + + result = g_parse_debug_string ("all,fooo,baz", keys, n_keys); + g_assert_cmpuint (result, ==, 1 | 2 | 8); + + result = g_parse_debug_string ("all:weird", keys, n_keys); + g_assert_cmpuint (result, ==, 1 | 2 | 4); } static void log_warning_error_tests (void) { - if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR)) - { - g_message ("this is a g_message test."); - g_message ("non-printable UTF-8: \"\xc3\xa4\xda\x85\""); - g_message ("unsafe chars: \"\x10\x11\x12\n\t\x7f\x81\x82\x83\""); - exit (0); - } - g_test_trap_assert_passed(); - g_test_trap_assert_stderr ("*is a g_message test*"); - g_test_trap_assert_stderr ("*non-printable UTF-8*"); - g_test_trap_assert_stderr ("*unsafe chars*"); - if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR)) - { - g_warning ("harmless warning with parameters: %d %s %#x", 42, "Boo", 12345); - exit (0); - } - g_test_trap_assert_failed(); /* we have fatal-warnings enabled */ - g_test_trap_assert_stderr ("*harmless warning*"); - if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR)) - { - g_print (NULL); - exit (0); - } - g_test_trap_assert_failed(); /* we have fatal-warnings enabled */ - g_test_trap_assert_stderr ("*g_print*assertion*failed*"); - g_test_trap_assert_stderr ("*NULL*"); + g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, + "*is a g_message test*"); + g_message ("this is a g_message test."); + g_test_assert_expected_messages (); + + g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, + "*non-printable UTF-8*"); + g_message ("non-printable UTF-8: \"\xc3\xa4\xda\x85\""); + g_test_assert_expected_messages (); + + g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, + "*unsafe chars*"); + g_message ("unsafe chars: \"\x10\x11\x12\n\t\x7f\x81\x82\x83\""); + g_test_assert_expected_messages (); + + g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, + "*harmless warning*"); + g_warning ("harmless warning with parameters: %d %s %#x", 42, "Boo", 12345); + g_test_assert_expected_messages (); + + g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, + "*g_print*assertion*failed*"); + g_print (NULL); + g_test_assert_expected_messages (); } static void @@ -926,6 +943,7 @@ test_file_functions (void) remove (template); error = NULL; + name_used = NULL; strcpy (template, "zap" G_DIR_SEPARATOR_S "barXXXXXX"); fd = g_file_open_tmp (template, &name_used, &error); if (g_test_verbose()) @@ -935,10 +953,13 @@ test_file_functions (void) else g_print ("g_file_open_tmp correctly returns error: %s\n", error->message); } - close (fd); + if (fd != -1) + close (fd); g_clear_error (&error); + g_free (name_used); #ifdef G_OS_WIN32 + name_used = NULL; strcpy (template, "zap/barXXXXXX"); fd = g_file_open_tmp (template, &name_used, &error); if (g_test_verbose()) @@ -950,9 +971,11 @@ test_file_functions (void) } close (fd); g_clear_error (&error); + g_free (name_used); #endif strcpy (template, "zapXXXXXX"); + name_used = NULL; fd = g_file_open_tmp (template, &name_used, &error); if (fd == -1) g_error ("g_file_open_tmp didn't work for template '%s': %s\n", template, error->message); @@ -961,13 +984,16 @@ test_file_functions (void) close (fd); g_clear_error (&error); remove (name_used); + g_free (name_used); + name_used = NULL; fd = g_file_open_tmp (NULL, &name_used, &error); if (fd == -1) g_error ("g_file_open_tmp didn't work for a NULL template: %s\n", error->message); close (fd); g_clear_error (&error); remove (name_used); + g_free (name_used); } static void @@ -1535,6 +1561,8 @@ test_mem_chunks (void) } for (i = 0; i < 10000; i++) g_mem_chunk_free (mem_chunk, mem[i]); + + g_mem_chunk_destroy (mem_chunk); } #endif