From 524d1886f981e26b6881f75112b1c8695876347f Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Fri, 25 Mar 2016 14:34:20 -0400 Subject: [PATCH] tests: Remove scons-based testing code Completes issue #4: Investigate CTest Signed-off-by: Anna Schumaker --- include/tests/gui.h | 46 -------- include/tests/test.h | 102 ----------------- tests/Music/.gitignore | 1 + tests/Music/CMakeLists.txt | 5 + tests/Music/Hyrule_Symphony.album | 16 --- tests/Music/Ocarina_of_Time.album | 38 ------- tests/Music/gen_tracks.sh | 47 -------- tests/Music/invalid_track | 1 - tests/core/.gitignore | 9 -- tests/core/playlists/.gitignore | 3 + tests/core/tags/.gitignore | 3 +- tests/gen_library.sh | 26 ----- tests/gui/idle.c | 1 - tests/gui/model.c | 1 + tests/gui/playlist.c | 1 - tests/gui/queue.c | 1 - tests/gui/sidebar.c | 1 - tests/gui/view.c | 1 - tests/gui/window.c | 1 - tests/sanity.c | 94 ---------------- tests/test.c | 177 ------------------------------ 21 files changed, 11 insertions(+), 564 deletions(-) delete mode 100644 include/tests/gui.h create mode 100644 tests/Music/.gitignore delete mode 100644 tests/Music/Hyrule_Symphony.album delete mode 100644 tests/Music/Ocarina_of_Time.album delete mode 100644 tests/Music/gen_tracks.sh delete mode 100644 tests/Music/invalid_track create mode 100644 tests/core/playlists/.gitignore delete mode 100755 tests/gen_library.sh delete mode 100644 tests/sanity.c delete mode 100644 tests/test.c diff --git a/include/tests/gui.h b/include/tests/gui.h deleted file mode 100644 index faadc97a..00000000 --- a/include/tests/gui.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2016 (c) Anna Schumaker. - */ -#ifndef TESTS_GUI_H -#define TESTS_GUI_H - -#ifdef TEST_NEED_AUDIO -void __audio_can_accel() {} -void __audio_favorite() {} -void __audio_hide() {} -void __audio_pause_changed() {} -void __audio_seek() {} - -void __artwork_select_cover() {} -#endif - -#ifdef TEST_NEED_SIDEBAR -void __sidebar_keypress() {} -void __sidebar_resize() {} -void __sidebar_selection_changed() {} -#endif /* TEST_NEED_SIDEBAR */ - -#ifdef TEST_NEED_COLLECTION -void __collection_add() {} -void __collection_choose() {} -#endif /* TEST_NEED_COLLECTION */ - -#ifdef TEST_NEED_PLAYLIST -void __playlist_keypress() {} -void __playlist_selection_changed() {} -#endif /* TEST_NEED_PLAYLIST */ - -#ifdef TEST_NEED_QUEUE -void __queue_disabled() {} -void __queue_filter() {} -void __queue_filter_how_changed() {} -void __queue_random() {} -void __queue_repeat() {} -#endif /* TEST_NEED_QUEUE */ - -#ifdef TEST_NEED_WINDOW -void __window_configure() {} -void __window_state() {} -#endif /* TEST_NEED_WINDOW */ - -#endif /* TESTS_GUI_H */ diff --git a/include/tests/test.h b/include/tests/test.h index a26ae9a2..73675e9c 100644 --- a/include/tests/test.h +++ b/include/tests/test.h @@ -4,12 +4,7 @@ #ifndef OCARINA_TESTS_TEST_H #define OCARINA_TESTS_TEST_H -#include #include -#include -#include -#include -#include #define g_assert_cmpstr_free(lhs, cmp, rhs) \ @@ -18,101 +13,4 @@ do { \ g_free(lhs); \ } while (0) - -#ifndef __cplusplus -static inline gchar *lutos(long unsigned int u) - { return g_strdup_printf("%lu", u); } -static inline gchar *stos(const char *s) { return g_strdup(s); } -static inline gchar *utos(unsigned int u) { return g_strdup_printf("%u", u); } -static inline gchar *ltos(long int l) { return g_strdup_printf("%lu", l); } -static inline gchar *itos(int i) { return g_strdup_printf("%i", i); } -static inline gchar *ftos(float f) { return g_strdup_printf("%f", f); } -static inline gchar *btos(bool b) { return g_strdup(b ? "true" : "false"); } -static inline gchar *ptos(void *p) { return g_strdup_printf("%p", p); } - - -#define tostring(x) (_Generic((x), \ - char *: stos, \ - const char *: stos, \ - unsigned char: utos, \ - bool: btos, \ - long unsigned int: lutos, \ - unsigned int: utos, \ - short unsigned int: utos, \ - long int: ltos, \ - int: itos, \ - float:ftos, \ - void *:ptos \ - ) (x)) -#endif /* __cplusplus */ - - -struct UnitTest { - const char *t_name; - void (*t_func)(); -}; - -extern struct UnitTest unit_tests[]; -extern unsigned int unit_tests_size;; - - -#define UNIT_TEST(name, func) \ - [__COUNTER__] = { \ - .t_name = name, \ - .t_func = func, \ - } - - -#define DECLARE_UNIT_TESTS(...) \ - struct UnitTest unit_tests[] = {\ - __VA_ARGS__ \ - }; \ - unsigned int unit_tests_size = __COUNTER__ - - -extern unsigned int tests_failed; -void test_strings_equal(gchar *, gchar *, unsigned int); -void test_strings_not_equal(gchar *, gchar *, unsigned int); -void loop_strings_equal(gchar *, gchar *, unsigned int, unsigned int); -void loop_strings_not_equal(gchar *, gchar *, unsigned int, unsigned int); - - -#define test_equal(lhs, rhs) \ - test_strings_equal(tostring(lhs), tostring(rhs), __LINE__) - -#define test_not_equal(lhs, rhs) \ - test_strings_not_equal(tostring(lhs), tostring(rhs), __LINE__) - -#define test_str_equal(lhs, rhs) \ - test_strings_equal(lhs, g_strdup(rhs), __LINE__) - -#define test_loop_equal(lhs, rhs, i) \ - if (1) { \ - loop_strings_equal(tostring(lhs), tostring(rhs), i, __LINE__); \ - if (tests_failed > 0) \ - break; \ - } - -#define test_loop_not_equal(lhs, rhs, i) \ - if (1) { \ - loop_strings_not_equal(tostring(lhs), tostring(rhs), i, __LINE__); \ - if (tests_failed > 0) \ - break; \ - } - -#define test_loop_str_equal(lhs, rhs, i) \ - if (1) { \ - loop_strings_equal(lhs, tostring(rhs), i, __LINE__); \ - if (tests_failed > 0) \ - break; \ - } - -#define test_loop_passed() \ - if (tests_failed == 0) \ - test_equal(tests_failed, 0) - - -gchar *test_data_file(const gchar *); -bool test_data_file_exists(const gchar *); - #endif /* OCARINA_TESTS_TEST_H */ diff --git a/tests/Music/.gitignore b/tests/Music/.gitignore new file mode 100644 index 00000000..b43af059 --- /dev/null +++ b/tests/Music/.gitignore @@ -0,0 +1 @@ +invalid_track diff --git a/tests/Music/CMakeLists.txt b/tests/Music/CMakeLists.txt index d201d69e..98e40d1a 100644 --- a/tests/Music/CMakeLists.txt +++ b/tests/Music/CMakeLists.txt @@ -95,3 +95,8 @@ gen_track(32 24 "Serenade of Water") gen_track(33 25 "Nocturne of Shadow") gen_track(34 23 "Prelude of Light") gen_track(35 27 "Requiem of Spirit") + +# +# Generate an invalid track +# +file(WRITE invalid_track "abcdefghijklmnopqrstuvwxyz") diff --git a/tests/Music/Hyrule_Symphony.album b/tests/Music/Hyrule_Symphony.album deleted file mode 100644 index 5ad2d556..00000000 --- a/tests/Music/Hyrule_Symphony.album +++ /dev/null @@ -1,16 +0,0 @@ -Koji Kondo -1998 Hyrule Symphony -Game -243 Title Theme -130 Kokiri Forest -227 Hyrule Field -130 Hyrule Castle -206 Lon Lon Ranch -186 Kakariko Village -178 Death Mountain -221 Zora's Domain -273 Gerudo Valley -66 Ganondorf -185 Princess Zelda -232 Ocarina Medley -288 The Legend of Zelda Medley diff --git a/tests/Music/Ocarina_of_Time.album b/tests/Music/Ocarina_of_Time.album deleted file mode 100644 index f0599af4..00000000 --- a/tests/Music/Ocarina_of_Time.album +++ /dev/null @@ -1,38 +0,0 @@ -Koji Kondo -1998 Ocarina of Time -Video Game -170 Title Theme -80 Deku Tree -46 Fairy Flying -71 House -112 Kokiri Forest -133 Shop -134 Battle -164 Inside the Deku Tree -153 Boss Battle -327 Hyrule Field Main Theme -103 Market -90 Hyrule Castle Courtyard -62 Ocarina Songs -101 Ocarina of Time -271 LonLon Ranch -204 Kakariko Village -75 Lost Woods -171 Zora's Domain -72 Great Fairy's Fountain -159 Temple of Time -124 Chamber of the Sages -98 Horse Race -193 Kakariko Village Orchestra -99 Windmill Hut -172 Gerudo Valley -147 Ganondorf Battle -191 Last Battle -34 Zelda's Ocarina -433 Staff Credits Theme -18 Minuet of Forest -24 Bolero of Fire -24 Serenade of Water -25 Nocturne of Shadow -23 Prelude of Light -27 Requiem of Spirit diff --git a/tests/Music/gen_tracks.sh b/tests/Music/gen_tracks.sh deleted file mode 100644 index 6adf8db8..00000000 --- a/tests/Music/gen_tracks.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash - -function check_cmd() -{ - echo -n "Checking for $1 ... " - CMD=$(which $1 2>/dev/null) - if [ $? != 0 ]; then - echo "$1 not found" - exit 1 - fi - echo $CMD -} -check_cmd ffmpeg -check_cmd vorbiscomment - -TRACK=1 -FFMPEG="ffmpeg -hide_banner -nostdin -f s16le -i /dev/zero -codec libvorbis -loglevel warning" - -while read -r line; do - if [ -z "$ARTIST" ]; then - ARTIST="$line" - elif [ -z "$ALBUM" ]; then - YEAR=$(echo "$line" | cut -f 1 -d ' ') - ALBUM=$(echo "$line" | cut -f 1 -d ' ' --complement) - mkdir -p "$ALBUM" - elif [ -z "$GENRE" ]; then - GENRE="$line" - else - LENGTH=$(echo "$line" | cut -f 1 -d ' ') - TITLE=$(echo "$line" | cut -f -1 -d ' ' --complement) - NUMBER=$(printf "%02d" $TRACK) - FILE="$ALBUM/$NUMBER - $TITLE.ogg" - - if [ ! -f "$FILE" ]; then - echo "$FILE" - $FFMPEG -t "$LENGTH" "$FILE" - vorbiscomment -w "$FILE" -t "TITLE=$TITLE" \ - -t "ARTIST=$ARTIST" \ - -t "ALBUM=$ALBUM" \ - -t "GENRE=$GENRE" \ - -t "DATE=$YEAR" \ - -t "TRACKNUMBER=$NUMBER" - fi - - let TRACK=$TRACK+1 - fi -done < $1 diff --git a/tests/Music/invalid_track b/tests/Music/invalid_track deleted file mode 100644 index b0883f38..00000000 --- a/tests/Music/invalid_track +++ /dev/null @@ -1 +0,0 @@ -abcdefghijklmnopqrstuvwxyz diff --git a/tests/core/.gitignore b/tests/core/.gitignore index 8835222e..babbbc68 100644 --- a/tests/core/.gitignore +++ b/tests/core/.gitignore @@ -4,15 +4,6 @@ file date idle database -tags/artist -tags/album -tags/genre -tags/library -tags/track queue -playlists/system -playlists/artist -playlists/library -playlist tempq audio diff --git a/tests/core/playlists/.gitignore b/tests/core/playlists/.gitignore new file mode 100644 index 00000000..14edbbf9 --- /dev/null +++ b/tests/core/playlists/.gitignore @@ -0,0 +1,3 @@ +system +artist +library diff --git a/tests/core/tags/.gitignore b/tests/core/tags/.gitignore index c343ba0d..45d5f601 100644 --- a/tests/core/tags/.gitignore +++ b/tests/core/tags/.gitignore @@ -1,6 +1,5 @@ -album artist -generic +album genre library track diff --git a/tests/gen_library.sh b/tests/gen_library.sh deleted file mode 100755 index b203919f..00000000 --- a/tests/gen_library.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash -# -# Copyright 2013 (c) Anna Schumaker. -# -# Generate a test library in /tmp -# - -# $1 - File, $2 - Directory number -function tag_file() -{ - artist="Artist $2" - album="Album $2" - let date=2008+$2 - vorbiscomment -w $1 -t "ARTIST=$artist" -t "ALBUM=$album" -t "DATE=$date" -} - - -mkdir -p /tmp/ocarina/dir{1..5} - -for i in $(seq 5); do - cp tests/Music/*.ogg /tmp/ocarina/dir$i/ - - for f in /tmp/ocarina/dir$i/*; do - tag_file $f $i - done -done diff --git a/tests/gui/idle.c b/tests/gui/idle.c index 1a88fea7..be14b783 100644 --- a/tests/gui/idle.c +++ b/tests/gui/idle.c @@ -7,7 +7,6 @@ #include #include #include -#include #include static const unsigned int N = 100; diff --git a/tests/gui/model.c b/tests/gui/model.c index 65f0b9ba..65a2deea 100644 --- a/tests/gui/model.c +++ b/tests/gui/model.c @@ -8,6 +8,7 @@ #include #include #include +#include unsigned int count_insert = 0; unsigned int count_delete = 0; diff --git a/tests/gui/playlist.c b/tests/gui/playlist.c index c7f372ed..96bbdc78 100644 --- a/tests/gui/playlist.c +++ b/tests/gui/playlist.c @@ -7,7 +7,6 @@ #include #include #include -#include #include struct core_init_data init_data; diff --git a/tests/gui/queue.c b/tests/gui/queue.c index eea8ce8a..edd0953b 100644 --- a/tests/gui/queue.c +++ b/tests/gui/queue.c @@ -7,7 +7,6 @@ #include #include #include -#include #include static void *test_queue_init(struct queue *queue, void *data) diff --git a/tests/gui/sidebar.c b/tests/gui/sidebar.c index 0776a279..16861fe4 100644 --- a/tests/gui/sidebar.c +++ b/tests/gui/sidebar.c @@ -4,7 +4,6 @@ #include #include #include -#include #include static void test_sidebar() diff --git a/tests/gui/view.c b/tests/gui/view.c index b33fdc15..3f59eaf6 100644 --- a/tests/gui/view.c +++ b/tests/gui/view.c @@ -9,7 +9,6 @@ #include #include #include -#include #include const gchar *QUEUE_SETTINGS[Q_MODEL_N_COLUMNS] = { diff --git a/tests/gui/window.c b/tests/gui/window.c index d6f6e748..cb91f370 100644 --- a/tests/gui/window.c +++ b/tests/gui/window.c @@ -5,7 +5,6 @@ #include #include #include -#include #include GMainLoop *main_loop; diff --git a/tests/sanity.c b/tests/sanity.c deleted file mode 100644 index e15aac20..00000000 --- a/tests/sanity.c +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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), -); diff --git a/tests/test.c b/tests/test.c deleted file mode 100644 index db733d0f..00000000 --- a/tests/test.c +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright 2015 (c) Anna Schumaker. - */ -#include -#include -#include -#include - - -static unsigned int test_num; -unsigned int tests_failed = 0; - - -static void test_print_result(bool passed, unsigned int line) -{ - printf("\t%u: ", test_num++); - if (passed) - printf("Success!\n"); - else { - printf("Failed at line %u.\n", line); - tests_failed++; - } -} - -static void test_loop_print_result(bool passed, unsigned int i, - unsigned int line) -{ - if (!passed) { - printf("\t%u: ", test_num++); - printf("Failed loop at line: %u (i = %u)\n", line, i); - tests_failed++; - } -} - -static void test_equal_common(gchar *lhs, gchar *rhs, bool passed) -{ - if (!passed) { - printf("\t\t Actual: %s\n", lhs); - printf("\t\tExpected: %s\n", rhs); - } - g_free(lhs); - g_free(rhs); -} - -static void test_not_equal_common(gchar *lhs, gchar *rhs, bool passed) -{ - if (!passed) - printf("\t\tUnexpected: %s\n", lhs); - g_free(lhs); - g_free(rhs); -} - -/* - * lhs and rhs should be newly allocated strings so we can - * free them in test{_not}_equal_common(). - */ -void test_strings_equal(gchar *lhs, gchar *rhs, unsigned int line) -{ - bool passed = strcmp(lhs, rhs) == 0; - - test_print_result(passed, line); - test_equal_common(lhs, rhs, passed); -} - -void test_strings_not_equal(gchar *lhs, gchar *rhs, unsigned int line) -{ - bool passed = strcmp(lhs, rhs) != 0; - - test_print_result(passed, line); - test_not_equal_common(lhs, rhs, passed); -} - -void loop_strings_equal(gchar *lhs, gchar *rhs, unsigned int i, - unsigned int line) -{ - bool passed = strcmp(lhs, rhs) == 0; - - test_loop_print_result(passed, i, line); - test_equal_common(lhs, rhs, passed); -} - -void loop_strings_not_equal(gchar *lhs, gchar *rhs, unsigned int i, - unsigned int line) -{ - bool passed = strcmp(lhs, rhs) != 0; - - test_loop_print_result(passed, i, line); - test_not_equal_common(lhs, rhs, passed); -} - -static void run_test(struct UnitTest *test) -{ - test_num = 0; - - if (!test->t_name || !test->t_func) - return; - - printf("Testing %s\n", test->t_name); - test->t_func(); - printf("\n"); - - if (tests_failed > 0) - printf("\n%u tests failed =(\n\n", tests_failed); -} - -gchar *test_data_file(const gchar *name) -{ - return g_strjoin("/", g_get_user_data_dir(), "ocarina-test", name, NULL); -} - -gchar *test_cache_file(const gchar *name) -{ - return g_strjoin("/", g_get_user_cache_dir(), "ocarina-test", name, NULL); -} - -bool test_data_file_exists(const gchar *name) -{ - GFileTest test = G_FILE_TEST_EXISTS; - gchar *dir; - bool ret; - - if (!name) - test = G_FILE_TEST_IS_DIR; - - dir = g_strjoin("/", g_get_user_data_dir(), "ocarina-test", name, NULL); - ret = g_file_test(dir, test); - g_free(dir); - return ret; -} - -static void test_rm_dir(const gchar *path) -{ - const gchar *file = NULL; - GDir *dir = g_dir_open(path, 0, NULL); - - if (!dir) - return; - - while ((file = g_dir_read_name(dir)) != NULL) { - gchar *fullpath = g_strjoin("/", path, file, NULL); - if (g_file_test(fullpath, G_FILE_TEST_IS_DIR)) - test_rm_dir(fullpath); - g_remove(fullpath); - g_free(fullpath); - } - - g_dir_close(dir); - g_rmdir(path); -} - -static void test_rm_dirs() -{ - gchar *data = test_data_file(NULL); - gchar *cache = test_cache_file(NULL); - - test_rm_dir(data); - test_rm_dir(cache); - - g_free(data); - g_free(cache); -} - -int main(int argc, char **argv) -{ - unsigned int i; - - if (test_data_file_exists(NULL)) - test_rm_dirs(); - - for (i = 0; i < unit_tests_size; i++) { - run_test(&unit_tests[i]); - if (tests_failed != 0) - break; - } - printf("\n"); - return tests_failed; -}