static gboolean traverse_func (const char *path, const char *filename, gpointer data) { ol_test_expect (GPOINTER_TO_INT (data) == 123); gchar *fullpath = g_build_path (G_DIR_SEPARATOR_S, path, filename, NULL); ol_test_expect (g_file_test (fullpath, G_FILE_TEST_EXISTS)); g_free (fullpath); return TRUE; }
void test_string () { char *string = g_strdup ("Tiger Soldier"); char *strold = string; gboolean ret = ol_cmd_get_string ("echo Cmd test", &string); ol_test_expect (ret == TRUE); ol_test_expect (strcmp (string, "Cmd test\n") == 0); if (string) g_free (string); ol_test_expect (strcmp (strold, "Tiger Soldier") == 0); g_free (strold); }
void escape_test () { unlink (DB_FILE); ol_test_expect (ol_lrclib_init (DB_FILE)); char *path = NULL; char *ESCAPE_PATH = "p'a't'h"; OlMusicInfo *info = ol_music_info_new (); ol_music_info_set_uri (info, "U'R'I"); ol_music_info_set_title (info, "t'i't'l'e"); ol_music_info_set_artist (info, "a'r't'i's't"); ol_music_info_set_album (info, "a'l'b'u'm"); /* Music info with URI */ ol_test_expect (ol_lrclib_assign_lyric (info, ESCAPE_PATH) != 0); ol_test_expect (ol_lrclib_find (info, &path) != 0); ol_test_expect (strcmp (path, ESCAPE_PATH) == 0); g_free (path); ol_music_info_set_uri (info, NULL); ol_test_expect (ol_lrclib_find (info, &path) == 0); ol_test_expect (ol_lrclib_assign_lyric (info, ESCAPE_PATH) != 0); ol_test_expect (ol_lrclib_find (info, &path) != 0); ol_test_expect (strcmp (path, ESCAPE_PATH) == 0); g_free (path); ol_lrclib_unload (); unlink (DB_FILE); }
static void search_complete_cb (OlLyricSourceSearchTask *task, enum OlLyricSourceStatus status, GList *results, gpointer userdata) { printf ("search complete: "); print_status (status); ol_test_expect (status == (gsize)userdata); if (status == OL_LYRIC_SOURCE_STATUS_SUCCESS) { if (results) { test_download (OL_LYRIC_SOURCE_CANDIDATE (results->data)); test_download_cancel (OL_LYRIC_SOURCE_CANDIDATE (results->data)); } for (; results; results = results->next) { OlLyricSourceCandidate *candidate; candidate = OL_LYRIC_SOURCE_CANDIDATE (results->data); printf ("(%s)%s - %s - %s\n", ol_lyric_source_candidate_get_sourceid (candidate), ol_lyric_source_candidate_get_title (candidate), ol_lyric_source_candidate_get_artist (candidate), ol_lyric_source_candidate_get_album (candidate)); } } task_cnt--; check_quit (); }
void create_db_test () { unlink (DB_FILE); ol_test_expect (ol_lrclib_init (DB_FILE)); ol_lrclib_unload (); unlink (DB_FILE); }
void query_by_info_test () { unlink (DB_FILE); ol_test_expect (ol_lrclib_init (DB_FILE)); char *path = NULL; OlMusicInfo *info = prepare_music (); ol_music_info_set_uri (info, NULL); /* Music info with URI */ ol_test_expect (ol_lrclib_assign_lyric (info, PATH_NOURI) != 0); ol_test_expect (ol_lrclib_find (info, &path) != 0); ol_test_expect (strcmp (path, PATH_NOURI) == 0); g_free (path); ol_music_info_set_uri (info, URI); ol_test_expect (ol_lrclib_find (info, &path) != 0); ol_test_expect (strcmp (path, PATH_NOURI) == 0); g_free (path); ol_music_info_set_artist (info, "no artist"); ol_test_expect (ol_lrclib_find (info, &path) == 0); ol_lrclib_unload (); unlink (DB_FILE); }
void test_hashtable (void) { static const int INT_VALUE = 23840; static const char *STR_VALUE = "String Value"; static char *STRV_VALUE[] = { "Str1", "Str2", NULL, }; GHashTable *ht = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify)g_value_free); GValue *value = g_new0 (GValue, 1); g_value_init (value, G_TYPE_INT); g_value_set_int (value, INT_VALUE); g_hash_table_insert (ht, g_strdup ("int"), value); value = g_new0 (GValue, 1); g_value_init (value, G_TYPE_STRING); g_value_set_string (value, STR_VALUE); g_hash_table_insert (ht, g_strdup ("str"), value); value = g_new0 (GValue, 1); g_value_init (value, G_TYPE_STRV); g_value_set_boxed (value, STRV_VALUE); g_hash_table_insert (ht, g_strdup ("strv"), value); ol_test_expect (ol_get_int_from_hash_table (ht, "int") == INT_VALUE); ol_test_expect (strcmp (ol_get_string_from_hash_table (ht, "str"), STR_VALUE) == 0); ol_test_expect (g_strv_length (ol_get_str_list_from_hash_table (ht, "strv")) == g_strv_length (STRV_VALUE)); ol_test_expect (ol_get_int_from_hash_table (ht, "str") == -1); ol_test_expect (ol_get_int_from_hash_table (ht, "not_exists") == -1); ol_test_expect (ol_get_string_from_hash_table (ht, "int") == NULL); ol_test_expect (ol_get_string_from_hash_table (ht, "not_exists") == NULL); ol_test_expect (ol_get_str_list_from_hash_table (ht, "str") == NULL); ol_test_expect (ol_get_str_list_from_hash_table (ht, "not_exists") == NULL); g_hash_table_destroy (ht); }
static void download_complete_cb (OlLyricSourceDownloadTask *task, enum OlLyricSourceStatus status, const gchar *content, guint len, gpointer userdata) { printf ("download #%d complete: ", ol_lyric_source_task_get_id (OL_LYRIC_SOURCE_TASK (task))); print_status (status); ol_test_expect (status == (gsize)userdata); printf ("len: %u\n", len); printf ("%s\n", content); task_cnt--; check_quit (); }
void db_exist_test () { OlMusicInfo *info = prepare_music (); char *path = NULL; /* Music info with URI */ unlink (DB_FILE); ol_test_expect (ol_lrclib_init (DB_FILE)); ol_test_expect (ol_lrclib_find (info, &path) == 0); ol_test_expect (ol_lrclib_assign_lyric (info, PATH) != 0); ol_test_expect (ol_lrclib_find (info, &path) != 0); ol_test_expect (strcmp (path, PATH) == 0); g_free (path); ol_lrclib_unload (); ol_test_expect (ol_lrclib_init (DB_FILE)); ol_test_expect (ol_lrclib_find (info, &path) != 0); ol_test_expect (strcmp (path, PATH) == 0); g_free (path); ol_lrclib_unload (); unlink (DB_FILE); }
void basic_test () { int ret = ol_lrclib_init (DB_FILE); ol_test_expect (ret != 0); OlMusicInfo *info = prepare_music (); ol_test_expect (ol_lrclib_assign_lyric (info, PATH) != 0); char *path; ol_test_expect (ol_lrclib_find (info, &path) != 0); ol_test_expect (strcmp (path, PATH) == 0); g_free (path); ol_music_info_set_uri (info, "URI 2"); ol_test_expect (ol_lrclib_find (info, &path) == 0); printf ("path is: %s\n", path); ol_music_info_set_uri (info, NULL); ol_test_expect (ol_lrclib_assign_lyric (info, PATH_NOURI) != 0); ol_test_expect (ol_lrclib_find (info, &path) != 0); ol_test_expect (strcmp (path, PATH_NOURI) == 0); g_free (path); ol_lrclib_unload (); unlink (DB_FILE); }
void test_int () { int sum; const char *cmd = "expr 3 + 2"; const int ans = 5; gboolean ret = ol_cmd_get_int ("expr 3 + 2", &sum); ol_test_expect (ret == TRUE); ol_test_expect (sum == ans); ret = ol_cmd_get_int ("/home/", &sum); ol_test_expect (ret == FALSE); ol_test_expect (sum == ans); ret = ol_cmd_get_int ("pgrep init", &sum); ol_test_expect (ret == TRUE); ret = ol_cmd_get_int ("pgrep /asdf/", &sum); ol_test_expect (ret == FALSE); }
void test_null_string () { gboolean ret = ol_cmd_get_string ("ls", NULL); ol_test_expect (ret == TRUE); }
void assign_lrc_test () { unlink (DB_FILE); ol_test_expect (ol_lrclib_init (DB_FILE)); OlMusicInfo *info = prepare_music (); char *path = NULL; /* Music info with URI */ ol_test_expect (ol_lrclib_find (info, &path) == 0); ol_test_expect (ol_lrclib_assign_lyric (info, PATH) != 0); ol_test_expect (ol_lrclib_find (info, &path) != 0); ol_test_expect (strcmp (path, PATH) == 0); g_free (path); ol_music_info_set_title (info, NULL); ol_test_expect (ol_lrclib_find (info, &path) != 0); ol_test_expect (strcmp (path, PATH) == 0); g_free (path); ol_test_expect (ol_lrclib_assign_lyric (info, PATH2) != 0); ol_test_expect (ol_lrclib_find (info, &path) != 0); ol_test_expect (strcmp (path, PATH2) == 0); g_free (path); /* Music info without URI */ ol_music_info_destroy (info); info = prepare_music (); ol_music_info_set_uri (info, NULL); ol_test_expect (ol_lrclib_assign_lyric (info, PATH_NOURI) != 0); ol_test_expect (ol_lrclib_find (info, &path) != 0); ol_test_expect (strcmp (path, PATH_NOURI) == 0); g_free (path); ol_test_expect (ol_lrclib_assign_lyric (info, PATH_NOURI2) != 0); ol_test_expect (ol_lrclib_find (info, &path) != 0); ol_test_expect (strcmp (path, PATH_NOURI2) == 0); g_free (path); ol_test_expect (ol_lrclib_assign_lyric (info, NULL) != 0); ol_test_expect (ol_lrclib_find (info, &path) != 0); ol_test_expect (path == NULL); /* Music info with part of members */ ol_music_info_destroy (info); info = prepare_music (); ol_music_info_set_uri (info, NULL); ol_music_info_set_album (info, NULL); ol_test_expect (ol_lrclib_assign_lyric (info, PATH_NOALBUM) != 0); ol_test_expect (ol_lrclib_find (info, &path) != 0); ol_test_expect (strcmp (path, PATH_NOALBUM) == 0); g_free (path); ol_test_expect (ol_lrclib_assign_lyric (info, PATH_NOALBUM2) != 0); ol_test_expect (ol_lrclib_find (info, &path) != 0); ol_test_expect (strcmp (path, PATH_NOALBUM2) == 0); g_free (path); ol_test_expect (ol_lrclib_assign_lyric (info, NULL) != 0); ol_test_expect (ol_lrclib_find (info, &path) != 0); ol_test_expect (path == NULL); /* Music info with out title and uri */ ol_music_info_destroy (info); info = prepare_music (); ol_music_info_set_uri (info, NULL); ol_music_info_set_title (info, NULL); ol_test_expect (ol_lrclib_assign_lyric (info, NULL) == 0); ol_test_expect (ol_lrclib_find (info, &path) == 0); ol_lrclib_unload (); unlink (DB_FILE); }
void query_by_uri_test () { unlink (DB_FILE); ol_test_expect (ol_lrclib_init (DB_FILE)); OlMusicInfo *info = prepare_music (); char *path = NULL; /* Music info with URI */ ol_test_expect (ol_lrclib_assign_lyric (info, PATH) != 0); ol_test_expect (ol_lrclib_find (info, &path) != 0); ol_test_expect (strcmp (path, PATH) == 0); g_free (path); ol_music_info_set_title (info, ""); ol_test_expect (ol_lrclib_find (info, &path) != 0); ol_test_expect (strcmp (path, PATH) == 0); g_free (path); ol_music_info_set_artist (info, ""); ol_test_expect (ol_lrclib_find (info, &path) != 0); ol_test_expect (strcmp (path, PATH) == 0); g_free (path); ol_music_info_set_album (info, ""); ol_test_expect (ol_lrclib_find (info, &path) != 0); ol_test_expect (strcmp (path, PATH) == 0); g_free (path); ol_music_info_destroy (info); info = prepare_music (); ol_music_info_set_uri (info, URI2); ol_test_expect (ol_lrclib_find (info, &path) == 0); ol_music_info_set_uri (info, NULL); ol_test_expect (ol_lrclib_find (info, &path) == 0); ol_lrclib_unload (); unlink (DB_FILE); }