END_TEST START_TEST (uri_parse_scheme_test) { int res; const char *uri; char *host = NULL, *path = NULL, *username = NULL, *password = NULL; unsigned int port = 0; pr_table_t *params = NULL; params = pr_table_alloc(p, 1); mark_point(); uri = "foo"; res = sqlconf_uri_parse(p, uri, &host, &port, &path, &username, &password, params); fail_unless(res < 0, "Failed to handle invalid URI '%s'", uri); fail_unless(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL, strerror(errno), errno); mark_point(); uri = "foobarbaz"; res = sqlconf_uri_parse(p, uri, &host, &port, &path, &username, &password, params); fail_unless(res < 0, "Failed to handle invalid URI '%s'", uri); fail_unless(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL, strerror(errno), errno); mark_point(); uri = "sql://"; res = sqlconf_uri_parse(p, uri, &host, &port, &path, &username, &password, params); fail_unless(res < 0, "Failed to handle invalid URI '%s'", uri); fail_unless(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL, strerror(errno), errno); pr_table_free(params); }
END_TEST START_TEST(tc_buffer_clear) { const char append_buf[] = {'1', '2', '3', '4', '5'}; size_t bsize; achat_rc rc; rc = acc_bufferinit(buffer); fail_if(rc != ACHAT_RC_OK, "Failed to initialize buffer, rc = %i", rc); mark_point(); /* Make sure length of append_buf is really smaller */ /* than ACHAT_BUFFER_DEFAULTSZ */ fail_if(sizeof(append_buf) > ACHAT_BUFFER_DEFAULTSZ, "len(append_buf) > ACHAT_BUFFER_DEFAULTSZ"); mark_point(); rc = acc_bufferappend(buffer, append_buf, sizeof(append_buf)); fail_if(rc != ACHAT_RC_OK, "Failed to append to buffer, rc = %i", rc); mark_point(); rc = acc_bufferclear(buffer); fail_if(rc != ACHAT_RC_OK, "Failed to clear the buffer, rc = %i", rc); bsize = acc_bufferlen(buffer); fail_if(bsize != 0, "Length of buffer is wrong, is %i but 0 expected", bsize); mark_point(); rc = acc_bufferfree(buffer); fail_if(rc != ACHAT_RC_OK, "Failed to free the buffer, rc = %i", rc); mark_point(); }
END_TEST START_TEST(tc_core_blocking) { struct achat_channel *c = NULL; achat_rc rc = ACHAT_RC_ERROR; c = acc_create(); fail_if(c == NULL, "couldn't create channel"); mark_point(); rc = acc_setblockingmode(c, ACC_BLOCKING); fail_if(rc != ACHAT_RC_OK, "acc_setblockingmode failed with rc=%d", rc); fail_if(c->blocking != ACC_BLOCKING, "blocking not set correctly"); mark_point(); rc = acc_setblockingmode(c, ACC_NON_BLOCKING); fail_if(rc != ACHAT_RC_OK, "acc_setblockingmode failed with rc=%d", rc); fail_if(c->blocking != ACC_NON_BLOCKING, "blocking not set correctly"); mark_point(); rc = acc_setblockingmode(c, -1); fail_if(rc != ACHAT_RC_INVALPARAM, "blockingmode expected to fail with rc=%d but returned rc=%d", ACHAT_RC_INVALPARAM, rc); mark_point(); rc = acc_setblockingmode(c, 2); fail_if(rc != ACHAT_RC_INVALPARAM, "blockingmode expected to fail with rc=%d but returned rc=%d", ACHAT_RC_INVALPARAM, rc); mark_point(); rc = acc_destroy(c); fail_if(rc != ACHAT_RC_OK, "destroy failed with rc=%d", rc); }
END_TEST START_TEST (tls_sess_free_test) { int res; res = proxy_tls_sess_free(NULL); fail_unless(res < 0, "Failed to handle null pool"); fail_unless(errno == EINVAL, "Expected EINVAL (%d), got '%s' (%d)", EINVAL, strerror(errno), errno); mark_point(); res = proxy_tls_sess_free(p); fail_unless(res == 0, "Failed to release TLS API session resources: %s", strerror(errno)); }
END_TEST START_TEST(tc_buffer_consume_empty) { size_t bsize; achat_rc rc; rc = acc_bufferinit(buffer); fail_if(rc != ACHAT_RC_OK, "Failed to initialize buffer, rc = %i", rc); mark_point(); rc = acc_bufferconsume(buffer, 42); fail_if(rc != ACHAT_RC_ERROR, "An error was expected, rc = %i", rc); bsize = acc_bufferlen(buffer); fail_if(bsize != 0, "Length of buffer is wrong, is %i but 0 expected", bsize); mark_point(); rc = acc_bufferfree(buffer); fail_if(rc != ACHAT_RC_OK, "Failed to free the buffer, rc = %i", rc); mark_point(); }
static void start_playerendpoint (void) { GstElement *pipeline = gst_pipeline_new (NULL); GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); GstElement *playerendpoint = gst_element_factory_make ("playerendpoint", NULL); GMainLoop *loop = g_main_loop_new (NULL, TRUE); g_object_set (G_OBJECT (pipeline), "async-handling", TRUE, NULL); gst_bus_add_signal_watch (bus); g_signal_connect (bus, "message", G_CALLBACK (bus_msg), pipeline); g_signal_connect (G_OBJECT (playerendpoint), "eos", G_CALLBACK (playerendpoint_eos), loop); g_object_set (G_OBJECT (playerendpoint), "uri", "http://ci.kurento.com/downloads/small.webm", NULL); gst_bin_add (GST_BIN (pipeline), playerendpoint); gst_element_set_state (pipeline, GST_STATE_PLAYING); mark_point (); g_object_set (G_OBJECT (playerendpoint), "state", KMS_URI_END_POINT_STATE_START, NULL); mark_point (); g_main_loop_run (loop); mark_point (); gst_element_set_state (pipeline, GST_STATE_NULL); gst_bus_remove_signal_watch (bus); g_object_unref (bus); g_main_loop_unref (loop); g_object_unref (pipeline); }
END_TEST START_TEST (localtime_test) { struct tm *res; time_t now; mark_point(); res = pr_localtime(NULL, NULL); fail_unless(res == NULL, "Failed to handle null arguments"); fail_unless(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL, strerror(errno), errno); time(&now); mark_point(); res = pr_localtime(NULL, &now); fail_unless(res != NULL, "Failed to handle %lu: %s", (unsigned long) now, strerror(errno)); mark_point(); res = pr_localtime(p, &now); fail_unless(res != NULL, "Failed to handle %lu: %s", (unsigned long) now, strerror(errno)); }
GST_END_TEST GST_START_TEST (delay_stream) { GMainLoop *loop = g_main_loop_new (NULL, TRUE); GstElement *pipeline = gst_pipeline_new (__FUNCTION__); GstElement *agnosticbin = gst_element_factory_make ("agnosticbin", "agnosticbin"); GstElement *fakesink = gst_element_factory_make ("fakesink", NULL); GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); gst_bus_add_signal_watch (bus); g_signal_connect (bus, "message", G_CALLBACK (bus_msg), pipeline); g_object_set (G_OBJECT (fakesink), "async", FALSE, "sync", FALSE, "signal-handoffs", TRUE, NULL); g_signal_connect (G_OBJECT (fakesink), "handoff", G_CALLBACK (fakesink_hand_off), loop); gst_bin_add_many (GST_BIN (pipeline), agnosticbin, fakesink, NULL); gst_element_link (agnosticbin, fakesink); gst_element_set_state (pipeline, GST_STATE_PLAYING); g_timeout_add_seconds (1, link_source, pipeline); g_timeout_add_seconds (11, timeout_check, pipeline); mark_point (); g_main_loop_run (loop); mark_point (); gst_element_set_state (pipeline, GST_STATE_NULL); gst_bus_remove_signal_watch (bus); g_object_unref (pipeline); g_object_unref (bus); g_main_loop_unref (loop); }
/* * check if we can connect a src machine to a sink while playing */ static void test_bt_setup_dynamic_add_src (BT_TEST_ARGS) { BT_TEST_START; GST_INFO ("-- arrange --"); BtSequence *sequence = (BtSequence *) check_gobject_get_object_property (song, "sequence"); BtMachine *sink = BT_MACHINE (bt_sink_machine_new (song, "master", NULL)); BtMachine *gen1 = BT_MACHINE (bt_source_machine_new (song, "gen1", "audiotestsrc", 0L, NULL)); bt_wire_new (song, gen1, sink, NULL); GstElement *element1 = (GstElement *) check_gobject_get_object_property (gen1, "machine"); g_object_set (sequence, "length", 64L, "loop", TRUE, NULL); bt_sequence_add_track (sequence, gen1, -1); g_object_set (element1, "wave", /* silence */ 4, NULL); bt_machine_set_param_defaults (gen1); /* play the song */ if (bt_song_play (song)) { mark_point (); check_run_main_loop_until_playing_or_error (song); GST_DEBUG ("song plays"); BtMachine *gen2 = BT_MACHINE (bt_source_machine_new (song, "gen2", "audiotestsrc", 0L, NULL)); GstElement *element2 = (GstElement *) check_gobject_get_object_property (gen2, "machine"); g_object_set (element2, "wave", /* silence */ 4, NULL); bt_machine_set_param_defaults (gen2); bt_wire_new (song, gen2, sink, NULL); gst_object_unref (element2); g_usleep (G_USEC_PER_SEC / 10); /* stop the song */ bt_song_stop (song); } else { fail ("playing of song failed"); } GST_INFO ("-- cleanup --"); g_object_unref (sequence); BT_TEST_END; }
} END_TEST START_TEST(register_1_3_2_1) { nua_handle_t *nh = nua_handle(nua, NULL, TAG_END()); S2_CASE("1.3.2.1", "Register behind NAT", "Authenticate, outbound activated"); mark_point(); s2->registration->nh = nh; make_auth_natted_register(nh, NUTAG_PROXY(s2sip->tcp.contact->m_url), TAG_END()); fail_if(!tport_is_tcp(s2->registration->tport)); s2_register_teardown(); }
END_TEST START_TEST (strtime2_test) { const char *res; char *expected; time_t now; mark_point(); now = 0; expected = "Thu Jan 01 00:00:00 1970"; res = pr_strtime2(now, TRUE); fail_unless(res != NULL, "Failed to convert time %lu: %s", (unsigned long) now, strerror(errno)); fail_unless(strcmp(res, expected) == 0, "Expected '%s', got '%s'", expected, res); }
GST_END_TEST GST_START_TEST (static_link) { GMainLoop *loop = g_main_loop_new (NULL, TRUE); GstElement *pipeline = gst_pipeline_new (__FUNCTION__); GstElement *videotestsrc = gst_element_factory_make ("videotestsrc", NULL); GstElement *fakesink = gst_element_factory_make ("fakesink", NULL); GstElement *agnosticbin = gst_element_factory_make ("agnosticbin", NULL); GstElement *decoder = gst_element_factory_make ("vp8dec", NULL); GstElement *fakesink2 = gst_element_factory_make ("fakesink", NULL); gboolean ret; GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); g_object_set (G_OBJECT (pipeline), "async-handling", TRUE, NULL); g_object_set (G_OBJECT (videotestsrc), "is-live", TRUE, NULL); gst_bus_add_signal_watch (bus); g_signal_connect (bus, "message", G_CALLBACK (bus_msg), pipeline); g_object_set (G_OBJECT (fakesink2), "sync", FALSE, "signal-handoffs", TRUE, NULL); g_signal_connect (G_OBJECT (fakesink2), "handoff", G_CALLBACK (fakesink_hand_off), loop); mark_point (); gst_bin_add_many (GST_BIN (pipeline), videotestsrc, agnosticbin, fakesink, decoder, fakesink2, NULL); mark_point (); ret = gst_element_link_many (videotestsrc, agnosticbin, fakesink, NULL); fail_unless (ret); mark_point (); ret = gst_element_link_many (agnosticbin, decoder, fakesink2, NULL); fail_unless (ret); mark_point (); gst_element_set_state (pipeline, GST_STATE_PLAYING); mark_point (); g_timeout_add_seconds (10, timeout_check, pipeline); mark_point (); g_main_loop_run (loop); mark_point (); gst_element_set_state (pipeline, GST_STATE_NULL); gst_bus_remove_signal_watch (bus); g_object_unref (bus); g_object_unref (pipeline); g_main_loop_unref (loop); }
static void set_up(void) { (void) unlink(db_test_table); if (p == NULL) { p = permanent_pool = make_sub_pool(NULL); session.c = NULL; session.notes = NULL; } if (getenv("TEST_VERBOSE") != NULL) { pr_trace_set_levels("proxy.db", 1, 20); } mark_point(); proxy_db_init(p); }
END_TEST START_TEST(tc_buffer_add2_lt_defaultsz) { const char append_buf1[] = {'1', '2', '3', '4', '5'}; const char append_buf2[] = {'6', '7', '8', '9', '0'}; const int sz_buf1 = sizeof(append_buf1); const int sz_buf2 = sizeof(append_buf2); size_t bsize; void *buf; achat_rc rc; rc = acc_bufferinit(buffer); fail_if(rc != ACHAT_RC_OK, "Failed to initialize buffer, rc = %i", rc); mark_point(); /* Make sure length of append_buf1/2 is really smaller */ /* than ACHAT_BUFFER_DEFAULTSZ */ fail_if(sz_buf1 + sz_buf2 > ACHAT_BUFFER_DEFAULTSZ, "len(append_buf) > ACHAT_BUFFER_DEFAULTSZ"); mark_point(); rc = acc_bufferappend(buffer, append_buf1, sz_buf1); fail_if(rc != ACHAT_RC_OK, "Failed to append to buffer, rc = %i", rc); mark_point(); rc = acc_bufferappend(buffer, append_buf2, sz_buf2); fail_if(rc != ACHAT_RC_OK, "Failed to append to buffer, rc = %i", rc); mark_point(); bsize = acc_bufferlen(buffer); fail_if(bsize != sz_buf1 + sz_buf2, "Length of buffer is wrong, is %i but %i expected", bsize, sz_buf1 + sz_buf2); mark_point(); buf = acc_bufferptr(buffer); fail_if(memcmp(buf, append_buf1, sz_buf1) != 0, "Unexpected content of buffer"); fail_if(memcmp(buf + sz_buf1, append_buf2, sz_buf2) != 0, "Unexpected content of buffer"); mark_point(); rc = acc_bufferfree(buffer); fail_if(rc != ACHAT_RC_OK, "Failed to free the buffer, rc = %i", rc); mark_point(); }
} END_TEST START_TEST(register_1_2_3) { nua_handle_t *nh; struct message *m; S2_CASE("1.2.3", "Register behind NAT", "Outbound activated by error response"); nh = nua_handle(nua, NULL, TAG_END()); nua_register(nh, TAG_END()); mark_point(); m = s2_sip_wait_for_request(SIP_METHOD_REGISTER); fail_if(!m); fail_if(!m->sip->sip_contact || m->sip->sip_contact->m_next); s2_sip_respond_to(m, NULL, 400, "Bad Contact", SIPTAG_VIA(natted_via(m, receive_natted)), TAG_END()); s2_sip_free_message(m); fail_unless_event(nua_r_register, 100); m = s2_sip_wait_for_request(SIP_METHOD_REGISTER); fail_if(!m); s2_save_register(m); s2_sip_respond_to(m, NULL, SIP_200_OK, SIPTAG_CONTACT(s2->registration->contact), SIPTAG_VIA(natted_via(m, receive_natted)), TAG_END()); s2_sip_free_message(m); fail_unless(s2->registration->contact != NULL); fail_if(s2->registration->contact->m_next != NULL); fail_unless_event(nua_r_register, 200); s2->registration->nh = nh; s2_register_teardown(); } END_TEST
GST_END_TEST GST_START_TEST (valve_test) { GstElement *pipeline = gst_pipeline_new (__FUNCTION__); GstElement *videotestsrc = gst_element_factory_make ("videotestsrc", NULL); GstElement *fakesink = gst_element_factory_make ("fakesink", NULL); GstElement *agnosticbin = gst_element_factory_make ("agnosticbin", NULL); GstElement *valve = gst_element_factory_make ("valve", NULL); GstElement *decoder = gst_element_factory_make ("vp8dec", NULL); GstElement *fakesink2 = gst_element_factory_make ("fakesink", "fakesink"); gboolean ret; GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); GThread *thread; g_object_set_data (G_OBJECT (pipeline), VALVE_KEY, valve); loop = g_main_loop_new (NULL, TRUE); g_object_set (G_OBJECT (pipeline), "async-handling", TRUE, NULL); g_object_set (G_OBJECT (videotestsrc), "is-live", TRUE, NULL); gst_bus_add_signal_watch (bus); g_signal_connect (bus, "message", G_CALLBACK (bus_msg), pipeline); g_object_set_data (G_OBJECT (fakesink2), DECODER_KEY, decoder); g_object_set_data (G_OBJECT (decoder), AGNOSTIC_KEY, agnosticbin); mark_point (); gst_bin_add_many (GST_BIN (pipeline), videotestsrc, agnosticbin, fakesink, valve, decoder, fakesink2, NULL); mark_point (); ret = gst_element_link_many (videotestsrc, agnosticbin, fakesink, NULL); fail_unless (ret); mark_point (); ret = gst_element_link_many (agnosticbin, valve, decoder, fakesink2, NULL); fail_unless (ret); mark_point (); gst_element_set_state (pipeline, GST_STATE_PLAYING); thread = g_thread_new ("toggle", toggle_thread, pipeline); g_thread_unref (thread); g_timeout_add_seconds (10, timeout_check, pipeline); mark_point (); g_main_loop_run (loop); mark_point (); gst_element_set_state (pipeline, GST_STATE_NULL); gst_bus_remove_signal_watch (bus); g_object_unref (pipeline); g_object_unref (bus); g_main_loop_unref (loop); }
GST_END_TEST GST_START_TEST (encoded_input_n_encoded_ouput) { loop = g_main_loop_new (NULL, TRUE); GstElement *pipeline = gst_pipeline_new (__FUNCTION__); GstElement *audiotestsrc = gst_element_factory_make ("audiotestsrc", NULL); GstElement *encoder = gst_element_factory_make ("alawenc", NULL); GstElement *agnosticbin = gst_element_factory_make ("agnosticbin", "agnosticbin"); gboolean ret; int *count, i; GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); g_object_set (G_OBJECT (pipeline), "async-handling", TRUE, NULL); gst_bus_add_signal_watch (bus); g_signal_connect (bus, "message", G_CALLBACK (bus_msg), pipeline); mark_point (); gst_bin_add_many (GST_BIN (pipeline), audiotestsrc, encoder, agnosticbin, NULL); mark_point (); ret = gst_element_link_many (audiotestsrc, encoder, agnosticbin, NULL); fail_unless (ret); mark_point (); gst_element_set_state (pipeline, GST_STATE_PLAYING); mark_point (); count = g_malloc0 (sizeof (int)); *count = N_ITERS; g_object_set_data_full (G_OBJECT (pipeline), COUNT_KEY, count, g_free); GST_INFO ("Connecting %d outputs", N_ITERS); g_timeout_add_seconds (6, timeout_check, pipeline); for (i = 0; i < N_ITERS; i++) { g_timeout_add (700, connect_output, pipeline); } mark_point (); g_main_loop_run (loop); mark_point (); gst_element_set_state (pipeline, GST_STATE_NULL); gst_bus_remove_signal_watch (bus); g_object_unref (bus); g_object_unref (pipeline); g_main_loop_unref (loop); }
END_TEST START_TEST (test_print_output) { int command_id = 1; print_output(-1); add_output("Hello, world!"); print_output(command_id); mark_point(); set_output_error(); command_id = -1; add_output("Hello, world!"); print_output(command_id); // Only exit value 0 can be tested here ... }
END_TEST START_TEST(test_parent_check) { struct parent_req mreq = {}; mark_point(); mreq.op = PARENT_OPEN; fail_unless(parent_check(&mreq) == EXIT_SUCCESS, "PARENT_OPEN check failed"); mark_point(); mreq.op = PARENT_CLOSE; fail_unless(parent_check(&mreq) == EXIT_SUCCESS, "PARENT_CLOSE check failed"); #ifdef HAVE_LINUX_ETHTOOL_H mark_point(); mreq.op = PARENT_ETHTOOL_GSET; mreq.index = ifindex; mreq.len = sizeof(struct ethtool_cmd); fail_unless(parent_check(&mreq) == EXIT_SUCCESS, "PARENT_ETHTOOL_GSET check failed"); mark_point(); mreq.op = PARENT_ETHTOOL_GDRV; mreq.index = ifindex; mreq.len = sizeof(struct ethtool_drvinfo); fail_unless(parent_check(&mreq) == EXIT_SUCCESS, "PARENT_ETHTOOL_GDRV check failed"); #endif #ifdef SIOCSIFDESCR mark_point(); mreq.op = PARENT_DESCR; mreq.index = ifindex; mreq.len = 0; fail_unless(parent_check(&mreq) == EXIT_SUCCESS, "PARENT_DESCR check failed"); #endif #ifndef HAVE_LINUX_ETHTOOL_H mark_point(); mreq.op = PARENT_ETHTOOL_GSET; fail_unless(parent_check(&mreq) == EXIT_FAILURE, "parent_check should fail"); #endif }
END_TEST START_TEST (auth_cache_uid2name_failed_test) { int res; const char *name; authtable authtab; char *sym_name = "uid2name"; /* Load the appropriate AUTH symbol, and call it. */ memset(&authtab, 0, sizeof(authtab)); authtab.name = sym_name; authtab.handler = decline_uid2name; authtab.m = &unit_tests_module; res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab); fail_unless(res == 0, "Failed to add '%s' AUTH symbol: %s", sym_name, strerror(errno)); mark_point(); name = pr_auth_uid2name(p, PR_TEST_AUTH_UID); fail_unless(name != NULL, "Expected name, got null"); fail_unless(strcmp(name, PR_TEST_AUTH_UID_STR) == 0, "Expected name '%s', got '%s'", PR_TEST_AUTH_UID_STR, name); fail_unless(uid2name_count == 1, "Expected call count 1, got %u", uid2name_count); /* Call again; the call counter should NOT increment due to caching. */ name = pr_auth_uid2name(p, PR_TEST_AUTH_UID); fail_unless(name != NULL, "Expected name, got null"); fail_unless(strcmp(name, PR_TEST_AUTH_UID_STR) == 0, "Expected name '%s', got '%s'", PR_TEST_AUTH_UID_STR, name); fail_unless(uid2name_count == 1, "Expected call count 1, got %u", uid2name_count); pr_stash_remove_symbol(PR_SYM_AUTH, sym_name, &unit_tests_module); }
END_TEST START_TEST (var_rewind_test) { int ok; const char *res, *desc; (void) var_free(); mark_point(); pr_var_rewind(); (void) var_init(); pr_var_rewind(); ok = pr_var_set(p, "%{foo}", "test", PR_VAR_TYPE_STR, "bar", NULL, 0); fail_unless(ok == 0, "Failed to add var: %s", strerror(errno)); res = pr_var_next(&desc); fail_unless(res != NULL, "Failed to get next key: %s", strerror(errno)); fail_unless(desc != NULL, "Expected non-null desc"); fail_unless(strcmp(desc, "test") == 0, "Expected desc '%s', got '%s'", "test", desc); res = pr_var_next(&desc); fail_unless(res == NULL, "Expected no more keys, got '%s'", res); pr_var_rewind(); res = pr_var_next(&desc); fail_unless(res != NULL, "Failed to get next key: %s", strerror(errno)); fail_unless(desc != NULL, "Expected non-null desc"); fail_unless(strcmp(desc, "test") == 0, "Expected desc '%s', got '%s'", "test", desc); res = pr_var_next(&desc); fail_unless(res == NULL, "Expected no more keys, got '%s'", res); }
END_TEST START_TEST (dir_abs_path_test) { char *res; const char *path; res = dir_abs_path(NULL, NULL, TRUE); fail_unless(res == NULL, "Failed to handle null arguments"); fail_unless(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL, strerror(errno), errno); res = dir_abs_path(p, NULL, TRUE); fail_unless(res == NULL, "Failed to handle null path"); fail_unless(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL, strerror(errno), errno); mark_point(); path = "/foo"; res = dir_abs_path(p, path, TRUE); fail_unless(path != NULL, "Failed to get absolute path for '%s': %s", path, strerror(errno)); fail_unless(strcmp(res, path) == 0, "Expected '%s', got '%s'", path, res); }
END_TEST /* check that the cache does reasonable reference counting. * * missing: overwrite case. */ START_TEST(item_destruction) { GObject *obj = g_object_new(PT_CACHE_TYPE, NULL); PtCache *cache = PT_CACHE(obj); fail_unless(cache != NULL); GObject *o = g_object_new(G_TYPE_OBJECT, NULL), *o2 = g_object_new(G_TYPE_OBJECT, NULL); pt_cache_put(cache, GINT_TO_POINTER(1), 0, o); pt_cache_put(cache, GINT_TO_POINTER(2), 0, o2); gpointer o_ptr = o, o2_ptr = o2; fail_unless(o_ptr != NULL); fail_unless(o2_ptr != NULL); g_object_add_weak_pointer(o, &o_ptr); g_object_add_weak_pointer(o2, &o2_ptr); g_object_unref(o); g_object_unref(o2); mark_point(); GObject *linger = pt_cache_get(cache, GINT_TO_POINTER(1)); fail_unless(linger != NULL); g_object_ref(linger); g_object_unref(cache); fail_unless(o_ptr != NULL); fail_unless(o2_ptr == NULL); g_object_unref(linger); fail_unless(o_ptr == NULL); }
END_TEST START_TEST(tc_buffer_consume_partial) { const char append_buf[] = {'1', '2', '3', '4', '5'}; size_t bsize; void *buf; achat_rc rc; rc = acc_bufferinit(buffer); fail_if(rc != ACHAT_RC_OK, "Failed to initialize buffer, rc = %i", rc); mark_point(); /* Make sure length of append_buf is really smaller */ /* than ACHAT_BUFFER_DEFAULTSZ */ fail_if(sizeof(append_buf) > ACHAT_BUFFER_DEFAULTSZ, "len(append_buf) > ACHAT_BUFFER_DEFAULTSZ"); mark_point(); rc = acc_bufferappend(buffer, append_buf, sizeof(append_buf)); fail_if(rc != ACHAT_RC_OK, "Failed to append to buffer, rc = %i", rc); mark_point(); rc = acc_bufferconsume(buffer, 2); fail_if(rc != ACHAT_RC_OK, "Failed to remove from buffer, rc = %i", rc); bsize = acc_bufferlen(buffer); fail_if(bsize != sizeof(append_buf) - 2, "Length of buffer is wrong, is %i but %i expected", bsize, sizeof(append_buf) - 2); mark_point(); buf = acc_bufferptr(buffer); fail_if(memcmp(buf, append_buf + 2, bsize) != 0, "Unexpected content of buffer"); mark_point(); rc = acc_bufferfree(buffer); fail_if(rc != ACHAT_RC_OK, "Failed to free the buffer, rc = %i", rc); mark_point(); }
END_TEST START_TEST (auth_getgrent_test) { int res; struct group *gr; authtable authtab; char *sym_name = "getgrent"; gr = pr_auth_getgrent(NULL); fail_unless(gr == NULL, "Found grent unexpectedly"); fail_unless(errno == EINVAL, "Failed to set errno to EINVAL, got %d (%s)", errno, strerror(errno)); gr = pr_auth_getgrent(p); fail_unless(gr == NULL, "Found grent unexpectedly"); fail_unless(getgrent_count == 0, "Expected call count 0, got %u", getgrent_count); mark_point(); /* Load the appropriate AUTH symbol, and call it. */ memset(&authtab, 0, sizeof(authtab)); authtab.name = sym_name; authtab.handler = handle_getgrent; authtab.m = &unit_tests_module; res = pr_stash_add_symbol(PR_SYM_AUTH, &authtab); fail_unless(res == 0, "Failed to add '%s' AUTH symbol: %s", sym_name, strerror(errno)); gr = pr_auth_getgrent(p); fail_unless(gr != NULL, "Failed to find grent: %s", strerror(errno)); fail_unless(getgrent_count == 1, "Expected call count 1, got %u", getgrent_count); pr_stash_remove_symbol(PR_SYM_AUTH, sym_name, &unit_tests_module); }
static void fakesink_hand_off2 (GstElement * fakesink, GstBuffer * buf, GstPad * pad, gpointer data) { static int count = 0; static int cycles = 0; GMainLoop *loop = (GMainLoop *) data; if (count++ > 10) { count = 0; if (cycles++ > 10) { g_object_set (G_OBJECT (fakesink), "signal-handoffs", FALSE, NULL); GST_DEBUG ("Quit loop"); g_idle_add (quit_main_loop_idle, loop); } else { GstElement *decoder = g_object_get_data (G_OBJECT (fakesink), DECODER_KEY); g_object_set (G_OBJECT (fakesink), "signal-handoffs", FALSE, NULL); mark_point (); g_idle_add (idle_unlink, decoder); } } }
END_TEST START_TEST(tc_buffer_add_gt_defaultsz) { int *append_buf; size_t sz_buf; unsigned int i; size_t bsize; void *buf; achat_rc rc; rc = acc_bufferinit(buffer); fail_if(rc != ACHAT_RC_OK, "Failed to initialize buffer, rc = %i", rc); mark_point(); /* Initialize append_buf with a size > ACHAT_BUFFER_DEFAULTSZ */ sz_buf = ACHAT_BUFFER_DEFAULTSZ + 1; append_buf = calloc(sz_buf, sizeof(int)); for (i = 0; i < sz_buf; i++) append_buf[i] = i; mark_point(); rc = acc_bufferappend(buffer, append_buf, sz_buf); fail_if(rc != ACHAT_RC_OK, "Failed to append to buffer, rc = %i", rc); mark_point(); bsize = acc_bufferlen(buffer); fail_if(bsize != sz_buf, "Length of buffer is wrong, is %i but %i expected", bsize, sz_buf); mark_point(); buf = acc_bufferptr(buffer); fail_if(memcmp(buf, append_buf, bsize) != 0, "Unexpected content of buffer"); mark_point(); rc = acc_bufferfree(buffer); fail_if(rc != ACHAT_RC_OK, "Failed to free the buffer, rc = %i", rc); mark_point(); }
GST_END_TEST GST_START_TEST (encoded_input_to_valve) { loop = g_main_loop_new (NULL, TRUE); GstElement *pipeline = gst_pipeline_new (__FUNCTION__); GstElement *audiotestsrc = gst_element_factory_make ("audiotestsrc", NULL); GstElement *encoder = gst_element_factory_make ("alawenc", NULL); GstElement *valve = gst_element_factory_make ("valve", "valve"); GstElement *agnosticbin = gst_element_factory_make ("agnosticbin", NULL); gboolean ret; GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); g_object_set (G_OBJECT (pipeline), "async-handling", TRUE, NULL); gst_bus_add_signal_watch (bus); g_signal_connect (bus, "message", G_CALLBACK (bus_msg), pipeline); g_object_set (G_OBJECT (valve), "drop", TRUE, NULL); mark_point (); gst_bin_add_many (GST_BIN (pipeline), audiotestsrc, encoder, agnosticbin, valve, NULL); mark_point (); ret = gst_element_link_many (audiotestsrc, encoder, agnosticbin, valve, NULL); fail_unless (ret); mark_point (); gst_element_set_state (pipeline, GST_STATE_PLAYING); mark_point (); g_timeout_add_seconds (6, timeout_check, pipeline); g_timeout_add (700, connect_appsink, pipeline); mark_point (); g_main_loop_run (loop); mark_point (); gst_element_set_state (pipeline, GST_STATE_NULL); gst_bus_remove_signal_watch (bus); g_object_unref (bus); g_object_unref (pipeline); g_main_loop_unref (loop); }
END_TEST START_TEST(test_csum_nosuchfile) { size_t len; TaskEventSpy spy(jobCtrl, anTASKEVT_CSUM_GET); mark_point(); wxString file = wxFileName::GetTempDir() + wxT("/blablubb"); fail_if(wxFileExists(file), "File already exists"); mark_point(); ComCsumGetTask *task = new ComCsumGetTask; task->addPath(file); mark_point(); jobCtrl->addTask(task); spy.waitForInvocation(1); mark_point(); fail_unless(task->getComTaskResult() == ComTask::RESULT_SUCCESS, "Checksum request failed!\n" "ComTaskResult = %i\n" "ResultDetails = %i\n", task->getComTaskResult(), task->getResultDetails()); fail_unless(task->getChecksumError(0) == ENOENT, "Checksum error: %s (%i)\n", anoubis_strerror(task->getChecksumError(0)), task->getChecksumError(0)); fail_unless(task->haveKeyId() == false, "A key-id is assigned"); len = task->getChecksumLen(0, ANOUBIS_SIG_TYPE_CS); fail_unless(len == 0, "Task contains a checksum"); mark_point(); const u_int8_t *cs; bool ok = task->getChecksumData(0, ANOUBIS_SIG_TYPE_CS, cs, len); fail_unless(!ok && len == 0, "Task contains a checksum!\n"); mark_point(); }
END_TEST /* filter flushing got dropped with OpenSync 0.30 API START_TEST (filter_flush) { char *testbed = setup_testbed("filter_setup"); OSyncError *error = NULL; OSyncGroup *group = osync_group_new(&error); fail_unless(group != NULL, NULL); fail_unless(error == NULL, NULL); osync_group_load(group, "configs/group", &error); fail_unless(error == NULL, osync_error_print(&error)); fail_unless(group != NULL, NULL); mark_point(); OSyncMember *leftmember = osync_group_nth_member(group, 0); OSyncMember *rightmember = osync_group_nth_member(group, 1); OSyncFilter *filter1 = osync_filter_new("mockobjtype1", OSYNC_FILTER_DENY, &error); OSyncFilter *filter2 = osync_filter_new("mockobjtype1", OSYNC_FILTER_DENY, &error); fail_unless(filter1 != NULL, NULL); fail_unless(filter2 != NULL, NULL); osync_group_add_filter(group, filter1); osync_group_add_filter(group, filter2); mark_point(); fail_unless(osync_group_num_filters(group) == 2, NULL); fail_unless(osync_group_nth_filter(group, 0) == filter1, NULL); fail_unless(osync_group_nth_filter(group, 1) == filter2, NULL); mark_point(); osync_group_flush_filters(group); fail_unless(osync_group_num_filters(group) == 0, NULL); destroy_testbed(testbed); } END_TEST */ START_TEST (filter_sync_deny_all) { char *testbed = setup_testbed("filter_sync_deny_all"); char *formatdir = g_strdup_printf("%s/formats", testbed); char *plugindir = g_strdup_printf("%s/plugins", testbed); OSyncError *error = NULL; OSyncGroup *group = osync_group_new(&error); fail_unless(group != NULL, NULL); fail_unless(error == NULL, NULL); osync_group_set_schemadir(group, testbed); osync_group_load(group, "configs/group", &error); fail_unless(error == NULL, osync_error_print(&error)); fail_unless(group != NULL, NULL); mark_point(); OSyncFilter *filter1 = osync_filter_new("mockobjtype1", OSYNC_FILTER_DENY, &error); OSyncFilter *filter2 = osync_filter_new("mockobjtype1", OSYNC_FILTER_DENY, &error); fail_unless(filter1 != NULL, NULL); fail_unless(filter2 != NULL, NULL); osync_group_add_filter(group, filter1); osync_group_add_filter(group, filter2); mark_point(); OSyncEngine *engine = osync_engine_new(group, &error); mark_point(); fail_unless(engine != NULL, NULL); osync_engine_set_plugindir(engine, plugindir); osync_engine_set_formatdir(engine, formatdir); osync_engine_set_schemadir(engine, testbed); fail_unless(osync_engine_initialize(engine, &error), osync_error_print(&error)); synchronize_once(engine, &error); osync_engine_finalize(engine, &error); fail_unless(osync_testing_file_exists("data1/testdata"), NULL); fail_unless(osync_testing_file_exists("data2/testdata2"), NULL); g_free(formatdir); g_free(plugindir); destroy_testbed(testbed); }