GLib has shipped a testing framework for many years already, so we can make use of it, replacing the external "check". The conversion only switches framework without changing the structure of the tests, making use of the more appropriate assertion in the various places. Signed-off-by: Pino Toscano <ptoscano@xxxxxxxxxx> --- configure.ac | 1 - libosinfo.spec.in | 1 - tests/Makefile.am | 3 +- tests/test-db.c | 165 +++++++++++++++++-------------------- tests/test-device.c | 33 ++------ tests/test-devicelist.c | 77 +++++++---------- tests/test-entity.c | 195 ++++++++++++++++++++------------------------ tests/test-filter.c | 111 +++++++++++-------------- tests/test-install-script.c | 92 ++++++++------------- tests/test-isodetect.c | 138 ++++++++++++++----------------- tests/test-list.c | 145 +++++++++++++++----------------- tests/test-loader.c | 33 ++------ tests/test-mediauris.c | 44 ++++------ tests/test-os.c | 122 ++++++++++++--------------- tests/test-oslist.c | 77 +++++++---------- tests/test-platform.c | 61 ++++++-------- tests/test-platformlist.c | 77 +++++++---------- tests/test-product.c | 100 ++++++++++------------- tests/test-productfilter.c | 143 +++++++++++++++----------------- tests/test-treeuris.c | 44 ++++------ 20 files changed, 694 insertions(+), 968 deletions(-) diff --git a/configure.ac b/configure.ac index 99abe94..d834c89 100644 --- a/configure.ac +++ b/configure.ac @@ -57,7 +57,6 @@ AC_ARG_ENABLE([tests], if test "x$enable_tests" != "xno" ; then have_curl=no - PKG_CHECK_MODULES([CHECK], [check]) PKG_CHECK_MODULES([CURL], [libcurl], [have_curl=yes], [:]) AC_SUBST(CURL_CFLAGS) AC_SUBST(CURL_LIBS) diff --git a/libosinfo.spec.in b/libosinfo.spec.in index 5a5e6f8..f3e3690 100644 --- a/libosinfo.spec.in +++ b/libosinfo.spec.in @@ -11,7 +11,6 @@ BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) URL: https://libosinfo.org/ BuildRequires: intltool BuildRequires: glib2-devel -BuildRequires: check-devel BuildRequires: libxml2-devel >= 2.6.0 BuildRequires: libxslt-devel >= 1.0.0 BuildRequires: vala diff --git a/tests/Makefile.am b/tests/Makefile.am index 9315e04..7566d3c 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -30,7 +30,6 @@ COMMON_LDADD = \ $(COVERAGE_LDFLAGS) \ $(GLIB_LIBS) \ $(GOBJECT_LIBS) \ - $(CHECK_LIBS) \ ../osinfo/libosinfo-1.0.la COMMON_CFLAGS = \ $(WARN_CFLAGS) \ @@ -40,7 +39,7 @@ COMMON_CFLAGS = \ -I$(top_srcdir) \ -DSRCDIR="\"$(abs_top_srcdir)\"" \ -DBUILDDIR="\"$(abs_top_builddir)\"" \ - $(CHECK_CFLAGS) + $(NULL) test_entity_LDADD = $(COMMON_LDADD) test_entity_CFLAGS = $(COMMON_CFLAGS) diff --git a/tests/test-db.c b/tests/test-db.c index 31e80d1..ac0a529 100644 --- a/tests/test-db.c +++ b/tests/test-db.c @@ -21,22 +21,21 @@ #include <config.h> -#include <stdlib.h> #include <osinfo/osinfo.h> -#include <check.h> -START_TEST(test_basic) +static void +test_basic(void) { OsinfoDb *db = osinfo_db_new(); - fail_unless(OSINFO_IS_DB(db), "Db is not a DB"); + g_assert_true(OSINFO_IS_DB(db)); g_object_unref(db); } -END_TEST -START_TEST(test_device) +static void +test_device(void) { OsinfoDb *db = osinfo_db_new(); OsinfoDevice *dev1 = osinfo_device_new("dev1"); @@ -48,24 +47,24 @@ START_TEST(test_device) osinfo_db_add_device(db, dev3); OsinfoDeviceList *list = osinfo_db_get_device_list(db); - fail_unless(OSINFO_ENTITY(dev1) == osinfo_list_get_nth(OSINFO_LIST(list), 0), "Dev 1 is missing"); - fail_unless(OSINFO_ENTITY(dev2) == osinfo_list_get_nth(OSINFO_LIST(list), 1), "Dev 2 is missing"); - fail_unless(OSINFO_ENTITY(dev3) == osinfo_list_get_nth(OSINFO_LIST(list), 2), "Dev 3 is missing"); + g_assert_true(OSINFO_ENTITY(dev1) == osinfo_list_get_nth(OSINFO_LIST(list), 0)); + g_assert_true(OSINFO_ENTITY(dev2) == osinfo_list_get_nth(OSINFO_LIST(list), 1)); + g_assert_true(OSINFO_ENTITY(dev3) == osinfo_list_get_nth(OSINFO_LIST(list), 2)); g_object_unref(list); OsinfoDevice *dev = osinfo_db_get_device(db, "dev2"); - fail_unless(dev != NULL, "Device is NULL"); - fail_unless(dev == dev2, "Device was not dev2"); + g_assert_nonnull(dev); + g_assert_true(dev == dev2); g_object_unref(dev1); g_object_unref(dev2); g_object_unref(dev3); g_object_unref(db); } -END_TEST -START_TEST(test_platform) +static void +test_platform(void) { OsinfoDb *db = osinfo_db_new(); OsinfoPlatform *hv1 = osinfo_platform_new("hv1"); @@ -77,24 +76,24 @@ START_TEST(test_platform) osinfo_db_add_platform(db, hv3); OsinfoPlatformList *list = osinfo_db_get_platform_list(db); - fail_unless(OSINFO_ENTITY(hv1) == osinfo_list_get_nth(OSINFO_LIST(list), 0), "Hv 1 is missing"); - fail_unless(OSINFO_ENTITY(hv2) == osinfo_list_get_nth(OSINFO_LIST(list), 1), "Hv 2 is missing"); - fail_unless(OSINFO_ENTITY(hv3) == osinfo_list_get_nth(OSINFO_LIST(list), 2), "Hv 3 is missing"); + g_assert_true(OSINFO_ENTITY(hv1) == osinfo_list_get_nth(OSINFO_LIST(list), 0)); + g_assert_true(OSINFO_ENTITY(hv2) == osinfo_list_get_nth(OSINFO_LIST(list), 1)); + g_assert_true(OSINFO_ENTITY(hv3) == osinfo_list_get_nth(OSINFO_LIST(list), 2)); g_object_unref(list); OsinfoPlatform *hv = osinfo_db_get_platform(db, "hv2"); - fail_unless(hv != NULL, "Platform is NULL"); - fail_unless(hv == hv2, "Platform was not hv2"); + g_assert_nonnull(hv); + g_assert_true(hv == hv2); g_object_unref(hv1); g_object_unref(hv2); g_object_unref(hv3); g_object_unref(db); } -END_TEST -START_TEST(test_os) +static void +test_os(void) { OsinfoDb *db = osinfo_db_new(); OsinfoOs *os1 = osinfo_os_new("os1"); @@ -106,25 +105,25 @@ START_TEST(test_os) osinfo_db_add_os(db, os3); OsinfoOsList *list = osinfo_db_get_os_list(db); - fail_unless(OSINFO_ENTITY(os1) == osinfo_list_get_nth(OSINFO_LIST(list), 0), "Os 1 is missing"); - fail_unless(OSINFO_ENTITY(os2) == osinfo_list_get_nth(OSINFO_LIST(list), 1), "Os 2 is missing"); - fail_unless(OSINFO_ENTITY(os3) == osinfo_list_get_nth(OSINFO_LIST(list), 2), "Os 3 is missing"); + g_assert_true(OSINFO_ENTITY(os1) == osinfo_list_get_nth(OSINFO_LIST(list), 0)); + g_assert_true(OSINFO_ENTITY(os2) == osinfo_list_get_nth(OSINFO_LIST(list), 1)); + g_assert_true(OSINFO_ENTITY(os3) == osinfo_list_get_nth(OSINFO_LIST(list), 2)); g_object_unref(list); OsinfoOs *os = osinfo_db_get_os(db, "os2"); - fail_unless(os != NULL, "Os is NULL"); - fail_unless(os == os2, "Os was not os2"); + g_assert_nonnull(os); + g_assert_true(os == os2); g_object_unref(os1); g_object_unref(os2); g_object_unref(os3); g_object_unref(db); } -END_TEST -START_TEST(test_prop_device) +static void +test_prop_device(void) { OsinfoDb *db = osinfo_db_new(); OsinfoDevice *dev1 = osinfo_device_new("dev1"); @@ -161,11 +160,11 @@ START_TEST(test_prop_device) hasBad = TRUE; tmp = tmp->next; } - fail_unless(hasNetwork, "Missing network"); - fail_unless(hasAudio, "Missing audio"); - fail_unless(hasInput, "Missing input"); - fail_unless(hasDisplay, "Missing display"); - fail_unless(!hasBad, "Unexpected property"); + g_assert_true(hasNetwork); + g_assert_true(hasAudio); + g_assert_true(hasInput); + g_assert_true(hasDisplay); + g_assert_false(hasBad); g_list_free(uniq); @@ -174,10 +173,10 @@ START_TEST(test_prop_device) g_object_unref(dev3); g_object_unref(db); } -END_TEST -START_TEST(test_prop_platform) +static void +test_prop_platform(void) { OsinfoDb *db = osinfo_db_new(); OsinfoPlatform *hv1 = osinfo_platform_new("hv1"); @@ -211,10 +210,10 @@ START_TEST(test_prop_platform) hasBad = TRUE; tmp = tmp->next; } - fail_unless(hasAcme, "Missing acme"); - fail_unless(hasFrog, "Missing frog"); - fail_unless(hasDog, "Missing dog"); - fail_unless(!hasBad, "Unexpected property"); + g_assert_true(hasAcme); + g_assert_true(hasFrog); + g_assert_true(hasDog); + g_assert_false(hasBad); g_list_free(uniq); @@ -223,10 +222,10 @@ START_TEST(test_prop_platform) g_object_unref(hv3); g_object_unref(db); } -END_TEST -START_TEST(test_prop_os) +static void +test_prop_os(void) { OsinfoDb *db = osinfo_db_new(); OsinfoOs *os1 = osinfo_os_new("os1"); @@ -260,10 +259,10 @@ START_TEST(test_prop_os) hasBad = TRUE; tmp = tmp->next; } - fail_unless(hasAcme, "Missing acme"); - fail_unless(hasFrog, "Missing frog"); - fail_unless(hasDog, "Missing dog"); - fail_unless(!hasBad, "Unexpected property"); + g_assert_true(hasAcme); + g_assert_true(hasFrog); + g_assert_true(hasDog); + g_assert_false(hasBad); g_list_free(uniq); @@ -272,11 +271,11 @@ START_TEST(test_prop_os) g_object_unref(os3); g_object_unref(db); } -END_TEST -START_TEST(test_rel_os) +static void +test_rel_os(void) { OsinfoDb *db = osinfo_db_new(); OsinfoOs *os1 = osinfo_os_new("os1"); @@ -321,12 +320,12 @@ START_TEST(test_rel_os) hasBad = TRUE; } - fail_unless(!hasOs1, "Unexpected OS 1"); - fail_unless(hasOs2, "Missing OS 2"); - fail_unless(hasOs3, "Missing OS 3"); - fail_unless(!hasOs4, "Unexpected OS 4"); - fail_unless(!hasOs5, "Unexpected OS 5"); - fail_unless(!hasBad, "Unexpected property"); + g_assert_false(hasOs1); + g_assert_true(hasOs2); + g_assert_true(hasOs3); + g_assert_false(hasOs4); + g_assert_false(hasOs5); + g_assert_false(hasBad); g_object_unref(sublist); @@ -349,12 +348,12 @@ START_TEST(test_rel_os) hasBad = TRUE; } - fail_unless(!hasOs1, "Unexpected OS 1"); - fail_unless(!hasOs2, "Unexpected OS 2"); - fail_unless(!hasOs3, "Unexpected OS 3"); - fail_unless(!hasOs4, "Unexpected OS 4"); - fail_unless(hasOs5, "Missing OS 5"); - fail_unless(!hasBad, "Unexpected property"); + g_assert_false(hasOs1); + g_assert_false(hasOs2); + g_assert_false(hasOs3); + g_assert_false(hasOs4); + g_assert_true(hasOs5); + g_assert_false(hasBad); g_object_unref(sublist); @@ -377,12 +376,12 @@ START_TEST(test_rel_os) hasBad = TRUE; } - fail_unless(!hasOs1, "Unexpected OS 1"); - fail_unless(!hasOs2, "Unexpected OS 2"); - fail_unless(!hasOs3, "Unexpected OS 3"); - fail_unless(hasOs4, "Missing OS 4"); - fail_unless(!hasOs5, "Unexpected OS 5"); - fail_unless(!hasBad, "Unexpected property"); + g_assert_false(hasOs1); + g_assert_false(hasOs2); + g_assert_false(hasOs3); + g_assert_true(hasOs4); + g_assert_false(hasOs5); + g_assert_false(hasBad); g_object_unref(sublist); @@ -394,33 +393,23 @@ START_TEST(test_rel_os) g_object_unref(os5); g_object_unref(db); } -END_TEST -static Suite * -list_suite(void) +int +main(int argc, char *argv[]) { - Suite *s = suite_create("List"); - TCase *tc = tcase_create("Core"); - tcase_add_test(tc, test_basic); - tcase_add_test(tc, test_device); - tcase_add_test(tc, test_platform); - tcase_add_test(tc, test_os); - tcase_add_test(tc, test_prop_device); - tcase_add_test(tc, test_prop_platform); - tcase_add_test(tc, test_prop_os); - tcase_add_test(tc, test_rel_os); - suite_add_tcase(s, tc); - return s; -} + g_test_init(&argc, &argv, NULL); -int main(void) -{ - int number_failed; - Suite *s = list_suite(); - SRunner *sr = srunner_create(s); + g_test_add_func("/db/basic", test_basic); + g_test_add_func("/db/device", test_device); + g_test_add_func("/db/platform", test_platform); + g_test_add_func("/db/os", test_os); + g_test_add_func("/db/prop_device", test_prop_device); + g_test_add_func("/db/prop_platform", test_prop_platform); + g_test_add_func("/db/prop_os", test_prop_os); + g_test_add_func("/db/rel_os", test_rel_os); /* Make sure we catch unexpected g_warning() */ g_log_set_always_fatal(G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING); @@ -437,11 +426,7 @@ int main(void) osinfo_oslist_get_type(); osinfo_filter_get_type(); - srunner_run_all(sr, CK_ENV); - number_failed = srunner_ntests_failed(sr); - srunner_free(sr); - - return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; + return g_test_run(); } /* * Local variables: diff --git a/tests/test-device.c b/tests/test-device.c index c7b2a82..f14eeba 100644 --- a/tests/test-device.c +++ b/tests/test-device.c @@ -21,39 +21,28 @@ #include <config.h> -#include <stdlib.h> #include <osinfo/osinfo.h> -#include <check.h> -START_TEST(test_basic) +static void +test_basic(void) { OsinfoDevice *device = osinfo_device_new("e1000"); - fail_unless(OSINFO_IS_DEVICE(device), "Device is a device object"); - fail_unless(g_strcmp0(osinfo_entity_get_id(OSINFO_ENTITY(device)), "e1000") == 0, "Device ID was e1000"); + g_assert_true(OSINFO_IS_DEVICE(device)); + g_assert_cmpstr(osinfo_entity_get_id(OSINFO_ENTITY(device)), ==, "e1000"); g_object_unref(device); } -END_TEST -static Suite * -device_suite(void) +int +main(int argc, char *argv[]) { - Suite *s = suite_create("Device"); - TCase *tc = tcase_create("Core"); - tcase_add_test(tc, test_basic); - suite_add_tcase(s, tc); - return s; -} + g_test_init(&argc, &argv, NULL); -int main(void) -{ - int number_failed; - Suite *s = device_suite(); - SRunner *sr = srunner_create(s); + g_test_add_func("/device/basic", test_basic); /* Make sure we catch unexpected g_warning() */ g_log_set_always_fatal(G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING); @@ -61,11 +50,7 @@ int main(void) /* Upfront so we don't confuse valgrind */ osinfo_device_get_type(); - srunner_run_all(sr, CK_ENV); - number_failed = srunner_ntests_failed(sr); - srunner_free(sr); - - return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; + return g_test_run(); } /* * Local variables: diff --git a/tests/test-devicelist.c b/tests/test-devicelist.c index b83d6ca..cd69793 100644 --- a/tests/test-devicelist.c +++ b/tests/test-devicelist.c @@ -21,12 +21,11 @@ #include <config.h> -#include <stdlib.h> #include <osinfo/osinfo.h> -#include <check.h> -START_TEST(test_union) +static void +test_union(void) { OsinfoDeviceList *list1 = osinfo_devicelist_new(); OsinfoDeviceList *list2 = osinfo_devicelist_new(); @@ -45,7 +44,7 @@ START_TEST(test_union) list3 = OSINFO_DEVICELIST(osinfo_list_new_union(OSINFO_LIST(list1), OSINFO_LIST(list2))); - fail_unless(osinfo_list_get_length(OSINFO_LIST(list3)) == 4, "List did not have 4 elements"); + g_assert_cmpint(osinfo_list_get_length(OSINFO_LIST(list3)), ==, 4); gboolean has1 = FALSE; gboolean has2 = FALSE; @@ -66,11 +65,11 @@ START_TEST(test_union) else hasBad = TRUE; } - fail_unless(has1, "List was missing entity 1"); - fail_unless(has2, "List was missing entity 2"); - fail_unless(has3, "List was missing entity 3"); - fail_unless(has4, "List was missing entity 4"); - fail_unless(!hasBad, "List had unexpected entity"); + g_assert_true(has1); + g_assert_true(has2); + g_assert_true(has3); + g_assert_true(has4); + g_assert_false(hasBad); g_object_unref(ent1); g_object_unref(ent2); @@ -80,10 +79,10 @@ START_TEST(test_union) g_object_unref(list2); g_object_unref(list3); } -END_TEST -START_TEST(test_intersect) +static void +test_intersect(void) { OsinfoDeviceList *list1 = osinfo_devicelist_new(); OsinfoDeviceList *list2 = osinfo_devicelist_new(); @@ -104,7 +103,7 @@ START_TEST(test_intersect) list3 = OSINFO_DEVICELIST(osinfo_list_new_intersection(OSINFO_LIST(list1), OSINFO_LIST(list2))); - fail_unless(osinfo_list_get_length(OSINFO_LIST(list3)) == 2, "List did not have 2 elements"); + g_assert_cmpint(osinfo_list_get_length(OSINFO_LIST(list3)), ==, 2); gboolean has1 = FALSE; gboolean has2 = FALSE; @@ -125,11 +124,11 @@ START_TEST(test_intersect) else hasBad = TRUE; } - fail_unless(has1, "List was missing entity 1"); - fail_unless(!has2, "List had unexpected entity 2"); - fail_unless(has3, "List was missing entity 3"); - fail_unless(!has4, "List had unexpected entity 4"); - fail_unless(!hasBad, "List had unexpected entity"); + g_assert_true(has1); + g_assert_false(has2); + g_assert_true(has3); + g_assert_false(has4); + g_assert_false(hasBad); g_object_unref(ent1); g_object_unref(ent2); @@ -139,10 +138,10 @@ START_TEST(test_intersect) g_object_unref(list2); g_object_unref(list3); } -END_TEST -START_TEST(test_filter) +static void +test_filter(void) { OsinfoDeviceList *list1 = osinfo_devicelist_new(); OsinfoDeviceList *list2; @@ -168,7 +167,7 @@ START_TEST(test_filter) list2 = OSINFO_DEVICELIST(osinfo_list_new_filtered(OSINFO_LIST(list1), filter)); - fail_unless(osinfo_list_get_length(OSINFO_LIST(list2)) == 3, "List did not have 3 elements"); + g_assert_cmpint(osinfo_list_get_length(OSINFO_LIST(list2)), ==, 3); gboolean has1 = FALSE; gboolean has2 = FALSE; @@ -189,11 +188,11 @@ START_TEST(test_filter) else hasBad = TRUE; } - fail_unless(has1, "List was missing entity 1"); - fail_unless(has2, "List was missing entity 2"); - fail_unless(has3, "List was missing entity 3"); - fail_unless(!has4, "List had unexpected entity 4"); - fail_unless(!hasBad, "List had unexpected entity"); + g_assert_true(has1); + g_assert_true(has2); + g_assert_true(has3); + g_assert_false(has4); + g_assert_false(hasBad); g_object_unref(ent1); g_object_unref(ent2); @@ -203,26 +202,16 @@ START_TEST(test_filter) g_object_unref(list1); g_object_unref(list2); } -END_TEST -static Suite * -list_suite(void) +int +main(int argc, char *argv[]) { - Suite *s = suite_create("List"); - TCase *tc = tcase_create("Core"); - tcase_add_test(tc, test_union); - tcase_add_test(tc, test_intersect); - tcase_add_test(tc, test_filter); - suite_add_tcase(s, tc); - return s; -} + g_test_init(&argc, &argv, NULL); -int main(void) -{ - int number_failed; - Suite *s = list_suite(); - SRunner *sr = srunner_create(s); + g_test_add_func("/devicelist/union", test_union); + g_test_add_func("/devicelist/intersect", test_intersect); + g_test_add_func("/devicelist/filter", test_filter); /* Make sure we catch unexpected g_warning() */ g_log_set_always_fatal(G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING); @@ -232,11 +221,7 @@ int main(void) osinfo_devicelist_get_type(); osinfo_filter_get_type(); - srunner_run_all(sr, CK_ENV); - number_failed = srunner_ntests_failed(sr); - srunner_free(sr); - - return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; + return g_test_run(); } /* * Local variables: diff --git a/tests/test-entity.c b/tests/test-entity.c index 15da5ff..5f7233b 100644 --- a/tests/test-entity.c +++ b/tests/test-entity.c @@ -21,9 +21,7 @@ #include <config.h> -#include <stdlib.h> #include <osinfo/osinfo.h> -#include <check.h> /* OsinfoEntity is abstract, so we need to trivially subclass it to test it */ typedef struct _OsinfoDummy OsinfoDummy; @@ -47,70 +45,69 @@ static void osinfo_dummy_class_init(OsinfoDummyClass *klass G_GNUC_UNUSED){} static void osinfo_dummy_init(OsinfoDummy *self G_GNUC_UNUSED) {} -START_TEST(test_id) +static void +test_id(void) { OsinfoEntity *ent = g_object_new(osinfo_dummy_get_type(), "id", "myentity", NULL); gchar *id; - fail_unless(g_strcmp0(osinfo_entity_get_id(ent), "myentity") == 0, - "Entity id was not 'myentity'"); + g_assert_cmpstr(osinfo_entity_get_id(ent), ==, "myentity"); g_object_get(ent, "id", &id, NULL); - fail_unless(g_strcmp0(id, "myentity") == 0, - "Entity id was not 'myentity'"); + g_assert_cmpstr(id, ==, "myentity"); g_free(id); g_object_unref(ent); } -END_TEST -START_TEST(test_empty_props) +static void +test_empty_props(void) { OsinfoEntity *ent = g_object_new(osinfo_dummy_get_type(), "id", "myentity", NULL); GList *keys = osinfo_entity_get_param_keys(ent); - fail_unless(keys != NULL, "Entity param key list was not empty"); - fail_unless(keys->next == NULL, "Entity param key list was not empty"); + g_assert_nonnull(keys); + g_assert_null(keys->next); g_list_free(keys); const gchar *value = osinfo_entity_get_param_value(ent, "wibble"); - fail_unless(value == NULL, "Entity param value was not NULL"); + g_assert_null(value); GList *values = osinfo_entity_get_param_value_list(ent, "wibble"); - fail_unless(values == NULL, "Entity param value list was not NULL"); + g_assert_null(values); g_object_unref(ent); } -END_TEST -START_TEST(test_single_prop_value) +static void +test_single_prop_value(void) { OsinfoEntity *ent = g_object_new(osinfo_dummy_get_type(), "id", "myentity", NULL); osinfo_entity_add_param(ent, "hello", "world"); GList *keys = osinfo_entity_get_param_keys(ent); - fail_unless(keys != NULL, "Entity param key list was empty"); - fail_unless(keys->next->next == NULL, "Entity param key list has too many values"); - fail_unless(g_strcmp0(keys->data, "hello") == 0, "Entity param key was not 'hello'"); + g_assert_nonnull(keys); + g_assert_null(keys->next->next); + g_assert_cmpstr(keys->data, ==, "hello"); g_list_free(keys); const gchar *value = osinfo_entity_get_param_value(ent, "hello"); - fail_unless(g_strcmp0(value, "world") == 0, "Entity param value was not 'world'"); + g_assert_cmpstr(value, ==, "world"); value = osinfo_entity_get_param_value(ent, "world"); - fail_unless(value == NULL, "Entity param bogus value was not NULL"); + g_assert_null(value); GList *values = osinfo_entity_get_param_value_list(ent, "hello"); - fail_unless(values != NULL, "Entity param value list was empty"); - fail_unless(values->next == NULL, "Entity param value list has too many values"); - fail_unless(g_strcmp0(values->data, "world") == 0, "Entity param list value was not 'world'"); + g_assert_nonnull(values); + g_assert_null(values->next); + g_assert_cmpstr(values->data, ==, "world"); g_list_free(values); g_object_unref(ent); } -END_TEST -START_TEST(test_multi_prop_value) +static void +test_multi_prop_value(void) { OsinfoEntity *ent = g_object_new(osinfo_dummy_get_type(), "id", "myentity", NULL); @@ -119,31 +116,31 @@ START_TEST(test_multi_prop_value) osinfo_entity_add_param(ent, "hello", "elephant"); GList *keys = osinfo_entity_get_param_keys(ent); - fail_unless(keys != NULL, "Entity param key list was empty"); - fail_unless(keys->next->next == NULL, "Entity param key list has too many values"); - fail_unless(g_strcmp0(keys->data, "hello") == 0, "Entity param key was not 'hello'"); + g_assert_nonnull(keys); + g_assert_null(keys->next->next); + g_assert_cmpstr(keys->data, ==, "hello"); g_list_free(keys); const gchar *value = osinfo_entity_get_param_value(ent, "hello"); - fail_unless(g_strcmp0(value, "world") == 0, "Entity param value was not 'world'"); + g_assert_cmpstr(value, ==, "world"); value = osinfo_entity_get_param_value(ent, "world"); - fail_unless(value == NULL, "Entity param bogus value was not NULL"); + g_assert_null(value); GList *values = osinfo_entity_get_param_value_list(ent, "hello"); - fail_unless(values != NULL, "Entity param value list was empty"); - fail_unless(values->next != NULL, "Entity param value list doesn't have enough values"); - fail_unless(values->next->next != NULL, "Entity param value list doesn't have enough values"); - fail_unless(values->next->next->next == NULL, "Entity param value list has too many values"); - fail_unless(g_strcmp0(values->data, "world") == 0, "Entity param list first value was not 'world'"); - fail_unless(g_strcmp0(values->next->data, "fred") == 0, "Entity param list second value was not 'fred'"); - fail_unless(g_strcmp0(values->next->next->data, "elephant") == 0, "Entity param list third was not 'elephant'"); + g_assert_nonnull(values); + g_assert_nonnull(values->next); + g_assert_nonnull(values->next->next); + g_assert_null(values->next->next->next); + g_assert_cmpstr(values->data, ==, "world"); + g_assert_cmpstr(values->next->data, ==, "fred"); + g_assert_cmpstr(values->next->next->data, ==, "elephant"); g_list_free(values); g_object_unref(ent); } -END_TEST -START_TEST(test_multi_props) +static void +test_multi_props(void) { OsinfoEntity *ent = g_object_new(osinfo_dummy_get_type(), "id", "myentity", NULL); @@ -168,43 +165,43 @@ START_TEST(test_multi_props) foundBad = TRUE; tmp = tmp->next; } - fail_unless(foundHello, "Entity param key list was missing 'hello'"); - fail_unless(foundFish, "Entity param key list was missing 'fish'"); - fail_unless(foundKevin, "Entity param key list was missing 'kevin'"); - fail_unless(!foundBad, "Entity param key list has unexpected key"); + g_assert_true(foundHello); + g_assert_true(foundFish); + g_assert_true(foundKevin); + g_assert_false(foundBad); g_list_free(keys); const gchar *value = osinfo_entity_get_param_value(ent, "hello"); - fail_unless(g_strcmp0(value, "world") == 0, "Entity param value was not 'world'"); + g_assert_cmpstr(value, ==, "world"); value = osinfo_entity_get_param_value(ent, "fish"); - fail_unless(g_strcmp0(value, "food") == 0, "Entity param value was not 'food'"); + g_assert_cmpstr(value, ==, "food"); value = osinfo_entity_get_param_value(ent, "kevin"); - fail_unless(g_strcmp0(value, "bacon") == 0, "Entity param value was not 'bacon'"); + g_assert_cmpstr(value, ==, "bacon"); GList *values = osinfo_entity_get_param_value_list(ent, "hello"); - fail_unless(values != NULL, "Entity param value list was empty"); - fail_unless(values->next == NULL, "Entity param value list has too many values"); - fail_unless(g_strcmp0(values->data, "world") == 0, "Entity param list value was not 'world'"); + g_assert_nonnull(values); + g_assert_null(values->next); + g_assert_cmpstr(values->data, ==, "world"); g_list_free(values); values = osinfo_entity_get_param_value_list(ent, "fish"); - fail_unless(values != NULL, "Entity param value list was empty"); - fail_unless(values->next == NULL, "Entity param value list has too many values"); - fail_unless(g_strcmp0(values->data, "food") == 0, "Entity param list value was not 'food'"); + g_assert_nonnull(values); + g_assert_null(values->next); + g_assert_cmpstr(values->data, ==, "food"); g_list_free(values); values = osinfo_entity_get_param_value_list(ent, "kevin"); - fail_unless(values != NULL, "Entity param value list was empty"); - fail_unless(values->next == NULL, "Entity param value list has too many values"); - fail_unless(g_strcmp0(values->data, "bacon") == 0, "Entity param list value was not 'bacon'"); + g_assert_nonnull(values); + g_assert_null(values->next); + g_assert_cmpstr(values->data, ==, "bacon"); g_list_free(values); g_object_unref(ent); } -END_TEST -START_TEST(test_multi_props_clear) +static void +test_multi_props_clear(void) { OsinfoEntity *ent = g_object_new(osinfo_dummy_get_type(), "id", "myentity", NULL); @@ -225,15 +222,15 @@ START_TEST(test_multi_props_clear) foundBad = TRUE; tmp = tmp->next; } - fail_unless(foundHello, "Entity param key list was missing 'hello'"); - fail_unless(foundFish, "Entity param key list was missing 'fish'"); - fail_unless(!foundBad, "Entity param key list has unexpected key"); + g_assert_true(foundHello); + g_assert_true(foundFish); + g_assert_false(foundBad); g_list_free(keys); const gchar *value = osinfo_entity_get_param_value(ent, "hello"); - fail_unless(g_strcmp0(value, "world") == 0, "Entity param value was not 'world'"); + g_assert_cmpstr(value, ==, "world"); value = osinfo_entity_get_param_value(ent, "fish"); - fail_unless(g_strcmp0(value, "food") == 0, "Entity param value was not 'food'"); + g_assert_cmpstr(value, ==, "food"); osinfo_entity_clear_param(ent, "hello"); @@ -251,15 +248,15 @@ START_TEST(test_multi_props_clear) foundBad = TRUE; tmp = tmp->next; } - fail_unless(!foundHello, "Entity param key list has unexpected 'hello'"); - fail_unless(foundFish, "Entity param key list was missing 'fish'"); - fail_unless(!foundBad, "Entity param key list has unexpected key"); + g_assert_false(foundHello); + g_assert_true(foundFish); + g_assert_false(foundBad); g_list_free(keys); value = osinfo_entity_get_param_value(ent, "hello"); - fail_unless(g_strcmp0(value, NULL) == 0, "Entity param value was not removed"); + g_assert_null(value); value = osinfo_entity_get_param_value(ent, "fish"); - fail_unless(g_strcmp0(value, "food") == 0, "Entity param value was not 'food'"); + g_assert_cmpstr(value, ==, "food"); osinfo_entity_add_param(ent, "hello", "world"); osinfo_entity_clear_param(ent, "fish"); @@ -278,63 +275,53 @@ START_TEST(test_multi_props_clear) foundBad = TRUE; tmp = tmp->next; } - fail_unless(foundHello, "Entity param key list has unexpected 'hello'"); - fail_unless(!foundFish, "Entity param key list was missing 'fish'"); - fail_unless(!foundBad, "Entity param key list has unexpected key"); + g_assert_true(foundHello); + g_assert_false(foundFish); + g_assert_false(foundBad); g_list_free(keys); value = osinfo_entity_get_param_value(ent, "hello"); - fail_unless(g_strcmp0(value, "world") == 0, "Entity param value was not readded"); + g_assert_cmpstr(value, ==, "world"); value = osinfo_entity_get_param_value(ent, "fish"); - fail_unless(g_strcmp0(value, NULL) == 0, "Entity param value was not removed"); + g_assert_null(value); g_object_unref(ent); } -END_TEST -START_TEST(test_int64_props) +static void +test_int64_props(void) { OsinfoEntity *ent = g_object_new(osinfo_dummy_get_type(), "id", "myentity", NULL); osinfo_entity_set_param_int64(ent, "my_int", 10); - fail_unless(osinfo_entity_get_param_value_int64(ent, "my_int") == 10); + g_assert_true(osinfo_entity_get_param_value_int64(ent, "my_int") == 10); osinfo_entity_set_param_int64(ent, "my_neg_int", -20); - fail_unless(osinfo_entity_get_param_value_int64(ent, "my_neg_int") == -20); + g_assert_true(osinfo_entity_get_param_value_int64(ent, "my_neg_int") == -20); osinfo_entity_set_param_int64(ent, "my_str", 30); - fail_unless(osinfo_entity_get_param_value_int64(ent, "my_str") == 30); + g_assert_true(osinfo_entity_get_param_value_int64(ent, "my_str") == 30); osinfo_entity_set_param_int64(ent, "my_neg_str", -40); - fail_unless(osinfo_entity_get_param_value_int64(ent, "my_neg_str") == -40); - fail_unless(osinfo_entity_get_param_value_int64_with_default(ent, "my_neg_str", 1234) == -40); + g_assert_true(osinfo_entity_get_param_value_int64(ent, "my_neg_str") == -40); + g_assert_true(osinfo_entity_get_param_value_int64_with_default(ent, "my_neg_str", 1234) == -40); - fail_unless(osinfo_entity_get_param_value_int64(ent, "missing") == -1); - fail_unless(osinfo_entity_get_param_value_int64_with_default(ent, "missing", 1234) == 1234); + g_assert_true(osinfo_entity_get_param_value_int64(ent, "missing") == -1); + g_assert_true(osinfo_entity_get_param_value_int64_with_default(ent, "missing", 1234) == 1234); g_object_unref(ent); } -END_TEST -static Suite * -entity_suite(void) +int +main(int argc, char *argv[]) { - Suite *s = suite_create("Entity"); - TCase *tc = tcase_create("Core"); - tcase_add_test(tc, test_id); - tcase_add_test(tc, test_empty_props); - tcase_add_test(tc, test_single_prop_value); - tcase_add_test(tc, test_multi_prop_value); - tcase_add_test(tc, test_multi_props); - tcase_add_test(tc, test_multi_props_clear); - tcase_add_test(tc, test_int64_props); - suite_add_tcase(s, tc); - return s; -} + g_test_init(&argc, &argv, NULL); -int main(void) -{ - int number_failed; - Suite *s = entity_suite(); - SRunner *sr = srunner_create(s); + g_test_add_func("/entity/id", test_id); + g_test_add_func("/entity/empty_props", test_empty_props); + g_test_add_func("/entity/single_prop_value", test_single_prop_value); + g_test_add_func("/entity/multi_prop_value", test_multi_prop_value); + g_test_add_func("/entity/multi_props", test_multi_props); + g_test_add_func("/entity/multi_props_clear", test_multi_props_clear); + g_test_add_func("/entity/int64_props", test_int64_props); /* Make sure we catch unexpected g_warning() */ g_log_set_always_fatal(G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING); @@ -342,11 +329,7 @@ int main(void) /* Upfront so we don't confuse valgrind */ osinfo_dummy_get_type(); - srunner_run_all(sr, CK_ENV); - number_failed = srunner_ntests_failed(sr); - srunner_free(sr); - - return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; + return g_test_run(); } /* * Local variables: diff --git a/tests/test-filter.c b/tests/test-filter.c index 7813325..3fbeb3e 100644 --- a/tests/test-filter.c +++ b/tests/test-filter.c @@ -21,63 +21,62 @@ #include <config.h> -#include <stdlib.h> #include <osinfo/osinfo.h> -#include <check.h> -START_TEST(test_basic) +static void +test_basic(void) { OsinfoFilter *filter = osinfo_filter_new(); OsinfoDevice *dev = osinfo_device_new("e1000"); - fail_unless(OSINFO_IS_FILTER(filter), "Filter is a filter object"); - fail_unless(osinfo_filter_matches(filter, OSINFO_ENTITY(dev)), "Filter matches device"); + g_assert_true(OSINFO_IS_FILTER(filter)); + g_assert_true(osinfo_filter_matches(filter, OSINFO_ENTITY(dev))); osinfo_filter_add_constraint(filter, "class", "network"); GList *keys = osinfo_filter_get_constraint_keys(filter); - fail_unless(keys != NULL, "missing key"); - fail_unless(g_strcmp0(keys->data, "class") == 0, "missing key"); - fail_unless(keys->next == NULL, "too many keys"); + g_assert_nonnull(keys); + g_assert_cmpstr(keys->data, ==, "class"); + g_assert_null(keys->next); g_list_free(keys); osinfo_filter_add_constraint(filter, "class", "audio"); keys = osinfo_filter_get_constraint_keys(filter); - fail_unless(keys != NULL, "missing key"); - fail_unless(g_strcmp0(keys->data, "class") == 0, "missing key"); - fail_unless(keys->next == NULL, "too many keys"); + g_assert_nonnull(keys); + g_assert_cmpstr(keys->data, ==, "class"); + g_assert_null(keys->next); g_list_free(keys); osinfo_filter_add_constraint(filter, "bus", "pci"); keys = osinfo_filter_get_constraint_keys(filter); - fail_unless(keys != NULL, "missing key"); - fail_unless(keys->next != NULL, "not enough keys"); - fail_unless(g_strcmp0(keys->data, "bus") == 0, "missing bus key"); - fail_unless(g_strcmp0(keys->next->data, "class") == 0, "missing class key"); - fail_unless(keys->next->next == NULL, "too many keys"); + g_assert_nonnull(keys); + g_assert_nonnull(keys->next); + g_assert_cmpstr(keys->data, ==, "bus"); + g_assert_cmpstr(keys->next->data, ==, "class"); + g_assert_null(keys->next->next); g_list_free(keys); GList *values = osinfo_filter_get_constraint_values(filter, "bus"); - fail_unless(values != NULL, "missing value"); - fail_unless(g_strcmp0(values->data, "pci") == 0, "missing value"); - fail_unless(values->next == NULL, "too many keys"); + g_assert_nonnull(values); + g_assert_cmpstr(values->data, ==, "pci"); + g_assert_null(values->next); g_list_free(values); values = osinfo_filter_get_constraint_values(filter, "class"); - fail_unless(values != NULL, "missing value"); - fail_unless(values->next != NULL, "not enough values"); - fail_unless(g_strcmp0(values->data, "audio") == 0, "missing value"); - fail_unless(g_strcmp0(values->next->data, "network") == 0, "missing value"); - fail_unless(values->next->next == NULL, "too many values"); + g_assert_nonnull(values); + g_assert_nonnull(values->next); + g_assert_cmpstr(values->data, ==, "audio"); + g_assert_cmpstr(values->next->data, ==, "network"); + g_assert_null(values->next->next); g_list_free(values); g_object_unref(dev); g_object_unref(filter); } -END_TEST -START_TEST(test_filter_single) +static void +test_filter_single(void) { OsinfoFilter *filter = osinfo_filter_new(); OsinfoDevice *dev = osinfo_device_new("e1000"); @@ -85,21 +84,21 @@ START_TEST(test_filter_single) osinfo_entity_add_param(OSINFO_ENTITY(dev), "bus", "pci"); osinfo_filter_add_constraint(filter, "class", "network"); - fail_unless(!osinfo_filter_matches(filter, OSINFO_ENTITY(dev)), "Filter does not match device"); + g_assert_false(osinfo_filter_matches(filter, OSINFO_ENTITY(dev))); osinfo_entity_add_param(OSINFO_ENTITY(dev), "class", "network"); - fail_unless(osinfo_filter_matches(filter, OSINFO_ENTITY(dev)), "Filter matches device"); + g_assert_true(osinfo_filter_matches(filter, OSINFO_ENTITY(dev))); osinfo_filter_clear_constraint(filter, "class"); osinfo_filter_add_constraint(filter, "class", "audio"); - fail_unless(!osinfo_filter_matches(filter, OSINFO_ENTITY(dev)), "Filter does not match device"); + g_assert_false(osinfo_filter_matches(filter, OSINFO_ENTITY(dev))); g_object_unref(dev); g_object_unref(filter); } -END_TEST -START_TEST(test_filter_multi) +static void +test_filter_multi(void) { OsinfoFilter *filter = osinfo_filter_new(); OsinfoDevice *dev = osinfo_device_new("e1000"); @@ -107,26 +106,26 @@ START_TEST(test_filter_multi) osinfo_entity_add_param(OSINFO_ENTITY(dev), "bus", "pci"); osinfo_filter_add_constraint(filter, "bus", "isa"); - fail_unless(!osinfo_filter_matches(filter, OSINFO_ENTITY(dev)), "Filter does not match device"); + g_assert_false(osinfo_filter_matches(filter, OSINFO_ENTITY(dev))); osinfo_filter_add_constraint(filter, "bus", "pci"); /* XXX is this right ? Multiple values for a filter constraint * is treated as requiring all constraint values to match, not * required any to match */ - //fail_unless(osinfo_filter_matches(filter, OSINFO_ENTITY(dev)), "Filter matches device"); - fail_unless(!osinfo_filter_matches(filter, OSINFO_ENTITY(dev)), "Filter does not match device"); + //g_assert_true(osinfo_filter_matches(filter, OSINFO_ENTITY(dev))); + g_assert_false(osinfo_filter_matches(filter, OSINFO_ENTITY(dev))); osinfo_filter_clear_constraints(filter); osinfo_filter_add_constraint(filter, "bus", "pci"); - fail_unless(osinfo_filter_matches(filter, OSINFO_ENTITY(dev)), "Filter matches device"); + g_assert_true(osinfo_filter_matches(filter, OSINFO_ENTITY(dev))); g_object_unref(dev); g_object_unref(filter); } -END_TEST -START_TEST(test_filter_combine) +static void +test_filter_combine(void) { OsinfoFilter *filter = osinfo_filter_new(); OsinfoDevice *dev1 = osinfo_device_new("e1000"); @@ -139,38 +138,28 @@ START_TEST(test_filter_combine) osinfo_entity_add_param(OSINFO_ENTITY(dev2), "class", "network"); osinfo_filter_add_constraint(filter, "class", "network"); - fail_unless(osinfo_filter_matches(filter, OSINFO_ENTITY(dev1)), "Filter does not match device"); - fail_unless(osinfo_filter_matches(filter, OSINFO_ENTITY(dev2)), "Filter does not match device"); + g_assert_true(osinfo_filter_matches(filter, OSINFO_ENTITY(dev1))); + g_assert_true(osinfo_filter_matches(filter, OSINFO_ENTITY(dev2))); osinfo_filter_add_constraint(filter, "bus", "isa"); - fail_unless(!osinfo_filter_matches(filter, OSINFO_ENTITY(dev1)), "Filter match device"); - fail_unless(osinfo_filter_matches(filter, OSINFO_ENTITY(dev2)), "Filter does not match device"); + g_assert_false(osinfo_filter_matches(filter, OSINFO_ENTITY(dev1))); + g_assert_true(osinfo_filter_matches(filter, OSINFO_ENTITY(dev2))); g_object_unref(dev1); g_object_unref(dev2); g_object_unref(filter); } -END_TEST -static Suite * -filter_suite(void) +int +main(int argc, char *argv[]) { - Suite *s = suite_create("Filter"); - TCase *tc = tcase_create("Core"); - tcase_add_test(tc, test_basic); - tcase_add_test(tc, test_filter_single); - tcase_add_test(tc, test_filter_multi); - tcase_add_test(tc, test_filter_combine); - suite_add_tcase(s, tc); - return s; -} + g_test_init(&argc, &argv, NULL); -int main(void) -{ - int number_failed; - Suite *s = filter_suite(); - SRunner *sr = srunner_create(s); + g_test_add_func("/filter/basic", test_basic); + g_test_add_func("/filter/filter_single", test_filter_single); + g_test_add_func("/filter/filter_multi", test_filter_multi); + g_test_add_func("/filter/filter_combine", test_filter_combine); /* Make sure we catch unexpected g_warning() */ g_log_set_always_fatal(G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING); @@ -179,11 +168,7 @@ int main(void) osinfo_device_get_type(); osinfo_filter_get_type(); - srunner_run_all(sr, CK_ENV); - number_failed = srunner_ntests_failed(sr); - srunner_free(sr); - - return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; + return g_test_run(); } /* * Local variables: diff --git a/tests/test-install-script.c b/tests/test-install-script.c index 2e72106..129d995 100644 --- a/tests/test-install-script.c +++ b/tests/test-install-script.c @@ -21,10 +21,7 @@ #include <config.h> -#include <config.h> -#include <stdlib.h> #include <osinfo/osinfo.h> -#include <check.h> static GError *error = NULL; static gchar *actualData = NULL; @@ -130,7 +127,8 @@ static OsinfoMedia *create_media(void) return media; } -START_TEST(test_script_file) +static void +test_script_file(void) { OsinfoInstallScript *script; OsinfoInstallConfig *config = test_get_config(); @@ -144,7 +142,7 @@ START_TEST(test_script_file) "file://" SRCDIR "/tests/install-script.xsl"); osinfo_loader_process_path(loader, SRCDIR "/tests/dbdata", &error); - fail_unless(error == NULL, error ? error->message : "none"); + g_assert_no_error(error); db = g_object_ref(osinfo_loader_get_db(loader)); g_object_unref(loader); @@ -152,7 +150,7 @@ START_TEST(test_script_file) TRUE); media = create_media(); - fail_unless(osinfo_db_identify_media(db, media), "Failed to identify media"); + g_assert_true(osinfo_db_identify_media(db, media)); osinfo_install_script_generate_for_media_async(script, media, @@ -165,10 +163,9 @@ START_TEST(test_script_file) g_main_loop_run(loop); unlink(BUILDDIR "/tests/install-script-actual.txt"); - fail_unless(error == NULL, error ? error->message : "none"); + g_assert_no_error(error); - fail_unless(strcmp(actualData, expectData) == 0, "Actual '%s' match expect '%s'", - actualData, expectData); + g_assert_cmpstr(actualData, ==, expectData); g_free(actualData); g_object_unref(media); @@ -177,11 +174,11 @@ START_TEST(test_script_file) g_object_unref(script); g_main_loop_unref(loop); } -END_TEST -START_TEST(test_script_data) +static void +test_script_data(void) { OsinfoInstallScript *script; OsinfoInstallConfig *config = test_get_config(); @@ -193,16 +190,16 @@ START_TEST(test_script_data) gchar *data; g_file_load_contents(file, NULL, &data, NULL, NULL, &error); - fail_unless(error == NULL, error ? error->message : "none"); + g_assert_no_error(error); g_object_unref(file); osinfo_loader_process_path(loader, SRCDIR "/tests/dbdata", &error); - fail_unless(error == NULL, error ? error->message : "none"); + g_assert_no_error(error); db = g_object_ref(osinfo_loader_get_db(loader)); g_object_unref(loader); media = create_media(); - fail_unless(osinfo_db_identify_media(db, media), "Failed to identify media"); + g_assert_true(osinfo_db_identify_media(db, media)); script = osinfo_install_script_new_data("http://example.com", "jeos", @@ -222,7 +219,7 @@ START_TEST(test_script_data) g_main_loop_run(loop); unlink(BUILDDIR "/tests/install-script-actual.txt"); - fail_unless(error == NULL, error ? error->message : "none"); + g_assert_no_error(error); g_free(data); g_free(actualData); @@ -232,9 +229,9 @@ START_TEST(test_script_data) g_object_unref(script); g_main_loop_unref(loop); } -END_TEST -START_TEST(test_script_datamap) +static void +test_script_datamap(void) { OsinfoLoader *loader = osinfo_loader_new(); OsinfoDb *db; @@ -244,40 +241,34 @@ START_TEST(test_script_datamap) GMainLoop *loop; osinfo_loader_process_path(loader, SRCDIR "/tests/dbdata", &error); - fail_unless(error == NULL, error ? error->message : "none"); + g_assert_no_error(error); db = g_object_ref(osinfo_loader_get_db(loader)); g_object_unref(loader); - fail_unless(osinfo_db_get_datamap(db, "http://example.com/libosinfo/test-datamap") != NULL, "Could not find OsinfoDatamap 'test-datamap'"); - fail_unless(osinfo_db_get_datamap(db, "http://example.com/libosinfo/test-datamap2") != NULL, "Could not find OsinfoDatamap 'test-datamap2'"); + g_assert_nonnull(osinfo_db_get_datamap(db, "http://example.com/libosinfo/test-datamap")); + g_assert_nonnull(osinfo_db_get_datamap(db, "http://example.com/libosinfo/test-datamap2")); script = osinfo_db_get_install_script(db, "http://example.com/libosinfo/test-install-script"); - fail_unless(script != NULL, "Could not find OsinfoInstallScript 'test-install-script'"); + g_assert_nonnull(script); config = osinfo_install_config_new("http://example.com"); osinfo_install_config_set_l10n_keyboard(config, "unknown"); - fail_unless(g_strcmp0(osinfo_install_config_get_l10n_keyboard(config), "unknown") == 0, - "Got %s instead of 'unknown'", osinfo_install_config_get_l10n_keyboard(config)); + g_assert_cmpstr(osinfo_install_config_get_l10n_keyboard(config), ==, "unknown"); osinfo_install_config_set_l10n_keyboard(config, "val1"); - fail_unless(g_strcmp0(osinfo_install_config_get_l10n_keyboard(config), "val1") == 0, - "Got %s instead of 'val1'", osinfo_install_config_get_l10n_keyboard(config)); + g_assert_cmpstr(osinfo_install_config_get_l10n_keyboard(config), ==, "val1"); osinfo_install_config_set_l10n_keyboard(config, "val2"); - fail_unless(g_strcmp0(osinfo_install_config_get_l10n_keyboard(config), "val2") == 0, - "Got %s instead of 'val2'", osinfo_install_config_get_l10n_keyboard(config)); + g_assert_cmpstr(osinfo_install_config_get_l10n_keyboard(config), ==, "val2"); osinfo_install_config_set_l10n_keyboard(config, "val3"); - fail_unless(g_strcmp0(osinfo_install_config_get_l10n_keyboard(config), "val3") == 0, - "Got %s instead of 'val3'", osinfo_install_config_get_l10n_keyboard(config)); + g_assert_cmpstr(osinfo_install_config_get_l10n_keyboard(config), ==, "val3"); osinfo_install_config_set_l10n_keyboard(config, "VAL1"); - fail_unless(g_strcmp0(osinfo_install_config_get_l10n_keyboard(config), "VAL1") == 0, - "Got %s instead of 'VAL1", osinfo_install_config_get_l10n_keyboard(config)); + g_assert_cmpstr(osinfo_install_config_get_l10n_keyboard(config), ==, "VAL1"); osinfo_install_config_set_l10n_language(config, "en_EN"); - fail_unless(g_strcmp0(osinfo_install_config_get_l10n_language(config), "en_EN") == 0, - "Got %s instead of 'en_EN'", osinfo_install_config_get_l10n_language(config)); + g_assert_cmpstr(osinfo_install_config_get_l10n_language(config), ==, "en_EN"); osinfo_install_config_set_l10n_language(config, "fr_FR"); osinfo_install_config_set_l10n_timezone(config, "Europe/Paris"); @@ -300,10 +291,9 @@ START_TEST(test_script_datamap) g_main_loop_run(loop); unlink(BUILDDIR "/tests/install-script-actual.txt"); - fail_unless(error == NULL, error ? error->message : "none"); + g_assert_no_error(error); - fail_unless(strcmp(actualData, expectData2) == 0, "Actual '%s' match expect '%s'", - actualData, expectData2); + g_assert_cmpstr(actualData, ==, expectData2); g_free(actualData); g_object_unref(db); @@ -311,28 +301,16 @@ START_TEST(test_script_datamap) g_object_unref(config); g_main_loop_unref(loop); } -END_TEST -static Suite * -list_suite(void) +int +main(int argc, char *argv[]) { - Suite *s = suite_create("List"); - TCase *tc = tcase_create("Core"); - tcase_set_timeout(tc, 120); - - tcase_add_test(tc, test_script_file); - tcase_add_test(tc, test_script_data); - tcase_add_test(tc, test_script_datamap); - suite_add_tcase(s, tc); - return s; -} + g_test_init(&argc, &argv, NULL); -int main(void) -{ - int number_failed; - Suite *s = list_suite(); - SRunner *sr = srunner_create(s); + g_test_add_func("/install-script/script_file", test_script_file); + g_test_add_func("/install-script/script_data", test_script_data); + g_test_add_func("/install-script/script_datamap", test_script_datamap); /* Make sure we catch unexpected g_warning() */ g_log_set_always_fatal(G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING); @@ -349,11 +327,7 @@ int main(void) osinfo_oslist_get_type(); osinfo_filter_get_type(); - srunner_run_all(sr, CK_ENV); - number_failed = srunner_ntests_failed(sr); - srunner_free(sr); - - return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; + return g_test_run(); } /* * Local variables: diff --git a/tests/test-isodetect.c b/tests/test-isodetect.c index 7214531..97c86c4 100644 --- a/tests/test-isodetect.c +++ b/tests/test-isodetect.c @@ -22,8 +22,8 @@ #include <config.h> #include <stdlib.h> +#include <string.h> #include <osinfo/osinfo.h> -#include <check.h> struct ISOInfo { gchar *shortid; @@ -321,15 +321,13 @@ static void test_langs(struct ISOInfo *info) langs = osinfo_media_get_languages(info->media); for (it = langs; it != NULL; it = it->next) { - fail_unless(g_hash_table_contains(info->langs, it->data), - "%s not a known language for ISO %s", - it->data, info->filename); + g_test_message("checking ISO %s, language %s", + info->filename, (const char *)it->data); + g_assert_true(g_hash_table_contains(info->langs, it->data)); g_hash_table_remove(info->langs, it->data); } g_list_free(langs); - fail_unless(g_hash_table_size(info->langs) == 0, - "some languages were not identified on ISO %s", - info->filename); + g_assert_cmpint(g_hash_table_size(info->langs), ==, 0); } static void test_one(const gchar *vendor) @@ -340,15 +338,15 @@ static void test_one(const gchar *vendor) GList *tmp; GError *error = NULL; - fail_unless(OSINFO_IS_LOADER(loader), "Loader is not a LOADER"); - fail_unless(OSINFO_IS_DB(db), "Db is not a DB"); + g_assert_true(OSINFO_IS_LOADER(loader)); + g_assert_true(OSINFO_IS_DB(db)); osinfo_loader_process_default_path(loader, &error); - fail_unless(error == NULL, error ? error->message : "none"); + g_assert_no_error(error); isos = load_isos(vendor, &error); - fail_unless(isos != NULL, "ISOs must not be NULL"); + g_assert_nonnull(isos); tmp = isos; while (tmp) { @@ -356,14 +354,13 @@ static void test_one(const gchar *vendor) gboolean matched = osinfo_db_identify_media(db, info->media); OsinfoOs *os; - fail_unless(matched, "ISO %s was not matched by OS %s", - info->filename, info->shortid); + g_test_message("checking OS %s for ISO %s", + info->shortid, info->filename); + g_assert_true(matched); g_object_get(info->media, "os", &os, NULL); const gchar *shortid = osinfo_product_get_short_id(OSINFO_PRODUCT(os)); - fail_unless(g_str_equal(shortid, info->shortid), - "ISO %s matched OS %s instead of expected %s", - info->filename, shortid, info->shortid); + g_assert_cmpstr(shortid, ==, info->shortid); g_object_unref(G_OBJECT(os)); test_langs(info); @@ -376,120 +373,109 @@ static void test_one(const gchar *vendor) g_object_unref(loader); } -START_TEST(test_fedora) +static void +test_fedora(void) { test_one("fedora"); } -END_TEST -START_TEST(test_rhel) +static void +test_rhel(void) { test_one("rhel"); } -END_TEST -START_TEST(test_ubuntu) +static void +test_ubuntu(void) { test_one("ubuntu"); } -END_TEST -START_TEST(test_debian) +static void +test_debian(void) { test_one("debian"); } -END_TEST -START_TEST(test_windows) +static void +test_windows(void) { test_one("windows"); } -END_TEST -START_TEST(test_freebsd) +static void +test_freebsd(void) { test_one("freebsd"); } -END_TEST -START_TEST(test_openbsd) +static void +test_openbsd(void) { test_one("openbsd"); } -END_TEST -START_TEST(test_opensuse) +static void +test_opensuse(void) { test_one("opensuse"); } -END_TEST -START_TEST(test_centos) +static void +test_centos(void) { test_one("centos"); } -END_TEST -START_TEST(test_gnome) +static void +test_gnome(void) { test_one("gnome"); } -END_TEST -START_TEST(test_altlinux) +static void +test_altlinux(void) { test_one("altlinux"); } -END_TEST -START_TEST(test_mageia) +static void +test_mageia(void) { test_one("mageia"); } -END_TEST -START_TEST(test_sles) +static void +test_sles(void) { test_one("sles"); } -END_TEST -START_TEST(test_sled) +static void +test_sled(void) { test_one("sled"); } -END_TEST -static Suite * -list_suite(void) +int +main(int argc, char *argv[]) { - Suite *s = suite_create("List"); - TCase *tc = tcase_create("Core"); - tcase_set_timeout(tc, 20); - - tcase_add_test(tc, test_fedora); - tcase_add_test(tc, test_rhel); - tcase_add_test(tc, test_ubuntu); - tcase_add_test(tc, test_debian); - tcase_add_test(tc, test_windows); - tcase_add_test(tc, test_freebsd); - tcase_add_test(tc, test_openbsd); - tcase_add_test(tc, test_opensuse); - tcase_add_test(tc, test_centos); - tcase_add_test(tc, test_gnome); - tcase_add_test(tc, test_altlinux); - tcase_add_test(tc, test_mageia); - tcase_add_test(tc, test_sles); - tcase_add_test(tc, test_sled); - suite_add_tcase(s, tc); - return s; -} - -int main(void) -{ - int number_failed; - Suite *s = list_suite(); - SRunner *sr = srunner_create(s); + g_test_init(&argc, &argv, NULL); + + g_test_add_func("/isodetect/fedora", test_fedora); + g_test_add_func("/isodetect/rhel", test_rhel); + g_test_add_func("/isodetect/ubuntu", test_ubuntu); + g_test_add_func("/isodetect/debian", test_debian); + g_test_add_func("/isodetect/windows", test_windows); + g_test_add_func("/isodetect/freebsd", test_freebsd); + g_test_add_func("/isodetect/openbsd", test_openbsd); + g_test_add_func("/isodetect/opensuse", test_opensuse); + g_test_add_func("/isodetect/centos", test_centos); + g_test_add_func("/isodetect/gnome", test_gnome); + g_test_add_func("/isodetect/altlinux", test_altlinux); + g_test_add_func("/isodetect/mageia", test_mageia); + g_test_add_func("/isodetect/sles", test_sles); + g_test_add_func("/isodetect/sled", test_sled); /* Make sure we catch unexpected g_warning() */ g_log_set_always_fatal(G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING); @@ -506,11 +492,7 @@ int main(void) osinfo_oslist_get_type(); osinfo_filter_get_type(); - srunner_run_all(sr, CK_ENV); - number_failed = srunner_ntests_failed(sr); - srunner_free(sr); - - return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; + return g_test_run(); } /* * Local variables: diff --git a/tests/test-list.c b/tests/test-list.c index 5480482..df1c973 100644 --- a/tests/test-list.c +++ b/tests/test-list.c @@ -21,9 +21,7 @@ #include <config.h> -#include <stdlib.h> #include <osinfo/osinfo.h> -#include <check.h> /* OsinfoEntity is abstract, so we need to trivially subclass it to test it */ typedef struct _OsinfoDummy OsinfoDummy; @@ -69,46 +67,47 @@ static void osinfo_dummy_list_init(OsinfoDummyList *self G_GNUC_UNUSED) {} -START_TEST(test_basic) +static void +test_basic(void) { OsinfoList *list = g_object_new(osinfo_dummy_list_get_type(), NULL); - fail_unless(osinfo_list_get_length(list) == 0, "List was not empty"); - fail_unless(osinfo_list_find_by_id(list, "wibble") == NULL, "List was not empty"); + g_assert_cmpint(osinfo_list_get_length(list), ==, 0); + g_assert_null(osinfo_list_find_by_id(list, "wibble")); GType type; g_object_get(list, "element-type", &type, NULL); - fail_unless(type == OSINFO_TYPE_ENTITY, "Type is not entity"); + g_assert_cmpint(type, ==, OSINFO_TYPE_ENTITY); type = osinfo_list_get_element_type(list); - fail_unless(type == OSINFO_TYPE_ENTITY, "Type is not entity"); + g_assert_cmpint(type, ==, OSINFO_TYPE_ENTITY); g_object_unref(list); } -END_TEST -START_TEST(test_lookup) +static void +test_lookup(void) { OsinfoList *list = g_object_new(osinfo_dummy_list_get_type(), NULL); OsinfoEntity *ent = g_object_new(osinfo_dummy_get_type(), "id", "wibble", NULL); osinfo_list_add(list, ent); - fail_unless(osinfo_list_get_length(list) == 1, "List does not contain a single element"); - fail_unless(osinfo_list_get_nth(list, 0) == ent, "Lookup wrong element"); - fail_unless(osinfo_list_find_by_id(list, "wibble") != NULL, "Could not find element"); - fail_unless(osinfo_list_find_by_id(list, "fish") == NULL, "Found wrong element"); + g_assert_cmpint(osinfo_list_get_length(list), ==, 1); + g_assert_true(osinfo_list_get_nth(list, 0) == ent); + g_assert_nonnull(osinfo_list_find_by_id(list, "wibble")); + g_assert_null(osinfo_list_find_by_id(list, "fish")); g_object_unref(ent); g_object_unref(list); } -END_TEST -START_TEST(test_duplicate) +static void +test_duplicate(void) { OsinfoList *list = g_object_new(osinfo_dummy_list_get_type(), NULL); OsinfoEntity *ent = g_object_new(osinfo_dummy_get_type(), "id", "wibble", NULL); @@ -117,20 +116,20 @@ START_TEST(test_duplicate) osinfo_list_add(list, ent); osinfo_list_add(list, ent_dup); - fail_unless(osinfo_list_get_length(list) == 1, "List does not contain a single element"); - fail_unless(osinfo_list_get_nth(list, 0) == ent_dup, "Lookup wrong element"); - fail_unless(osinfo_list_find_by_id(list, "wibble") != NULL, "Could not find element"); - fail_unless(osinfo_list_find_by_id(list, "fish") == NULL, "Found wrong element"); + g_assert_cmpint(osinfo_list_get_length(list), ==, 1); + g_assert_true(osinfo_list_get_nth(list, 0) == ent_dup); + g_assert_nonnull(osinfo_list_find_by_id(list, "wibble")); + g_assert_null(osinfo_list_find_by_id(list, "fish")); g_object_unref(ent); g_object_unref(ent_dup); g_object_unref(list); } -END_TEST -START_TEST(test_union) +static void +test_union(void) { OsinfoList *list1 = g_object_new(osinfo_dummy_list_get_type(), NULL); OsinfoList *list2 = g_object_new(osinfo_dummy_list_get_type(), NULL); @@ -151,7 +150,7 @@ START_TEST(test_union) osinfo_list_add_union(list3, list1, list2); - fail_unless(osinfo_list_get_length(list3) == 4, "List did not have 4 elements"); + g_assert_cmpint(osinfo_list_get_length(list3), ==, 4); gboolean has1 = FALSE; gboolean has2 = FALSE; @@ -172,11 +171,11 @@ START_TEST(test_union) else hasBad = TRUE; } - fail_unless(has1, "List was missing entity 1"); - fail_unless(has2, "List was missing entity 2"); - fail_unless(has3, "List was missing entity 3"); - fail_unless(has4, "List was missing entity 4"); - fail_unless(!hasBad, "List had unexpected entity"); + g_assert_true(has1); + g_assert_true(has2); + g_assert_true(has3); + g_assert_true(has4); + g_assert_false(hasBad); g_object_unref(ent1); g_object_unref(ent1_dup); @@ -187,10 +186,10 @@ START_TEST(test_union) g_object_unref(list2); g_object_unref(list3); } -END_TEST -START_TEST(test_intersect) +static void +test_intersect(void) { OsinfoList *list1 = g_object_new(osinfo_dummy_list_get_type(), NULL); OsinfoList *list2 = g_object_new(osinfo_dummy_list_get_type(), NULL); @@ -212,7 +211,7 @@ START_TEST(test_intersect) osinfo_list_add_intersection(list3, list1, list2); - fail_unless(osinfo_list_get_length(list3) == 2, "List did not have 2 elements"); + g_assert_cmpint(osinfo_list_get_length(list3), ==, 2); gboolean has1 = FALSE; gboolean has2 = FALSE; @@ -233,11 +232,11 @@ START_TEST(test_intersect) else hasBad = TRUE; } - fail_unless(has1, "List was missing entity 1"); - fail_unless(!has2, "List had unexpected entity 2"); - fail_unless(has3, "List was missing entity 3"); - fail_unless(!has4, "List had unexpected entity 4"); - fail_unless(!hasBad, "List had unexpected entity"); + g_assert_true(has1); + g_assert_false(has2); + g_assert_true(has3); + g_assert_false(has4); + g_assert_false(hasBad); g_object_unref(ent1); g_object_unref(ent1_dup); @@ -248,10 +247,10 @@ START_TEST(test_intersect) g_object_unref(list2); g_object_unref(list3); } -END_TEST -START_TEST(test_filter) +static void +test_filter(void) { OsinfoList *list1 = g_object_new(osinfo_dummy_list_get_type(), NULL); OsinfoList *list2 = g_object_new(osinfo_dummy_list_get_type(), NULL); @@ -277,7 +276,7 @@ START_TEST(test_filter) osinfo_list_add_filtered(list2, list1, filter); - fail_unless(osinfo_list_get_length(list2) == 3, "List did not have 3 elements"); + g_assert_cmpint(osinfo_list_get_length(list2), ==, 3); gboolean has1 = FALSE; gboolean has2 = FALSE; @@ -298,11 +297,11 @@ START_TEST(test_filter) else hasBad = TRUE; } - fail_unless(has1, "List was missing entity 1"); - fail_unless(has2, "List was missing entity 2"); - fail_unless(has3, "List was missing entity 3"); - fail_unless(!has4, "List had unexpected entity 4"); - fail_unless(!hasBad, "List had unexpected entity"); + g_assert_true(has1); + g_assert_true(has2); + g_assert_true(has3); + g_assert_false(has4); + g_assert_false(hasBad); g_object_unref(ent1); g_object_unref(ent2); @@ -312,7 +311,6 @@ START_TEST(test_filter) g_object_unref(list1); g_object_unref(list2); } -END_TEST struct iterateData { OsinfoEntity *ent1; @@ -343,7 +341,8 @@ static void iterator(gpointer data, gpointer opaque) idata->hasBad = TRUE; } -START_TEST(test_iterate) +static void +test_iterate(void) { OsinfoList *list1 = g_object_new(osinfo_dummy_list_get_type(), NULL); OsinfoList *list2 = g_object_new(osinfo_dummy_list_get_type(), NULL); @@ -366,22 +365,22 @@ START_TEST(test_iterate) GList *elements = osinfo_list_get_elements(list1); g_list_foreach(elements, iterator, &data); g_list_free(elements); - fail_unless(data.has1, "List was missing entity 1"); - fail_unless(data.has2, "List was missing entity 2"); - fail_unless(data.has3, "List was missing entity 3"); - fail_unless(!data.has4, "List has unexpected entity 4"); - fail_unless(!data.hasBad, "List had unexpected entity"); + g_assert_true(data.has1); + g_assert_true(data.has2); + g_assert_true(data.has3); + g_assert_false(data.has4); + g_assert_false(data.hasBad); data.has1 = data.has2 = data.has3 = data.has4 = data.hasBad = FALSE; elements = osinfo_list_get_elements(list2); g_list_foreach(elements, iterator, &data); g_list_free(elements); - fail_unless(data.has1, "List was missing entity 1"); - fail_unless(!data.has2, "List has unexpected entity 2"); - fail_unless(!data.has3, "List has unexpected entity 3"); - fail_unless(data.has4, "List was missing entity 4"); - fail_unless(!data.hasBad, "List had unexpected entity"); + g_assert_true(data.has1); + g_assert_false(data.has2); + g_assert_false(data.has3); + g_assert_true(data.has4); + g_assert_false(data.hasBad); g_object_unref(ent1); g_object_unref(ent2); @@ -390,29 +389,19 @@ START_TEST(test_iterate) g_object_unref(list1); g_object_unref(list2); } -END_TEST -static Suite * -list_suite(void) +int +main(int argc, char *argv[]) { - Suite *s = suite_create("List"); - TCase *tc = tcase_create("Core"); - tcase_add_test(tc, test_basic); - tcase_add_test(tc, test_lookup); - tcase_add_test(tc, test_duplicate); - tcase_add_test(tc, test_union); - tcase_add_test(tc, test_intersect); - tcase_add_test(tc, test_filter); - tcase_add_test(tc, test_iterate); - suite_add_tcase(s, tc); - return s; -} + g_test_init(&argc, &argv, NULL); -int main(void) -{ - int number_failed; - Suite *s = list_suite(); - SRunner *sr = srunner_create(s); + g_test_add_func("/list/basic", test_basic); + g_test_add_func("/list/lookup", test_lookup); + g_test_add_func("/list/duplicate", test_duplicate); + g_test_add_func("/list/union", test_union); + g_test_add_func("/list/intersect", test_intersect); + g_test_add_func("/list/filter", test_filter); + g_test_add_func("/list/iterate", test_iterate); /* Make sure we catch unexpected g_warning() */ g_log_set_always_fatal(G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING); @@ -422,11 +411,7 @@ int main(void) osinfo_dummy_list_get_type(); osinfo_filter_get_type(); - srunner_run_all(sr, CK_ENV); - number_failed = srunner_ntests_failed(sr); - srunner_free(sr); - - return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; + return g_test_run(); } /* * Local variables: diff --git a/tests/test-loader.c b/tests/test-loader.c index 78c6713..680075d 100644 --- a/tests/test-loader.c +++ b/tests/test-loader.c @@ -21,39 +21,28 @@ #include <config.h> -#include <stdlib.h> #include <osinfo/osinfo.h> -#include <check.h> -START_TEST(test_basic) +static void +test_basic(void) { OsinfoLoader *loader = osinfo_loader_new(); - fail_unless(OSINFO_IS_LOADER(loader), "Loader is not a LOADER"); + g_assert_true(OSINFO_IS_LOADER(loader)); GError *error = NULL; osinfo_loader_process_default_path(loader, &error); - fail_unless(error == NULL, error ? error->message : "none"); + g_assert_no_error(error); g_object_unref(loader); } -END_TEST -static Suite * -loader_suite(void) +int +main(int argc, char *argv[]) { - Suite *s = suite_create("Loader"); - TCase *tc = tcase_create("Core"); - tcase_add_test(tc, test_basic); - suite_add_tcase(s, tc); - return s; -} + g_test_init(&argc, &argv, NULL); -int main(void) -{ - int number_failed; - Suite *s = loader_suite(); - SRunner *sr = srunner_create(s); + g_test_add_func("/loader/basic", test_basic); /* Make sure we catch unexpected g_warning() */ g_log_set_always_fatal(G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING); @@ -71,11 +60,7 @@ int main(void) osinfo_filter_get_type(); osinfo_loader_get_type(); - srunner_run_all(sr, CK_ENV); - number_failed = srunner_ntests_failed(sr); - srunner_free(sr); - - return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; + return g_test_run(); } /* * Local variables: diff --git a/tests/test-mediauris.c b/tests/test-mediauris.c index 52d1e1c..5ac2c8e 100644 --- a/tests/test-mediauris.c +++ b/tests/test-mediauris.c @@ -21,10 +21,8 @@ #include <config.h> -#include <config.h> #include <stdlib.h> #include <osinfo/osinfo.h> -#include <check.h> #include <curl/curl.h> static void test_media(OsinfoMediaList *medialist, GError **error, CURL *curl) @@ -43,14 +41,15 @@ static void test_media(OsinfoMediaList *medialist, GError **error, CURL *curl) continue; } - g_print("%s\n", url); + g_test_message("%s", url); curl_easy_setopt(curl, CURLOPT_URL, url); res = curl_easy_perform(curl); if (res != CURLE_OK) { curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code); } - fail_unless(res == CURLE_OK, "Failed HEAD (res=%d, %s; code=%ld) on %s", res, curl_easy_strerror(res), response_code, url); + g_test_message("res=%d, %s; code=%ld", res, curl_easy_strerror(res), response_code); + g_assert_cmpint(res, ==, CURLE_OK); tmp = tmp->next; } @@ -58,7 +57,8 @@ static void test_media(OsinfoMediaList *medialist, GError **error, CURL *curl) g_list_free(mediael); } -START_TEST(test_uris) +static void +test_uris(void) { CURL *curl; OsinfoLoader *loader = osinfo_loader_new(); @@ -81,11 +81,11 @@ START_TEST(test_uris) curl_easy_setopt(curl, CURLOPT_VERBOSE, debug_level > 0 ? 1L : 0L); } - fail_unless(OSINFO_IS_LOADER(loader), "Loader is not a LOADER"); - fail_unless(OSINFO_IS_DB(db), "Db is not a DB"); + g_assert_true(OSINFO_IS_LOADER(loader)); + g_assert_true(OSINFO_IS_DB(db)); osinfo_loader_process_default_path(loader, &error); - fail_unless(error == NULL, error ? error->message : "none"); + g_assert_no_error(error); oslist = osinfo_db_get_os_list(db); tmp = osel = osinfo_list_get_elements(OSINFO_LIST(oslist)); @@ -95,7 +95,7 @@ START_TEST(test_uris) test_media(medialist, &error, curl); - fail_unless(error == NULL, error ? error->message : "none"); + g_assert_no_error(error); g_object_unref(medialist); tmp = tmp->next; @@ -109,27 +109,17 @@ START_TEST(test_uris) g_object_unref(loader); } -END_TEST -static Suite * -list_suite(void) +int +main(int argc, char *argv[]) { - Suite *s = suite_create("List"); - TCase *tc = tcase_create("Core"); - tcase_set_timeout(tc, 300); + int ret; - tcase_add_test(tc, test_uris); - suite_add_tcase(s, tc); - return s; -} + g_test_init(&argc, &argv, NULL); -int main(void) -{ - int number_failed; - Suite *s = list_suite(); - SRunner *sr = srunner_create(s); + g_test_add_func("/mediauris/uris", test_uris); /* Make sure we catch unexpected g_warning() */ g_log_set_always_fatal(G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING); @@ -150,13 +140,11 @@ int main(void) osinfo_oslist_get_type(); osinfo_filter_get_type(); - srunner_run_all(sr, CK_ENV); - number_failed = srunner_ntests_failed(sr); - srunner_free(sr); + ret = g_test_run(); curl_global_cleanup(); - return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; + return ret; } /* * Local variables: diff --git a/tests/test-os.c b/tests/test-os.c index 3c60e17..d62117c 100644 --- a/tests/test-os.c +++ b/tests/test-os.c @@ -21,24 +21,23 @@ #include <config.h> -#include <stdlib.h> #include <osinfo/osinfo.h> -#include <check.h> -START_TEST(test_basic) +static void +test_basic(void) { OsinfoOs *os = osinfo_os_new("pony"); - fail_unless(OSINFO_IS_OS(os), "Os is a os object"); - fail_unless(g_strcmp0(osinfo_entity_get_id(OSINFO_ENTITY(os)), "pony") == 0, "Os ID was pony"); + g_assert_true(OSINFO_IS_OS(os)); + g_assert_cmpstr(osinfo_entity_get_id(OSINFO_ENTITY(os)), ==, "pony"); g_object_unref(os); } -END_TEST -START_TEST(test_devices) +static void +test_devices(void) { OsinfoOs *os = osinfo_os_new("awesome"); OsinfoDevice *dev1 = osinfo_device_new("e1000"); @@ -51,19 +50,19 @@ START_TEST(test_devices) OsinfoDeviceList *devices = osinfo_os_get_devices(os, NULL); - fail_unless(osinfo_list_get_length(OSINFO_LIST(devices)) == 2, "Os has two devices"); - fail_unless(osinfo_list_get_nth(OSINFO_LIST(devices), 0) == OSINFO_ENTITY(dev1), "Got device 1"); - fail_unless(osinfo_list_get_nth(OSINFO_LIST(devices), 1) == OSINFO_ENTITY(dev2), "Got device 2"); + g_assert_cmpint(osinfo_list_get_length(OSINFO_LIST(devices)), ==, 2); + g_assert_true(osinfo_list_get_nth(OSINFO_LIST(devices), 0) == OSINFO_ENTITY(dev1)); + g_assert_true(osinfo_list_get_nth(OSINFO_LIST(devices), 1) == OSINFO_ENTITY(dev2)); g_object_unref(devices); g_object_unref(dev1); g_object_unref(dev2); g_object_unref(os); } -END_TEST -START_TEST(test_loader) +static void +test_loader(void) { OsinfoLoader *loader; OsinfoDb *db; @@ -73,69 +72,64 @@ START_TEST(test_loader) loader = osinfo_loader_new(); osinfo_loader_process_path(loader, SRCDIR "/tests/dbdata", &error); - fail_unless(error == NULL, error ? error->message:"none"); + g_assert_no_error(error); db = osinfo_loader_get_db(loader); os = osinfo_db_get_os(db, "http://libosinfo.org/test/os/test1"); - fail_unless(os != NULL, "could not find OS 'test1'"); + g_assert_nonnull(os); str = osinfo_product_get_short_id(OSINFO_PRODUCT(os)); - fail_unless(g_strcmp0(str, "test1") == 0, "wrong OS short-id"); + g_assert_cmpstr(str, ==, "test1"); str = osinfo_product_get_name(OSINFO_PRODUCT(os)); - fail_unless(g_strcmp0(str, "Test 1") == 0, "wrong OS name"); + g_assert_cmpstr(str, ==, "Test 1"); str = osinfo_product_get_version(OSINFO_PRODUCT(os)); - fail_unless(g_strcmp0(str, "unknown") == 0, "wrong OS version"); + g_assert_cmpstr(str, ==, "unknown"); str = osinfo_product_get_vendor(OSINFO_PRODUCT(os)); - fail_unless(g_strcmp0(str, "libosinfo.org") == 0, "wrong OS vendor"); + g_assert_cmpstr(str, ==, "libosinfo.org"); str = osinfo_os_get_family(os); - fail_unless(g_strcmp0(str, "test") == 0, "wrong OS family"); - fail_unless(osinfo_os_get_release_status(os) == OSINFO_RELEASE_STATUS_PRERELEASE, - "OS should be a pre-release"); + g_assert_cmpstr(str, ==, "test"); + g_assert_cmpint(osinfo_os_get_release_status(os), ==, OSINFO_RELEASE_STATUS_PRERELEASE); os = osinfo_db_get_os(db, "http://libosinfo.org/test/os/test2"); - fail_unless(os != NULL, "could not find OS 'test2'"); + g_assert_nonnull(os); str = osinfo_product_get_short_id(OSINFO_PRODUCT(os)); - fail_unless(g_strcmp0(str, "test2") == 0, "wrong OS short-id"); + g_assert_cmpstr(str, ==, "test2"); str = osinfo_product_get_name(OSINFO_PRODUCT(os)); - fail_unless(str == NULL, "wrong OS name"); + g_assert_null(str); str = osinfo_product_get_version(OSINFO_PRODUCT(os)); - fail_unless(str == NULL, "wrong OS version"); + g_assert_null(str); str = osinfo_product_get_vendor(OSINFO_PRODUCT(os)); - fail_unless(str == NULL, "wrong OS vendor"); + g_assert_null(str); str = osinfo_os_get_family(os); - fail_unless(str == NULL, "wrong OS family"); - fail_unless(osinfo_os_get_release_status(os) == OSINFO_RELEASE_STATUS_RELEASED, - "OS should be a released one"); + g_assert_null(str); + g_assert_cmpint(osinfo_os_get_release_status(os), ==, OSINFO_RELEASE_STATUS_RELEASED); os = osinfo_db_get_os(db, "http://libosinfo.org/test/os/test3"); - fail_unless(os != NULL, "could not find OS 'test3'"); + g_assert_nonnull(os); str = osinfo_product_get_short_id(OSINFO_PRODUCT(os)); - fail_unless(g_strcmp0(str, "test3") == 0, "wrong OS short-id"); - fail_unless(osinfo_os_get_release_status(os) == OSINFO_RELEASE_STATUS_RELEASED, - "OS should be a released one"); + g_assert_cmpstr(str, ==, "test3"); + g_assert_cmpint(osinfo_os_get_release_status(os), ==, OSINFO_RELEASE_STATUS_RELEASED); os = osinfo_db_get_os(db, "http://libosinfo.org/test/os/test4"); - fail_unless(os != NULL, "could not find OS 'test4'"); + g_assert_nonnull(os); str = osinfo_product_get_short_id(OSINFO_PRODUCT(os)); - fail_unless(g_strcmp0(str, "test4") == 0, "wrong OS short-id"); - fail_unless(osinfo_os_get_release_status(os) == OSINFO_RELEASE_STATUS_SNAPSHOT, - "OS should be a snapshot"); + g_assert_cmpstr(str, ==, "test4"); + g_assert_cmpint(osinfo_os_get_release_status(os), ==, OSINFO_RELEASE_STATUS_SNAPSHOT); os = osinfo_db_get_os(db, "http://libosinfo.org/test/os/test5"); - fail_unless(os != NULL, "could not find OS 'test5'"); + g_assert_nonnull(os); str = osinfo_product_get_short_id(OSINFO_PRODUCT(os)); - fail_unless(g_strcmp0(str, "test5") == 0, "wrong OS short-id"); + g_assert_cmpstr(str, ==, "test5"); /* 'test5' OS intentionnally contains an invalid release status */ g_test_expect_message(NULL, G_LOG_LEVEL_CRITICAL, "*(osinfo_entity_get_param_value_enum): should not be reached*"); - fail_unless(osinfo_os_get_release_status(os) == OSINFO_RELEASE_STATUS_RELEASED, - "OS should be a released one"); + g_assert_cmpint(osinfo_os_get_release_status(os), ==, OSINFO_RELEASE_STATUS_RELEASED); g_object_unref(loader); } -END_TEST -START_TEST(test_devices_filter) +static void +test_devices_filter(void) { OsinfoOs *os = osinfo_os_new("awesome"); OsinfoDevice *dev1 = osinfo_device_new("e1000"); @@ -154,10 +148,10 @@ START_TEST(test_devices_filter) OsinfoDeviceList *devices = osinfo_os_get_devices(os, filter); - fail_unless(osinfo_list_get_length(OSINFO_LIST(devices)) == 1, "Os has one devices"); + g_assert_cmpint(osinfo_list_get_length(OSINFO_LIST(devices)), ==, 1); OsinfoEntity *ent = osinfo_list_get_nth(OSINFO_LIST(devices), 0); - fail_unless(OSINFO_IS_DEVICE(ent), "entity is a device"); - fail_unless(OSINFO_DEVICE(ent) == dev1, "device is e1000"); + g_assert_true(OSINFO_IS_DEVICE(ent)); + g_assert_true(OSINFO_DEVICE(ent) == dev1); g_object_unref(devices); g_object_unref(filter); @@ -165,10 +159,10 @@ START_TEST(test_devices_filter) g_object_unref(dev2); g_object_unref(os); } -END_TEST -START_TEST(test_device_driver) +static void +test_device_driver(void) { OsinfoOs *os = osinfo_os_new("awesome"); OsinfoDevice *dev1 = osinfo_device_new("e1000"); @@ -193,28 +187,18 @@ START_TEST(test_device_driver) g_object_unref(dev2); g_object_unref(os); } -END_TEST -static Suite * -os_suite(void) +int +main(int argc, char *argv[]) { - Suite *s = suite_create("Os"); - TCase *tc = tcase_create("Core"); - tcase_add_test(tc, test_basic); - tcase_add_test(tc, test_loader); - tcase_add_test(tc, test_devices); - tcase_add_test(tc, test_devices_filter); - tcase_add_test(tc, test_device_driver); - suite_add_tcase(s, tc); - return s; -} + g_test_init(&argc, &argv, NULL); -int main(void) -{ - int number_failed; - Suite *s = os_suite(); - SRunner *sr = srunner_create(s); + g_test_add_func("/os/basic", test_basic); + g_test_add_func("/os/loader", test_loader); + g_test_add_func("/os/devices", test_devices); + g_test_add_func("/os/devices_filter", test_devices_filter); + g_test_add_func("/os/device_driver", test_device_driver); /* Make sure we catch unexpected g_warning() */ g_log_set_always_fatal(G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING); @@ -227,11 +211,7 @@ int main(void) osinfo_devicelist_get_type(); osinfo_filter_get_type(); - srunner_run_all(sr, CK_ENV); - number_failed = srunner_ntests_failed(sr); - srunner_free(sr); - - return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; + return g_test_run(); } /* * Local variables: diff --git a/tests/test-oslist.c b/tests/test-oslist.c index 22ff83b..c85f822 100644 --- a/tests/test-oslist.c +++ b/tests/test-oslist.c @@ -21,12 +21,11 @@ #include <config.h> -#include <stdlib.h> #include <osinfo/osinfo.h> -#include <check.h> -START_TEST(test_union) +static void +test_union(void) { OsinfoOsList *list1 = osinfo_oslist_new(); OsinfoOsList *list2 = osinfo_oslist_new(); @@ -45,7 +44,7 @@ START_TEST(test_union) list3 = OSINFO_OSLIST(osinfo_list_new_union(OSINFO_LIST(list1), OSINFO_LIST(list2))); - fail_unless(osinfo_list_get_length(OSINFO_LIST(list3)) == 4, "List did not have 4 elements"); + g_assert_cmpint(osinfo_list_get_length(OSINFO_LIST(list3)), ==, 4); gboolean has1 = FALSE; gboolean has2 = FALSE; @@ -66,11 +65,11 @@ START_TEST(test_union) else hasBad = TRUE; } - fail_unless(has1, "List was missing entity 1"); - fail_unless(has2, "List was missing entity 2"); - fail_unless(has3, "List was missing entity 3"); - fail_unless(has4, "List was missing entity 4"); - fail_unless(!hasBad, "List had unexpected entity"); + g_assert_true(has1); + g_assert_true(has2); + g_assert_true(has3); + g_assert_true(has4); + g_assert_false(hasBad); g_object_unref(ent1); g_object_unref(ent2); @@ -80,10 +79,10 @@ START_TEST(test_union) g_object_unref(list2); g_object_unref(list3); } -END_TEST -START_TEST(test_intersect) +static void +test_intersect(void) { OsinfoOsList *list1 = osinfo_oslist_new(); OsinfoOsList *list2 = osinfo_oslist_new(); @@ -104,7 +103,7 @@ START_TEST(test_intersect) list3 = OSINFO_OSLIST(osinfo_list_new_intersection(OSINFO_LIST(list1), OSINFO_LIST(list2))); - fail_unless(osinfo_list_get_length(OSINFO_LIST(list3)) == 2, "List did not have 2 elements"); + g_assert_cmpint(osinfo_list_get_length(OSINFO_LIST(list3)), ==, 2); gboolean has1 = FALSE; gboolean has2 = FALSE; @@ -125,11 +124,11 @@ START_TEST(test_intersect) else hasBad = TRUE; } - fail_unless(has1, "List was missing entity 1"); - fail_unless(!has2, "List had unexpected entity 2"); - fail_unless(has3, "List was missing entity 3"); - fail_unless(!has4, "List had unexpected entity 4"); - fail_unless(!hasBad, "List had unexpected entity"); + g_assert_true(has1); + g_assert_false(has2); + g_assert_true(has3); + g_assert_false(has4); + g_assert_false(hasBad); g_object_unref(ent1); g_object_unref(ent2); @@ -139,10 +138,10 @@ START_TEST(test_intersect) g_object_unref(list2); g_object_unref(list3); } -END_TEST -START_TEST(test_filter) +static void +test_filter(void) { OsinfoOsList *list1 = osinfo_oslist_new(); OsinfoOsList *list2; @@ -168,7 +167,7 @@ START_TEST(test_filter) list2 = OSINFO_OSLIST(osinfo_list_new_filtered(OSINFO_LIST(list1), filter)); - fail_unless(osinfo_list_get_length(OSINFO_LIST(list2)) == 3, "List did not have 3 elements"); + g_assert_cmpint(osinfo_list_get_length(OSINFO_LIST(list2)), ==, 3); gboolean has1 = FALSE; gboolean has2 = FALSE; @@ -189,11 +188,11 @@ START_TEST(test_filter) else hasBad = TRUE; } - fail_unless(has1, "List was missing entity 1"); - fail_unless(has2, "List was missing entity 2"); - fail_unless(has3, "List was missing entity 3"); - fail_unless(!has4, "List had unexpected entity 4"); - fail_unless(!hasBad, "List had unexpected entity"); + g_assert_true(has1); + g_assert_true(has2); + g_assert_true(has3); + g_assert_false(has4); + g_assert_false(hasBad); g_object_unref(ent1); g_object_unref(ent2); @@ -203,26 +202,16 @@ START_TEST(test_filter) g_object_unref(list1); g_object_unref(list2); } -END_TEST -static Suite * -list_suite(void) +int +main(int argc, char *argv[]) { - Suite *s = suite_create("List"); - TCase *tc = tcase_create("Core"); - tcase_add_test(tc, test_union); - tcase_add_test(tc, test_intersect); - tcase_add_test(tc, test_filter); - suite_add_tcase(s, tc); - return s; -} + g_test_init(&argc, &argv, NULL); -int main(void) -{ - int number_failed; - Suite *s = list_suite(); - SRunner *sr = srunner_create(s); + g_test_add_func("/oslist/union", test_union); + g_test_add_func("/oslist/intersect", test_intersect); + g_test_add_func("/oslist/filter", test_filter); /* Make sure we catch unexpected g_warning() */ g_log_set_always_fatal(G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING); @@ -232,11 +221,7 @@ int main(void) osinfo_oslist_get_type(); osinfo_filter_get_type(); - srunner_run_all(sr, CK_ENV); - number_failed = srunner_ntests_failed(sr); - srunner_free(sr); - - return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; + return g_test_run(); } /* * Local variables: diff --git a/tests/test-platform.c b/tests/test-platform.c index 8a49983..a518529 100644 --- a/tests/test-platform.c +++ b/tests/test-platform.c @@ -21,24 +21,23 @@ #include <config.h> -#include <stdlib.h> #include <osinfo/osinfo.h> -#include <check.h> -START_TEST(test_basic) +static void +test_basic(void) { OsinfoPlatform *platform = osinfo_platform_new("awesome"); - fail_unless(OSINFO_IS_PLATFORM(platform), "Platform is a platform object"); - fail_unless(g_strcmp0(osinfo_entity_get_id(OSINFO_ENTITY(platform)), "awesome") == 0, "Platform ID was awesome"); + g_assert_true(OSINFO_IS_PLATFORM(platform)); + g_assert_cmpstr(osinfo_entity_get_id(OSINFO_ENTITY(platform)), ==, "awesome"); g_object_unref(platform); } -END_TEST -START_TEST(test_devices) +static void +test_devices(void) { OsinfoPlatform *hv = osinfo_platform_new("awesome"); OsinfoDevice *dev1 = osinfo_device_new("e1000"); @@ -51,7 +50,7 @@ START_TEST(test_devices) OsinfoDeviceList *devices = osinfo_platform_get_devices(hv, NULL); - fail_unless(osinfo_list_get_length(OSINFO_LIST(devices)) == 2, "Platform has two devices"); + g_assert_cmpint(osinfo_list_get_length(OSINFO_LIST(devices)), ==, 2); gboolean hasDev1 = FALSE; gboolean hasDev2 = FALSE; @@ -59,7 +58,7 @@ START_TEST(test_devices) int i; for (i = 0; i < osinfo_list_get_length(OSINFO_LIST(devices)); i++) { OsinfoEntity *ent = osinfo_list_get_nth(OSINFO_LIST(devices), i); - fail_unless(OSINFO_IS_DEVICE(ent), "entity is a device"); + g_assert_true(OSINFO_IS_DEVICE(ent)); if (OSINFO_DEVICE(ent) == dev1) hasDev1 = TRUE; else if (OSINFO_DEVICE(ent) == dev2) @@ -67,19 +66,19 @@ START_TEST(test_devices) else hasBad = TRUE; } - fail_unless(hasDev1, "Device 1 is missing"); - fail_unless(hasDev2, "Device 2 is missing"); - fail_unless(!hasBad, "Device was not expected"); + g_assert_true(hasDev1); + g_assert_true(hasDev2); + g_assert_false(hasBad); g_object_unref(devices); g_object_unref(dev1); g_object_unref(dev2); g_object_unref(hv); } -END_TEST -START_TEST(test_devices_filter) +static void +test_devices_filter(void) { OsinfoPlatform *hv = osinfo_platform_new("awesome"); OsinfoDevice *dev1 = osinfo_device_new("e1000"); @@ -98,10 +97,10 @@ START_TEST(test_devices_filter) OsinfoDeviceList *devices = osinfo_platform_get_devices(hv, filter); - fail_unless(osinfo_list_get_length(OSINFO_LIST(devices)) == 1, "Platform has one devices"); + g_assert_cmpint(osinfo_list_get_length(OSINFO_LIST(devices)), ==, 1); OsinfoEntity *ent = osinfo_list_get_nth(OSINFO_LIST(devices), 0); - fail_unless(OSINFO_IS_DEVICE(ent), "entity is a device"); - fail_unless(OSINFO_DEVICE(ent) == dev1, "device is e1000"); + g_assert_true(OSINFO_IS_DEVICE(ent)); + g_assert_true(OSINFO_DEVICE(ent) == dev1); g_object_unref(devices); g_object_unref(filter); @@ -109,27 +108,17 @@ START_TEST(test_devices_filter) g_object_unref(dev2); g_object_unref(hv); } -END_TEST -static Suite * -platform_suite(void) +int +main(int argc, char *argv[]) { - Suite *s = suite_create("Platform"); - TCase *tc = tcase_create("Core"); - tcase_add_test(tc, test_basic); - tcase_add_test(tc, test_devices); - tcase_add_test(tc, test_devices_filter); - suite_add_tcase(s, tc); - return s; -} + g_test_init(&argc, &argv, NULL); -int main(void) -{ - int number_failed; - Suite *s = platform_suite(); - SRunner *sr = srunner_create(s); + g_test_add_func("/platform/basic", test_basic); + g_test_add_func("/platform/devices", test_devices); + g_test_add_func("/platform/devices_filter", test_devices_filter); /* Make sure we catch unexpected g_warning() */ g_log_set_always_fatal(G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING); @@ -140,11 +129,7 @@ int main(void) osinfo_devicelist_get_type(); osinfo_filter_get_type(); - srunner_run_all(sr, CK_ENV); - number_failed = srunner_ntests_failed(sr); - srunner_free(sr); - - return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; + return g_test_run(); } /* * Local variables: diff --git a/tests/test-platformlist.c b/tests/test-platformlist.c index 0310050..f502911 100644 --- a/tests/test-platformlist.c +++ b/tests/test-platformlist.c @@ -21,12 +21,11 @@ #include <config.h> -#include <stdlib.h> #include <osinfo/osinfo.h> -#include <check.h> -START_TEST(test_union) +static void +test_union(void) { OsinfoPlatformList *list1 = osinfo_platformlist_new(); OsinfoPlatformList *list2 = osinfo_platformlist_new(); @@ -45,7 +44,7 @@ START_TEST(test_union) list3 = OSINFO_PLATFORMLIST(osinfo_list_new_union(OSINFO_LIST(list1), OSINFO_LIST(list2))); - fail_unless(osinfo_list_get_length(OSINFO_LIST(list3)) == 4, "List did not have 4 elements"); + g_assert_cmpint(osinfo_list_get_length(OSINFO_LIST(list3)), ==, 4); gboolean has1 = FALSE; gboolean has2 = FALSE; @@ -66,11 +65,11 @@ START_TEST(test_union) else hasBad = TRUE; } - fail_unless(has1, "List was missing entity 1"); - fail_unless(has2, "List was missing entity 2"); - fail_unless(has3, "List was missing entity 3"); - fail_unless(has4, "List was missing entity 4"); - fail_unless(!hasBad, "List had unexpected entity"); + g_assert_true(has1); + g_assert_true(has2); + g_assert_true(has3); + g_assert_true(has4); + g_assert_false(hasBad); g_object_unref(ent1); g_object_unref(ent2); @@ -80,10 +79,10 @@ START_TEST(test_union) g_object_unref(list2); g_object_unref(list3); } -END_TEST -START_TEST(test_intersect) +static void +test_intersect(void) { OsinfoPlatformList *list1 = osinfo_platformlist_new(); OsinfoPlatformList *list2 = osinfo_platformlist_new(); @@ -104,7 +103,7 @@ START_TEST(test_intersect) list3 = OSINFO_PLATFORMLIST(osinfo_list_new_intersection(OSINFO_LIST(list1), OSINFO_LIST(list2))); - fail_unless(osinfo_list_get_length(OSINFO_LIST(list3)) == 2, "List did not have 2 elements"); + g_assert_cmpint(osinfo_list_get_length(OSINFO_LIST(list3)), ==, 2); gboolean has1 = FALSE; gboolean has2 = FALSE; @@ -125,11 +124,11 @@ START_TEST(test_intersect) else hasBad = TRUE; } - fail_unless(has1, "List was missing entity 1"); - fail_unless(!has2, "List had unexpected entity 2"); - fail_unless(has3, "List was missing entity 3"); - fail_unless(!has4, "List had unexpected entity 4"); - fail_unless(!hasBad, "List had unexpected entity"); + g_assert_true(has1); + g_assert_false(has2); + g_assert_true(has3); + g_assert_false(has4); + g_assert_false(hasBad); g_object_unref(ent1); g_object_unref(ent2); @@ -139,10 +138,10 @@ START_TEST(test_intersect) g_object_unref(list2); g_object_unref(list3); } -END_TEST -START_TEST(test_filter) +static void +test_filter(void) { OsinfoPlatformList *list1 = osinfo_platformlist_new(); OsinfoPlatformList *list2; @@ -168,7 +167,7 @@ START_TEST(test_filter) list2 = OSINFO_PLATFORMLIST(osinfo_list_new_filtered(OSINFO_LIST(list1), filter)); - fail_unless(osinfo_list_get_length(OSINFO_LIST(list2)) == 3, "List did not have 3 elements"); + g_assert_cmpint(osinfo_list_get_length(OSINFO_LIST(list2)), ==, 3); gboolean has1 = FALSE; gboolean has2 = FALSE; @@ -189,11 +188,11 @@ START_TEST(test_filter) else hasBad = TRUE; } - fail_unless(has1, "List was missing entity 1"); - fail_unless(has2, "List was missing entity 2"); - fail_unless(has3, "List was missing entity 3"); - fail_unless(!has4, "List had unexpected entity 4"); - fail_unless(!hasBad, "List had unexpected entity"); + g_assert_true(has1); + g_assert_true(has2); + g_assert_true(has3); + g_assert_false(has4); + g_assert_false(hasBad); g_object_unref(ent1); g_object_unref(ent2); @@ -203,26 +202,16 @@ START_TEST(test_filter) g_object_unref(list1); g_object_unref(list2); } -END_TEST -static Suite * -list_suite(void) +int +main(int argc, char *argv[]) { - Suite *s = suite_create("List"); - TCase *tc = tcase_create("Core"); - tcase_add_test(tc, test_union); - tcase_add_test(tc, test_intersect); - tcase_add_test(tc, test_filter); - suite_add_tcase(s, tc); - return s; -} + g_test_init(&argc, &argv, NULL); -int main(void) -{ - int number_failed; - Suite *s = list_suite(); - SRunner *sr = srunner_create(s); + g_test_add_func("/platformlist/union", test_union); + g_test_add_func("/platformlist/intersect", test_intersect); + g_test_add_func("/platformlist/filter", test_filter); /* Make sure we catch unexpected g_warning() */ g_log_set_always_fatal(G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING); @@ -232,11 +221,7 @@ int main(void) osinfo_platformlist_get_type(); osinfo_filter_get_type(); - srunner_run_all(sr, CK_ENV); - number_failed = srunner_ntests_failed(sr); - srunner_free(sr); - - return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; + return g_test_run(); } /* * Local variables: diff --git a/tests/test-product.c b/tests/test-product.c index f9ddb12..8d58f1c 100644 --- a/tests/test-product.c +++ b/tests/test-product.c @@ -21,9 +21,7 @@ #include <config.h> -#include <stdlib.h> #include <osinfo/osinfo.h> -#include <check.h> /* OsinfoProduct is abstract, so we need to trivially subclass it to test it */ typedef struct _OsinfoDummy OsinfoDummy; @@ -51,19 +49,20 @@ static OsinfoProduct *osinfo_dummy_new(const gchar *id) { } -START_TEST(test_basic) +static void +test_basic(void) { OsinfoProduct *product = osinfo_dummy_new("pony"); - fail_unless(OSINFO_IS_PRODUCT(product), "Product is a product object"); - fail_unless(g_strcmp0(osinfo_entity_get_id(OSINFO_ENTITY(product)), "pony") == 0, "Product ID was pony"); + g_assert_true(OSINFO_IS_PRODUCT(product)); + g_assert_cmpstr(osinfo_entity_get_id(OSINFO_ENTITY(product)), ==, "pony"); g_object_unref(product); } -END_TEST -START_TEST(test_relproduct) +static void +test_relproduct(void) { OsinfoProduct *product1 = osinfo_dummy_new("pony"); OsinfoProduct *product2 = osinfo_dummy_new("donkey"); @@ -78,27 +77,26 @@ START_TEST(test_relproduct) osinfo_product_add_related(product1, OSINFO_PRODUCT_RELATIONSHIP_CLONES, product5); OsinfoProductList *product1rel = osinfo_product_get_related(product1, OSINFO_PRODUCT_RELATIONSHIP_DERIVES_FROM); - fail_unless(osinfo_list_get_length(OSINFO_LIST(product1rel)) == 1, "Product has 1 derived product"); - fail_unless(osinfo_list_get_nth(OSINFO_LIST(product1rel), 0) == OSINFO_ENTITY(product2), "derived product is product2"); + g_assert_cmpint(osinfo_list_get_length(OSINFO_LIST(product1rel)), ==, 1); + g_assert_true(osinfo_list_get_nth(OSINFO_LIST(product1rel), 0) == OSINFO_ENTITY(product2)); g_object_unref(product1rel); product1rel = osinfo_product_get_related(product1, OSINFO_PRODUCT_RELATIONSHIP_UPGRADES); - fail_unless(osinfo_list_get_length(OSINFO_LIST(product1rel)) == 2, "Product has 2 upgraded product"); - fail_unless((osinfo_list_get_nth(OSINFO_LIST(product1rel), 0) == OSINFO_ENTITY(product3) || - osinfo_list_get_nth(OSINFO_LIST(product1rel), 0) == OSINFO_ENTITY(product4)) && - (osinfo_list_get_nth(OSINFO_LIST(product1rel), 1) == OSINFO_ENTITY(product3) || - osinfo_list_get_nth(OSINFO_LIST(product1rel), 1) == OSINFO_ENTITY(product4)), - "upgraded productes are product3 + product4"); + g_assert_cmpint(osinfo_list_get_length(OSINFO_LIST(product1rel)), ==, 2); + g_assert_true((osinfo_list_get_nth(OSINFO_LIST(product1rel), 0) == OSINFO_ENTITY(product3) || + osinfo_list_get_nth(OSINFO_LIST(product1rel), 0) == OSINFO_ENTITY(product4)) && + (osinfo_list_get_nth(OSINFO_LIST(product1rel), 1) == OSINFO_ENTITY(product3) || + osinfo_list_get_nth(OSINFO_LIST(product1rel), 1) == OSINFO_ENTITY(product4))); g_object_unref(product1rel); product1rel = osinfo_product_get_related(product3, OSINFO_PRODUCT_RELATIONSHIP_UPGRADES); - fail_unless(osinfo_list_get_length(OSINFO_LIST(product1rel)) == 1, "Product has 1 upgraded product"); - fail_unless(osinfo_list_get_nth(OSINFO_LIST(product1rel), 0) == OSINFO_ENTITY(product4), "upgraded product is product4"); + g_assert_cmpint(osinfo_list_get_length(OSINFO_LIST(product1rel)), ==, 1); + g_assert_true(osinfo_list_get_nth(OSINFO_LIST(product1rel), 0) == OSINFO_ENTITY(product4)); g_object_unref(product1rel); product1rel = osinfo_product_get_related(product1, OSINFO_PRODUCT_RELATIONSHIP_CLONES); - fail_unless(osinfo_list_get_length(OSINFO_LIST(product1rel)) == 1, "Product has 1 upgraded product"); - fail_unless(osinfo_list_get_nth(OSINFO_LIST(product1rel), 0) == OSINFO_ENTITY(product5), "cloned product is product5"); + g_assert_cmpint(osinfo_list_get_length(OSINFO_LIST(product1rel)), ==, 1); + g_assert_true(osinfo_list_get_nth(OSINFO_LIST(product1rel), 0) == OSINFO_ENTITY(product5)); g_object_unref(product1rel); g_object_unref(product1); @@ -107,11 +105,11 @@ START_TEST(test_relproduct) g_object_unref(product4); g_object_unref(product5); } -END_TEST -START_TEST(test_supportdate) +static void +test_supportdate(void) { OsinfoProductList *products = osinfo_productlist_new(); OsinfoProduct *product1 = osinfo_dummy_new("pony"); @@ -138,9 +136,9 @@ START_TEST(test_supportdate) date = g_date_new_dmy(31, 12, 1999); osinfo_productfilter_add_support_date_constraint(filter, date); tmp = OSINFO_PRODUCTLIST(osinfo_list_new_filtered(OSINFO_LIST(products), OSINFO_FILTER(filter))); - fail_unless(osinfo_list_get_length(OSINFO_LIST(tmp)) == 2, "2 products"); - fail_unless(osinfo_list_get_nth(OSINFO_LIST(tmp), 0) == (OsinfoEntity*)product1, "Got product 1"); - fail_unless(osinfo_list_get_nth(OSINFO_LIST(tmp), 1) == (OsinfoEntity*)product3, "Got product 3"); + g_assert_cmpint(osinfo_list_get_length(OSINFO_LIST(tmp)), ==, 2); + g_assert_true(osinfo_list_get_nth(OSINFO_LIST(tmp), 0) == (OsinfoEntity*)product1); + g_assert_true(osinfo_list_get_nth(OSINFO_LIST(tmp), 1) == (OsinfoEntity*)product3); g_object_unref(tmp); g_date_free(date); @@ -148,10 +146,10 @@ START_TEST(test_supportdate) date = g_date_new_dmy(01, 01, 2000); osinfo_productfilter_add_support_date_constraint(filter, date); tmp = OSINFO_PRODUCTLIST(osinfo_list_new_filtered(OSINFO_LIST(products), OSINFO_FILTER(filter))); - fail_unless(osinfo_list_get_length(OSINFO_LIST(tmp)) == 3, "3 products"); - fail_unless(osinfo_list_get_nth(OSINFO_LIST(tmp), 0) == (OsinfoEntity*)product1, "Got product 1"); - fail_unless(osinfo_list_get_nth(OSINFO_LIST(tmp), 1) == (OsinfoEntity*)product2, "Got product 2"); - fail_unless(osinfo_list_get_nth(OSINFO_LIST(tmp), 2) == (OsinfoEntity*)product3, "Got product 3"); + g_assert_cmpint(osinfo_list_get_length(OSINFO_LIST(tmp)), ==, 3); + g_assert_true(osinfo_list_get_nth(OSINFO_LIST(tmp), 0) == (OsinfoEntity*)product1); + g_assert_true(osinfo_list_get_nth(OSINFO_LIST(tmp), 1) == (OsinfoEntity*)product2); + g_assert_true(osinfo_list_get_nth(OSINFO_LIST(tmp), 2) == (OsinfoEntity*)product3); g_object_unref(tmp); g_date_free(date); @@ -159,10 +157,10 @@ START_TEST(test_supportdate) date = g_date_new_dmy(01, 01, 2010); osinfo_productfilter_add_support_date_constraint(filter, date); tmp = OSINFO_PRODUCTLIST(osinfo_list_new_filtered(OSINFO_LIST(products), OSINFO_FILTER(filter))); - fail_unless(osinfo_list_get_length(OSINFO_LIST(tmp)) == 3, "3 products"); - fail_unless(osinfo_list_get_nth(OSINFO_LIST(tmp), 0) == (OsinfoEntity*)product1, "Got product 1"); - fail_unless(osinfo_list_get_nth(OSINFO_LIST(tmp), 1) == (OsinfoEntity*)product2, "Got product 2"); - fail_unless(osinfo_list_get_nth(OSINFO_LIST(tmp), 2) == (OsinfoEntity*)product3, "Got product 3"); + g_assert_cmpint(osinfo_list_get_length(OSINFO_LIST(tmp)), ==, 3); + g_assert_true(osinfo_list_get_nth(OSINFO_LIST(tmp), 0) == (OsinfoEntity*)product1); + g_assert_true(osinfo_list_get_nth(OSINFO_LIST(tmp), 1) == (OsinfoEntity*)product2); + g_assert_true(osinfo_list_get_nth(OSINFO_LIST(tmp), 2) == (OsinfoEntity*)product3); g_object_unref(tmp); g_date_free(date); @@ -170,11 +168,11 @@ START_TEST(test_supportdate) date = g_date_new_dmy(01, 05, 2005); osinfo_productfilter_add_support_date_constraint(filter, date); tmp = OSINFO_PRODUCTLIST(osinfo_list_new_filtered(OSINFO_LIST(products), OSINFO_FILTER(filter))); - fail_unless(osinfo_list_get_length(OSINFO_LIST(tmp)) == 4, "4 products"); - fail_unless(osinfo_list_get_nth(OSINFO_LIST(tmp), 0) == (OsinfoEntity*)product1, "Got product 1"); - fail_unless(osinfo_list_get_nth(OSINFO_LIST(tmp), 1) == (OsinfoEntity*)product2, "Got product 2"); - fail_unless(osinfo_list_get_nth(OSINFO_LIST(tmp), 2) == (OsinfoEntity*)product3, "Got product 3"); - fail_unless(osinfo_list_get_nth(OSINFO_LIST(tmp), 3) == (OsinfoEntity*)product4, "Got product 4"); + g_assert_cmpint(osinfo_list_get_length(OSINFO_LIST(tmp)), ==, 4); + g_assert_true(osinfo_list_get_nth(OSINFO_LIST(tmp), 0) == (OsinfoEntity*)product1); + g_assert_true(osinfo_list_get_nth(OSINFO_LIST(tmp), 1) == (OsinfoEntity*)product2); + g_assert_true(osinfo_list_get_nth(OSINFO_LIST(tmp), 2) == (OsinfoEntity*)product3); + g_assert_true(osinfo_list_get_nth(OSINFO_LIST(tmp), 3) == (OsinfoEntity*)product4); g_object_unref(tmp); g_date_free(date); @@ -185,27 +183,17 @@ START_TEST(test_supportdate) g_object_unref(filter); g_object_unref(products); } -END_TEST -static Suite * -product_suite(void) +int +main(int argc, char *argv[]) { - Suite *s = suite_create("Product"); - TCase *tc = tcase_create("Core"); - tcase_add_test(tc, test_basic); - tcase_add_test(tc, test_relproduct); - tcase_add_test(tc, test_supportdate); - suite_add_tcase(s, tc); - return s; -} + g_test_init(&argc, &argv, NULL); -int main(void) -{ - int number_failed; - Suite *s = product_suite(); - SRunner *sr = srunner_create(s); + g_test_add_func("/product/basic", test_basic); + g_test_add_func("/product/relproduct", test_relproduct); + g_test_add_func("/product/supportdate", test_supportdate); /* Make sure we catch unexpected g_warning() */ g_log_set_always_fatal(G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING); @@ -218,11 +206,7 @@ int main(void) osinfo_devicelist_get_type(); osinfo_filter_get_type(); - srunner_run_all(sr, CK_ENV); - number_failed = srunner_ntests_failed(sr); - srunner_free(sr); - - return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; + return g_test_run(); } /* * Local variables: diff --git a/tests/test-productfilter.c b/tests/test-productfilter.c index 239e1a4..021e45a 100644 --- a/tests/test-productfilter.c +++ b/tests/test-productfilter.c @@ -21,9 +21,7 @@ #include <config.h> -#include <stdlib.h> #include <osinfo/osinfo.h> -#include <check.h> /* OsinfoProduct is abstract, so we need to trivially subclass it to test it */ typedef struct _OsinfoDummy OsinfoDummy; @@ -51,62 +49,63 @@ static OsinfoProduct *osinfo_dummy_new(const gchar *id) { } -START_TEST(test_basic) +static void +test_basic(void) { OsinfoProductFilter *productfilter = osinfo_productfilter_new(); OsinfoProduct *product1 = osinfo_dummy_new("pretty"); OsinfoProduct *product2 = osinfo_dummy_new("ugly"); - fail_unless(OSINFO_IS_PRODUCTFILTER(productfilter), "ProductFilter is a productfilter object"); - fail_unless(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product1)), "ProductFilter matches PRODUCT"); + g_assert_true(OSINFO_IS_PRODUCTFILTER(productfilter)); + g_assert_true(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product1))); osinfo_productfilter_add_product_constraint(productfilter, OSINFO_PRODUCT_RELATIONSHIP_DERIVES_FROM, product1); GList *tmp = osinfo_productfilter_get_product_constraint_values(productfilter, OSINFO_PRODUCT_RELATIONSHIP_DERIVES_FROM); - fail_unless(tmp != NULL, "Unexpected missing PRODUCT"); - fail_unless(tmp->data == product1, "Derived PRODUCT is PRODUCT 1"); - fail_unless(tmp->next == NULL, "Too many derived PRODUCT"); + g_assert_nonnull(tmp); + g_assert_true(tmp->data == product1); + g_assert_null(tmp->next); g_list_free(tmp); tmp = osinfo_productfilter_get_product_constraint_values(productfilter, OSINFO_PRODUCT_RELATIONSHIP_CLONES); - fail_unless(tmp == NULL, "Unexpected cloned PRODUCT"); + g_assert_null(tmp); osinfo_productfilter_add_product_constraint(productfilter, OSINFO_PRODUCT_RELATIONSHIP_DERIVES_FROM, product2); tmp = osinfo_productfilter_get_product_constraint_values(productfilter, OSINFO_PRODUCT_RELATIONSHIP_DERIVES_FROM); - fail_unless(tmp != NULL, "Unexpected missing PRODUCT"); - fail_unless(tmp->data == product2, "Derived PRODUCT is PRODUCT 1"); - fail_unless(tmp->next != NULL, "Not enough derived PRODUCT"); - fail_unless(tmp->next->data == product1, "Derived PRODUCT is PRODUCT 1"); - fail_unless(tmp->next->next == NULL, "Too many derived PRODUCT"); + g_assert_nonnull(tmp); + g_assert_true(tmp->data == product2); + g_assert_nonnull(tmp->next); + g_assert_true(tmp->next->data == product1); + g_assert_null(tmp->next->next); g_list_free(tmp); osinfo_productfilter_add_product_constraint(productfilter, OSINFO_PRODUCT_RELATIONSHIP_UPGRADES, product1); tmp = osinfo_productfilter_get_product_constraint_values(productfilter, OSINFO_PRODUCT_RELATIONSHIP_UPGRADES); - fail_unless(tmp != NULL, "Unexpected missing PRODUCT"); - fail_unless(tmp->data == product1, "Derived PRODUCT is PRODUCT 1"); - fail_unless(tmp->next == NULL, "Too many derived PRODUCT"); + g_assert_nonnull(tmp); + g_assert_true(tmp->data == product1); + g_assert_null(tmp->next); g_list_free(tmp); osinfo_productfilter_add_product_constraint(productfilter, OSINFO_PRODUCT_RELATIONSHIP_CLONES, product1); tmp = osinfo_productfilter_get_product_constraint_values(productfilter, OSINFO_PRODUCT_RELATIONSHIP_CLONES); - fail_unless(tmp != NULL, "Unexpected missing PRODUCT"); - fail_unless(tmp->data == product1, "Derived PRODUCT is PRODUCT 1"); - fail_unless(tmp->next == NULL, "Too many derived PRODUCT"); + g_assert_nonnull(tmp); + g_assert_true(tmp->data == product1); + g_assert_null(tmp->next); g_list_free(tmp); g_object_unref(product2); g_object_unref(product1); g_object_unref(productfilter); } -END_TEST -START_TEST(test_productfilter_single) +static void +test_productfilter_single(void) { OsinfoProductFilter *productfilter = osinfo_productfilter_new(); OsinfoProduct *product1 = osinfo_dummy_new("hot"); @@ -119,10 +118,10 @@ START_TEST(test_productfilter_single) osinfo_product_add_related(product3, OSINFO_PRODUCT_RELATIONSHIP_DERIVES_FROM, product4); osinfo_productfilter_add_product_constraint(productfilter, OSINFO_PRODUCT_RELATIONSHIP_DERIVES_FROM, product2); - fail_unless(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product1)), "Filter matches PRODUCT 1"); - fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product2)), "Filter does not match PRODUCT 2"); - fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product3)), "Filter does not match PRODUCT 3"); - fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product4)), "Filter does not match PRODUCT 4"); + g_assert_true(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product1))); + g_assert_false(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product2))); + g_assert_false(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product3))); + g_assert_false(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product4))); g_object_unref(product1); g_object_unref(product2); @@ -130,10 +129,10 @@ START_TEST(test_productfilter_single) g_object_unref(product4); g_object_unref(productfilter); } -END_TEST -START_TEST(test_productfilter_multi) +static void +test_productfilter_multi(void) { OsinfoProductFilter *productfilter = osinfo_productfilter_new(); OsinfoProduct *product1 = osinfo_dummy_new("hot"); @@ -150,28 +149,28 @@ START_TEST(test_productfilter_multi) osinfo_productfilter_add_product_constraint(productfilter, OSINFO_PRODUCT_RELATIONSHIP_DERIVES_FROM, product2); osinfo_productfilter_add_product_constraint(productfilter, OSINFO_PRODUCT_RELATIONSHIP_CLONES, product5); - fail_unless(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product1)), "Filter matches PRODUCT 1"); - fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product2)), "Filter does not match PRODUCT 2"); - fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product3)), "Filter does not match PRODUCT 3"); - fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product4)), "Filter does not match PRODUCT 4"); - fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product5)), "Filter does not match PRODUCT 5"); + g_assert_true(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product1))); + g_assert_false(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product2))); + g_assert_false(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product3))); + g_assert_false(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product4))); + g_assert_false(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product5))); osinfo_productfilter_clear_product_constraint(productfilter, OSINFO_PRODUCT_RELATIONSHIP_CLONES); - fail_unless(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product1)), "Filter matches PRODUCT 1"); - fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product2)), "Filter does not match PRODUCT 2"); - fail_unless(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product3)), "Filter matches PRODUCT 3"); - fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product4)), "Filter does not match PRODUCT 4"); - fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product5)), "Filter does not match PRODUCT 5"); + g_assert_true(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product1))); + g_assert_false(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product2))); + g_assert_true(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product3))); + g_assert_false(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product4))); + g_assert_false(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product5))); osinfo_productfilter_clear_product_constraints(productfilter); osinfo_productfilter_add_product_constraint(productfilter, OSINFO_PRODUCT_RELATIONSHIP_UPGRADES, product5); - fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product1)), "Filter does not match PRODUCT 1"); - fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product2)), "Filter does not match PRODUCT 2"); - fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product3)), "Filter does not match PRODUCT 3"); - fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product4)), "Filter does not match PRODUCT 4"); - fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product5)), "Filter does not match PRODUCT 5"); + g_assert_false(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product1))); + g_assert_false(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product2))); + g_assert_false(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product3))); + g_assert_false(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product4))); + g_assert_false(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product5))); g_object_unref(product1); g_object_unref(product2); @@ -180,10 +179,10 @@ START_TEST(test_productfilter_multi) g_object_unref(product5); g_object_unref(productfilter); } -END_TEST -START_TEST(test_productfilter_combine) +static void +test_productfilter_combine(void) { OsinfoProductFilter *productfilter = osinfo_productfilter_new(); OsinfoProduct *product1 = osinfo_dummy_new("hot"); @@ -198,22 +197,22 @@ START_TEST(test_productfilter_combine) osinfo_entity_add_param(OSINFO_ENTITY(product3), "vendor", "acme"); osinfo_productfilter_add_product_constraint(productfilter, OSINFO_PRODUCT_RELATIONSHIP_DERIVES_FROM, product2); - fail_unless(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product1)), "Filter matches PRODUCT 1"); - fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product2)), "Filter does not match PRODUCT 2"); - fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product3)), "Filter does not match PRODUCT 3"); - fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product4)), "Filter does not match PRODUCT 4"); + g_assert_true(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product1))); + g_assert_false(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product2))); + g_assert_false(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product3))); + g_assert_false(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product4))); osinfo_filter_add_constraint(OSINFO_FILTER(productfilter), "vendor", "acme"); - fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product1)), "Filter does not match PRODUCT 1"); - fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product2)), "Filter does not match PRODUCT 2"); - fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product3)), "Filter does not match PRODUCT 3"); - fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product4)), "Filter does not match PRODUCT 4"); + g_assert_false(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product1))); + g_assert_false(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product2))); + g_assert_false(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product3))); + g_assert_false(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product4))); osinfo_productfilter_clear_product_constraint(productfilter, OSINFO_PRODUCT_RELATIONSHIP_DERIVES_FROM); - fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product1)), "Filter does not match PRODUCT 1"); - fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product2)), "Filter does not match PRODUCT 2"); - fail_unless(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product3)), "Filter matches PRODUCT 3"); - fail_unless(!osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product4)), "Filter does not match PRODUCT 4"); + g_assert_false(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product1))); + g_assert_false(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product2))); + g_assert_true(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product3))); + g_assert_false(osinfo_filter_matches(OSINFO_FILTER(productfilter), OSINFO_ENTITY(product4))); g_object_unref(product1); g_object_unref(product2); @@ -221,27 +220,17 @@ START_TEST(test_productfilter_combine) g_object_unref(product4); g_object_unref(productfilter); } -END_TEST -static Suite * -productfilter_suite(void) +int +main(int argc, char *argv[]) { - Suite *s = suite_create("ProductFilter"); - TCase *tc = tcase_create("Core"); - tcase_add_test(tc, test_basic); - tcase_add_test(tc, test_productfilter_single); - tcase_add_test(tc, test_productfilter_multi); - tcase_add_test(tc, test_productfilter_combine); - suite_add_tcase(s, tc); - return s; -} + g_test_init(&argc, &argv, NULL); -int main(void) -{ - int number_failed; - Suite *s = productfilter_suite(); - SRunner *sr = srunner_create(s); + g_test_add_func("/productfilter/basic", test_basic); + g_test_add_func("/productfilter/productfilter_single", test_productfilter_single); + g_test_add_func("/productfilter/productfilter_multi", test_productfilter_multi); + g_test_add_func("/productfilter/productfilter_combine", test_productfilter_combine); /* Make sure we catch unexpected g_warning() */ g_log_set_always_fatal(G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING); @@ -254,11 +243,7 @@ int main(void) osinfo_productfilter_get_type(); osinfo_product_get_type(); - srunner_run_all(sr, CK_ENV); - number_failed = srunner_ntests_failed(sr); - srunner_free(sr); - - return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; + return g_test_run(); } /* * Local variables: diff --git a/tests/test-treeuris.c b/tests/test-treeuris.c index defe3a7..e4bcdcc 100644 --- a/tests/test-treeuris.c +++ b/tests/test-treeuris.c @@ -21,10 +21,8 @@ #include <config.h> -#include <config.h> #include <stdlib.h> #include <osinfo/osinfo.h> -#include <check.h> #include <curl/curl.h> static void test_tree(OsinfoTreeList *treelist, GError **error, CURL *curl) @@ -43,14 +41,15 @@ static void test_tree(OsinfoTreeList *treelist, GError **error, CURL *curl) continue; } - g_print("%s\n", url); + g_test_message("%s", url); curl_easy_setopt(curl, CURLOPT_URL, url); res = curl_easy_perform(curl); if (res != CURLE_OK) { curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code); } - fail_unless(res == CURLE_OK, "Failed HEAD (res=%d, %s; code=%ld) on %s", res, curl_easy_strerror(res), response_code, url); + g_test_message("res=%d, %s; code=%ld", res, curl_easy_strerror(res), response_code); + g_assert_cmpint(res, ==, CURLE_OK); tmp = tmp->next; } @@ -58,7 +57,8 @@ static void test_tree(OsinfoTreeList *treelist, GError **error, CURL *curl) g_list_free(treeel); } -START_TEST(test_uris) +static void +test_uris(void) { CURL *curl; OsinfoLoader *loader = osinfo_loader_new(); @@ -81,11 +81,11 @@ START_TEST(test_uris) curl_easy_setopt(curl, CURLOPT_VERBOSE, debug_level > 0 ? 1L : 0L); } - fail_unless(OSINFO_IS_LOADER(loader), "Loader is not a LOADER"); - fail_unless(OSINFO_IS_DB(db), "Db is not a DB"); + g_assert_true(OSINFO_IS_LOADER(loader)); + g_assert_true(OSINFO_IS_DB(db)); osinfo_loader_process_default_path(loader, &error); - fail_unless(error == NULL, error ? error->message : "none"); + g_assert_no_error(error); oslist = osinfo_db_get_os_list(db); tmp = osel = osinfo_list_get_elements(OSINFO_LIST(oslist)); @@ -95,7 +95,7 @@ START_TEST(test_uris) test_tree(treelist, &error, curl); - fail_unless(error == NULL, error ? error->message : "none"); + g_assert_no_error(error); g_object_unref(treelist); tmp = tmp->next; @@ -109,27 +109,17 @@ START_TEST(test_uris) g_object_unref(loader); } -END_TEST -static Suite * -list_suite(void) +int +main(int argc, char *argv[]) { - Suite *s = suite_create("List"); - TCase *tc = tcase_create("Core"); - tcase_set_timeout(tc, 120); + int ret; - tcase_add_test(tc, test_uris); - suite_add_tcase(s, tc); - return s; -} + g_test_init(&argc, &argv, NULL); -int main(void) -{ - int number_failed; - Suite *s = list_suite(); - SRunner *sr = srunner_create(s); + g_test_add_func("/treeuris/uris", test_uris); /* Make sure we catch unexpected g_warning() */ g_log_set_always_fatal(G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING); @@ -150,13 +140,11 @@ int main(void) osinfo_oslist_get_type(); osinfo_filter_get_type(); - srunner_run_all(sr, CK_ENV); - number_failed = srunner_ntests_failed(sr); - srunner_free(sr); + ret = g_test_run(); curl_global_cleanup(); - return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; + return ret; } /* * Local variables: -- 2.13.6 _______________________________________________ Libosinfo mailing list Libosinfo@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libosinfo