static void run_performance_tests (xmmsv_t *databases, xmmsv_t *testcases, gint format) { xmmsv_list_iter_t *it; xmmsv_get_list_iter (databases, &it); while (xmmsv_list_iter_valid (it)) { xmms_medialib_t *medialib; const gchar *filename; xmmsv_list_iter_entry_string (it, &filename); if (format == FORMAT_PRETTY) g_print ("Running suite with: %s\n", filename); xmms_ipc_init (); xmms_config_init ("memory://"); xmms_config_property_register ("medialib.path", filename, NULL, NULL); medialib = xmms_medialib_init (); if (medialib == NULL) { g_print ("Could not open database: %s (%d)\n", filename, s4_errno ()); exit (EXIT_FAILURE); } run_tests (medialib, testcases, run_performance_test, format, filename); xmms_object_unref (medialib); xmms_config_shutdown (); xmms_ipc_shutdown (); xmmsv_list_iter_next (it); } }
/** * @internal Load the xmms2d configuration file. Creates the config directory * if needed. */ static void load_config (void) { gchar configdir[PATH_MAX]; if (!conffile) { conffile = XMMS_BUILD_PATH ("xmms2.conf"); } g_assert (strlen (conffile) <= XMMS_MAX_CONFIGFILE_LEN); if (!xmms_userconfdir_get (configdir, sizeof (configdir))) { xmms_log_error ("Could not get path to config dir"); } else if (!g_file_test (configdir, G_FILE_TEST_IS_DIR)) { g_mkdir_with_parents (configdir, 0755); } xmms_config_init (conffile); }
/** * Unit test predicate */ static void run_unit_test (xmms_medialib_t *mlib, const gchar *name, xmmsv_t *content, xmmsv_coll_t *coll, xmmsv_t *specification, xmmsv_t *expected, gint format, const gchar *datasetname) { gboolean matches, ordered = FALSE; xmmsv_t *ret, *value; xmms_error_t err; xmms_medialib_t *medialib; xmms_medialib_session_t *session; g_debug ("Running test: %s", name); xmms_ipc_init (); xmms_config_init ("memory://"); xmms_config_property_register ("medialib.path", "memory://", NULL, NULL); medialib = xmms_medialib_init (); populate_medialib (medialib, content); session = xmms_medialib_session_begin (medialib); ret = xmms_medialib_query (session, coll, specification, &err); xmms_medialib_session_commit (session); xmmsv_dict_get (expected, "result", &value); xmmsv_dict_entry_get_int (expected, "ordered", &ordered); if (ordered) { matches = xmmsv_compare (ret, value); } else { matches = xmmsv_compare_unordered (ret, value); } if (matches) { if (format == FORMAT_CSV) { g_print ("\"%s\", 1\n", name); } else { g_print ("............................................................ Success!"); g_print ("\r%s \n", name); } } else { if (format == FORMAT_CSV) { g_print ("\"%s\", 0\n", name); } else { g_print ("............................................................ Failure!"); g_print ("\r%s \n", name); } g_printerr ("The result: "); xmmsv_dump (ret); g_printerr ("Does not equal: "); xmmsv_dump (value); } xmmsv_unref (ret); xmms_object_unref (medialib); xmms_config_shutdown (); xmms_ipc_shutdown (); }
/** * Unit test predicate */ static gboolean run_unit_test (xmms_medialib_t *mlib, const gchar *name, xmmsv_t *content, xmmsv_t *coll, xmmsv_t *specification, xmmsv_t *expected, gint format, const gchar *datasetname) { gboolean matches, ordered = FALSE; xmmsv_t *ret, *value; xmms_medialib_t *medialib; xmms_coll_dag_t *dag; gint status; g_debug ("Running test: %s", name); xmms_ipc_init (); xmms_config_init ("memory://"); xmms_config_property_register ("medialib.path", "memory://", NULL, NULL); medialib = xmms_medialib_init (); dag = xmms_collection_init (medialib); populate_medialib (medialib, content); memory_status_calibrate (name); ret = XMMS_IPC_CALL (dag, XMMS_IPC_CMD_QUERY, xmmsv_ref (coll), xmmsv_ref (specification)); status = memory_status_verify (name); xmmsv_dict_get (expected, "result", &value); xmmsv_dict_entry_get_int (expected, "ordered", &ordered); if (!xmmsv_is_type (ret, XMMSV_TYPE_ERROR)) { if (ordered) { matches = xmmsv_compare (ret, value); } else { matches = xmmsv_compare_unordered (ret, value); } } else { matches = FALSE; } if (matches && status == MEMORY_OK) { if (format == FORMAT_CSV) { g_print ("\"%s\", 1\n", name); } else { g_print ("............................................................ Success!"); g_print ("\r%s \n", name); } } else { if (format == FORMAT_CSV) { g_print ("\"%s\", 0\n", name); } else { g_print ("............................................................ Failure!"); if (status & MEMORY_LEAK) { g_print (" Memory Leaks!"); } if (status & MEMORY_ERROR) { g_print (" Memory errors!"); } g_print ("\r%s \n", name); } if (!matches) { g_printerr ("The result:\n"); xmmsv_dump (ret); g_printerr ("Does not equal:\n"); xmmsv_dump (value); } } xmmsv_unref (ret); xmms_object_unref (medialib); xmms_object_unref (dag); xmms_config_shutdown (); xmms_ipc_shutdown (); return matches && status == MEMORY_OK; }