/* * Copyright 2015 (c) Anna Schumaker. */ #include #include #ifdef CONFIG_TESTING static const char *str = "Enabled"; #else /* CONFIG_TESTING */ static const char *str = "Disabled"; #endif /* CONFIG_TESTING */ static unsigned int counter = 0; static unsigned int inc_counter() { return counter++; } static void test_passing_tests() { unsigned int i; test_equal(0, 0); test_equal("2", "2"); test_equal((void *)4, (void *)4); test_equal(str, "Enabled"); test_equal(inc_counter(), 0); test_equal((bool)true, (bool)true); for (i = 0; i < 10; i++) test_loop_equal(i, i, i); test_loop_passed(); test_not_equal(0, 1); test_not_equal("2", "3"); test_not_equal((void *)4, (void *)5); test_not_equal(str, "Disabled"); test_not_equal(inc_counter(), 2); test_not_equal((bool)true, (bool)false); for (i = 0; i < 10; i++) test_loop_not_equal(i, i + 1, i); test_loop_passed(); } static void test_failing_tests() { unsigned int i; test_equal(0, 1); test_equal("2", "3"); test_equal((void *)4, (void *)5); test_equal(str, "Disabled"); test_equal(inc_counter(), 3); test_equal((bool)true, (bool)false); for (i = 0; i < 10; i++) test_loop_equal(i, i + 1, i); test_loop_passed(); test_not_equal(0, 0); test_not_equal("2", "2"); test_not_equal((void *)4, (void *)4); test_not_equal(str, "Enabled"); test_not_equal(inc_counter(), 3); test_not_equal((bool)true, (bool)true); for (i = 0; i < 10; i++) test_loop_not_equal(i, i, i); test_loop_passed(); tests_failed = 0; } static void test_utilities() { gchar *dir = test_data_file(NULL); gchar *file = test_data_file("sanity"); const gchar *data = g_get_user_data_dir(); gchar *ddata = g_strjoin("/", data, "ocarina-test", NULL); gchar *fdata = g_strjoin("/", data, "ocarina-test", "sanity", NULL); test_equal(dir, ddata); test_equal(file, fdata); test_equal(test_data_file_exists(NULL), (bool)false); test_equal(test_data_file_exists("sanity"), (bool)false); g_free(dir); g_free(file); g_free(ddata); g_free(fdata); } DECLARE_UNIT_TESTS( UNIT_TEST("Sanity Check", test_passing_tests), UNIT_TEST("Sanity Check (All should fail)", test_failing_tests), UNIT_TEST("Sanity Check Utility Functions", test_utilities), );