END_TEST START_TEST(test_ck_assert_int_lt) { int x = 2; int y = 3; ck_assert_int_lt(x, y); ck_assert_int_lt(x, x); #define LINENO_ck_assert_int_lt _STR(__LINE__) }
END_TEST START_TEST(bus_create) { char spath[128]; struct wpas *w, *s; int r; sprintf(spath, "/tmp/miracle-test-sock-%d", getpid()); /* test server creation */ s = TEST_INVALID_PTR; w = TEST_INVALID_PTR; unlink(spath); ck_assert_int_lt(access(spath, F_OK), 0); r = wpas_create(spath, &s); ck_assert_int_ge(r, 0); ck_assert(s != TEST_INVALID_PTR); ck_assert(s != NULL); ck_assert_int_ge(access(spath, F_OK), 0); r = wpas_create(spath, &w); ck_assert_int_eq(r, -EADDRINUSE); ck_assert(w == TEST_INVALID_PTR); ck_assert_int_ge(access(spath, F_OK), 0); wpas_unref(s); s = TEST_INVALID_PTR; ck_assert_int_lt(access(spath, F_OK), 0); /* test again with pre-existing but unused file */ ck_assert_int_ge(open(spath, O_RDWR | O_CREAT | O_CLOEXEC, S_IRWXU), 0); ck_assert_int_ge(access(spath, F_OK), 0); r = wpas_create(spath, &s); ck_assert_int_ge(r, 0); ck_assert(s != TEST_INVALID_PTR); ck_assert(s != NULL); ck_assert_int_ge(access(spath, F_OK), 0); wpas_unref(s); s = TEST_INVALID_PTR; ck_assert_int_lt(access(spath, F_OK), 0); }
END_TEST START_TEST(bus_open) { char spath[128]; struct wpas *w, *s; int r; sprintf(spath, "/tmp/miracle-test-sock-%d", getpid()); /* test client connection */ s = TEST_INVALID_PTR; w = TEST_INVALID_PTR; r = wpas_create(spath, &s); ck_assert_int_ge(r, 0); ck_assert_int_ge(access(spath, F_OK), 0); r = wpas_open(spath, &w); ck_assert_int_ge(r, 0); wpas_unref(w); wpas_unref(s); ck_assert_int_lt(access(spath, F_OK), 0); }
END_TEST START_TEST(bus_open) { const char *spath = "/tmp/miracle-test-sock"; struct wpas *w, *s; int r; /* test client connection */ s = TEST_INVALID_PTR; w = TEST_INVALID_PTR; r = wpas_create(spath, &s); ck_assert_int_ge(r, 0); ck_assert_int_ge(access(spath, F_OK), 0); r = wpas_open(spath, &w); ck_assert_int_ge(r, 0); wpas_unref(w); wpas_unref(s); ck_assert_int_lt(access(spath, F_OK), 0); }
END_TEST START_TEST (test_trust_creates_known_hosts_file_and_directory) { char dir[PATH_MAX]; int r = check_tmpdir(dir, sizeof(dir), ".neo4j_XXXXXX"); ck_assert_int_eq(r, 0); const char *kh_path = "/sub/dir/kh"; size_t dirlen = strlen(dir); ck_assert_int_lt(dirlen + strlen(kh_path), PATH_MAX); char path[PATH_MAX]; memcpy(path, dir, dirlen); strncpy(path + dirlen, kh_path, PATH_MAX - dirlen); ck_assert_int_eq(neo4j_config_set_known_hosts_file(config, path), 0); struct callback_data data; neo4j_config_set_unverified_host_callback(config, trust_host, &data); r = neo4j_check_known_hosts("host.local", 6546, "aa7b6261e21d7b2950e044453543bce3840429e2", config, 0); ck_assert_str_eq(data.host, "host.local:6546"); ck_assert_str_eq(data.fingerprint, "aa7b6261e21d7b2950e044453543bce3840429e2"); ck_assert_int_eq(data.reason, NEO4J_HOST_VERIFICATION_UNRECOGNIZED); ck_assert_int_eq(r, 0); neo4j_config_set_unverified_host_callback(config, NULL, NULL); r = neo4j_check_known_hosts("host.local", 6546, "aa7b6261e21d7b2950e044453543bce3840429e2", config, 0); ck_assert_int_eq(r, 0); }
END_TEST START_TEST(bus_invalid_create) { const char *ipath = "/tmp/miracle/invalid-test-dir/invalid-test-path"; struct wpas *s; int r; /* test invalid server */ s = TEST_INVALID_PTR; r = wpas_create(NULL, NULL); ck_assert_int_lt(r, 0); r = wpas_create(ipath, NULL); ck_assert_int_lt(r, 0); r = wpas_create(NULL, &s); ck_assert_int_lt(r, 0); ck_assert(s == TEST_INVALID_PTR); }
END_TEST START_TEST(bus_invalid_create) { char ipath[128]; struct wpas *s; int r; sprintf(ipath, "/tmp/miracle/invalid-test-dir/invalid-test-path-%d", getpid()); /* test invalid server */ s = TEST_INVALID_PTR; r = wpas_create(NULL, NULL); ck_assert_int_lt(r, 0); r = wpas_create(ipath, NULL); ck_assert_int_lt(r, 0); r = wpas_create(NULL, &s); ck_assert_int_lt(r, 0); ck_assert(s == TEST_INVALID_PTR); }
TEST_END_CASE START_TEST(msg_invalid_new) { struct wpas_message *m; struct wpas *w; int r; w = start_test_client(); m = TEST_INVALID_PTR; r = wpas_message_new_event(NULL, NULL, 0, NULL); ck_assert_int_lt(r, 0); ck_assert(m == TEST_INVALID_PTR); r = wpas_message_new_event(w, NULL, 0, NULL); ck_assert_int_lt(r, 0); ck_assert(m == TEST_INVALID_PTR); r = wpas_message_new_event(NULL, "name", 0, NULL); ck_assert_int_lt(r, 0); ck_assert(m == TEST_INVALID_PTR); r = wpas_message_new_event(NULL, NULL, 0, &m); ck_assert_int_lt(r, 0); ck_assert(m == TEST_INVALID_PTR); r = wpas_message_new_event(w, NULL, 0, &m); ck_assert_int_lt(r, 0); ck_assert(m == TEST_INVALID_PTR); r = wpas_message_new_event(w, "", 0, &m); ck_assert_int_lt(r, 0); ck_assert(m == TEST_INVALID_PTR); r = wpas_message_new_event(w, "name", 0, NULL); ck_assert_int_lt(r, 0); ck_assert(m == TEST_INVALID_PTR); r = wpas_message_new_event(NULL, "name", 0, &m); ck_assert_int_lt(r, 0); ck_assert(m == TEST_INVALID_PTR); stop_test_client(); }
TEST_END_CASE START_TEST(msg_new_invalid) { char data[128] = { }; struct rtsp *bus; struct rtsp_message *m; int r, fd; fd = dup(0); ck_assert_int_ge(fd, 0); r = rtsp_open(&bus, fd); ck_assert_int_ge(r, 0); /* request messages */ m = TEST_INVALID_PTR; r = rtsp_message_new_request(NULL, &m, "method", "uri"); ck_assert_int_lt(r, 0); ck_assert(m == TEST_INVALID_PTR); r = rtsp_message_new_request(bus, NULL, "method", "uri"); ck_assert_int_lt(r, 0); ck_assert(m == TEST_INVALID_PTR); r = rtsp_message_new_request(bus, &m, "", "uri"); ck_assert_int_lt(r, 0); ck_assert(m == TEST_INVALID_PTR); r = rtsp_message_new_request(bus, &m, NULL, "uri"); ck_assert_int_lt(r, 0); ck_assert(m == TEST_INVALID_PTR); r = rtsp_message_new_request(bus, &m, "method", ""); ck_assert_int_lt(r, 0); ck_assert(m == TEST_INVALID_PTR); r = rtsp_message_new_request(bus, &m, "method", NULL); ck_assert_int_lt(r, 0); ck_assert(m == TEST_INVALID_PTR); r = rtsp_message_new_request(bus, &m, "method", "uri"); ck_assert_int_ge(r, 0); ck_assert(m != TEST_INVALID_PTR); rtsp_message_unref(m); /* reply-for messages */ m = TEST_INVALID_PTR; r = rtsp_message_new_reply(NULL, &m, 1, 200, "OK"); ck_assert_int_lt(r, 0); ck_assert(m == TEST_INVALID_PTR); r = rtsp_message_new_reply(bus, NULL, 1, 200, "OK"); ck_assert_int_lt(r, 0); ck_assert(m == TEST_INVALID_PTR); r = rtsp_message_new_reply(bus, &m, 0, 200, "OK"); ck_assert_int_lt(r, 0); ck_assert(m == TEST_INVALID_PTR); r = rtsp_message_new_reply(bus, &m, 1, RTSP_ANY_CODE, "OK"); ck_assert_int_lt(r, 0); ck_assert(m == TEST_INVALID_PTR); r = rtsp_message_new_reply(bus, &m, 1, 200, "OK"); ck_assert_int_ge(r, 0); ck_assert(m != TEST_INVALID_PTR); rtsp_message_unref(m); /* data messages */ m = TEST_INVALID_PTR; r = rtsp_message_new_data(NULL, &m, 0, data, sizeof(data)); ck_assert_int_lt(r, 0); ck_assert(m == TEST_INVALID_PTR); r = rtsp_message_new_data(bus, NULL, 0, data, sizeof(data)); ck_assert_int_lt(r, 0); ck_assert(m == TEST_INVALID_PTR); r = rtsp_message_new_data(bus, &m, RTSP_ANY_CHANNEL, data, sizeof(data)); ck_assert_int_lt(r, 0); ck_assert(m == TEST_INVALID_PTR); r = rtsp_message_new_data(bus, &m, 0, NULL, sizeof(data)); ck_assert_int_lt(r, 0); ck_assert(m == TEST_INVALID_PTR); r = rtsp_message_new_data(bus, &m, 0, data, sizeof(data)); ck_assert_int_ge(r, 0); ck_assert(m != TEST_INVALID_PTR); rtsp_message_unref(m); /* invalid ops */ rtsp_message_ref(NULL); rtsp_message_unref(NULL); ck_assert_int_eq(rtsp_message_get_type(NULL), 0); ck_assert(!rtsp_message_get_method(NULL)); ck_assert(!rtsp_message_get_uri(NULL)); ck_assert_int_eq(rtsp_message_get_code(NULL), RTSP_ANY_CODE); ck_assert(!rtsp_message_get_phrase(NULL)); ck_assert_int_eq(rtsp_message_get_channel(NULL), RTSP_ANY_CHANNEL); ck_assert(!rtsp_message_get_payload(NULL)); ck_assert_int_eq(rtsp_message_get_payload_size(NULL), 0); ck_assert(!rtsp_message_is_request(NULL, NULL, NULL)); ck_assert(!rtsp_message_is_reply(NULL, RTSP_ANY_CODE, NULL)); ck_assert(!rtsp_message_is_data(NULL, RTSP_ANY_CHANNEL)); ck_assert(!rtsp_message_get_bus(NULL)); ck_assert(!rtsp_message_get_cookie(NULL)); ck_assert(!rtsp_message_is_sealed(NULL)); rtsp_unref(bus); }
END_TEST START_TEST(run_msg) { struct wpas_message *m; int r; start_test_client(); r = wpas_message_new_reply(client, &m); ck_assert_int_ge(r, 0); r = wpas_send(client, m, 0); ck_assert_int_ge(r, 0); r = wpas_send(client, m, 0); ck_assert_int_lt(r, 0); wpas_message_unref(m); r = wpas_message_new_reply(client, &m); ck_assert_int_ge(r, 0); wpas_message_set_peer(m, "/some/peer"); r = wpas_send(client, m, 0); ck_assert_int_ge(r, 0); r = wpas_send(client, m, 0); ck_assert_int_lt(r, 0); wpas_message_unref(m); r = wpas_message_new_reply(server, &m); ck_assert_int_ge(r, 0); r = wpas_send(server, m, 0); ck_assert_int_lt(r, 0); wpas_message_set_peer(m, "/some/peer"); r = wpas_send(server, m, 0); ck_assert_int_ge(r, 0); r = wpas_send(server, m, 0); ck_assert_int_lt(r, 0); wpas_message_unref(m); r = wpas_message_new_request(server, "sth", &m); ck_assert_int_ge(r, 0); r = wpas_call_async(server, m, NULL, NULL, 0, NULL); ck_assert_int_lt(r, 0); r = wpas_send(server, m, 0); ck_assert_int_lt(r, 0); wpas_message_set_peer(m, "/some/peer"); r = wpas_call_async(server, m, NULL, NULL, 0, NULL); ck_assert_int_lt(r, 0); r = wpas_send(server, m, 0); ck_assert_int_ge(r, 0); r = wpas_send(server, m, 0); ck_assert_int_lt(r, 0); wpas_message_unref(m); r = wpas_message_new_request(client, "sth", &m); ck_assert_int_ge(r, 0); r = wpas_call_async(client, m, NULL, NULL, 0, NULL); ck_assert_int_ge(r, 0); r = wpas_call_async(client, m, NULL, NULL, 0, NULL); ck_assert_int_lt(r, 0); wpas_message_unref(m); stop_test_client(); }