Sat, 22 Nov 2025 14:27:01 +0100
port old ucx2 tests to ucx3
--- a/src/server/plugins/postgresql/pgtest.c Sat Nov 22 12:49:20 2025 +0100 +++ b/src/server/plugins/postgresql/pgtest.c Sat Nov 22 14:27:01 2025 +0100 @@ -82,7 +82,7 @@ } } -void register_pg_tests(int argc, char **argv, UcxTestSuite *suite) { +void register_pg_tests(int argc, char **argv, CxTestSuite *suite) { test_connection = PQconnectdb(pg_connstr); if(!test_connection) { @@ -96,22 +96,22 @@ resdata.data = test_connection; test_root_lookup(); - ucx_test_register(suite, test_pg_conn); + cx_test_register(suite, test_pg_conn); if(!abort_pg_tests) { - ucx_test_register(suite, test_pg_lookup_root); + cx_test_register(suite, test_pg_lookup_root); - ucx_test_register(suite, test_pg_vfs_open); - ucx_test_register(suite, test_pg_vfs_io); - ucx_test_register(suite, test_pg_vfs_stat); - ucx_test_register(suite, test_pg_vfs_mkdir); - ucx_test_register(suite, test_pg_vfs_unlink); - ucx_test_register(suite, test_pg_vfs_rmdir); + cx_test_register(suite, test_pg_vfs_open); + cx_test_register(suite, test_pg_vfs_io); + cx_test_register(suite, test_pg_vfs_stat); + cx_test_register(suite, test_pg_vfs_mkdir); + cx_test_register(suite, test_pg_vfs_unlink); + cx_test_register(suite, test_pg_vfs_rmdir); - ucx_test_register(suite, test_pg_webdav_create_from_resdata); - ucx_test_register(suite, test_pg_prepare_tests); - ucx_test_register(suite, test_pg_webdav_propfind); - ucx_test_register(suite, test_pg_webdav_propfind_allprop); - ucx_test_register(suite, test_pg_webdav_proppatch_set); + cx_test_register(suite, test_pg_webdav_create_from_resdata); + cx_test_register(suite, test_pg_prepare_tests); + cx_test_register(suite, test_pg_webdav_propfind); + cx_test_register(suite, test_pg_webdav_propfind_allprop); + cx_test_register(suite, test_pg_webdav_proppatch_set); PGresult *result = PQexec(test_connection, "BEGIN"); PQclear(result); @@ -230,32 +230,30 @@ } -UCX_TEST(test_pg_conn) { +CX_TEST(test_pg_conn) { char *msg = test_connection ? PQerrorMessage(test_connection) : "no connection"; - UCX_TEST_BEGIN; + CX_TEST_DO { - if(abort_pg_tests) { - int msglen = strlen(msg); - if(msglen > 0 && msg[msglen-1] == '\n') { - msglen--; + if(abort_pg_tests) { + int msglen = strlen(msg); + if(msglen > 0 && msg[msglen-1] == '\n') { + msglen--; + } + fprintf(stdout, "%.*s: ", msglen, msg); + CX_TEST_ASSERT(1 == 0); + } else { + CX_TEST_ASSERT(1 == 1); } - fprintf(stdout, "%.*s: ", msglen, msg); - UCX_TEST_ASSERT(1 == 0, "skip pg tests"); - } else { - UCX_TEST_ASSERT(1 == 1, "ok"); + } - - UCX_TEST_END; } -UCX_TEST(test_pg_lookup_root) { - UCX_TEST_BEGIN; - - // test already done in test_root_lookup() - UCX_TEST_ASSERT(!abort_pg_tests, "Lookup failed"); - - UCX_TEST_END; +CX_TEST(test_pg_lookup_root) { + CX_TEST_DO { + // test already done in test_root_lookup() + CX_TEST_ASSERT(!abort_pg_tests); + } } @@ -264,29 +262,29 @@ } -UCX_TEST(test_pg_vfs_open) { +CX_TEST(test_pg_vfs_open) { Session *sn = testutil_session(); Request *rq = testutil_request(sn->pool, "PUT", "/"); rq->vfs = create_test_pgvfs(sn, rq); VFSContext *vfs = vfs_request_context(sn, rq); SYS_FILE file; - UCX_TEST_BEGIN; - - file = vfs_open(vfs, "/test_notfound1", O_RDONLY); - UCX_TEST_ASSERT(!file, "/test_notfound should not exist"); + CX_TEST_DO { + + file = vfs_open(vfs, "/test_notfound1", O_RDONLY); + CX_TEST_ASSERT(!file); + + file = vfs_open(vfs, "/test_file1", O_RDWR | O_CREAT); + CX_TEST_ASSERT(file); + + vfs_close(file); - file = vfs_open(vfs, "/test_file1", O_RDWR | O_CREAT); - UCX_TEST_ASSERT(file, "cannot create file 1"); - - vfs_close(file); - - UCX_TEST_END; + } testutil_destroy_session(sn); } -UCX_TEST(test_pg_vfs_io) { +CX_TEST(test_pg_vfs_io) { Session *sn = testutil_session(); Request *rq = testutil_request(sn->pool, "PUT", "/"); rq->vfs = create_test_pgvfs(sn, rq); @@ -294,175 +292,175 @@ SYS_FILE file; SYS_FILE file2; - UCX_TEST_BEGIN; - - file = vfs_open(vfs, "/test_f1", O_WRONLY | O_CREAT); - UCX_TEST_ASSERT(file, "cannot open file1"); - - int w = system_fwrite(file, "test1\n", 6); - UCX_TEST_ASSERT(w == 6, "fwrite ret (1)"); - w = system_fwrite(file, "2", 1); - UCX_TEST_ASSERT(w == 1, "fwrite ret (2)"); - - vfs_close(file); - - file = vfs_open(vfs, "/test_f1", O_RDONLY); - file2 = vfs_open(vfs, "/test_f2", O_WRONLY | O_CREAT); - UCX_TEST_ASSERT(file, "cannot open file1"); - UCX_TEST_ASSERT(file2, "cannot open file2"); + CX_TEST_DO { - char buf[128]; - int r = system_fread(file, buf, 128); - UCX_TEST_ASSERT(r == 7, "cannot read from file1"); - - w = system_fwrite(file2, buf, r); - UCX_TEST_ASSERT(w == 7, "cannot write to file2"); - - vfs_close(file); - vfs_close(file2); - - file2 = vfs_open(vfs, "/test_f2", O_RDONLY); - - r = system_fread(file, buf, 128); - UCX_TEST_ASSERT(r == 7, "fread ret"); - UCX_TEST_ASSERT(!memcmp(buf, "test1\n2", 7), "wrong buffer content after read"); - - vfs_close(file2); + file = vfs_open(vfs, "/test_f1", O_WRONLY | O_CREAT); + CX_TEST_ASSERT(file); + + int w = system_fwrite(file, "test1\n", 6); + CX_TEST_ASSERT(w == 6); + w = system_fwrite(file, "2", 1); + CX_TEST_ASSERT(w == 1); + + vfs_close(file); + + file = vfs_open(vfs, "/test_f1", O_RDONLY); + file2 = vfs_open(vfs, "/test_f2", O_WRONLY | O_CREAT); + CX_TEST_ASSERT(file); + CX_TEST_ASSERT(file2); + + char buf[128]; + int r = system_fread(file, buf, 128); + CX_TEST_ASSERT(r == 7); + + w = system_fwrite(file2, buf, r); + CX_TEST_ASSERT(w == 7); + + vfs_close(file); + vfs_close(file2); + + file2 = vfs_open(vfs, "/test_f2", O_RDONLY); + + r = system_fread(file, buf, 128); + CX_TEST_ASSERT(r == 7); + CX_TEST_ASSERT(!memcmp(buf, "test1\n2", 7)); + + vfs_close(file2); - UCX_TEST_END; + } testutil_destroy_session(sn); } -UCX_TEST(test_pg_vfs_stat) { +CX_TEST(test_pg_vfs_stat) { Session *sn = testutil_session(); Request *rq = testutil_request(sn->pool, "PUT", "/"); rq->vfs = create_test_pgvfs(sn, rq); VFSContext *vfs = vfs_request_context(sn, rq); - UCX_TEST_BEGIN; - - // testdata, content doesn't matter - char test1[512]; - memset(test1, 'x', 512); - const int test_len1 = 200; - const int test_len2 = 432; - - SYS_FILE f1 = vfs_open(vfs, "/test_s1", O_WRONLY|O_CREAT); - UCX_TEST_ASSERT(f1, "cannot open test_s1"); - system_fwrite(f1, test1, test_len1); - vfs_close(f1); + CX_TEST_DO { - SYS_FILE f2 = vfs_open(vfs, "/test_s2", O_RDWR|O_CREAT); - UCX_TEST_ASSERT(f2, "cannot open test_s2"); - system_fwrite(f2, test1, test_len2); - vfs_close(f2); - - struct stat st1, st2; - int r1 = vfs_stat(vfs, "/test_s1", &st1); - int r2 = vfs_stat(vfs, "/test_s2", &st2); + // testdata, content doesn't matter + char test1[512]; + memset(test1, 'x', 512); + const int test_len1 = 200; + const int test_len2 = 432; + + SYS_FILE f1 = vfs_open(vfs, "/test_s1", O_WRONLY|O_CREAT); + CX_TEST_ASSERT(f1); + system_fwrite(f1, test1, test_len1); + vfs_close(f1); + + SYS_FILE f2 = vfs_open(vfs, "/test_s2", O_RDWR|O_CREAT); + CX_TEST_ASSERT(f2); + system_fwrite(f2, test1, test_len2); + vfs_close(f2); + + struct stat st1, st2; + int r1 = vfs_stat(vfs, "/test_s1", &st1); + int r2 = vfs_stat(vfs, "/test_s2", &st2); + + CX_TEST_ASSERT(r1 == 0); + CX_TEST_ASSERT(r2 == 0); + + CX_TEST_ASSERT(st1.st_size == test_len1); + CX_TEST_ASSERT(st2.st_size == test_len2); + + int testfail = vfs_stat(vfs, "/test_stat_fail", &st1); + CX_TEST_ASSERT(testfail != 0); - UCX_TEST_ASSERT(r1 == 0, "stat1 failed"); - UCX_TEST_ASSERT(r2 == 0, "stat2 failed"); - - UCX_TEST_ASSERT(st1.st_size == test_len1, "s1 wrong length"); - UCX_TEST_ASSERT(st2.st_size == test_len2, "s2 wrong length"); - - int testfail = vfs_stat(vfs, "/test_stat_fail", &st1); - UCX_TEST_ASSERT(testfail != 0, "stat 3 should fail"); - - UCX_TEST_END; + } testutil_destroy_session(sn); } -UCX_TEST(test_pg_vfs_mkdir) { +CX_TEST(test_pg_vfs_mkdir) { Session *sn = testutil_session(); Request *rq = testutil_request(sn->pool, "PUT", "/"); rq->vfs = create_test_pgvfs(sn, rq); VFSContext *vfs = vfs_request_context(sn, rq); - UCX_TEST_BEGIN; - - struct stat s; - - SYS_FILE f1 = vfs_open(vfs, "/test_mkdir/file", O_WRONLY|O_CREAT); - UCX_TEST_ASSERT(f1 == NULL, "open should fail"); - - int r = vfs_mkdir(vfs, "/test_mkdir"); - UCX_TEST_ASSERT(r == 0, "mkdir failed"); - - r = vfs_stat(vfs, "/test_mkdir", &s); - UCX_TEST_ASSERT(r == 0, "stat (1) failed"); - - UCX_TEST_ASSERT(S_ISDIR(s.st_mode), "/test_mkdir is not a directory"); - - f1 = vfs_open(vfs, "/test_mkdir/file", O_WRONLY|O_CREAT); - vfs_close(f1); - UCX_TEST_ASSERT(f1, "open failed"); + CX_TEST_DO { - r = vfs_stat(vfs, "/test_mkdir/file", &s); - UCX_TEST_ASSERT(r == 0, "stat (2) failed"); + struct stat s; + + SYS_FILE f1 = vfs_open(vfs, "/test_mkdir/file", O_WRONLY|O_CREAT); + CX_TEST_ASSERT(f1 == NULL); + + int r = vfs_mkdir(vfs, "/test_mkdir"); + CX_TEST_ASSERT(r == 0); + + r = vfs_stat(vfs, "/test_mkdir", &s); + CX_TEST_ASSERT(r == 0); + + CX_TEST_ASSERT(S_ISDIR(s.st_mode)); + + f1 = vfs_open(vfs, "/test_mkdir/file", O_WRONLY|O_CREAT); + vfs_close(f1); + CX_TEST_ASSERT(f1); - r = vfs_mkdir(vfs, "/test_mkdir/test_sub"); - UCX_TEST_ASSERT(r == 0, "mkdir failed (2)"); + r = vfs_stat(vfs, "/test_mkdir/file", &s); + CX_TEST_ASSERT(r == 0); + + r = vfs_mkdir(vfs, "/test_mkdir/test_sub"); + CX_TEST_ASSERT(r == 0); + + r = vfs_stat(vfs, "/test_mkdir/test_sub", &s); + CX_TEST_ASSERT(r == 0); + CX_TEST_ASSERT(S_ISDIR(s.st_mode)); + + r = vfs_mkdir(vfs, "/test_mkdir/test_sub/test_sub2/"); + CX_TEST_ASSERT(r == 0); + + r = vfs_stat(vfs, "/test_mkdir/test_sub/test_sub2/", &s); + CX_TEST_ASSERT(r == 0); + CX_TEST_ASSERT(S_ISDIR(s.st_mode)); - r = vfs_stat(vfs, "/test_mkdir/test_sub", &s); - UCX_TEST_ASSERT(r == 0, "stat (3) failed"); - UCX_TEST_ASSERT(S_ISDIR(s.st_mode), "/test_mkdir/test_sub is not a directory"); - - r = vfs_mkdir(vfs, "/test_mkdir/test_sub/test_sub2/"); - UCX_TEST_ASSERT(r == 0, "mkdir failed (4)"); - - r = vfs_stat(vfs, "/test_mkdir/test_sub/test_sub2/", &s); - UCX_TEST_ASSERT(r == 0, "stat (4) failed"); - UCX_TEST_ASSERT(S_ISDIR(s.st_mode), "/test_mkdir/test_sub/test_sub2/ is not a directory"); - - UCX_TEST_END; + } testutil_destroy_session(sn); } -UCX_TEST(test_pg_vfs_unlink) { +CX_TEST(test_pg_vfs_unlink) { Session *sn = testutil_session(); Request *rq = testutil_request(sn->pool, "PUT", "/"); rq->vfs = create_test_pgvfs(sn, rq); VFSContext *vfs = vfs_request_context(sn, rq); - UCX_TEST_BEGIN; - - SYS_FILE f1 = vfs_open(vfs, "/test_unlink1", O_WRONLY|O_CREAT); - UCX_TEST_ASSERT(f1, "cannot create test file"); - system_fwrite(f1, "test", 4); - - PgFile *pgfile = f1->data; - Oid oid = pgfile->oid; - - vfs_close(f1); - - int r = vfs_unlink(vfs, "/test_unlink1"); - UCX_TEST_ASSERT(r == 0, "unlink failed"); + CX_TEST_DO { - f1 = vfs_open(vfs, "/test_unlink1", O_RDONLY); - UCX_TEST_ASSERT(f1 == NULL, "test file not deleted"); + SYS_FILE f1 = vfs_open(vfs, "/test_unlink1", O_WRONLY|O_CREAT); + CX_TEST_ASSERT(f1); + system_fwrite(f1, "test", 4); + + PgFile *pgfile = f1->data; + Oid oid = pgfile->oid; + + vfs_close(f1); + + int r = vfs_unlink(vfs, "/test_unlink1"); + CX_TEST_ASSERT(r == 0); + + f1 = vfs_open(vfs, "/test_unlink1", O_RDONLY); + CX_TEST_ASSERT(f1 == NULL); + + PGresult *result = PQexec(test_connection, "savepoint sp;"); + PQclear(result); + int pgfd = lo_open(test_connection, oid, INV_READ); + CX_TEST_ASSERT(pgfd < 0); + result = PQexec(test_connection, "rollback to savepoint sp;"); + PQclear(result); + + r = vfs_unlink(vfs, "/test_unlink1"); + CX_TEST_ASSERT(r); - PGresult *result = PQexec(test_connection, "savepoint sp;"); - PQclear(result); - int pgfd = lo_open(test_connection, oid, INV_READ); - UCX_TEST_ASSERT(pgfd < 0, "large object not deleted"); - result = PQexec(test_connection, "rollback to savepoint sp;"); - PQclear(result); - - r = vfs_unlink(vfs, "/test_unlink1"); - UCX_TEST_ASSERT(r, "unlink should fail"); - - UCX_TEST_END; + } testutil_destroy_session(sn); } -UCX_TEST(test_pg_vfs_rmdir) { +CX_TEST(test_pg_vfs_rmdir) { Session *sn = testutil_session(); Request *rq = testutil_request(sn->pool, "PUT", "/"); rq->vfs = create_test_pgvfs(sn, rq); @@ -470,37 +468,37 @@ PQexec(test_connection, "delete from Resource where parent_id is not null;"); - UCX_TEST_BEGIN; - - int r; - SYS_FILE f1; - - // prepare some dirs/files - r = vfs_mkdir(vfs, "/rmdir_test"); - UCX_TEST_ASSERT(r == 0, "mkdir failed (1)"); - r = vfs_mkdir(vfs, "/rmdir_test/subdir1"); - UCX_TEST_ASSERT(r == 0, "mkdir failed (2)"); - r = vfs_mkdir(vfs, "/rmdir_test/subdir2"); - UCX_TEST_ASSERT(r == 0, "mkdir failed (3)"); + CX_TEST_DO { - f1 = vfs_open(vfs, "/rmdir_test/subdir2/file", O_CREAT|O_WRONLY); - UCX_TEST_ASSERT(f1, "open failed"); - vfs_close(f1); - - // test rmdir - r = vfs_rmdir(vfs, "/rmdir_test/subdir1"); - UCX_TEST_ASSERT(r == 0, "rmdir failed");; - - r = vfs_rmdir(vfs, "/rmdir_test/subdir2"); - UCX_TEST_ASSERT(r != 0, "rmdir should fail if the dir is not empty"); - - r = vfs_unlink(vfs, "/rmdir_test/subdir2/file"); - UCX_TEST_ASSERT(r == 0, "unlink failed"); - - r = vfs_rmdir(vfs, "/rmdir_test/subdir2"); - UCX_TEST_ASSERT(r == 0, "rmdir failed 2"); - - UCX_TEST_END; + int r; + SYS_FILE f1; + + // prepare some dirs/files + r = vfs_mkdir(vfs, "/rmdir_test"); + CX_TEST_ASSERT(r == 0); + r = vfs_mkdir(vfs, "/rmdir_test/subdir1"); + CX_TEST_ASSERT(r == 0); + r = vfs_mkdir(vfs, "/rmdir_test/subdir2"); + CX_TEST_ASSERT(r == 0); + + f1 = vfs_open(vfs, "/rmdir_test/subdir2/file", O_CREAT|O_WRONLY); + CX_TEST_ASSERT(f1); + vfs_close(f1); + + // test rmdir + r = vfs_rmdir(vfs, "/rmdir_test/subdir1"); + CX_TEST_ASSERT(r == 0); + + r = vfs_rmdir(vfs, "/rmdir_test/subdir2"); + CX_TEST_ASSERT(r != 0); + + r = vfs_unlink(vfs, "/rmdir_test/subdir2/file"); + CX_TEST_ASSERT(r == 0); + + r = vfs_rmdir(vfs, "/rmdir_test/subdir2"); + CX_TEST_ASSERT(r == 0); + + } testutil_destroy_session(sn); } @@ -512,404 +510,401 @@ return pg_webdav_create_from_resdata(sn, rq, &test_repo, &resdata); } -UCX_TEST(test_pg_webdav_create_from_resdata) { +CX_TEST(test_pg_webdav_create_from_resdata) { Session *sn = testutil_session(); Request *rq = testutil_request(sn->pool, "PROPFIND", "/"); - UCX_TEST_BEGIN; + CX_TEST_DO { - WebdavBackend *dav = create_test_pgdav(sn, rq); - UCX_TEST_ASSERT(dav, "cannot create pg dav backend"); + WebdavBackend *dav = create_test_pgdav(sn, rq); + CX_TEST_ASSERT(dav); - UCX_TEST_END; + } } -UCX_TEST(test_pg_prepare_tests) { +CX_TEST(test_pg_prepare_tests) { Session *sn = testutil_session(); Request *rq = testutil_request(sn->pool, "PUT", "/"); rq->vfs = create_test_pgvfs(sn, rq); VFSContext *vfs = vfs_request_context(sn, rq); - UCX_TEST_BEGIN; - - vfs_mkdir(vfs, "/propfind"); - vfs_mkdir(vfs, "/proppatch"); - SYS_FILE f1; - - int64_t res1_id, res2_id; - - f1 = vfs_open(vfs, "/propfind/res1", O_WRONLY|O_CREAT); - UCX_TEST_ASSERT(f1, "res1 create failed"); - res1_id = ((PgFile*)f1->data)->resource_id; - vfs_close(f1); - - f1 = vfs_open(vfs, "/propfind/res2", O_WRONLY|O_CREAT); - UCX_TEST_ASSERT(f1, "res2 create failed"); - res2_id = ((PgFile*)f1->data)->resource_id; - vfs_close(f1); - - f1 = vfs_open(vfs, "/propfind/res3", O_WRONLY|O_CREAT); - UCX_TEST_ASSERT(f1, "res3 create failed"); - vfs_close(f1); - - int r = vfs_mkdir(vfs, "/propfind/sub"); - UCX_TEST_ASSERT(r == 0, "sub create failed"); - - f1 = vfs_open(vfs, "/propfind/sub/res4", O_WRONLY|O_CREAT); - UCX_TEST_ASSERT(f1, "res4 create failed"); - vfs_close(f1); - - f1 = vfs_open(vfs, "/proppatch/pp1", O_WRONLY|O_CREAT); - UCX_TEST_ASSERT(f1, "pp1 create failed"); - vfs_close(f1); + CX_TEST_DO { - // 2 properties for res1 - char idstr[32]; - snprintf(idstr, 32, "%" PRId64, res1_id); - const char* params[1] = { idstr }; - PGresult *result = PQexecParams( - test_connection, - "insert into Property(resource_id, prefix, xmlns, pname, pvalue) values ($1, 'x', 'http://example.com/', 'test', 'testvalue');", - 1, // number of parameters - NULL, - params, // parameter value - NULL, - NULL, - 0); // 0: result in text format - - UCX_TEST_ASSERT(PQresultStatus(result) == PGRES_COMMAND_OK, "cannot create property 1"); - PQclear(result); + vfs_mkdir(vfs, "/propfind"); + vfs_mkdir(vfs, "/proppatch"); + SYS_FILE f1; + + int64_t res1_id, res2_id; + + f1 = vfs_open(vfs, "/propfind/res1", O_WRONLY|O_CREAT); + CX_TEST_ASSERT(f1); + res1_id = ((PgFile*)f1->data)->resource_id; + vfs_close(f1); + + f1 = vfs_open(vfs, "/propfind/res2", O_WRONLY|O_CREAT); + CX_TEST_ASSERT(f1); + res2_id = ((PgFile*)f1->data)->resource_id; + vfs_close(f1); + + f1 = vfs_open(vfs, "/propfind/res3", O_WRONLY|O_CREAT); + CX_TEST_ASSERT(f1); + vfs_close(f1); + + int r = vfs_mkdir(vfs, "/propfind/sub"); + CX_TEST_ASSERT(r == 0); + + f1 = vfs_open(vfs, "/propfind/sub/res4", O_WRONLY|O_CREAT); + CX_TEST_ASSERT(f1); + vfs_close(f1); + + f1 = vfs_open(vfs, "/proppatch/pp1", O_WRONLY|O_CREAT); + CX_TEST_ASSERT(f1); + vfs_close(f1); + + // 2 properties for res1 + char idstr[32]; + snprintf(idstr, 32, "%" PRId64, res1_id); + const char* params[1] = { idstr }; + PGresult *result = PQexecParams( + test_connection, + "insert into Property(resource_id, prefix, xmlns, pname, pvalue) values ($1, 'x', 'http://example.com/', 'test', 'testvalue');", + 1, // number of parameters + NULL, + params, // parameter value + NULL, + NULL, + 0); // 0: result in text format + + CX_TEST_ASSERT(PQresultStatus(result) == PGRES_COMMAND_OK); + PQclear(result); + + result = PQexecParams( + test_connection, + "insert into Property(resource_id, prefix, xmlns, pname, pvalue) values ($1, 'x', 'http://example.com/', 'prop2', 'value2');", + 1, // number of parameters + NULL, + params, // parameter value + NULL, + NULL, + 0); // 0: result in text format + + CX_TEST_ASSERT(PQresultStatus(result) == PGRES_COMMAND_OK); + PQclear(result); + + // 1 property for res2 + snprintf(idstr, 32, "%" PRId64, res2_id); + result = PQexecParams( + test_connection, + "insert into Property(resource_id, prefix, xmlns, pname, pvalue) values ($1, 'x', 'http://example.com/', 'test', 'res2test');", + 1, // number of parameters + NULL, + params, // parameter value + NULL, + NULL, + 0); // 0: result in text format + + CX_TEST_ASSERT(PQresultStatus(result) == PGRES_COMMAND_OK); + PQclear(result); - result = PQexecParams( - test_connection, - "insert into Property(resource_id, prefix, xmlns, pname, pvalue) values ($1, 'x', 'http://example.com/', 'prop2', 'value2');", - 1, // number of parameters - NULL, - params, // parameter value - NULL, - NULL, - 0); // 0: result in text format - - UCX_TEST_ASSERT(PQresultStatus(result) == PGRES_COMMAND_OK, "cannot create property 1"); - PQclear(result); - - // 1 property for res2 - snprintf(idstr, 32, "%" PRId64, res2_id); - result = PQexecParams( - test_connection, - "insert into Property(resource_id, prefix, xmlns, pname, pvalue) values ($1, 'x', 'http://example.com/', 'test', 'res2test');", - 1, // number of parameters - NULL, - params, // parameter value - NULL, - NULL, - 0); // 0: result in text format - - UCX_TEST_ASSERT(PQresultStatus(result) == PGRES_COMMAND_OK, "cannot create property 1"); - PQclear(result); - - UCX_TEST_END; + } testutil_destroy_session(sn); } -UCX_TEST(test_pg_webdav_propfind) { +CX_TEST(test_pg_webdav_propfind) { Session *sn; Request *rq; TestIOStream *st; pblock *pb; - UCX_TEST_BEGIN; - - // test data: - // - // /propfind/ - // /propfind/res1 (2 properties: test, prop2) - // /propfind/res2 (1 property: test) - // /propfind/res3 - // /propfind/sub - // /propfind/sub/res4 - - int ret; - // Test 1 - init_test_webdav_method(&sn, &rq, &st, &pb, "PROPFIND", "/propfind/", PG_TEST_PROPFIND1); - rq->davCollection = create_test_pgdav(sn, rq); - pblock_nvinsert("depth", "0", rq->headers); - - ret = webdav_propfind(pb, sn, rq); - - UCX_TEST_ASSERT(ret == REQ_PROCEED, "webdav_propfind (1) failed"); - - TestMultistatus *ms = test_parse_multistatus(st->buf->space, st->buf->size); - UCX_TEST_ASSERT(ms, "propfind1: response is not valid xml"); - - TestResponse *r1 = MAP_GET(ms->responses, "/propfind/"); - UCX_TEST_ASSERT(r1, "propfind1: missing /propfind/ response"); - - UCX_TEST_ASSERT(cxMapSize(ms->responses) == 1, "propfind1: wrong response count"); - - TestProperty *p = MAP_GET(r1->properties, "DAV:resourcetype"); - UCX_TEST_ASSERT(p, "propfind1: missing property 'resourcetype'"); - UCX_TEST_ASSERT(p->status == 200, "propfind1: wrong status code for property 'resourcetype'"); - - p = MAP_GET(r1->properties, "DAV:getlastmodified"); - UCX_TEST_ASSERT(p, "propfind1: missing property 'getlastmodified'"); - UCX_TEST_ASSERT(p->status == 200, "propfind1: wrong status code for property 'getlastmodified'"); - - testutil_destroy_session(sn); - test_multistatus_destroy(ms); - testutil_iostream_destroy(st); - - - // Test 2 - init_test_webdav_method(&sn, &rq, &st, &pb, "PROPFIND", "/propfind/", PG_TEST_PROPFIND2); - rq->davCollection = create_test_pgdav(sn, rq); - pblock_nvinsert("depth", "1", rq->headers); - - ret = webdav_propfind(pb, sn, rq); - - //printf("\n\n%.*s\n", (int)st->buf->size, st->buf->space); - - UCX_TEST_ASSERT(ret == REQ_PROCEED, "webdav_propfind (2) failed"); - - ms = test_parse_multistatus(st->buf->space, st->buf->size); - UCX_TEST_ASSERT(ms, "propfind2: response is not valid xml"); - - r1 = MAP_GET(ms->responses, "/propfind/"); - UCX_TEST_ASSERT(r1, "propfind2: missing /propfind/ response"); + CX_TEST_DO { - UCX_TEST_ASSERT(cxMapSize(ms->responses) == 5, "propfind2: wrong response count"); - - r1 = MAP_GET(ms->responses, "/propfind/res2"); - UCX_TEST_ASSERT(r1, "propfind2: missing /propfind/res2 response"); - - p = MAP_GET(r1->properties, "http://example.com/test"); - UCX_TEST_ASSERT(p, "propfind2: missing property 'test'"); - UCX_TEST_ASSERT(p->status == 200, "propfind2: wrong status code for property 'test'"); - UCX_TEST_ASSERT(!strcmp(p->value, "res2test"), "propfind2: wrong property value"); - - - testutil_destroy_session(sn); - test_multistatus_destroy(ms); - testutil_iostream_destroy(st); - - - - // Test 3 - init_test_webdav_method(&sn, &rq, &st, &pb, "PROPFIND", "/propfind/", PG_TEST_PROPFIND2); - rq->davCollection = create_test_pgdav(sn, rq); - pblock_nvinsert("depth", "infinity", rq->headers); - - ret = webdav_propfind(pb, sn, rq); - - //printf("\n\n%.*s\n", (int)st->buf->size, st->buf->space); - - UCX_TEST_ASSERT(ret == REQ_PROCEED, "webdav_propfind (3) failed"); + // test data: + // + // /propfind/ + // /propfind/res1 (2 properties: test, prop2) + // /propfind/res2 (1 property: test) + // /propfind/res3 + // /propfind/sub + // /propfind/sub/res4 + + int ret; + // Test 1 + init_test_webdav_method(&sn, &rq, &st, &pb, "PROPFIND", "/propfind/", PG_TEST_PROPFIND1); + rq->davCollection = create_test_pgdav(sn, rq); + pblock_nvinsert("depth", "0", rq->headers); + + ret = webdav_propfind(pb, sn, rq); + + CX_TEST_ASSERT(ret == REQ_PROCEED); + + TestMultistatus *ms = test_parse_multistatus(st->buf->space, st->buf->size); + CX_TEST_ASSERT(ms); + + TestResponse *r1 = MAP_GET(ms->responses, "/propfind/"); + CX_TEST_ASSERT(r1); + + CX_TEST_ASSERT(cxMapSize(ms->responses) == 1); + + TestProperty *p = MAP_GET(r1->properties, "DAV:resourcetype"); + CX_TEST_ASSERT(p); + CX_TEST_ASSERT(p->status == 200); + + p = MAP_GET(r1->properties, "DAV:getlastmodified"); + CX_TEST_ASSERT(p); + CX_TEST_ASSERT(p->status == 200); + + testutil_destroy_session(sn); + test_multistatus_destroy(ms); + testutil_iostream_destroy(st); + + + // Test 2 + init_test_webdav_method(&sn, &rq, &st, &pb, "PROPFIND", "/propfind/", PG_TEST_PROPFIND2); + rq->davCollection = create_test_pgdav(sn, rq); + pblock_nvinsert("depth", "1", rq->headers); + + ret = webdav_propfind(pb, sn, rq); + + //printf("\n\n%.*s\n", (int)st->buf->size, st->buf->space); + + CX_TEST_ASSERT(ret == REQ_PROCEED); + + ms = test_parse_multistatus(st->buf->space, st->buf->size); + CX_TEST_ASSERT(ms); + + r1 = MAP_GET(ms->responses, "/propfind/"); + CX_TEST_ASSERT(r1); + + CX_TEST_ASSERT(cxMapSize(ms->responses) == 5); + + r1 = MAP_GET(ms->responses, "/propfind/res2"); + CX_TEST_ASSERT(r1); + + p = MAP_GET(r1->properties, "http://example.com/test"); + CX_TEST_ASSERT(p); + CX_TEST_ASSERT(p->status == 200); + CX_TEST_ASSERT(!strcmp(p->value, "res2test")); + + + testutil_destroy_session(sn); + test_multistatus_destroy(ms); + testutil_iostream_destroy(st); + + + + // Test 3 + init_test_webdav_method(&sn, &rq, &st, &pb, "PROPFIND", "/propfind/", PG_TEST_PROPFIND2); + rq->davCollection = create_test_pgdav(sn, rq); + pblock_nvinsert("depth", "infinity", rq->headers); + + ret = webdav_propfind(pb, sn, rq); + + //printf("\n\n%.*s\n", (int)st->buf->size, st->buf->space); + + CX_TEST_ASSERT(ret == REQ_PROCEED); + + ms = test_parse_multistatus(st->buf->space, st->buf->size); + CX_TEST_ASSERT(ms); + + r1 = MAP_GET(ms->responses, "/propfind/"); + CX_TEST_ASSERT(r1); + + CX_TEST_ASSERT(cxMapSize(ms->responses) == 6); + + + r1 = MAP_GET(ms->responses, "/propfind/res1"); + CX_TEST_ASSERT(r1); + + p = MAP_GET(r1->properties, "http://example.com/test"); + CX_TEST_ASSERT(p); + CX_TEST_ASSERT(p->status == 200); + CX_TEST_ASSERT(!strcmp(p->value, "testvalue")); + + p = MAP_GET(r1->properties, "http://example.com/prop2"); + CX_TEST_ASSERT(p); + CX_TEST_ASSERT(p->status == 200); + CX_TEST_ASSERT(!strcmp(p->value, "value2")); + + + r1 = MAP_GET(ms->responses, "/propfind/sub/res4"); + CX_TEST_ASSERT(r1); + + testutil_destroy_session(sn); + test_multistatus_destroy(ms); + testutil_iostream_destroy(st); - ms = test_parse_multistatus(st->buf->space, st->buf->size); - UCX_TEST_ASSERT(ms, "propfind3: response is not valid xml"); - - r1 = MAP_GET(ms->responses, "/propfind/"); - UCX_TEST_ASSERT(r1, "propfind3: missing /propfind/ response"); - - UCX_TEST_ASSERT(cxMapSize(ms->responses) == 6, "propfind3: wrong response count"); - - - r1 = MAP_GET(ms->responses, "/propfind/res1"); - UCX_TEST_ASSERT(r1, "propfind3: missing /propfind/sub/res1 response"); - - p = MAP_GET(r1->properties, "http://example.com/test"); - UCX_TEST_ASSERT(p, "propfind3: missing property 'test'"); - UCX_TEST_ASSERT(p->status == 200, "propfind3: wrong status code for property 'test'"); - UCX_TEST_ASSERT(!strcmp(p->value, "testvalue"), "propfind3: wrong property value"); - - p = MAP_GET(r1->properties, "http://example.com/prop2"); - UCX_TEST_ASSERT(p, "propfind3: missing property 'prop2'"); - UCX_TEST_ASSERT(p->status == 200, "propfind3: wrong status code for property 'prop2'"); - UCX_TEST_ASSERT(!strcmp(p->value, "value2"), "propfind3: wrong property value"); - - - r1 = MAP_GET(ms->responses, "/propfind/sub/res4"); - UCX_TEST_ASSERT(r1, "propfind3: missing /propfind/sub/res4 response"); - - testutil_destroy_session(sn); - test_multistatus_destroy(ms); - testutil_iostream_destroy(st); - - UCX_TEST_END; + } } -UCX_TEST(test_pg_webdav_propfind_allprop) { +CX_TEST(test_pg_webdav_propfind_allprop) { Session *sn; Request *rq; TestIOStream *st; pblock *pb; - UCX_TEST_BEGIN; - - // test data: - // - // /propfind/ - // /propfind/res1 (2 properties: test, prop2) - // /propfind/res2 (1 property: test) - // /propfind/res3 - // /propfind/sub - // /propfind/sub/res4 - - int ret; - TestResponse *r1; - TestProperty *p; - // Test 1 - init_test_webdav_method(&sn, &rq, &st, &pb, "PROPFIND", "/propfind/", PG_TEST_ALLPROP); - rq->davCollection = create_test_pgdav(sn, rq); - pblock_nvinsert("depth", "0", rq->headers); - - ret = webdav_propfind(pb, sn, rq); - - UCX_TEST_ASSERT(ret == REQ_PROCEED, "webdav_propfind (1) failed"); - - TestMultistatus *ms = test_parse_multistatus(st->buf->space, st->buf->size); - UCX_TEST_ASSERT(ms, "propfind1: response is not valid xml"); - - r1 = MAP_GET(ms->responses, "/propfind/"); - UCX_TEST_ASSERT(r1, "propfind1: missing /propfind/ response"); - UCX_TEST_ASSERT(cxMapSize(ms->responses) == 1, "propfind1: wrong response count"); - - p = MAP_GET(r1->properties, "DAV:resourcetype"); - UCX_TEST_ASSERT(r1, "propfind1: missing resourcetype property"); - - testutil_destroy_session(sn); - test_multistatus_destroy(ms); - testutil_iostream_destroy(st); - - // Test 2 - init_test_webdav_method(&sn, &rq, &st, &pb, "PROPFIND", "/propfind/", PG_TEST_ALLPROP); - rq->davCollection = create_test_pgdav(sn, rq); - pblock_nvinsert("depth", "1", rq->headers); - - ret = webdav_propfind(pb, sn, rq); - - //printf("\n\n%.*s\n", (int)st->buf->size, st->buf->space); - - UCX_TEST_ASSERT(ret == REQ_PROCEED, "webdav_propfind (2) failed"); - - ms = test_parse_multistatus(st->buf->space, st->buf->size); - UCX_TEST_ASSERT(ms, "propfind2: response is not valid xml"); - - r1 = MAP_GET(ms->responses, "/propfind/"); - UCX_TEST_ASSERT(r1, "propfind2: missing /propfind/ response"); - UCX_TEST_ASSERT(cxMapSize(ms->responses) == 5, "propfind2: wrong response count"); + CX_TEST_DO { - r1 = MAP_GET(ms->responses, "/propfind/res1"); - UCX_TEST_ASSERT(r1, "propfind2: missing /propfind/res1 response"); - - p = MAP_GET(r1->properties, "DAV:resourcetype"); - UCX_TEST_ASSERT(r1, "propfind2: missing resourcetype property"); - p = MAP_GET(r1->properties, "http://example.com/test"); - UCX_TEST_ASSERT(r1, "propfind2: missing test property"); - p = MAP_GET(r1->properties, "http://example.com/prop2"); - UCX_TEST_ASSERT(r1, "propfind2: missing prop2 property"); - - UCX_TEST_ASSERT(MAP_GET(ms->responses, "/propfind/res2"), "propfind2: missing /propfind/res2 response"); - UCX_TEST_ASSERT(MAP_GET(ms->responses, "/propfind/res3"), "propfind2: missing /propfind/res3 response"); - UCX_TEST_ASSERT(MAP_GET(ms->responses, "/propfind/sub/"), "propfind2: missing /propfind/sub response"); - - testutil_destroy_session(sn); - test_multistatus_destroy(ms); - testutil_iostream_destroy(st); - - // Test 3 - init_test_webdav_method(&sn, &rq, &st, &pb, "PROPFIND", "/propfind/", PG_TEST_ALLPROP); - rq->davCollection = create_test_pgdav(sn, rq); - pblock_nvinsert("depth", "infinity", rq->headers); - - ret = webdav_propfind(pb, sn, rq); - - UCX_TEST_ASSERT(ret == REQ_PROCEED, "webdav_propfind (2) failed"); - - ms = test_parse_multistatus(st->buf->space, st->buf->size); - UCX_TEST_ASSERT(ms, "propfind3: response is not valid xml"); - - r1 = MAP_GET(ms->responses, "/propfind/"); - UCX_TEST_ASSERT(r1, "propfind3: missing /propfind/ response"); - UCX_TEST_ASSERT(cxMapSize(ms->responses) == 6, "propfind3: wrong response count"); - - r1 = MAP_GET(ms->responses, "/propfind/res1"); - UCX_TEST_ASSERT(r1, "propfind3: missing /propfind/res1 response"); - - p = MAP_GET(r1->properties, "DAV:resourcetype"); - UCX_TEST_ASSERT(r1, "propfind3: missing resourcetype property"); - p = MAP_GET(r1->properties, "http://example.com/test"); - UCX_TEST_ASSERT(r1, "propfind3: missing test property"); - p = MAP_GET(r1->properties, "http://example.com/prop2"); - UCX_TEST_ASSERT(r1, "propfind3: missing prop2 property"); - - UCX_TEST_ASSERT(MAP_GET(ms->responses, "/propfind/res2"), "propfind3: missing /propfind/res2 response"); - UCX_TEST_ASSERT(MAP_GET(ms->responses, "/propfind/res3"), "propfind3: missing /propfind/res3 response"); - UCX_TEST_ASSERT(MAP_GET(ms->responses, "/propfind/sub/"), "propfind3: missing /propfind/sub response"); - UCX_TEST_ASSERT(MAP_GET(ms->responses, "/propfind/sub/res4"), "propfind3: missing /propfind/sub/res4 response"); - - testutil_destroy_session(sn); - test_multistatus_destroy(ms); - testutil_iostream_destroy(st); - - - UCX_TEST_END; + // test data: + // + // /propfind/ + // /propfind/res1 (2 properties: test, prop2) + // /propfind/res2 (1 property: test) + // /propfind/res3 + // /propfind/sub + // /propfind/sub/res4 + + int ret; + TestResponse *r1; + TestProperty *p; + // Test 1 + init_test_webdav_method(&sn, &rq, &st, &pb, "PROPFIND", "/propfind/", PG_TEST_ALLPROP); + rq->davCollection = create_test_pgdav(sn, rq); + pblock_nvinsert("depth", "0", rq->headers); + + ret = webdav_propfind(pb, sn, rq); + + CX_TEST_ASSERT(ret == REQ_PROCEED); + + TestMultistatus *ms = test_parse_multistatus(st->buf->space, st->buf->size); + CX_TEST_ASSERT(ms); + + r1 = MAP_GET(ms->responses, "/propfind/"); + CX_TEST_ASSERT(r1); + CX_TEST_ASSERT(cxMapSize(ms->responses) == 1); + + p = MAP_GET(r1->properties, "DAV:resourcetype"); + CX_TEST_ASSERT(r1); + + testutil_destroy_session(sn); + test_multistatus_destroy(ms); + testutil_iostream_destroy(st); + + // Test 2 + init_test_webdav_method(&sn, &rq, &st, &pb, "PROPFIND", "/propfind/", PG_TEST_ALLPROP); + rq->davCollection = create_test_pgdav(sn, rq); + pblock_nvinsert("depth", "1", rq->headers); + + ret = webdav_propfind(pb, sn, rq); + + //printf("\n\n%.*s\n", (int)st->buf->size, st->buf->space); + + CX_TEST_ASSERT(ret == REQ_PROCEED); + + ms = test_parse_multistatus(st->buf->space, st->buf->size); + CX_TEST_ASSERT(ms); + + r1 = MAP_GET(ms->responses, "/propfind/"); + CX_TEST_ASSERT(r1); + CX_TEST_ASSERT(cxMapSize(ms->responses) == 5); + + r1 = MAP_GET(ms->responses, "/propfind/res1"); + CX_TEST_ASSERT(r1); + + p = MAP_GET(r1->properties, "DAV:resourcetype"); + CX_TEST_ASSERT(r1); + p = MAP_GET(r1->properties, "http://example.com/test"); + CX_TEST_ASSERT(r1); + p = MAP_GET(r1->properties, "http://example.com/prop2"); + CX_TEST_ASSERT(r1); + + CX_TEST_ASSERT(MAP_GET(ms->responses, "/propfind/res2")); + CX_TEST_ASSERT(MAP_GET(ms->responses, "/propfind/res3")); + CX_TEST_ASSERT(MAP_GET(ms->responses, "/propfind/sub/")); + + testutil_destroy_session(sn); + test_multistatus_destroy(ms); + testutil_iostream_destroy(st); + + // Test 3 + init_test_webdav_method(&sn, &rq, &st, &pb, "PROPFIND", "/propfind/", PG_TEST_ALLPROP); + rq->davCollection = create_test_pgdav(sn, rq); + pblock_nvinsert("depth", "infinity", rq->headers); + + ret = webdav_propfind(pb, sn, rq); + + CX_TEST_ASSERT(ret == REQ_PROCEED); + + ms = test_parse_multistatus(st->buf->space, st->buf->size); + CX_TEST_ASSERT(ms); + + r1 = MAP_GET(ms->responses, "/propfind/"); + CX_TEST_ASSERT(r1); + CX_TEST_ASSERT(cxMapSize(ms->responses) == 6); + + r1 = MAP_GET(ms->responses, "/propfind/res1"); + CX_TEST_ASSERT(r1); + + p = MAP_GET(r1->properties, "DAV:resourcetype"); + CX_TEST_ASSERT(r1); + p = MAP_GET(r1->properties, "http://example.com/test"); + CX_TEST_ASSERT(r1); + p = MAP_GET(r1->properties, "http://example.com/prop2"); + CX_TEST_ASSERT(r1); + + CX_TEST_ASSERT(MAP_GET(ms->responses, "/propfind/res2")); + CX_TEST_ASSERT(MAP_GET(ms->responses, "/propfind/res3")); + CX_TEST_ASSERT(MAP_GET(ms->responses, "/propfind/sub/")); + CX_TEST_ASSERT(MAP_GET(ms->responses, "/propfind/sub/res4")); + + testutil_destroy_session(sn); + test_multistatus_destroy(ms); + testutil_iostream_destroy(st); + } } -UCX_TEST(test_pg_webdav_proppatch_set) { +CX_TEST(test_pg_webdav_proppatch_set) { Session *sn; Request *rq; TestIOStream *st; pblock *pb; - UCX_TEST_BEGIN; - - // test data: - // - // /propfind/ - // /propfind/res1 (2 properties: test, prop2) - // /propfind/res2 (1 property: test) - // /propfind/res3 - // /propfind/sub - // /propfind/sub/res4 - - int ret; - TestResponse *r1; - TestProperty *p; - // Test 1 - init_test_webdav_method(&sn, &rq, &st, &pb, "PROPPATCH", "/proppatch/pp1", PG_TEST_PROPPATCH1); - rq->davCollection = create_test_pgdav(sn, rq); - - ret = webdav_proppatch(pb, sn, rq); - UCX_TEST_ASSERT(ret == REQ_PROCEED, "proppatch1 failed"); - - //printf("\n\n%.*s\n", (int)st->buf->size, st->buf->space); + CX_TEST_DO { - TestMultistatus *ms = test_parse_multistatus(st->buf->space, st->buf->size); - UCX_TEST_ASSERT(ms, "proppatch1 response is not valid xml"); - - testutil_destroy_session(sn); - test_multistatus_destroy(ms); - testutil_iostream_destroy(st); - - // Test 2: xml property value - init_test_webdav_method(&sn, &rq, &st, &pb, "PROPPATCH", "/proppatch/pp1", PG_TEST_PROPPATCH2); - rq->davCollection = create_test_pgdav(sn, rq); + // test data: + // + // /propfind/ + // /propfind/res1 (2 properties: test, prop2) + // /propfind/res2 (1 property: test) + // /propfind/res3 + // /propfind/sub + // /propfind/sub/res4 + + int ret; + TestResponse *r1; + TestProperty *p; + // Test 1 + init_test_webdav_method(&sn, &rq, &st, &pb, "PROPPATCH", "/proppatch/pp1", PG_TEST_PROPPATCH1); + rq->davCollection = create_test_pgdav(sn, rq); + + ret = webdav_proppatch(pb, sn, rq); + CX_TEST_ASSERT(ret == REQ_PROCEED); + + //printf("\n\n%.*s\n", (int)st->buf->size, st->buf->space); + + TestMultistatus *ms = test_parse_multistatus(st->buf->space, st->buf->size); + CX_TEST_ASSERT(ms); + + testutil_destroy_session(sn); + test_multistatus_destroy(ms); + testutil_iostream_destroy(st); + + // Test 2: xml property value + init_test_webdav_method(&sn, &rq, &st, &pb, "PROPPATCH", "/proppatch/pp1", PG_TEST_PROPPATCH2); + rq->davCollection = create_test_pgdav(sn, rq); + + ret = webdav_proppatch(pb, sn, rq); + CX_TEST_ASSERT(ret == REQ_PROCEED); + + //printf("\n\n%.*s\n", (int)st->buf->size, st->buf->space); + + ms = test_parse_multistatus(st->buf->space, st->buf->size); + CX_TEST_ASSERT(ms); + + testutil_destroy_session(sn); + test_multistatus_destroy(ms); + testutil_iostream_destroy(st); - ret = webdav_proppatch(pb, sn, rq); - UCX_TEST_ASSERT(ret == REQ_PROCEED, "proppatch2 failed"); - - //printf("\n\n%.*s\n", (int)st->buf->size, st->buf->space); - - ms = test_parse_multistatus(st->buf->space, st->buf->size); - UCX_TEST_ASSERT(ms, "proppatch2 response is not valid xml"); - - testutil_destroy_session(sn); - test_multistatus_destroy(ms); - testutil_iostream_destroy(st); - - - UCX_TEST_END; + } }
--- a/src/server/plugins/postgresql/pgtest.h Sat Nov 22 12:49:20 2025 +0100 +++ b/src/server/plugins/postgresql/pgtest.h Sat Nov 22 14:27:01 2025 +0100 @@ -47,22 +47,22 @@ TestMultistatus* test_parse_multistatus(const char *space, size_t size); void test_multistatus_destroy(TestMultistatus *ms); -UCX_TEST(test_pg_conn); +CX_TEST(test_pg_conn); -UCX_TEST(test_pg_lookup_root); +CX_TEST(test_pg_lookup_root); -UCX_TEST(test_pg_vfs_open); -UCX_TEST(test_pg_vfs_io); -UCX_TEST(test_pg_vfs_stat); -UCX_TEST(test_pg_vfs_mkdir); -UCX_TEST(test_pg_vfs_unlink); -UCX_TEST(test_pg_vfs_rmdir); +CX_TEST(test_pg_vfs_open); +CX_TEST(test_pg_vfs_io); +CX_TEST(test_pg_vfs_stat); +CX_TEST(test_pg_vfs_mkdir); +CX_TEST(test_pg_vfs_unlink); +CX_TEST(test_pg_vfs_rmdir); -UCX_TEST(test_pg_webdav_create_from_resdata); -UCX_TEST(test_pg_prepare_tests); -UCX_TEST(test_pg_webdav_propfind); -UCX_TEST(test_pg_webdav_propfind_allprop); -UCX_TEST(test_pg_webdav_proppatch_set); +CX_TEST(test_pg_webdav_create_from_resdata); +CX_TEST(test_pg_prepare_tests); +CX_TEST(test_pg_webdav_propfind); +CX_TEST(test_pg_webdav_propfind_allprop); +CX_TEST(test_pg_webdav_proppatch_set); /* --------------------------- PROPFIND --------------------------- */
--- a/src/server/test/event.c Sat Nov 22 12:49:20 2025 +0100 +++ b/src/server/test/event.c Sat Nov 22 14:27:01 2025 +0100 @@ -40,29 +40,27 @@ int i2; } EVTest; -UCX_TEST(test_evhandler_create) { +CX_TEST(test_evhandler_create) { EventHandlerConfig cfg1 = { .nthreads = 1}; EventHandlerConfig cfg4 = { .nthreads = 4}; - UCX_TEST_BEGIN; - - EVHandler *ev1 = evhandler_create(&cfg1); - UCX_TEST_ASSERT(ev1, "evhandler_create (1) failed"); - UCX_TEST_ASSERT(ev1->numins == 1, "ev1 wrong number of instances"); - - EVHandler *ev2 = evhandler_create(&cfg4); - UCX_TEST_ASSERT(ev2, "evhandler_create (2) failed"); - UCX_TEST_ASSERT(ev2->numins == 4, "ev2 wrong number of instances"); - - - evhandler_shutdown(ev1); - evhandler_shutdown(ev2); - - evhandler_wait_and_destroy(ev1); - evhandler_wait_and_destroy(ev2); - - UCX_TEST_END; + CX_TEST_DO { + EVHandler *ev1 = evhandler_create(&cfg1); + CX_TEST_ASSERT(ev1); + CX_TEST_ASSERT(ev1->numins == 1); + + EVHandler *ev2 = evhandler_create(&cfg4); + CX_TEST_ASSERT(ev2); + CX_TEST_ASSERT(ev2->numins == 4); + + + evhandler_shutdown(ev1); + evhandler_shutdown(ev2); + + evhandler_wait_and_destroy(ev1); + evhandler_wait_and_destroy(ev2); + } } static int test_event_send_fn(EventHandler *h, Event *event) { @@ -91,7 +89,7 @@ } } -UCX_TEST(test_event_send) { +CX_TEST(test_event_send) { EventHandlerConfig cfg = { .nthreads = 1}; EVHandler *ev = evhandler_create(&cfg); @@ -103,27 +101,27 @@ pthread_mutex_init(&testdata.mutex, NULL); pthread_cond_init(&testdata.cond, NULL); - UCX_TEST_BEGIN; - - // test sending a single event - // the event signals completion in the testdata object - // wait up to 10 seconds for completion (it should be instantly) - - Event evt; - ZERO(&evt, sizeof(Event)); - evt.fn = test_event_send_fn; - evt.cookie = &testdata; + CX_TEST_DO { - int ret = event_send(h, &evt); - - // wait for event finish - testdata_wait_for_completion(&testdata); + // test sending a single event + // the event signals completion in the testdata object + // wait up to 10 seconds for completion (it should be instantly) + + Event evt; + ZERO(&evt, sizeof(Event)); + evt.fn = test_event_send_fn; + evt.cookie = &testdata; + + int ret = event_send(h, &evt); + + // wait for event finish + testdata_wait_for_completion(&testdata); + + CX_TEST_ASSERT(!ret); + CX_TEST_ASSERT(testdata.i1); + CX_TEST_ASSERT(testdata.i2); - UCX_TEST_ASSERT(!ret, "event_send failed"); - UCX_TEST_ASSERT(testdata.i1, "event callback not called"); - UCX_TEST_ASSERT(testdata.i2, "event callback received wrong event handler pointer"); - - UCX_TEST_END; + } pthread_mutex_destroy(&testdata.mutex); pthread_cond_destroy(&testdata.cond); @@ -176,7 +174,7 @@ return 0; } -UCX_TEST(test_event_send_multi) { +CX_TEST(test_event_send_multi) { EventHandlerConfig cfg = { .nthreads = 1}; EVHandler *ev = evhandler_create(&cfg); @@ -188,28 +186,28 @@ pthread_mutex_init(&testdata.mutex, NULL); pthread_cond_init(&testdata.cond, NULL); - UCX_TEST_BEGIN; - - // test sending multiple events - // the first callback test_event_send_multi_fn1 adds additional - // EV_TEST_NUM_EVENTS events to the handler + an additional - // finishing event, that notifies completion + CX_TEST_DO { - Event evt; - ZERO(&evt, sizeof(Event)); - evt.fn = test_event_send_multi_fn1; - evt.cookie = &testdata; - - int ret = event_send(h, &evt); + // test sending multiple events + // the first callback test_event_send_multi_fn1 adds additional + // EV_TEST_NUM_EVENTS events to the handler + an additional + // finishing event, that notifies completion + + Event evt; + ZERO(&evt, sizeof(Event)); + evt.fn = test_event_send_multi_fn1; + evt.cookie = &testdata; + + int ret = event_send(h, &evt); + + // wait for event finish + testdata_wait_for_completion(&testdata); + + CX_TEST_ASSERT(!ret); + CX_TEST_ASSERT(testdata.i1); + CX_TEST_ASSERT(testdata.i2 == EV_TEST_NUM_EVENTS); - // wait for event finish - testdata_wait_for_completion(&testdata); - - UCX_TEST_ASSERT(!ret, "event_send failed"); - UCX_TEST_ASSERT(testdata.i1, "event callback not called"); - UCX_TEST_ASSERT(testdata.i2 == EV_TEST_NUM_EVENTS, "event callback received wrong event handler pointer"); - - UCX_TEST_END; + } pthread_mutex_destroy(&testdata.mutex); pthread_cond_destroy(&testdata.cond);
--- a/src/server/test/event.h Sat Nov 22 12:49:20 2025 +0100 +++ b/src/server/test/event.h Sat Nov 22 14:27:01 2025 +0100 @@ -39,14 +39,14 @@ extern "C" { #endif -UCX_TEST(test_evhandler_create); -UCX_TEST(test_event_send); -UCX_TEST(test_event_send_multi); +CX_TEST(test_evhandler_create); +CX_TEST(test_event_send); +CX_TEST(test_event_send_multi); #ifdef __cplusplus } #endif -#endif /* EVENT_H */ +#endif /* TEST_EVENT_H */
--- a/src/server/test/io.c Sat Nov 22 12:49:20 2025 +0100 +++ b/src/server/test/io.c Sat Nov 22 14:27:01 2025 +0100 @@ -31,7 +31,7 @@ #include "testutils.h" -UCX_TEST(test_io_http_stream_parse_chunk_header_hdronly_first) { +CX_TEST(test_io_http_stream_parse_chunk_header_hdronly_first) { char *str = strdup("100\r\n"); size_t len = strlen(str); char *str2 = strdup("12345\r\n"); @@ -39,111 +39,111 @@ char *str3 = strdup("FF\r\n"); size_t len3 = strlen(str3); - UCX_TEST_BEGIN; - - int64_t chunklen; - int ret = http_stream_parse_chunk_header(str, len, TRUE, &chunklen); - UCX_TEST_ASSERT(ret == 5, "ret != 5"); - UCX_TEST_ASSERT(chunklen == 0x100, "wrong chunk length"); + CX_TEST_DO { - // test 2 - ret = http_stream_parse_chunk_header(str2, len2, TRUE, &chunklen); - UCX_TEST_ASSERT(ret == 7, "ret != 7 (test 2)"); - UCX_TEST_ASSERT(chunklen == 0x12345, "wrong chunk length (test 2)"); - - // test 3: hex test - ret = http_stream_parse_chunk_header(str3, len3, TRUE, &chunklen); - UCX_TEST_ASSERT(ret == 4, "ret != 7 (test 3)"); - UCX_TEST_ASSERT(chunklen == 0xFF, "wrong chunk length (test 3)"); + int64_t chunklen; + int ret = http_stream_parse_chunk_header(str, len, TRUE, &chunklen); + CX_TEST_ASSERT(ret == 5); + CX_TEST_ASSERT(chunklen == 0x100); + + // test 2 + ret = http_stream_parse_chunk_header(str2, len2, TRUE, &chunklen); + CX_TEST_ASSERT(ret == 7); + CX_TEST_ASSERT(chunklen == 0x12345); + + // test 3: hex test + ret = http_stream_parse_chunk_header(str3, len3, TRUE, &chunklen); + CX_TEST_ASSERT(ret == 4); + CX_TEST_ASSERT(chunklen == 0xFF); - UCX_TEST_END; + } free(str); free(str2); } -UCX_TEST(test_io_http_stream_parse_chunk_header_hdronly) { +CX_TEST(test_io_http_stream_parse_chunk_header_hdronly) { char *str = strdup("\r\n100\r\n"); size_t len = strlen(str); char *str2 = strdup("\nab\n"); size_t len2 = strlen(str2); - UCX_TEST_BEGIN; - - int64_t chunklen; - int ret = http_stream_parse_chunk_header(str, len, FALSE, &chunklen); - UCX_TEST_ASSERT(ret == 7, "ret != 7"); - UCX_TEST_ASSERT(chunklen == 0x100, "wrong chunk length"); + CX_TEST_DO { - // test 2 with just \n as line break - ret = http_stream_parse_chunk_header(str2, len2, FALSE, &chunklen); - UCX_TEST_ASSERT(ret == 4, "ret != 5 (test 2)"); - UCX_TEST_ASSERT(chunklen == 0xab, "wrong chunk length (test 2)"); + int64_t chunklen; + int ret = http_stream_parse_chunk_header(str, len, FALSE, &chunklen); + CX_TEST_ASSERT(ret == 7); + CX_TEST_ASSERT(chunklen == 0x100); + + // test 2 with just \n as line break + ret = http_stream_parse_chunk_header(str2, len2, FALSE, &chunklen); + CX_TEST_ASSERT(ret == 4); + CX_TEST_ASSERT(chunklen == 0xab); - UCX_TEST_END; + } free(str); free(str2); } -UCX_TEST(test_io_http_stream_parse_chunk_header_hdronly_seq_fail) { +CX_TEST(test_io_http_stream_parse_chunk_header_hdronly_seq_fail) { // test: after the first chunk header, \r\n is required before any new header char *str = strdup("ff\r\n"); size_t len = strlen(str); - UCX_TEST_BEGIN; + CX_TEST_DO { - int64_t chunklen; - int ret = http_stream_parse_chunk_header(str, len, FALSE, &chunklen); - UCX_TEST_ASSERT(ret == -1, "ret != -1"); + int64_t chunklen; + int ret = http_stream_parse_chunk_header(str, len, FALSE, &chunklen); + CX_TEST_ASSERT(ret == -1); - UCX_TEST_END; + } free(str); } -UCX_TEST(test_io_http_stream_parse_chunk_header_hdr_data) { +CX_TEST(test_io_http_stream_parse_chunk_header_hdr_data) { char *str = strdup("\r\nb\r\nhello world\r\n"); size_t len = strlen(str); - UCX_TEST_BEGIN; + CX_TEST_DO { - int64_t chunklen; - int ret = http_stream_parse_chunk_header(str, len, FALSE, &chunklen); - UCX_TEST_ASSERT(ret == 5, "ret != 5"); + int64_t chunklen; + int ret = http_stream_parse_chunk_header(str, len, FALSE, &chunklen); + CX_TEST_ASSERT(ret == 5); - UCX_TEST_END; + } free(str); } -UCX_TEST(test_io_http_stream_parse_chunk_header_empty) { +CX_TEST(test_io_http_stream_parse_chunk_header_empty) { char *str = ""; size_t len = strlen(str); - UCX_TEST_BEGIN; + CX_TEST_DO { - int64_t chunklen; - int ret = http_stream_parse_chunk_header(str, len, FALSE, &chunklen); - UCX_TEST_ASSERT(ret == 0, "ret != 0"); - - ret = http_stream_parse_chunk_header(str, len, TRUE, &chunklen); - UCX_TEST_ASSERT(ret == 0, "ret != 0 (test 2)"); + int64_t chunklen; + int ret = http_stream_parse_chunk_header(str, len, FALSE, &chunklen); + CX_TEST_ASSERT(ret == 0); + + ret = http_stream_parse_chunk_header(str, len, TRUE, &chunklen); + CX_TEST_ASSERT(ret == 0); - UCX_TEST_END; + } } -UCX_TEST(test_io_http_stream_parse_chunk_header_partial_first) { +CX_TEST(test_io_http_stream_parse_chunk_header_partial_first) { char *str = strdup("123"); size_t len = strlen(str); - UCX_TEST_BEGIN; + CX_TEST_DO { - int64_t chunklen; - int ret = http_stream_parse_chunk_header(str, len, TRUE, &chunklen); - UCX_TEST_ASSERT(ret == 0, "ret != 0"); + int64_t chunklen; + int ret = http_stream_parse_chunk_header(str, len, TRUE, &chunklen); + CX_TEST_ASSERT(ret == 0); - UCX_TEST_END; + } free(str); } -UCX_TEST(test_io_http_stream_parse_chunk_header_partial) { +CX_TEST(test_io_http_stream_parse_chunk_header_partial) { char *str = strdup("123"); size_t len = strlen(str); char *str2 = strdup("\r\n"); @@ -153,26 +153,26 @@ char *str4 = strdup("\r\n123"); size_t len4 = strlen(str4); - UCX_TEST_BEGIN; + CX_TEST_DO { - int64_t chunklen; - int ret = http_stream_parse_chunk_header(str, len, TRUE, &chunklen); - UCX_TEST_ASSERT(ret == 0, "ret != 0"); - ret = http_stream_parse_chunk_header(str2, len2, FALSE, &chunklen); - UCX_TEST_ASSERT(ret == 0, "ret != 0"); - ret = http_stream_parse_chunk_header(str3, len3, FALSE, &chunklen); - UCX_TEST_ASSERT(ret == 0, "ret != 0"); - ret = http_stream_parse_chunk_header(str4, len4, FALSE, &chunklen); - UCX_TEST_ASSERT(ret == 0, "ret != 0"); + int64_t chunklen; + int ret = http_stream_parse_chunk_header(str, len, TRUE, &chunklen); + CX_TEST_ASSERT(ret == 0); + ret = http_stream_parse_chunk_header(str2, len2, FALSE, &chunklen); + CX_TEST_ASSERT(ret == 0); + ret = http_stream_parse_chunk_header(str3, len3, FALSE, &chunklen); + CX_TEST_ASSERT(ret == 0); + ret = http_stream_parse_chunk_header(str4, len4, FALSE, &chunklen); + CX_TEST_ASSERT(ret == 0); - UCX_TEST_END; + } free(str); free(str2); free(str3); free(str4); } -UCX_TEST(test_io_http_stream_parse_chunk_header_invalid) { +CX_TEST(test_io_http_stream_parse_chunk_header_invalid) { char *str = strdup("hello\r\n"); size_t len = strlen(str); char *str2 = strdup("x4\r\n\r\n123\r\n"); @@ -186,42 +186,41 @@ char *str6 = strdup("\r\n\r\n1 23\r\n"); size_t len6 = strlen(str3); - UCX_TEST_BEGIN; - - int64_t chunklen; - int ret; - - ret = http_stream_parse_chunk_header(str, len, TRUE, &chunklen); - UCX_TEST_ASSERT(ret == -1, "ret != -1 (test 1a)"); - ret = http_stream_parse_chunk_header(str, len, FALSE, &chunklen); - UCX_TEST_ASSERT(ret == -1, "ret != -1 (test 1b)"); - - ret = http_stream_parse_chunk_header(str2, len2, TRUE, &chunklen); - UCX_TEST_ASSERT(ret == -1, "ret != -1 (test 2a)"); - ret = http_stream_parse_chunk_header(str2, len2, FALSE, &chunklen); - UCX_TEST_ASSERT(ret == -1, "ret != -1 (test 2b)"); + CX_TEST_DO { + int64_t chunklen; + int ret; + + ret = http_stream_parse_chunk_header(str, len, TRUE, &chunklen); + CX_TEST_ASSERT(ret == -1); + ret = http_stream_parse_chunk_header(str, len, FALSE, &chunklen); + CX_TEST_ASSERT(ret == -1); + + ret = http_stream_parse_chunk_header(str2, len2, TRUE, &chunklen); + CX_TEST_ASSERT(ret == -1); + ret = http_stream_parse_chunk_header(str2, len2, FALSE, &chunklen); + CX_TEST_ASSERT(ret == -1); + + ret = http_stream_parse_chunk_header(str3, len3, TRUE, &chunklen); + CX_TEST_ASSERT(ret == -1); + ret = http_stream_parse_chunk_header(str3, len3, FALSE, &chunklen); + CX_TEST_ASSERT(ret == -1); + + ret = http_stream_parse_chunk_header(str4, len4, TRUE, &chunklen); + CX_TEST_ASSERT(ret == -1); + ret = http_stream_parse_chunk_header(str4, len4, FALSE, &chunklen); + CX_TEST_ASSERT(ret == -1); + + ret = http_stream_parse_chunk_header(str5, len5, TRUE, &chunklen); + CX_TEST_ASSERT(ret == -1); + ret = http_stream_parse_chunk_header(str5, len5, FALSE, &chunklen); + CX_TEST_ASSERT(ret == -1); + + ret = http_stream_parse_chunk_header(str6, len6, TRUE, &chunklen); + CX_TEST_ASSERT(ret == -1); + ret = http_stream_parse_chunk_header(str6, len6, FALSE, &chunklen); + CX_TEST_ASSERT(ret == -1); + } - ret = http_stream_parse_chunk_header(str3, len3, TRUE, &chunklen); - UCX_TEST_ASSERT(ret == -1, "ret != -1 (test 3a)"); - ret = http_stream_parse_chunk_header(str3, len3, FALSE, &chunklen); - UCX_TEST_ASSERT(ret == -1, "ret != -1 (test 3b)"); - - ret = http_stream_parse_chunk_header(str4, len4, TRUE, &chunklen); - UCX_TEST_ASSERT(ret == -1, "ret != -1 (test 4a)"); - ret = http_stream_parse_chunk_header(str4, len4, FALSE, &chunklen); - UCX_TEST_ASSERT(ret == -1, "ret != -1 (test 4b)"); - - ret = http_stream_parse_chunk_header(str5, len5, TRUE, &chunklen); - UCX_TEST_ASSERT(ret == -1, "ret != -1 (test 5a)"); - ret = http_stream_parse_chunk_header(str5, len5, FALSE, &chunklen); - UCX_TEST_ASSERT(ret == -1, "ret != -1 (test 5b)"); - - ret = http_stream_parse_chunk_header(str6, len6, TRUE, &chunklen); - UCX_TEST_ASSERT(ret == -1, "ret != -1 (test 6a)"); - ret = http_stream_parse_chunk_header(str6, len6, FALSE, &chunklen); - UCX_TEST_ASSERT(ret == -1, "ret != -1 (test 6b)"); - - UCX_TEST_END; free(str); free(str2); free(str3); @@ -230,7 +229,7 @@ free(str6); } -UCX_TEST(test_io_http_stream_parse_chunk_header_zero) { +CX_TEST(test_io_http_stream_parse_chunk_header_zero) { char *str = strdup("\r\n0\r\n\r\n"); size_t len = strlen(str); char *str2 = strdup("0\r\n\r\n"); @@ -243,26 +242,26 @@ size_t len4 = strlen(str4); - UCX_TEST_BEGIN; + CX_TEST_DO { - int64_t chunklen = -1; - int ret = http_stream_parse_chunk_header(str, len, FALSE, &chunklen); - UCX_TEST_ASSERT(ret == 7, "ret != 7"); - UCX_TEST_ASSERT(chunklen == 0, "chunklen != 0"); + int64_t chunklen = -1; + int ret = http_stream_parse_chunk_header(str, len, FALSE, &chunklen); + CX_TEST_ASSERT(ret == 7); + CX_TEST_ASSERT(chunklen == 0); + + chunklen = -1; + ret = http_stream_parse_chunk_header(str2, len2, TRUE, &chunklen); + CX_TEST_ASSERT(ret == 5); + CX_TEST_ASSERT(chunklen == 0); + + // expect 0 (incomplete) + ret = http_stream_parse_chunk_header(str3, len3, FALSE, &chunklen); + CX_TEST_ASSERT(ret == 0); + + ret = http_stream_parse_chunk_header(str4, len4, FALSE, &chunklen); + CX_TEST_ASSERT(ret == 0); - chunklen = -1; - ret = http_stream_parse_chunk_header(str2, len2, TRUE, &chunklen); - UCX_TEST_ASSERT(ret == 5, "ret != 5 (test 2)"); - UCX_TEST_ASSERT(chunklen == 0, "chunklen != 0 (test 2)"); - - // expect 0 (incomplete) - ret = http_stream_parse_chunk_header(str3, len3, FALSE, &chunklen); - UCX_TEST_ASSERT(ret == 0, "ret != 3 (test 3)"); - - ret = http_stream_parse_chunk_header(str4, len4, FALSE, &chunklen); - UCX_TEST_ASSERT(ret == 0, "ret != 3 (test 4)"); - - UCX_TEST_END; + } free(str); free(str2); free(str3); @@ -270,104 +269,102 @@ } -UCX_TEST(test_io_httpstream_write) { +CX_TEST(test_io_httpstream_write) { Session *sn = testutil_session(); TestIOStream *st = testutil_iostream(2048, TRUE); IOStream *http = httpstream_new(sn->pool, (IOStream*)st); - UCX_TEST_BEGIN; - - char *msg = "hello world!"; - size_t msglen = strlen(msg); - - ssize_t w = net_write(http, msg, msglen); - - UCX_TEST_ASSERT(w == msglen, "wrong size returned by net_write"); - UCX_TEST_ASSERT(st->buf->size == msglen, "wrong buffer size"); - UCX_TEST_ASSERT(!memcmp(st->buf->space, msg, msglen), "wrong buffer content"); + CX_TEST_DO { - // test again, make sure the second message is written directly after the wirst one - char *msg2 = "test"; - size_t msglen2 = strlen(msg2); - - w = net_write(http, msg2, msglen2); + char *msg = "hello world!"; + size_t msglen = strlen(msg); + + ssize_t w = net_write(http, msg, msglen); + + CX_TEST_ASSERT(w == msglen); + CX_TEST_ASSERT(st->buf->size == msglen); + CX_TEST_ASSERT(!memcmp(st->buf->space, msg, msglen)); + + // test again, make sure the second message is written directly after the wirst one + char *msg2 = "test"; + size_t msglen2 = strlen(msg2); + + w = net_write(http, msg2, msglen2); + + CX_TEST_ASSERT(w == msglen2); + CX_TEST_ASSERT(st->buf->size == msglen+msglen2); + CX_TEST_ASSERT(!memcmp(st->buf->space + msglen, msg2, msglen2)); - UCX_TEST_ASSERT(w == msglen2, "wrong size returned by net_write (2)"); - UCX_TEST_ASSERT(st->buf->size == msglen+msglen2, "wrong buffer size (2)"); - UCX_TEST_ASSERT(!memcmp(st->buf->space + msglen, msg2, msglen2), "wrong buffer content (2)"); - - UCX_TEST_END; + } testutil_destroy_session(sn); } -UCX_TEST(test_io_httpstream_chunked_write) { +CX_TEST(test_io_httpstream_chunked_write) { Session *sn = testutil_session(); TestIOStream *st = testutil_iostream(2048, TRUE); IOStream *http = httpstream_new(sn->pool, (IOStream*)st); httpstream_enable_chunked_write(http); - UCX_TEST_BEGIN; - - char *msg = "hello world!"; - size_t msglen = strlen(msg); - - char *bufmsg = "c\r\nhello world!\r\n"; - size_t bufmsglen = strlen(bufmsg); - - ssize_t w = net_write(http, msg, msglen); - - cxstring s1 = cx_strn(st->buf->space, st->buf->size); - cxstring s2 = cx_strn(bufmsg, bufmsglen); + CX_TEST_DO { - UCX_TEST_ASSERT(w == msglen, "wrong size returned by net_write"); - UCX_TEST_ASSERT(st->buf->size == bufmsglen, "wrong buffer size"); - UCX_TEST_ASSERT(!cx_strcasecmp(s1, s2), "wrong buffer content"); + char *msg = "hello world!"; + size_t msglen = strlen(msg); + + char *bufmsg = "c\r\nhello world!\r\n"; + size_t bufmsglen = strlen(bufmsg); + + ssize_t w = net_write(http, msg, msglen); + + cxstring s1 = cx_strn(st->buf->space, st->buf->size); + cxstring s2 = cx_strn(bufmsg, bufmsglen); + + CX_TEST_ASSERT(w == msglen); + CX_TEST_ASSERT(st->buf->size == bufmsglen); + CX_TEST_ASSERT(!cx_strcasecmp(s1, s2)); + + // write again + w = net_write(http, msg, msglen); + CX_TEST_ASSERT(w == msglen); + CX_TEST_ASSERT(st->buf->size == 2*bufmsglen); + + cxstring s3 = cx_strn(st->buf->space+bufmsglen, bufmsglen); + CX_TEST_ASSERT(!cx_strcasecmp(s2, s3)); - // write again - w = net_write(http, msg, msglen); - UCX_TEST_ASSERT(w == msglen, "write 2: wrong return value"); - UCX_TEST_ASSERT(st->buf->size == 2*bufmsglen, "write 2: wrong buf size"); - - cxstring s3 = cx_strn(st->buf->space+bufmsglen, bufmsglen); - UCX_TEST_ASSERT(!cx_strcasecmp(s2, s3), "write 2: wrong buf content"); - - - UCX_TEST_END; + } } -UCX_TEST(test_io_httpstream_chunked_write_end) { +CX_TEST(test_io_httpstream_chunked_write_end) { Session *sn = testutil_session(); TestIOStream *st = testutil_iostream(2048, TRUE); IOStream *http = httpstream_new(sn->pool, (IOStream*)st); httpstream_enable_chunked_write(http); - UCX_TEST_BEGIN; - - char *msg = "hello world!"; - size_t msglen = strlen(msg); - - char *bufmsg = "c\r\nhello world!\r\n0\r\n\r\n"; - size_t bufmsglen = strlen(bufmsg); + CX_TEST_DO { - ssize_t w = net_write(http, msg, msglen); - net_finish(http); - - cxstring s1 = cx_strn(st->buf->space, st->buf->size); - cxstring s2 = cx_strn(bufmsg, bufmsglen); + char *msg = "hello world!"; + size_t msglen = strlen(msg); + + char *bufmsg = "c\r\nhello world!\r\n0\r\n\r\n"; + size_t bufmsglen = strlen(bufmsg); + + ssize_t w = net_write(http, msg, msglen); + net_finish(http); + + cxstring s1 = cx_strn(st->buf->space, st->buf->size); + cxstring s2 = cx_strn(bufmsg, bufmsglen); + + CX_TEST_ASSERT(w == msglen); + CX_TEST_ASSERT(st->buf->size == bufmsglen); + CX_TEST_ASSERT(!cx_strcasecmp(s1, s2)); - UCX_TEST_ASSERT(w == msglen, "wrong size returned by net_write"); - UCX_TEST_ASSERT(st->buf->size == bufmsglen, "wrong buffer size"); - UCX_TEST_ASSERT(!cx_strcasecmp(s1, s2), "wrong buffer content"); - - - UCX_TEST_END; + } } -UCX_TEST(test_io_httpstream_chunked_write_xx) { +CX_TEST(test_io_httpstream_chunked_write_xx) { // This test creates a giant buffer and writes it with // chunked transfer encoding to the http stream with varying chunk length @@ -377,91 +374,91 @@ IOStream *http = httpstream_new(sn->pool, (IOStream*)st); httpstream_enable_chunked_write(http); - UCX_TEST_BEGIN; - - // create test data - CxBuffer *testdata = cxBufferCreate(NULL, 1024*1024*4, cxDefaultAllocator, 0); - for(size_t i=0;i<testdata->capacity;i++) { - cxBufferPut(testdata, 35+(i%91)); - } - - // write chunks, start with single diget chunk length and increase - // chunk size with each step - size_t pos = 0; - int j = 0; - ssize_t i=15; - while(pos<testdata->size) { - char *buf = testdata->space + pos; - size_t remaining = testdata->size - pos; - ssize_t len = pos + i < remaining ? i : remaining; - pos += len; - - ssize_t w = net_write(http, buf, len); - - UCX_TEST_ASSERT(w == len, "wrong size returned by net_write"); - i+=100; // increase chunk size - j++; // debug - } - - // terminate chunk - net_finish(http); - - // code below also used in test_io_httpstream_chunked_write_xx_limit - - // make sure the output is correctly encoded - // extract chunks from st->buf by using http_stream_parse_chunk_header - // (which should be well-tested) - WSBool first_chunk = TRUE; - int64_t chunklen = 0; + CX_TEST_DO { - char *buf = st->buf->space; - size_t bufsize = st->buf->size; - - pos = 0; // st->buf position - size_t srcpos = 0; // testdata position - int debug_counter = 0; - while(pos < bufsize) { - ssize_t remaining = bufsize - pos; - ssize_t src_remaining = testdata->size - srcpos; - - int ret = http_stream_parse_chunk_header(buf+pos, remaining, first_chunk, &chunklen); - first_chunk = FALSE; - - // ret must always be > 0 (0: incomplete chunk header, -1: invalid syntax) - UCX_TEST_ASSERT(ret > 0, "http_stream_parse_chunk_header ret <= 0"); - if(chunklen == 0) { - UCX_TEST_ASSERT(src_remaining == 0, "stream end reached but src_remaining > 0"); - break; + // create test data + CxBuffer *testdata = cxBufferCreate(NULL, 1024*1024*4, cxDefaultAllocator, 0); + for(size_t i=0;i<testdata->capacity;i++) { + cxBufferPut(testdata, 35+(i%91)); + } + + // write chunks, start with single diget chunk length and increase + // chunk size with each step + size_t pos = 0; + int j = 0; + ssize_t i=15; + while(pos<testdata->size) { + char *buf = testdata->space + pos; + size_t remaining = testdata->size - pos; + ssize_t len = pos + i < remaining ? i : remaining; + pos += len; + + ssize_t w = net_write(http, buf, len); + + CX_TEST_ASSERT(w == len); + i+=100; // increase chunk size + j++; // debug } - - UCX_TEST_ASSERT(chunklen <= src_remaining, "chunklen > src_remaining"); - - char *src_chunk = testdata->space+srcpos; - char *buf_chunk = buf+pos+ret; - - UCX_TEST_ASSERT(!memcmp(buf_chunk, src_chunk, chunklen), "memcmp failed"); - - pos += ret + chunklen; - srcpos += chunklen; - - debug_counter++; + + // terminate chunk + net_finish(http); + + // code below also used in test_io_httpstream_chunked_write_xx_limit + + // make sure the output is correctly encoded + // extract chunks from st->buf by using http_stream_parse_chunk_header + // (which should be well-tested) + WSBool first_chunk = TRUE; + int64_t chunklen = 0; + + char *buf = st->buf->space; + size_t bufsize = st->buf->size; + + pos = 0; // st->buf position + size_t srcpos = 0; // testdata position + int debug_counter = 0; + while(pos < bufsize) { + ssize_t remaining = bufsize - pos; + ssize_t src_remaining = testdata->size - srcpos; + + int ret = http_stream_parse_chunk_header(buf+pos, remaining, first_chunk, &chunklen); + first_chunk = FALSE; + + // ret must always be > 0 (0: incomplete chunk header, -1: invalid syntax) + CX_TEST_ASSERT(ret > 0); + if(chunklen == 0) { + CX_TEST_ASSERT(src_remaining == 0); + break; + } + + CX_TEST_ASSERT(chunklen <= src_remaining); + + char *src_chunk = testdata->space+srcpos; + char *buf_chunk = buf+pos+ret; + + CX_TEST_ASSERT(!memcmp(buf_chunk, src_chunk, chunklen)); + + pos += ret + chunklen; + srcpos += chunklen; + + debug_counter++; + } + + cxBufferFree(testdata); + testutil_destroy_session(sn); + testutil_iostream_destroy(st); + } - - cxBufferFree(testdata); - testutil_destroy_session(sn); - testutil_iostream_destroy(st); - - UCX_TEST_END; } -UCX_TEST(test_io_httpstream_chunked_write_partial_header) { +CX_TEST(test_io_httpstream_chunked_write_partial_header) { Session *sn = testutil_session(); TestIOStream *st = testutil_iostream(2048, TRUE); IOStream *http = httpstream_new(sn->pool, (IOStream*)st); httpstream_enable_chunked_write(http); - UCX_TEST_BEGIN; + CX_TEST_DO { memset(st->buf->space, 0, st->buf->capacity); @@ -473,89 +470,89 @@ // only 1 byte of the header is written, 0 bytes of msg ssize_t w = net_write(http, msg, msglen); - UCX_TEST_ASSERT(w == 0, "write 1: wrong return value"); - UCX_TEST_ASSERT(st->buf->size == 1, "write 1: wrong buf size"); - UCX_TEST_ASSERT(tolower(st->buf->space[0]) == 'c', "write 1: wrong buf content"); + CX_TEST_ASSERT(w == 0); + CX_TEST_ASSERT(st->buf->size == 1); + CX_TEST_ASSERT(tolower(st->buf->space[0]) == 'c'); // next header byte: '\r' w = net_write(http, msg, msglen); - UCX_TEST_ASSERT(w == 0, "write 2: wrong return value"); - UCX_TEST_ASSERT(st->buf->size == 2, "write 2: wrong buf size"); - UCX_TEST_ASSERT(st->buf->space[1] == '\r', "write 2: wrong content"); + CX_TEST_ASSERT(w == 0); + CX_TEST_ASSERT(st->buf->size == 2); + CX_TEST_ASSERT(st->buf->space[1] == '\r'); // next header byte: '\n' w = net_write(http, msg, msglen); - UCX_TEST_ASSERT(w == 0, "write 3: wrong return value"); - UCX_TEST_ASSERT(st->buf->size == 3, "write 3: wrong buf size"); - UCX_TEST_ASSERT(st->buf->space[2] == '\n', "write 3: wrong content"); + CX_TEST_ASSERT(w == 0); + CX_TEST_ASSERT(st->buf->size == 3); + CX_TEST_ASSERT(st->buf->space[2] == '\n'); // next: content w = net_write(http, msg, msglen); - UCX_TEST_ASSERT(w == 1, "write 4: wrong return value"); - UCX_TEST_ASSERT(st->buf->size == 4, "write 3: wrong buf size"); - UCX_TEST_ASSERT(st->buf->space[3] == msg[0], "write 3: wrong content"); + CX_TEST_ASSERT(w == 1); + CX_TEST_ASSERT(st->buf->size == 4); + CX_TEST_ASSERT(st->buf->space[3] == msg[0]); testutil_destroy_session(sn); testutil_iostream_destroy(st); - UCX_TEST_END; + } } -UCX_TEST(test_io_httpstream_chunked_write_partial_data) { +CX_TEST(test_io_httpstream_chunked_write_partial_data) { Session *sn = testutil_session(); TestIOStream *st = testutil_iostream(2048, TRUE); IOStream *http = httpstream_new(sn->pool, (IOStream*)st); httpstream_enable_chunked_write(http); - UCX_TEST_BEGIN; - - memset(st->buf->space, 0, st->buf->capacity); - - char *msg = "hello world!"; - size_t msglen = strlen(msg); - size_t msglen_orig = msglen; - - // limit first write to 3 to only write the header - st->max_write = 3; - io_set_max_writes(1); - - ssize_t w = net_write(http, msg, msglen); - - UCX_TEST_ASSERT(w == 0, "write 1: wrong return value"); - UCX_TEST_ASSERT(st->buf->size == 3, "write 1: wrong buf size"); - UCX_TEST_ASSERT(st->buf->space[0] == 'c', "write 1: wrong buf content"); - UCX_TEST_ASSERT(st->buf->space[2] == '\n', "write 1: wrong buf content"); + CX_TEST_DO { - w = net_write(http, msg, msglen); - UCX_TEST_ASSERT(w == 3, "write 2: wrong return value"); - UCX_TEST_ASSERT(st->buf->size == 6, "write 2: wrong buf size"); - UCX_TEST_ASSERT(!memcmp(st->buf->space, "c\r\nhel\0", 7), "write 2: wrong buf content"); - - msg += w; - msglen -= w; - - w = net_write(http, msg, msglen); - UCX_TEST_ASSERT(w == 3, "write 3: wrong return value"); - UCX_TEST_ASSERT(st->buf->size == 9, "write 3: wrong buf size"); - UCX_TEST_ASSERT(!memcmp(st->buf->space, "c\r\nhello \0", 10), "write 3: wrong buf content"); + memset(st->buf->space, 0, st->buf->capacity); + + char *msg = "hello world!"; + size_t msglen = strlen(msg); + size_t msglen_orig = msglen; + + // limit first write to 3 to only write the header + st->max_write = 3; + io_set_max_writes(1); + + ssize_t w = net_write(http, msg, msglen); + + CX_TEST_ASSERT(w == 0); + CX_TEST_ASSERT(st->buf->size == 3); + CX_TEST_ASSERT(st->buf->space[0] == 'c'); + CX_TEST_ASSERT(st->buf->space[2] == '\n'); + + w = net_write(http, msg, msglen); + CX_TEST_ASSERT(w == 3); + CX_TEST_ASSERT(st->buf->size == 6); + CX_TEST_ASSERT(!memcmp(st->buf->space, "c\r\nhel\0", 7)); + + msg += w; + msglen -= w; + + w = net_write(http, msg, msglen); + CX_TEST_ASSERT(w == 3); + CX_TEST_ASSERT(st->buf->size == 9); + CX_TEST_ASSERT(!memcmp(st->buf->space, "c\r\nhello \0", 10)); + + st->max_write = 1024; + msg += w; + msglen -= w; + + w = net_write(http, msg, msglen); + CX_TEST_ASSERT(w == msglen); + CX_TEST_ASSERT(st->buf->size == 3 + msglen_orig + 2); + CX_TEST_ASSERT(!memcmp(st->buf->space, "c\r\nhello world!\r\n", st->buf->size)); + + testutil_destroy_session(sn); + testutil_iostream_destroy(st); - st->max_write = 1024; - msg += w; - msglen -= w; - - w = net_write(http, msg, msglen); - UCX_TEST_ASSERT(w == msglen, "write 4: wrong return value"); - UCX_TEST_ASSERT(st->buf->size == 3 + msglen_orig + 2, "write 4: wrong buf size"); - UCX_TEST_ASSERT(!memcmp(st->buf->space, "c\r\nhello world!\r\n", st->buf->size), "write 4: wrong buf content"); - - testutil_destroy_session(sn); - testutil_iostream_destroy(st); - - UCX_TEST_END; + } } -UCX_TEST(test_io_httpstream_chunked_write_partial_trailer) { +CX_TEST(test_io_httpstream_chunked_write_partial_trailer) { Session *sn = testutil_session(); TestIOStream *st = testutil_iostream(2048, TRUE); @@ -563,60 +560,60 @@ httpstream_enable_chunked_write(http); io_set_max_writes(1); - UCX_TEST_BEGIN; - - memset(st->buf->space, 0, st->buf->capacity); - - char *msg = "hello world!"; - size_t msglen = strlen(msg); - - char *msg2 = "newmsg"; - size_t msglen2 = strlen(msg2); - - char *msg3 = "msg3"; - size_t msglen3 = strlen(msg3); - - st->max_write = 3 + msglen; // header + msg, but without trailer - - ssize_t w = net_write(http, msg, msglen); - - UCX_TEST_ASSERT(w == msglen, "write 1: wrong return value"); - UCX_TEST_ASSERT(st->buf->size == 3 + msglen, "write 1: wrong buf size"); - UCX_TEST_ASSERT(!memcmp(st->buf->space, "c\r\nhello world!\0", st->buf->size + 1), "write 1: wrong buf content"); - - st->max_write = 2 + 3 + msglen2; // trailer + new header + new msg, without new trailer + CX_TEST_DO { - w = net_write(http, msg2, msglen2); - UCX_TEST_ASSERT(w == msglen2, "write 2: wrong return value"); - UCX_TEST_ASSERT(st->buf->size == 3 + msglen + 2 + 3 + msglen2, "write 2: wrong buf size"); - UCX_TEST_ASSERT(!memcmp(st->buf->space, "c\r\nhello world!\r\n6\r\nnewmsg\0", st->buf->size + 1), "write 2: wrong buf content"); - - // limit write to 1 byte: two writes required for trailer, net_write should return 0 - st->max_write = 1; - - w = net_write(http, "dummymsg", 8); - UCX_TEST_ASSERT(w == 0, "write 3: wrong return value"); + memset(st->buf->space, 0, st->buf->capacity); + + char *msg = "hello world!"; + size_t msglen = strlen(msg); + + char *msg2 = "newmsg"; + size_t msglen2 = strlen(msg2); + + char *msg3 = "msg3"; + size_t msglen3 = strlen(msg3); + + st->max_write = 3 + msglen; // header + msg, but without trailer + + ssize_t w = net_write(http, msg, msglen); + + CX_TEST_ASSERT(w == msglen); + CX_TEST_ASSERT(st->buf->size == 3 + msglen); + CX_TEST_ASSERT(!memcmp(st->buf->space, "c\r\nhello world!\0", st->buf->size + 1)); + + st->max_write = 2 + 3 + msglen2; // trailer + new header + new msg, without new trailer + + w = net_write(http, msg2, msglen2); + CX_TEST_ASSERT(w == msglen2); + CX_TEST_ASSERT(st->buf->size == 3 + msglen + 2 + 3 + msglen2); + CX_TEST_ASSERT(!memcmp(st->buf->space, "c\r\nhello world!\r\n6\r\nnewmsg\0", st->buf->size + 1)); + + // limit write to 1 byte: two writes required for trailer, net_write should return 0 + st->max_write = 1; + + w = net_write(http, "dummymsg", 8); + CX_TEST_ASSERT(w == 0); + + w = net_write(http, "dummymsg", 8); + CX_TEST_ASSERT(w == 0); + CX_TEST_ASSERT(st->buf->size == 3 + msglen + 2 + 3 + msglen2 + 2); + CX_TEST_ASSERT(!memcmp(st->buf->space, "c\r\nhello world!\r\n6\r\nnewmsg\r\n\0", st->buf->size + 1)); + + st->max_write = 1024; + w = net_write(http, msg3, msglen3); + + CX_TEST_ASSERT(w == msglen3); + CX_TEST_ASSERT(st->buf->size == 3 + msglen + 2 + 3 + msglen2 + 2 + 3 + msglen3 + 2); + CX_TEST_ASSERT(!memcmp(st->buf->space, "c\r\nhello world!\r\n6\r\nnewmsg\r\n4\r\nmsg3\r\n", st->buf->size + 1)); + + + testutil_destroy_session(sn); + testutil_iostream_destroy(st); - w = net_write(http, "dummymsg", 8); - UCX_TEST_ASSERT(w == 0, "write 4: wrong return value"); - UCX_TEST_ASSERT(st->buf->size == 3 + msglen + 2 + 3 + msglen2 + 2, "write 4: wrong buf size"); - UCX_TEST_ASSERT(!memcmp(st->buf->space, "c\r\nhello world!\r\n6\r\nnewmsg\r\n\0", st->buf->size + 1), "write 4: wrong buf content"); - - st->max_write = 1024; - w = net_write(http, msg3, msglen3); - - UCX_TEST_ASSERT(w == msglen3, "write 5: wrong return value"); - UCX_TEST_ASSERT(st->buf->size == 3 + msglen + 2 + 3 + msglen2 + 2 + 3 + msglen3 + 2, "write 5: wrong buf size"); - UCX_TEST_ASSERT(!memcmp(st->buf->space, "c\r\nhello world!\r\n6\r\nnewmsg\r\n4\r\nmsg3\r\n", st->buf->size + 1), "write 5: wrong buf content"); - - - testutil_destroy_session(sn); - testutil_iostream_destroy(st); - - UCX_TEST_END; + } } -UCX_TEST(test_io_httpstream_chunked_write_partial_trailer_partial_header) { +CX_TEST(test_io_httpstream_chunked_write_partial_trailer_partial_header) { Session *sn = testutil_session(); TestIOStream *st = testutil_iostream(2048, TRUE); @@ -624,59 +621,59 @@ httpstream_enable_chunked_write(http); io_set_max_writes(1); - UCX_TEST_BEGIN; - - memset(st->buf->space, 0, st->buf->capacity); - - char *msg = "hello world!"; - size_t msglen = strlen(msg); - - char *msg2 = "newmsg"; - size_t msglen2 = strlen(msg2); - - // Test: write partial trailer followed by partial header write - - st->max_write = 3 + msglen + 1; - - ssize_t w = net_write(http, msg, msglen); - - UCX_TEST_ASSERT(w == msglen, "write 1: wrong return value"); - UCX_TEST_ASSERT(st->buf->size == 3 + msglen + 1, "write 1: wrong buf size"); - UCX_TEST_ASSERT(!memcmp(st->buf->space, "c\r\nhello world!\r\0", st->buf->size + 1), "write 1: wrong buf content"); - - st->max_write = 2; // write 1 trailer byte and 1 header byte - - w = net_write(http, msg2, msglen2); + CX_TEST_DO { - UCX_TEST_ASSERT(w == 0, "write 2: wrong return value"); - UCX_TEST_ASSERT(st->buf->size == 3 + msglen + 2 + 1, "write 2: wrong buf size"); - UCX_TEST_ASSERT(!memcmp(st->buf->space, "c\r\nhello world!\r\n6\0", st->buf->size + 1), "write 2: wrong buf content"); - - // force partial header write again - st->max_write = 1; - - w = net_write(http, msg2, msglen2); - - UCX_TEST_ASSERT(w == 0, "write 3: wrong return value"); - UCX_TEST_ASSERT(st->buf->size == 3 + msglen + 2 + 2, "write 3: wrong buf size"); - UCX_TEST_ASSERT(!memcmp(st->buf->space, "c\r\nhello world!\r\n6\r\0", st->buf->size + 1), "write 3: wrong buf content"); + memset(st->buf->space, 0, st->buf->capacity); + + char *msg = "hello world!"; + size_t msglen = strlen(msg); + + char *msg2 = "newmsg"; + size_t msglen2 = strlen(msg2); + + // Test: write partial trailer followed by partial header write + + st->max_write = 3 + msglen + 1; + + ssize_t w = net_write(http, msg, msglen); + + CX_TEST_ASSERT(w == msglen); + CX_TEST_ASSERT(st->buf->size == 3 + msglen + 1); + CX_TEST_ASSERT(!memcmp(st->buf->space, "c\r\nhello world!\r\0", st->buf->size + 1)); + + st->max_write = 2; // write 1 trailer byte and 1 header byte + + w = net_write(http, msg2, msglen2); + + CX_TEST_ASSERT(w == 0); + CX_TEST_ASSERT(st->buf->size == 3 + msglen + 2 + 1); + CX_TEST_ASSERT(!memcmp(st->buf->space, "c\r\nhello world!\r\n6\0", st->buf->size + 1)); + + // force partial header write again + st->max_write = 1; + + w = net_write(http, msg2, msglen2); + + CX_TEST_ASSERT(w == 0); + CX_TEST_ASSERT(st->buf->size == 3 + msglen + 2 + 2); + CX_TEST_ASSERT(!memcmp(st->buf->space, "c\r\nhello world!\r\n6\r\0", st->buf->size + 1)); + + st->max_write = 1024; + + w = net_write(http, msg2, msglen2); + + CX_TEST_ASSERT(w ==msglen2); + CX_TEST_ASSERT(st->buf->size == 3 + msglen + 2 + 3 + msglen2 + 2); + CX_TEST_ASSERT(!memcmp(st->buf->space, "c\r\nhello world!\r\n6\r\nnewmsg\r\n", st->buf->size + 1)); + + + testutil_destroy_session(sn); + testutil_iostream_destroy(st); - st->max_write = 1024; - - w = net_write(http, msg2, msglen2); - - UCX_TEST_ASSERT(w ==msglen2, "write 4: wrong return value"); - UCX_TEST_ASSERT(st->buf->size == 3 + msglen + 2 + 3 + msglen2 + 2, "write 4: wrong buf size"); - UCX_TEST_ASSERT(!memcmp(st->buf->space, "c\r\nhello world!\r\n6\r\nnewmsg\r\n", st->buf->size + 1), "write 4: wrong buf content"); - - - testutil_destroy_session(sn); - testutil_iostream_destroy(st); - - UCX_TEST_END; + } } -UCX_TEST(test_io_httpstream_chunked_write_data_2x) { +CX_TEST(test_io_httpstream_chunked_write_data_2x) { Session *sn = testutil_session(); TestIOStream *st = testutil_iostream(2048, TRUE); @@ -684,46 +681,46 @@ httpstream_enable_chunked_write(http); io_set_max_writes(1); - UCX_TEST_BEGIN; - - memset(st->buf->space, 0, st->buf->capacity); - - // Test: First write a partial header, which forces a chunk with a specific - // size. After that, write a message, that is bigger than the first - // chunk, forcing a start of a second chunk, in one big writev op. - - char *msg = "hello world!"; - size_t msglen = strlen(msg); - - char *msg2 = "newmsg"; - size_t msglen2 = strlen(msg2); - - char *msg_big = "hello world!newmsg"; - size_t msglen_big = strlen(msg_big); - - st->max_write = 1; + CX_TEST_DO { - ssize_t w = net_write(http, msg, msglen); // first chunk: msg - - UCX_TEST_ASSERT(w == 0, "write 1: wrong return value"); - UCX_TEST_ASSERT(st->buf->size == 1, "write 1: wrong buf size"); - - st->max_write = 1024; - - w = net_write(http, msg_big, msglen_big); // first chunk + new chunk + memset(st->buf->space, 0, st->buf->capacity); + + // Test: First write a partial header, which forces a chunk with a specific + // size. After that, write a message, that is bigger than the first + // chunk, forcing a start of a second chunk, in one big writev op. + + char *msg = "hello world!"; + size_t msglen = strlen(msg); + + char *msg2 = "newmsg"; + size_t msglen2 = strlen(msg2); + + char *msg_big = "hello world!newmsg"; + size_t msglen_big = strlen(msg_big); + + st->max_write = 1; + + ssize_t w = net_write(http, msg, msglen); // first chunk: msg + + CX_TEST_ASSERT(w == 0); + CX_TEST_ASSERT(st->buf->size == 1); + + st->max_write = 1024; + + w = net_write(http, msg_big, msglen_big); // first chunk + new chunk + + CX_TEST_ASSERT(w == msglen_big); + CX_TEST_ASSERT(st->buf->size == 3 + msglen + 2 + 3 + msglen2 + 2); + CX_TEST_ASSERT(!memcmp(st->buf->space, "c\r\nhello world!\r\n6\r\nnewmsg\r\n", st->buf->size + 1)); + + + testutil_destroy_session(sn); + testutil_iostream_destroy(st); - UCX_TEST_ASSERT(w == msglen_big, "write 2: wrong return value"); - UCX_TEST_ASSERT(st->buf->size == 3 + msglen + 2 + 3 + msglen2 + 2, "write 2: wrong buf size"); - UCX_TEST_ASSERT(!memcmp(st->buf->space, "c\r\nhello world!\r\n6\r\nnewmsg\r\n", st->buf->size + 1), "write 2: wrong buf content"); - - - testutil_destroy_session(sn); - testutil_iostream_destroy(st); - - UCX_TEST_END; + } } -UCX_TEST(test_io_httpstream_chunked_write_xx_limit) { +CX_TEST(test_io_httpstream_chunked_write_xx_limit) { Session *sn = testutil_session(); TestIOStream *st = testutil_iostream(2048, TRUE); @@ -731,105 +728,105 @@ httpstream_enable_chunked_write(http); io_set_max_writes(1); - UCX_TEST_BEGIN; - - // Test: create testdata and write it in varying chunk sizes, but - // limit TestIOStream to 1 to 3 byte writes - - // create test data - CxBuffer *testdata = cxBufferCreate(NULL, 1024*16, cxDefaultAllocator, 0); - for(size_t i=0;i<testdata->capacity;i++) { - cxBufferPut(testdata, 35+(i%91)); - } - - st->max_write = 1; + CX_TEST_DO { - size_t pos = 0; - int chunksize = 1; - while(pos < testdata->size) { - size_t available = testdata->size - pos; - - char *chunk = testdata->space + pos; - size_t chunklen = chunksize > available ? available : chunksize; - - // write chunk - size_t chunkpos = 0; - int max_writes = chunklen + 24; // max number of write attempts - int writes = 0; - while(chunkpos < chunklen) { - ssize_t w = net_write(http, chunk+chunkpos, chunklen-chunkpos); - UCX_TEST_ASSERT(w >= 0, "net_write failed"); - chunkpos += w; - - writes++; - UCX_TEST_ASSERT(writes < max_writes, "max writes attempts reached"); + // Test: create testdata and write it in varying chunk sizes, but + // limit TestIOStream to 1 to 3 byte writes + + // create test data + CxBuffer *testdata = cxBufferCreate(NULL, 1024*16, cxDefaultAllocator, 0); + for(size_t i=0;i<testdata->capacity;i++) { + cxBufferPut(testdata, 35+(i%91)); } - - pos += chunklen; - chunksize += 5; - - // increase max write size at some point - if(pos + chunksize >= testdata->size) { - st->max_write = INT_MAX; - } else if(pos > 1024*2) { - if(pos < 1024*8) { - st->max_write = 2; - } else { - st->max_write = 3; + + st->max_write = 1; + + size_t pos = 0; + int chunksize = 1; + while(pos < testdata->size) { + size_t available = testdata->size - pos; + + char *chunk = testdata->space + pos; + size_t chunklen = chunksize > available ? available : chunksize; + + // write chunk + size_t chunkpos = 0; + int max_writes = chunklen + 24; // max number of write attempts + int writes = 0; + while(chunkpos < chunklen) { + ssize_t w = net_write(http, chunk+chunkpos, chunklen-chunkpos); + CX_TEST_ASSERT(w >= 0); + chunkpos += w; + + writes++; + CX_TEST_ASSERT(writes < max_writes); + } + + pos += chunklen; + chunksize += 5; + + // increase max write size at some point + if(pos + chunksize >= testdata->size) { + st->max_write = INT_MAX; + } else if(pos > 1024*2) { + if(pos < 1024*8) { + st->max_write = 2; + } else { + st->max_write = 3; + } } } - } - - // terminate chunk - net_finish(http); - - - // same code as test_io_httpstream_chunked_write_xx - - // make sure the output is correctly encoded - // extract chunks from st->buf by using http_stream_parse_chunk_header - // (which should be well-tested) - - WSBool first_chunk = TRUE; - int64_t chunklen = 0; - - char *buf = st->buf->space; - size_t bufsize = st->buf->size; + + // terminate chunk + net_finish(http); + + + // same code as test_io_httpstream_chunked_write_xx + + // make sure the output is correctly encoded + // extract chunks from st->buf by using http_stream_parse_chunk_header + // (which should be well-tested) + + WSBool first_chunk = TRUE; + int64_t chunklen = 0; + + char *buf = st->buf->space; + size_t bufsize = st->buf->size; + + pos = 0; // st->buf position + size_t srcpos = 0; // testdata position + int debug_counter = 0; + while(pos < bufsize) { + ssize_t remaining = bufsize - pos; + ssize_t src_remaining = testdata->size - srcpos; + + int ret = http_stream_parse_chunk_header(buf+pos, remaining, first_chunk, &chunklen); + first_chunk = FALSE; + + // ret must always be > 0 (0: incomplete chunk header, -1: invalid syntax) + CX_TEST_ASSERT(ret > 0); + if(chunklen == 0) { + CX_TEST_ASSERT(src_remaining == 0); + break; + } + + CX_TEST_ASSERT(chunklen <= src_remaining); + + char *src_chunk = testdata->space+srcpos; + char *buf_chunk = buf+pos+ret; + + CX_TEST_ASSERT(!memcmp(buf_chunk, src_chunk, chunklen)); + + pos += ret + chunklen; + srcpos += chunklen; + + debug_counter++; + } + + + testutil_destroy_session(sn); + testutil_iostream_destroy(st); + cxBufferFree(testdata); - pos = 0; // st->buf position - size_t srcpos = 0; // testdata position - int debug_counter = 0; - while(pos < bufsize) { - ssize_t remaining = bufsize - pos; - ssize_t src_remaining = testdata->size - srcpos; - - int ret = http_stream_parse_chunk_header(buf+pos, remaining, first_chunk, &chunklen); - first_chunk = FALSE; - - // ret must always be > 0 (0: incomplete chunk header, -1: invalid syntax) - UCX_TEST_ASSERT(ret > 0, "http_stream_parse_chunk_header ret <= 0"); - if(chunklen == 0) { - UCX_TEST_ASSERT(src_remaining == 0, "stream end reached but src_remaining > 0"); - break; - } - - UCX_TEST_ASSERT(chunklen <= src_remaining, "chunklen > src_remaining"); - - char *src_chunk = testdata->space+srcpos; - char *buf_chunk = buf+pos+ret; - - UCX_TEST_ASSERT(!memcmp(buf_chunk, src_chunk, chunklen), "memcmp failed"); - - pos += ret + chunklen; - srcpos += chunklen; - - debug_counter++; } - - - testutil_destroy_session(sn); - testutil_iostream_destroy(st); - cxBufferFree(testdata); - - UCX_TEST_END; }
--- a/src/server/test/io.h Sat Nov 22 12:49:20 2025 +0100 +++ b/src/server/test/io.h Sat Nov 22 14:27:01 2025 +0100 @@ -39,26 +39,26 @@ extern "C" { #endif -UCX_TEST(test_io_http_stream_parse_chunk_header_hdronly_first); -UCX_TEST(test_io_http_stream_parse_chunk_header_hdronly); -UCX_TEST(test_io_http_stream_parse_chunk_header_hdronly_seq_fail); -UCX_TEST(test_io_http_stream_parse_chunk_header_hdr_data); -UCX_TEST(test_io_http_stream_parse_chunk_header_empty); -UCX_TEST(test_io_http_stream_parse_chunk_header_partial_first); -UCX_TEST(test_io_http_stream_parse_chunk_header_partial); -UCX_TEST(test_io_http_stream_parse_chunk_header_invalid); -UCX_TEST(test_io_http_stream_parse_chunk_header_zero); +CX_TEST(test_io_http_stream_parse_chunk_header_hdronly_first); +CX_TEST(test_io_http_stream_parse_chunk_header_hdronly); +CX_TEST(test_io_http_stream_parse_chunk_header_hdronly_seq_fail); +CX_TEST(test_io_http_stream_parse_chunk_header_hdr_data); +CX_TEST(test_io_http_stream_parse_chunk_header_empty); +CX_TEST(test_io_http_stream_parse_chunk_header_partial_first); +CX_TEST(test_io_http_stream_parse_chunk_header_partial); +CX_TEST(test_io_http_stream_parse_chunk_header_invalid); +CX_TEST(test_io_http_stream_parse_chunk_header_zero); -UCX_TEST(test_io_httpstream_write); -UCX_TEST(test_io_httpstream_chunked_write); -UCX_TEST(test_io_httpstream_chunked_write_xx); -UCX_TEST(test_io_httpstream_chunked_write_end); -UCX_TEST(test_io_httpstream_chunked_write_partial_header); -UCX_TEST(test_io_httpstream_chunked_write_partial_data); -UCX_TEST(test_io_httpstream_chunked_write_partial_trailer); -UCX_TEST(test_io_httpstream_chunked_write_partial_trailer_partial_header); -UCX_TEST(test_io_httpstream_chunked_write_data_2x); -UCX_TEST(test_io_httpstream_chunked_write_xx_limit); +CX_TEST(test_io_httpstream_write); +CX_TEST(test_io_httpstream_chunked_write); +CX_TEST(test_io_httpstream_chunked_write_xx); +CX_TEST(test_io_httpstream_chunked_write_end); +CX_TEST(test_io_httpstream_chunked_write_partial_header); +CX_TEST(test_io_httpstream_chunked_write_partial_data); +CX_TEST(test_io_httpstream_chunked_write_partial_trailer); +CX_TEST(test_io_httpstream_chunked_write_partial_trailer_partial_header); +CX_TEST(test_io_httpstream_chunked_write_data_2x); +CX_TEST(test_io_httpstream_chunked_write_xx_limit); #ifdef __cplusplus
--- a/src/server/test/main.c Sat Nov 22 12:49:20 2025 +0100 +++ b/src/server/test/main.c Sat Nov 22 14:27:01 2025 +0100 @@ -51,7 +51,7 @@ #include "io.h" #include "event.h" -void register_pg_tests(int argc, char **argv, UcxTestSuite *suite); +void register_pg_tests(int argc, char **argv, CxTestSuite *suite); void test() { @@ -70,106 +70,106 @@ //test(); - printf("%s", "Webserver Test Suite\n====================\n\n"); + //printf("%s", "Webserver Test Suite\n====================\n\n"); - UcxTestSuite* suite = ucx_test_suite_new(); + CxTestSuite *suite = cx_test_suite_new("webserver"); // util tests - ucx_test_register(suite, test_util_uri_escape_alphanum); - ucx_test_register(suite, test_util_uri_escape_space); - ucx_test_register(suite, test_util_uri_escape_latin); - ucx_test_register(suite, test_util_uri_escape_kanji); + cx_test_register(suite, test_util_uri_escape_alphanum); + cx_test_register(suite, test_util_uri_escape_space); + cx_test_register(suite, test_util_uri_escape_latin); + cx_test_register(suite, test_util_uri_escape_kanji); // event tests - ucx_test_register(suite, test_evhandler_create); - ucx_test_register(suite, test_event_send); - ucx_test_register(suite, test_event_send_multi); + cx_test_register(suite, test_evhandler_create); + cx_test_register(suite, test_event_send); + cx_test_register(suite, test_event_send_multi); // object tests - ucx_test_register(suite, test_expr_parse_expr_value); - ucx_test_register(suite, test_expr_parse_expr_neg_value); - ucx_test_register(suite, test_expr_parse_expr_value_str); - ucx_test_register(suite, test_expr_parse_expr_value_bool); - ucx_test_register(suite, test_expr_parse_expr_value_var); - ucx_test_register(suite, test_expr_parse_expr_not_value); - ucx_test_register(suite, test_expr_parse_expr_sign_value); - ucx_test_register(suite, test_expr_parse_expr_compare2values); - ucx_test_register(suite, test_expr_parse_expr_compare2value_expr); - ucx_test_register(suite, test_expr_parse_expr_compare2expr_value); - ucx_test_register(suite, test_expr_parse_expr_bracket); - ucx_test_register(suite, test_expr_op_defined_simple); - ucx_test_register(suite, test_expr_op_defined); - ucx_test_register(suite, test_expr_op_file_exists_simple); - ucx_test_register(suite, test_expr_parse_expr_func_arg0); - ucx_test_register(suite, test_expr_parse_expr_func_arg1); - ucx_test_register(suite, test_expr_parse_expr_func_arg3); - ucx_test_register(suite, test_expr_parse_expr_func_expr1); - ucx_test_register(suite, test_expr_parse_expr_func_expr2); + cx_test_register(suite, test_expr_parse_expr_value); + cx_test_register(suite, test_expr_parse_expr_neg_value); + cx_test_register(suite, test_expr_parse_expr_value_str); + cx_test_register(suite, test_expr_parse_expr_value_bool); + cx_test_register(suite, test_expr_parse_expr_value_var); + cx_test_register(suite, test_expr_parse_expr_not_value); + cx_test_register(suite, test_expr_parse_expr_sign_value); + cx_test_register(suite, test_expr_parse_expr_compare2values); + cx_test_register(suite, test_expr_parse_expr_compare2value_expr); + cx_test_register(suite, test_expr_parse_expr_compare2expr_value); + cx_test_register(suite, test_expr_parse_expr_bracket); + cx_test_register(suite, test_expr_op_defined_simple); + cx_test_register(suite, test_expr_op_defined); + cx_test_register(suite, test_expr_op_file_exists_simple); + cx_test_register(suite, test_expr_parse_expr_func_arg0); + cx_test_register(suite, test_expr_parse_expr_func_arg1); + cx_test_register(suite, test_expr_parse_expr_func_arg3); + cx_test_register(suite, test_expr_parse_expr_func_expr1); + cx_test_register(suite, test_expr_parse_expr_func_expr2); // io tests - ucx_test_register(suite, test_io_http_stream_parse_chunk_header_hdronly_first); - ucx_test_register(suite, test_io_http_stream_parse_chunk_header_hdronly); - ucx_test_register(suite, test_io_http_stream_parse_chunk_header_hdronly_seq_fail); - ucx_test_register(suite, test_io_http_stream_parse_chunk_header_hdr_data); - ucx_test_register(suite, test_io_http_stream_parse_chunk_header_empty); - ucx_test_register(suite, test_io_http_stream_parse_chunk_header_partial_first); - ucx_test_register(suite, test_io_http_stream_parse_chunk_header_partial); - ucx_test_register(suite, test_io_http_stream_parse_chunk_header_invalid); - ucx_test_register(suite, test_io_http_stream_parse_chunk_header_zero); - ucx_test_register(suite, test_io_httpstream_write); - ucx_test_register(suite, test_io_httpstream_chunked_write); - ucx_test_register(suite, test_io_httpstream_chunked_write_end); - ucx_test_register(suite, test_io_httpstream_chunked_write_xx); - ucx_test_register(suite, test_io_httpstream_chunked_write_partial_header); - ucx_test_register(suite, test_io_httpstream_chunked_write_partial_data); - ucx_test_register(suite, test_io_httpstream_chunked_write_partial_trailer); - ucx_test_register(suite, test_io_httpstream_chunked_write_partial_trailer_partial_header); - ucx_test_register(suite, test_io_httpstream_chunked_write_data_2x); - ucx_test_register(suite, test_io_httpstream_chunked_write_xx_limit); + cx_test_register(suite, test_io_http_stream_parse_chunk_header_hdronly_first); + cx_test_register(suite, test_io_http_stream_parse_chunk_header_hdronly); + cx_test_register(suite, test_io_http_stream_parse_chunk_header_hdronly_seq_fail); + cx_test_register(suite, test_io_http_stream_parse_chunk_header_hdr_data); + cx_test_register(suite, test_io_http_stream_parse_chunk_header_empty); + cx_test_register(suite, test_io_http_stream_parse_chunk_header_partial_first); + cx_test_register(suite, test_io_http_stream_parse_chunk_header_partial); + cx_test_register(suite, test_io_http_stream_parse_chunk_header_invalid); + cx_test_register(suite, test_io_http_stream_parse_chunk_header_zero); + cx_test_register(suite, test_io_httpstream_write); + cx_test_register(suite, test_io_httpstream_chunked_write); + cx_test_register(suite, test_io_httpstream_chunked_write_end); + cx_test_register(suite, test_io_httpstream_chunked_write_xx); + cx_test_register(suite, test_io_httpstream_chunked_write_partial_header); + cx_test_register(suite, test_io_httpstream_chunked_write_partial_data); + cx_test_register(suite, test_io_httpstream_chunked_write_partial_trailer); + cx_test_register(suite, test_io_httpstream_chunked_write_partial_trailer_partial_header); + cx_test_register(suite, test_io_httpstream_chunked_write_data_2x); + cx_test_register(suite, test_io_httpstream_chunked_write_xx_limit); // vfs tests - ucx_test_register(suite, test_vfs_open); - ucx_test_register(suite, test_vfs_mkdir); - ucx_test_register(suite, test_vfs_opendir); - ucx_test_register(suite, test_vfs_readdir); - ucx_test_register(suite, test_vfs_unlink); - ucx_test_register(suite, test_vfs_rmdir); + cx_test_register(suite, test_vfs_open); + cx_test_register(suite, test_vfs_mkdir); + cx_test_register(suite, test_vfs_opendir); + cx_test_register(suite, test_vfs_readdir); + cx_test_register(suite, test_vfs_unlink); + cx_test_register(suite, test_vfs_rmdir); // writer tests - ucx_test_register(suite, test_writer_putc); - ucx_test_register(suite, test_writer_flush); - ucx_test_register(suite, test_writer_put); + cx_test_register(suite, test_writer_putc); + cx_test_register(suite, test_writer_flush); + cx_test_register(suite, test_writer_put); // xml tests - ucx_test_register(suite, test_wsxml_iterator); - ucx_test_register(suite, test_wsxml_get_required_namespaces); - ucx_test_register(suite, test_wsxml_write_nodes); - ucx_test_register(suite, test_wsxml_nslist2string); - ucx_test_register(suite, test_wsxml_string2nslist); + cx_test_register(suite, test_wsxml_iterator); + cx_test_register(suite, test_wsxml_get_required_namespaces); + cx_test_register(suite, test_wsxml_write_nodes); + cx_test_register(suite, test_wsxml_nslist2string); + cx_test_register(suite, test_wsxml_string2nslist); // webdav tests - ucx_test_register(suite, test_webdav_plist_add); - ucx_test_register(suite, test_webdav_plist_size); - ucx_test_register(suite, test_propfind_parse); - ucx_test_register(suite, test_proppatch_parse); - ucx_test_register(suite, test_lock_parse); - ucx_test_register(suite, test_rqbody2buffer); - ucx_test_register(suite, test_webdav_plist_iterator); - ucx_test_register(suite, test_webdav_plist_iterator_remove_current); - ucx_test_register(suite, test_msresponse_addproperty); - ucx_test_register(suite, test_webdav_propfind_init); - ucx_test_register(suite, test_webdav_op_propfind_begin); - ucx_test_register(suite, test_webdav_op_propfind_children); - ucx_test_register(suite, test_proppatch_msresponse); - ucx_test_register(suite, test_msresponse_addproperty_with_errors); - ucx_test_register(suite, test_webdav_op_proppatch); - ucx_test_register(suite, test_webdav_vfs_op_do); - ucx_test_register(suite, test_webdav_delete); + cx_test_register(suite, test_webdav_plist_add); + cx_test_register(suite, test_webdav_plist_size); + cx_test_register(suite, test_propfind_parse); + cx_test_register(suite, test_proppatch_parse); + cx_test_register(suite, test_lock_parse); + cx_test_register(suite, test_rqbody2buffer); + cx_test_register(suite, test_webdav_plist_iterator); + cx_test_register(suite, test_webdav_plist_iterator_remove_current); + cx_test_register(suite, test_msresponse_addproperty); + cx_test_register(suite, test_webdav_propfind_init); + cx_test_register(suite, test_webdav_op_propfind_begin); + cx_test_register(suite, test_webdav_op_propfind_children); + cx_test_register(suite, test_proppatch_msresponse); + cx_test_register(suite, test_msresponse_addproperty_with_errors); + cx_test_register(suite, test_webdav_op_proppatch); + cx_test_register(suite, test_webdav_vfs_op_do); + cx_test_register(suite, test_webdav_delete); // webdav methods - ucx_test_register(suite, test_webdav_propfind); - ucx_test_register(suite, test_webdav_proppatch); - ucx_test_register(suite, test_webdav_put); + cx_test_register(suite, test_webdav_propfind); + cx_test_register(suite, test_webdav_proppatch); + cx_test_register(suite, test_webdav_put); // plugin tests #ifdef ENABLE_POSTGRESQL @@ -177,7 +177,7 @@ #endif // run tests - ucx_test_run(suite, stdout); + cx_test_run_stdout(suite); fflush(stdout); return EXIT_SUCCESS;
--- a/src/server/test/object.c Sat Nov 22 12:49:20 2025 +0100 +++ b/src/server/test/object.c Sat Nov 22 14:27:01 2025 +0100 @@ -36,116 +36,116 @@ #include "object.h" -UCX_TEST(test_expr_parse_expr_value) { +CX_TEST(test_expr_parse_expr_value) { pool_handle_t *pool = pool_create(); CxList *tokens = cxLinkedListCreate(pool_allocator(pool), NULL, sizeof(cxstring)); cxstring token = cx_str("123"); cxListAdd(tokens, &token); - UCX_TEST_BEGIN; - - size_t pos = 0; - NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos); + CX_TEST_DO { - UCX_TEST_ASSERT(pos == 1, "wrong token pos"); - UCX_TEST_ASSERT(expr, "expression is null"); - UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_INT, "wrong type"); + size_t pos = 0; + NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos); + + CX_TEST_ASSERT(pos == 1); + CX_TEST_ASSERT(expr); + CX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_INT); - UCX_TEST_END; + } pool_destroy(pool); } -UCX_TEST(test_expr_parse_expr_neg_value) { +CX_TEST(test_expr_parse_expr_neg_value) { pool_handle_t *pool = pool_create(); CxList *tokens = cxLinkedListCreate(pool_allocator(pool), NULL, sizeof(cxstring)); cxstring token = cx_str("-123"); cxListAdd(tokens, &token); - UCX_TEST_BEGIN; - - size_t pos = 0; - NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos); + CX_TEST_DO { - UCX_TEST_ASSERT(pos == 1, "wrong token pos"); - UCX_TEST_ASSERT(expr, "expression is null"); - UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_INT, "wrong type"); - UCX_TEST_ASSERT(expr->value.i == -123, "wrong value"); + size_t pos = 0; + NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos); + + CX_TEST_ASSERT(pos == 1); + CX_TEST_ASSERT(expr); + CX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_INT); + CX_TEST_ASSERT(expr->value.i == -123); - UCX_TEST_END; + } pool_destroy(pool); } -UCX_TEST(test_expr_parse_expr_value_str) { +CX_TEST(test_expr_parse_expr_value_str) { pool_handle_t *pool = pool_create(); CxList *tokens = cxLinkedListCreate(pool_allocator(pool), NULL, sizeof(cxstring)); cxstring token = cx_str("\"hello world\""); cxListAdd(tokens, &token); - UCX_TEST_BEGIN; - - size_t pos = 0; - NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos); + CX_TEST_DO { - UCX_TEST_ASSERT(pos == 1, "wrong token pos"); - UCX_TEST_ASSERT(expr, "expression is null"); - UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_STRING, "wrong type"); - UCX_TEST_ASSERT(!cx_strcmp(expr->value.str, cx_str("hello world")), "wrong value"); + size_t pos = 0; + NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos); + + CX_TEST_ASSERT(pos == 1); + CX_TEST_ASSERT(expr); + CX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_STRING); + CX_TEST_ASSERT(!cx_strcmp(expr->value.str, cx_str("hello world"))); - UCX_TEST_END; + } pool_destroy(pool); } -UCX_TEST(test_expr_parse_expr_value_bool) { +CX_TEST(test_expr_parse_expr_value_bool) { pool_handle_t *pool = pool_create(); CxList *tokens = cxLinkedListCreate(pool_allocator(pool), NULL, sizeof(cxstring)); cxstring token = cx_str("true"); cxListAdd(tokens, &token); - UCX_TEST_BEGIN; - - size_t pos = 0; - NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos); + CX_TEST_DO { - UCX_TEST_ASSERT(pos == 1, "wrong token pos"); - UCX_TEST_ASSERT(expr, "expression is null"); - UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_BOOL, "wrong type"); - UCX_TEST_ASSERT(expr->value.b == 1, "wrong value"); + size_t pos = 0; + NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos); + + CX_TEST_ASSERT(pos == 1); + CX_TEST_ASSERT(expr); + CX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_BOOL); + CX_TEST_ASSERT(expr->value.b == 1); - UCX_TEST_END; + } pool_destroy(pool); } -UCX_TEST(test_expr_parse_expr_value_var) { +CX_TEST(test_expr_parse_expr_value_var) { pool_handle_t *pool = pool_create(); CxList *tokens = cxLinkedListCreate(pool_allocator(pool), NULL, sizeof(cxstring)); cxstring token = cx_str("$test"); cxListAdd(tokens, &token); - UCX_TEST_BEGIN; - - size_t pos = 0; - NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos); + CX_TEST_DO { - UCX_TEST_ASSERT(pos == 1, "wrong token pos"); - UCX_TEST_ASSERT(expr, "expression is null"); - UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_VARIABLE, "wrong type"); - UCX_TEST_ASSERT(!cx_strcmp(expr->value.var, cx_str("test")), "wrong var name"); + size_t pos = 0; + NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos); + + CX_TEST_ASSERT(pos == 1); + CX_TEST_ASSERT(expr); + CX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_VARIABLE); + CX_TEST_ASSERT(!cx_strcmp(expr->value.var, cx_str("test"))); - UCX_TEST_END; + } pool_destroy(pool); } -UCX_TEST(test_expr_parse_expr_not_value) { +CX_TEST(test_expr_parse_expr_not_value) { pool_handle_t *pool = pool_create(); CxList *tokens = cxLinkedListCreate(pool_allocator(pool), NULL, sizeof(cxstring)); @@ -154,26 +154,26 @@ token = cx_str("true"); cxListAdd(tokens, &token); - UCX_TEST_BEGIN; - - size_t pos = 0; - NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos); - - UCX_TEST_ASSERT(pos == 2, "wrong token pos"); - UCX_TEST_ASSERT(expr, "expression is null"); + CX_TEST_DO { - UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_UNARY, "wrong root expression type"); - UCX_TEST_ASSERT(expr->left, "missing left expression"); - UCX_TEST_ASSERT(!expr->right, "right expression should be null"); - UCX_TEST_ASSERT(expr->left->type == NSAPI_EXPRESSION_BOOL, "left expression has wrong type"); - UCX_TEST_ASSERT(expr->left->value.b == 1, "left expression has wrong value"); + size_t pos = 0; + NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos); + + CX_TEST_ASSERT(pos == 2); + CX_TEST_ASSERT(expr); + + CX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_UNARY); + CX_TEST_ASSERT(expr->left); + CX_TEST_ASSERT(!expr->right); + CX_TEST_ASSERT(expr->left->type == NSAPI_EXPRESSION_BOOL); + CX_TEST_ASSERT(expr->left->value.b == 1); - UCX_TEST_END; + } pool_destroy(pool); } -UCX_TEST(test_expr_parse_expr_sign_value) { +CX_TEST(test_expr_parse_expr_sign_value) { pool_handle_t *pool = pool_create(); CxList *tokens1 = cxLinkedListCreate(pool_allocator(pool), NULL, sizeof(cxstring)); @@ -188,34 +188,34 @@ token = cx_str("123"); cxListAdd(tokens2, &token); - UCX_TEST_BEGIN; - - size_t pos = 0; - NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens1, &pos); - - UCX_TEST_ASSERT(pos == 2, "test1: wrong token pos"); - UCX_TEST_ASSERT(expr, "test1: expression is null"); - - pos = 0; - expr = expr_parse_logical_expr(pool, tokens2, &pos); + CX_TEST_DO { - UCX_TEST_ASSERT(pos == 2, "test2: wrong token pos"); - UCX_TEST_ASSERT(expr, "test2: expression is null"); + size_t pos = 0; + NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens1, &pos); + + CX_TEST_ASSERT(pos == 2); + CX_TEST_ASSERT(expr); + + pos = 0; + expr = expr_parse_logical_expr(pool, tokens2, &pos); + + CX_TEST_ASSERT(pos == 2); + CX_TEST_ASSERT(expr); + + CX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_UNARY); + CX_TEST_ASSERT(expr->operator == NSAPI_EXPRESSION_SUB); + CX_TEST_ASSERT(expr->left); + CX_TEST_ASSERT(expr->left->type == NSAPI_EXPRESSION_INT); + CX_TEST_ASSERT(expr->left->value.i == 123); - UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_UNARY, "wrong expression type"); - UCX_TEST_ASSERT(expr->operator == NSAPI_EXPRESSION_SUB, "wrong expression operator"); - UCX_TEST_ASSERT(expr->left, "missing left expresion"); - UCX_TEST_ASSERT(expr->left->type == NSAPI_EXPRESSION_INT, "left expression has wrong type"); - UCX_TEST_ASSERT(expr->left->value.i == 123, "left expression has wrong value"); - - UCX_TEST_END; + } pool_destroy(pool); } -UCX_TEST(test_expr_parse_expr_compare2values) { +CX_TEST(test_expr_parse_expr_compare2values) { pool_handle_t *pool = pool_create(); CxList *tokens = cxLinkedListCreate(pool_allocator(pool), NULL, sizeof(cxstring)); @@ -226,27 +226,27 @@ token = cx_str("2"); cxListAdd(tokens, &token); - UCX_TEST_BEGIN; - - size_t pos = 0; - NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos); - - UCX_TEST_ASSERT(pos == 3, "wrong token pos"); - UCX_TEST_ASSERT(expr, "expression is null"); + CX_TEST_DO { - UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_BINARY, "wrong expression type"); - UCX_TEST_ASSERT(expr->left, "left expression is null"); - UCX_TEST_ASSERT(expr->right, "right expression is null"); + size_t pos = 0; + NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos); + + CX_TEST_ASSERT(pos == 3); + CX_TEST_ASSERT(expr); + + CX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_BINARY); + CX_TEST_ASSERT(expr->left); + CX_TEST_ASSERT(expr->right); + + CX_TEST_ASSERT(expr->left->operator == NSAPI_EXPRESSION_NOOP); + CX_TEST_ASSERT(expr->right->operator == NSAPI_EXPRESSION_NOOP); - UCX_TEST_ASSERT(expr->left->operator == NSAPI_EXPRESSION_NOOP, "left should be a literal with no operator"); - UCX_TEST_ASSERT(expr->right->operator == NSAPI_EXPRESSION_NOOP, "right should be a literal with no operator"); - - UCX_TEST_END; + } pool_destroy(pool); } -UCX_TEST(test_expr_parse_expr_compare2value_expr) { +CX_TEST(test_expr_parse_expr_compare2value_expr) { pool_handle_t *pool = pool_create(); CxList *tokens = cxLinkedListCreate(pool_allocator(pool), NULL, sizeof(cxstring)); @@ -261,27 +261,27 @@ token = cx_str("1"); cxListAdd(tokens, &token); - UCX_TEST_BEGIN; - - size_t pos = 0; - NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos); - - UCX_TEST_ASSERT(pos == 5, "wrong token pos"); - UCX_TEST_ASSERT(expr, "expression is null"); + CX_TEST_DO { - UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_BINARY, "wrong expression type"); - UCX_TEST_ASSERT(expr->left, "left expression is null"); - UCX_TEST_ASSERT(expr->right, "right expression is null"); + size_t pos = 0; + NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos); + + CX_TEST_ASSERT(pos == 5); + CX_TEST_ASSERT(expr); + + CX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_BINARY); + CX_TEST_ASSERT(expr->left); + CX_TEST_ASSERT(expr->right); + + CX_TEST_ASSERT(expr->left->operator == NSAPI_EXPRESSION_NOOP); + CX_TEST_ASSERT(expr->right->operator == NSAPI_EXPRESSION_ADD); - UCX_TEST_ASSERT(expr->left->operator == NSAPI_EXPRESSION_NOOP, "left should be a literal with no operator"); - UCX_TEST_ASSERT(expr->right->operator == NSAPI_EXPRESSION_ADD, "right should be a binary expression"); - - UCX_TEST_END; + } pool_destroy(pool); } -UCX_TEST(test_expr_parse_expr_compare2expr_value) { +CX_TEST(test_expr_parse_expr_compare2expr_value) { pool_handle_t *pool = pool_create(); CxList *tokens = cxLinkedListCreate(pool_allocator(pool), NULL, sizeof(cxstring)); @@ -296,32 +296,32 @@ token = cx_str("2"); cxListAdd(tokens, &token); - UCX_TEST_BEGIN; - - size_t pos = 0; - NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos); - - UCX_TEST_ASSERT(pos == 5, "wrong token pos"); - UCX_TEST_ASSERT(expr, "expression is null"); + CX_TEST_DO { - UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_BINARY, "wrong expression type"); - UCX_TEST_ASSERT(expr->left, "left expression is null"); - UCX_TEST_ASSERT(expr->right, "right expression is null"); - UCX_TEST_ASSERT(expr->right->value.i == 2, "right wrong value"); + size_t pos = 0; + NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos); + + CX_TEST_ASSERT(pos == 5); + CX_TEST_ASSERT(expr); + + CX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_BINARY); + CX_TEST_ASSERT(expr->left); + CX_TEST_ASSERT(expr->right); + CX_TEST_ASSERT(expr->right->value.i == 2); + + CX_TEST_ASSERT(expr->left->operator == NSAPI_EXPRESSION_ADD); + CX_TEST_ASSERT(expr->right->operator == NSAPI_EXPRESSION_NOOP); + CX_TEST_ASSERT(expr->left->left); + CX_TEST_ASSERT(expr->left->right); + CX_TEST_ASSERT(expr->left->left->value.i == 1); + CX_TEST_ASSERT(expr->left->right->value.i == 1); - UCX_TEST_ASSERT(expr->left->operator == NSAPI_EXPRESSION_ADD, "left should be a binary operation"); - UCX_TEST_ASSERT(expr->right->operator == NSAPI_EXPRESSION_NOOP, "right should be NOOP"); - UCX_TEST_ASSERT(expr->left->left, "ADD-op missing left"); - UCX_TEST_ASSERT(expr->left->right, "ADD-op missing right"); - UCX_TEST_ASSERT(expr->left->left->value.i == 1, "ADD-op: wrong left value"); - UCX_TEST_ASSERT(expr->left->right->value.i == 1, "ADD-op: wrong right value"); - - UCX_TEST_END; + } pool_destroy(pool); } -UCX_TEST(test_expr_parse_expr_bracket) { +CX_TEST(test_expr_parse_expr_bracket) { pool_handle_t *pool = pool_create(); // expression: 2 * (1 + 2) == 6 @@ -345,30 +345,30 @@ token = cx_str("6"); cxListAdd(tokens, &token); - UCX_TEST_BEGIN; - - size_t pos = 0; - NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos); + CX_TEST_DO { - UCX_TEST_ASSERT(pos == 9, "wrong token pos"); - UCX_TEST_ASSERT(expr, "expression is null"); - UCX_TEST_ASSERT(expr->operator == NSAPI_EXPRESSION_EQ, "root: wrong operator"); - UCX_TEST_ASSERT(expr->left, "missing left expression"); - UCX_TEST_ASSERT(expr->right, "missing right expression"); - UCX_TEST_ASSERT(expr->right->type == NSAPI_EXPRESSION_INT, "right expression has wrong type"); - UCX_TEST_ASSERT(expr->left->operator == NSAPI_EXPRESSION_MUL, "left expression has wrong operator"); - UCX_TEST_ASSERT(expr->left->left, "mul: missing left"); - UCX_TEST_ASSERT(expr->left->right, "mul: missing right"); - UCX_TEST_ASSERT(expr->left->right->operator == NSAPI_EXPRESSION_ADD, "missing add operator"); - UCX_TEST_ASSERT(expr->left->right->left, "add: missing left"); - UCX_TEST_ASSERT(expr->left->right->left, "add: missing right"); + size_t pos = 0; + NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos); + + CX_TEST_ASSERT(pos == 9); + CX_TEST_ASSERT(expr); + CX_TEST_ASSERT(expr->operator == NSAPI_EXPRESSION_EQ); + CX_TEST_ASSERT(expr->left); + CX_TEST_ASSERT(expr->right); + CX_TEST_ASSERT(expr->right->type == NSAPI_EXPRESSION_INT); + CX_TEST_ASSERT(expr->left->operator == NSAPI_EXPRESSION_MUL); + CX_TEST_ASSERT(expr->left->left); + CX_TEST_ASSERT(expr->left->right); + CX_TEST_ASSERT(expr->left->right->operator == NSAPI_EXPRESSION_ADD); + CX_TEST_ASSERT(expr->left->right->left); + CX_TEST_ASSERT(expr->left->right->left); - UCX_TEST_END; + } pool_destroy(pool); } -UCX_TEST(test_expr_op_defined_simple) { +CX_TEST(test_expr_op_defined_simple) { pool_handle_t *pool = pool_create(); CxList *tokens = cxLinkedListCreate(pool_allocator(pool), NULL, sizeof(cxstring)); @@ -378,24 +378,24 @@ token = cx_str("$testvar1"); cxListAdd(tokens, &token); - UCX_TEST_BEGIN; - - size_t pos = 0; - NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos); + CX_TEST_DO { - UCX_TEST_ASSERT(pos == 2, "wrong token pos"); - UCX_TEST_ASSERT(expr, "expression is null"); - UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_UNARY, "wrong type"); - UCX_TEST_ASSERT(expr->operator == NSAPI_EXPRESSION_VALUE_DEFINED, "wrong operator"); - UCX_TEST_ASSERT(expr->left, "missing left operand"); - UCX_TEST_ASSERT(expr->left->type == NSAPI_EXPRESSION_VARIABLE, "operand is not a variable"); + size_t pos = 0; + NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos); + + CX_TEST_ASSERT(pos == 2); + CX_TEST_ASSERT(expr); + CX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_UNARY); + CX_TEST_ASSERT(expr->operator == NSAPI_EXPRESSION_VALUE_DEFINED); + CX_TEST_ASSERT(expr->left); + CX_TEST_ASSERT(expr->left->type == NSAPI_EXPRESSION_VARIABLE); - UCX_TEST_END; + } pool_destroy(pool); } -UCX_TEST(test_expr_op_defined) { +CX_TEST(test_expr_op_defined) { pool_handle_t *pool = pool_create(); CxList *tokens = cxLinkedListCreate(pool_allocator(pool), NULL, sizeof(cxstring)); @@ -414,27 +414,27 @@ token = cx_str("$var"); cxListAdd(tokens, &token); - UCX_TEST_BEGIN; - - size_t pos = 0; - NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos); + CX_TEST_DO { - UCX_TEST_ASSERT(pos == 5, "wrong token pos"); - UCX_TEST_ASSERT(expr, "expression is null"); - UCX_TEST_ASSERT(expr->operator == NSAPI_EXPRESSION_EQ, "wrong operator"); - UCX_TEST_ASSERT(expr->left, "missing left"); - UCX_TEST_ASSERT(expr->right, "missing right"); - UCX_TEST_ASSERT(expr->left->type == NSAPI_EXPRESSION_BOOL, "left expression is not a bool"); - UCX_TEST_ASSERT(expr->right->operator == NSAPI_EXPRESSION_NOT, "right: wrong operator"); - UCX_TEST_ASSERT(expr->right->left, "not op: missing left"); - UCX_TEST_ASSERT(expr->right->left->operator == NSAPI_EXPRESSION_VALUE_DEFINED, "missing defined operator"); + size_t pos = 0; + NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos); + + CX_TEST_ASSERT(pos == 5); + CX_TEST_ASSERT(expr); + CX_TEST_ASSERT(expr->operator == NSAPI_EXPRESSION_EQ); + CX_TEST_ASSERT(expr->left); + CX_TEST_ASSERT(expr->right); + CX_TEST_ASSERT(expr->left->type == NSAPI_EXPRESSION_BOOL); + CX_TEST_ASSERT(expr->right->operator == NSAPI_EXPRESSION_NOT); + CX_TEST_ASSERT(expr->right->left); + CX_TEST_ASSERT(expr->right->left->operator == NSAPI_EXPRESSION_VALUE_DEFINED); - UCX_TEST_END; + } pool_destroy(pool); } -UCX_TEST(test_expr_op_file_exists_simple) { +CX_TEST(test_expr_op_file_exists_simple) { pool_handle_t *pool = pool_create(); CxList *tokens = cxLinkedListCreate(pool_allocator(pool), NULL, sizeof(cxstring)); @@ -444,25 +444,25 @@ token = cx_str("\"/path/file\""); cxListAdd(tokens, &token); - UCX_TEST_BEGIN; - - size_t pos = 0; - NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos); + CX_TEST_DO { - UCX_TEST_ASSERT(pos == 2, "wrong token pos"); - UCX_TEST_ASSERT(expr, "expression is null"); - UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_UNARY, "wrong type"); - UCX_TEST_ASSERT(expr->operator == NSAPI_EXPRESSION_FILE_DIR_EXISTS, "wrong operator"); - UCX_TEST_ASSERT(expr->left, "missing left operand"); - UCX_TEST_ASSERT(expr->left->type == NSAPI_EXPRESSION_STRING, "operand is not a string"); - UCX_TEST_ASSERT(!cx_strcmp(expr->left->value.str, cx_str("/path/file")), "wrong string operand"); + size_t pos = 0; + NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos); + + CX_TEST_ASSERT(pos == 2); + CX_TEST_ASSERT(expr); + CX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_UNARY); + CX_TEST_ASSERT(expr->operator == NSAPI_EXPRESSION_FILE_DIR_EXISTS); + CX_TEST_ASSERT(expr->left); + CX_TEST_ASSERT(expr->left->type == NSAPI_EXPRESSION_STRING); + CX_TEST_ASSERT(!cx_strcmp(expr->left->value.str, cx_str("/path/file"))); - UCX_TEST_END; + } pool_destroy(pool); } -UCX_TEST(test_expr_parse_expr_func_arg0) { +CX_TEST(test_expr_parse_expr_func_arg0) { pool_handle_t *pool = pool_create(); CxList *tokens = cxLinkedListCreate(pool_allocator(pool), NULL, sizeof(cxstring)); @@ -473,19 +473,19 @@ token = cx_str(")"); cxListAdd(tokens, &token); - UCX_TEST_BEGIN; - - size_t pos = 0; - NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos); + CX_TEST_DO { - UCX_TEST_ASSERT(pos == 3, "wrong token pos"); - UCX_TEST_ASSERT(expr, "expression is null"); - UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_IDENTIFIER, "wrong expression type"); - UCX_TEST_ASSERT(expr->operator == NSAPI_EXPRESSION_CALL, "wrong expression operator"); - UCX_TEST_ASSERT(!expr->left, "left is not null"); - UCX_TEST_ASSERT(!expr->right, "right is not null"); + size_t pos = 0; + NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos); + + CX_TEST_ASSERT(pos == 3); + CX_TEST_ASSERT(expr); + CX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_IDENTIFIER); + CX_TEST_ASSERT(expr->operator == NSAPI_EXPRESSION_CALL); + CX_TEST_ASSERT(!expr->left); + CX_TEST_ASSERT(!expr->right); - UCX_TEST_END; + } pool_destroy(pool); } @@ -518,7 +518,7 @@ } -UCX_TEST(test_expr_parse_expr_func_arg1) { +CX_TEST(test_expr_parse_expr_func_arg1) { pool_handle_t *pool = pool_create(); CxList *tokens = cxLinkedListCreate(pool_allocator(pool), NULL, sizeof(cxstring)); @@ -531,29 +531,29 @@ token = cx_str(")"); cxListAdd(tokens, &token); - UCX_TEST_BEGIN; - - size_t pos = 0; - NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos); + CX_TEST_DO { - UCX_TEST_ASSERT(pos == cxListSize(tokens), "wrong token pos"); - UCX_TEST_ASSERT(expr, "expression is null"); - UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_IDENTIFIER, "wrong expression type"); - UCX_TEST_ASSERT(expr->operator == NSAPI_EXPRESSION_CALL, "wrong expression operator"); + size_t pos = 0; + NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos); + + CX_TEST_ASSERT(pos == cxListSize(tokens)); + CX_TEST_ASSERT(expr); + CX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_IDENTIFIER); + CX_TEST_ASSERT(expr->operator == NSAPI_EXPRESSION_CALL); + + size_t numArgs = 0; + NSAPIExpression args[8]; + int err = test_get_args(args, 8, &numArgs, expr->left); + CX_TEST_ASSERT(err == 0); + CX_TEST_ASSERT(numArgs == 1); + CX_TEST_ASSERT(args[0].value.i == 1); - size_t numArgs = 0; - NSAPIExpression args[8]; - int err = test_get_args(args, 8, &numArgs, expr->left); - UCX_TEST_ASSERT(err == 0, "too much args"); - UCX_TEST_ASSERT(numArgs == 1, "wrong arg count"); - UCX_TEST_ASSERT(args[0].value.i == 1, "wrong arg value"); - - UCX_TEST_END; + } pool_destroy(pool); } -UCX_TEST(test_expr_parse_expr_func_arg3) { +CX_TEST(test_expr_parse_expr_func_arg3) { pool_handle_t *pool = pool_create(); CxList *tokens = cxLinkedListCreate(pool_allocator(pool), NULL, sizeof(cxstring)); @@ -574,31 +574,31 @@ token = cx_str(")"); cxListAdd(tokens, &token); - UCX_TEST_BEGIN; - - size_t pos = 0; - NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos); - - UCX_TEST_ASSERT(pos == cxListSize(tokens), "wrong token pos"); - UCX_TEST_ASSERT(expr, "expression is null"); - UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_IDENTIFIER, "wrong expression type"); - UCX_TEST_ASSERT(expr->operator == NSAPI_EXPRESSION_CALL, "wrong expression operator"); + CX_TEST_DO { - size_t numArgs = 0; - NSAPIExpression args[8]; - int err = test_get_args(args, 8, &numArgs, expr->left); - UCX_TEST_ASSERT(err == 0, "too much args"); - UCX_TEST_ASSERT(numArgs == 3, "wrong arg count"); - UCX_TEST_ASSERT(args[0].value.i == 1, "arg0: wrong value"); - UCX_TEST_ASSERT(args[1].value.i == 2, "arg1: wrong value"); - UCX_TEST_ASSERT(args[2].value.i == 3, "arg2: wrong value"); + size_t pos = 0; + NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos); + + CX_TEST_ASSERT(pos == cxListSize(tokens)); + CX_TEST_ASSERT(expr); + CX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_IDENTIFIER); + CX_TEST_ASSERT(expr->operator == NSAPI_EXPRESSION_CALL); + + size_t numArgs = 0; + NSAPIExpression args[8]; + int err = test_get_args(args, 8, &numArgs, expr->left); + CX_TEST_ASSERT(err == 0); + CX_TEST_ASSERT(numArgs == 3); + CX_TEST_ASSERT(args[0].value.i == 1); + CX_TEST_ASSERT(args[1].value.i == 2); + CX_TEST_ASSERT(args[2].value.i == 3); - UCX_TEST_END; + } pool_destroy(pool); } -UCX_TEST(test_expr_parse_expr_func_expr1) { +CX_TEST(test_expr_parse_expr_func_expr1) { pool_handle_t *pool = pool_create(); CxList *tokens = cxLinkedListCreate(pool_allocator(pool), NULL, sizeof(cxstring)); @@ -619,32 +619,32 @@ token = cx_str(")"); cxListAdd(tokens, &token); - UCX_TEST_BEGIN; - - size_t pos = 0; - NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos); - - UCX_TEST_ASSERT(pos == cxListSize(tokens), "wrong token pos"); - UCX_TEST_ASSERT(expr, "expression is null"); - UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_IDENTIFIER, "wrong expression type"); - UCX_TEST_ASSERT(expr->operator == NSAPI_EXPRESSION_CALL, "wrong expression operator"); + CX_TEST_DO { - size_t numArgs = 0; - NSAPIExpression args[8]; - int err = test_get_args(args, 8, &numArgs, expr->left); - UCX_TEST_ASSERT(err == 0, "too much args"); - UCX_TEST_ASSERT(numArgs == 2, "wrong arg count"); - UCX_TEST_ASSERT(args[0].value.i == 1, "arg0: wrong value"); - UCX_TEST_ASSERT(args[1].operator == NSAPI_EXPRESSION_ADD, "arg1: wrong operator"); - UCX_TEST_ASSERT(args[1].left && args[1].right, "arg1: missing operator values"); - UCX_TEST_ASSERT(args[1].left->value.i == 2 && args[1].right->value.i == 3, "arg1: wrong operator values"); + size_t pos = 0; + NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos); + + CX_TEST_ASSERT(pos == cxListSize(tokens)); + CX_TEST_ASSERT(expr); + CX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_IDENTIFIER); + CX_TEST_ASSERT(expr->operator == NSAPI_EXPRESSION_CALL); + + size_t numArgs = 0; + NSAPIExpression args[8]; + int err = test_get_args(args, 8, &numArgs, expr->left); + CX_TEST_ASSERT(err == 0); + CX_TEST_ASSERT(numArgs == 2); + CX_TEST_ASSERT(args[0].value.i == 1); + CX_TEST_ASSERT(args[1].operator == NSAPI_EXPRESSION_ADD); + CX_TEST_ASSERT(args[1].left && args[1].right); + CX_TEST_ASSERT(args[1].left->value.i == 2 && args[1].right->value.i == 3); - UCX_TEST_END; + } pool_destroy(pool); } -UCX_TEST(test_expr_parse_expr_func_expr2) { +CX_TEST(test_expr_parse_expr_func_expr2) { pool_handle_t *pool = pool_create(); CxList *tokens = cxLinkedListCreate(pool_allocator(pool), NULL, sizeof(cxstring)); @@ -675,29 +675,29 @@ token = cx_str(")"); cxListAdd(tokens, &token); - UCX_TEST_BEGIN; - - size_t pos = 0; - NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos); - - UCX_TEST_ASSERT(pos == cxListSize(tokens), "wrong token pos"); - UCX_TEST_ASSERT(expr, "expression is null"); - UCX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_IDENTIFIER, "wrong expression type"); - UCX_TEST_ASSERT(expr->operator == NSAPI_EXPRESSION_CALL, "wrong expression operator"); + CX_TEST_DO { - size_t numArgs = 0; - NSAPIExpression args[8]; - int err = test_get_args(args, 8, &numArgs, expr->left); - UCX_TEST_ASSERT(err == 0, "too much args"); - UCX_TEST_ASSERT(numArgs == 3, "wrong arg count"); - UCX_TEST_ASSERT(args[0].operator == NSAPI_EXPRESSION_ADD, "arg0: wrong operator"); - UCX_TEST_ASSERT(args[0].left && args[0].right, "arg0: missing operator values"); - UCX_TEST_ASSERT(args[1].operator == NSAPI_EXPRESSION_CALL, "arg1: wrong operator"); - UCX_TEST_ASSERT(args[1].left, "arg1: missing args"); - UCX_TEST_ASSERT(args[2].type == NSAPI_EXPRESSION_INT, "arg2: wrong type"); - UCX_TEST_ASSERT(args[2].value.i == 6, "arg2: wrong value"); + size_t pos = 0; + NSAPIExpression *expr = expr_parse_logical_expr(pool, tokens, &pos); + + CX_TEST_ASSERT(pos == cxListSize(tokens)); + CX_TEST_ASSERT(expr); + CX_TEST_ASSERT(expr->type == NSAPI_EXPRESSION_IDENTIFIER); + CX_TEST_ASSERT(expr->operator == NSAPI_EXPRESSION_CALL); + + size_t numArgs = 0; + NSAPIExpression args[8]; + int err = test_get_args(args, 8, &numArgs, expr->left); + CX_TEST_ASSERT(err == 0); + CX_TEST_ASSERT(numArgs == 3); + CX_TEST_ASSERT(args[0].operator == NSAPI_EXPRESSION_ADD); + CX_TEST_ASSERT(args[0].left && args[0].right); + CX_TEST_ASSERT(args[1].operator == NSAPI_EXPRESSION_CALL); + CX_TEST_ASSERT(args[1].left); + CX_TEST_ASSERT(args[2].type == NSAPI_EXPRESSION_INT); + CX_TEST_ASSERT(args[2].value.i == 6); - UCX_TEST_END; + } pool_destroy(pool); }
--- a/src/server/test/object.h Sat Nov 22 12:49:20 2025 +0100 +++ b/src/server/test/object.h Sat Nov 22 14:27:01 2025 +0100 @@ -37,29 +37,29 @@ extern "C" { #endif -UCX_TEST(test_expr_parse_expr_value); -UCX_TEST(test_expr_parse_expr_neg_value); -UCX_TEST(test_expr_parse_expr_value_str); -UCX_TEST(test_expr_parse_expr_value_bool); -UCX_TEST(test_expr_parse_expr_value_var); -UCX_TEST(test_expr_parse_expr_not_value); -UCX_TEST(test_expr_parse_expr_sign_value); +CX_TEST(test_expr_parse_expr_value); +CX_TEST(test_expr_parse_expr_neg_value); +CX_TEST(test_expr_parse_expr_value_str); +CX_TEST(test_expr_parse_expr_value_bool); +CX_TEST(test_expr_parse_expr_value_var); +CX_TEST(test_expr_parse_expr_not_value); +CX_TEST(test_expr_parse_expr_sign_value); -UCX_TEST(test_expr_parse_expr_compare2values); -UCX_TEST(test_expr_parse_expr_compare2value_expr); -UCX_TEST(test_expr_parse_expr_compare2expr_value); +CX_TEST(test_expr_parse_expr_compare2values); +CX_TEST(test_expr_parse_expr_compare2value_expr); +CX_TEST(test_expr_parse_expr_compare2expr_value); -UCX_TEST(test_expr_parse_expr_bracket); +CX_TEST(test_expr_parse_expr_bracket); -UCX_TEST(test_expr_op_defined_simple); -UCX_TEST(test_expr_op_defined); -UCX_TEST(test_expr_op_file_exists_simple); +CX_TEST(test_expr_op_defined_simple); +CX_TEST(test_expr_op_defined); +CX_TEST(test_expr_op_file_exists_simple); -UCX_TEST(test_expr_parse_expr_func_arg0); -UCX_TEST(test_expr_parse_expr_func_arg1); -UCX_TEST(test_expr_parse_expr_func_arg3); -UCX_TEST(test_expr_parse_expr_func_expr1); -UCX_TEST(test_expr_parse_expr_func_expr2); +CX_TEST(test_expr_parse_expr_func_arg0); +CX_TEST(test_expr_parse_expr_func_arg1); +CX_TEST(test_expr_parse_expr_func_arg3); +CX_TEST(test_expr_parse_expr_func_expr1); +CX_TEST(test_expr_parse_expr_func_expr2);
--- a/src/server/test/test.c Sat Nov 22 12:49:20 2025 +0100 +++ b/src/server/test/test.c Sat Nov 22 14:27:01 2025 +0100 @@ -28,64 +28,3 @@ #include "test.h" -UcxTestSuite* ucx_test_suite_new() { - UcxTestSuite* suite = (UcxTestSuite*) malloc(sizeof(UcxTestSuite)); - if (suite != NULL) { - suite->success = 0; - suite->failure = 0; - suite->tests = NULL; - } - - return suite; -} - -void ucx_test_suite_free(UcxTestSuite* suite) { - UcxTestList *l = suite->tests; - while (l != NULL) { - UcxTestList *e = l; - l = l->next; - free(e); - } - free(suite); -} - -int ucx_test_register(UcxTestSuite* suite, UcxTest test) { - if (suite->tests) { - UcxTestList *newelem = (UcxTestList*) malloc(sizeof(UcxTestList)); - if (newelem) { - newelem->test = test; - newelem->next = NULL; - - UcxTestList *last = suite->tests; - while (last->next) { - last = last->next; - } - last->next = newelem; - - return EXIT_SUCCESS; - } else { - return EXIT_FAILURE; - } - } else { - suite->tests = (UcxTestList*) malloc(sizeof(UcxTestList)); - if (suite->tests) { - suite->tests->test = test; - suite->tests->next = NULL; - - return EXIT_SUCCESS; - } else { - return EXIT_FAILURE; - } - } -} - -void ucx_test_run(UcxTestSuite* suite, FILE* output) { - suite->success = 0; - suite->failure = 0; - for (UcxTestList* elem = suite->tests ; elem ; elem = elem->next) { - elem->test(suite, output); - } - fwrite("\nAll test completed.\n", 1, 21, output); - fprintf(output, " Total: %u\n Success: %u\n Failure: %u\n", - suite->success+suite->failure, suite->success, suite->failure); -}
--- a/src/server/test/test.h Sat Nov 22 12:49:20 2025 +0100 +++ b/src/server/test/test.h Sat Nov 22 14:27:01 2025 +0100 @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright 2017 Mike Becker, Olaf Wintermann All rights reserved. + * Copyright 2025 Olaf Wintermann All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -25,217 +25,23 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ - -/** - * @file: test.h - * - * UCX Test Framework. - * - * Usage of this test framework: - * - * **** IN HEADER FILE: **** - * - * <pre> - * UCX_TEST(function_name); - * UCX_TEST_SUBROUTINE(subroutine_name, paramlist); // optional - * </pre> - * - * **** IN SOURCE FILE: **** - * <pre> - * UCX_TEST_SUBROUTINE(subroutine_name, paramlist) { - * // tests with UCX_TEST_ASSERT() - * } - * - * UCX_TEST(function_name) { - * // memory allocation and other stuff here - * #UCX_TEST_BEGIN - * // tests with UCX_TEST_ASSERT() and/or - * // calls with UCX_TEST_CALL_SUBROUTINE() here - * #UCX_TEST_END - * // cleanup of memory here - * } - * </pre> - * - * <b>Note:</b> if a test fails, a longjump is performed - * back to the #UCX_TEST_BEGIN macro! - * - * <b>Attention:</b> Do not call own functions within a test, that use - * UCX_TEST_ASSERT() macros and are not defined by using UCX_TEST_SUBROUTINE(). - * - * - * @author Mike Becker - * @author Olaf Wintermann - * - */ -#ifndef UCX_TEST_H -#define UCX_TEST_H +#ifndef WS_TEST_H +#define WS_TEST_H #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <setjmp.h> + +#include <cx/test.h> #ifdef __cplusplus extern "C" { #endif -#ifndef __FUNCTION__ - -/** - * Alias for the <code>__func__</code> preprocessor macro. - * Some compilers use <code>__func__</code> and others use __FUNCTION__. - * We use __FUNCTION__ so we define it for those compilers which use - * <code>__func__</code>. - */ -#define __FUNCTION__ __func__ -#endif - -/** Type for the UcxTestSuite. */ -typedef struct UcxTestSuite UcxTestSuite; - -/** Pointer to a test function. */ -typedef void(*UcxTest)(UcxTestSuite*,FILE*); - -/** Type for the internal list of test cases. */ -typedef struct UcxTestList UcxTestList; - -/** Structure for the internal list of test cases. */ -struct UcxTestList { - - /** Test case. */ - UcxTest test; - - /** Pointer to the next list element. */ - UcxTestList *next; -}; - -/** - * A test suite containing multiple test cases. - */ -struct UcxTestSuite { - - /** The number of successful tests after the suite has been run. */ - unsigned int success; - - /** The number of failed tests after the suite has been run. */ - unsigned int failure; - - /** - * Internal list of test cases. - * Use ucx_test_register() to add tests to this list. - */ - UcxTestList *tests; -}; - -/** - * Creates a new test suite. - * @return a new test suite - */ -UcxTestSuite* ucx_test_suite_new(); - -/** - * Destroys a test suite. - * @param suite the test suite to destroy - */ -void ucx_test_suite_free(UcxTestSuite* suite); - -/** - * Registers a test function with the specified test suite. - * - * @param suite the suite, the test function shall be added to - * @param test the test function to register - * @return <code>EXIT_SUCCESS</code> on success or - * <code>EXIT_FAILURE</code> on failure - */ -int ucx_test_register(UcxTestSuite* suite, UcxTest test); - -/** - * Runs a test suite and writes the test log to the specified stream. - * @param suite the test suite to run - * @param outstream the stream the log shall be written to - */ -void ucx_test_run(UcxTestSuite* suite, FILE* outstream); - -/** - * Macro for a #UcxTest function header. - * - * Use this macro to declare and/or define a #UcxTest function. - * - * @param name the name of the test function - */ -#define UCX_TEST(name) void name(UcxTestSuite* _suite_,FILE *_output_) - -/** - * Marks the begin of a test. - * <b>Note:</b> Any UCX_TEST_ASSERT() calls must be performed <b>after</b> - * #UCX_TEST_BEGIN. - * - * @see #UCX_TEST_END - */ -#define UCX_TEST_BEGIN fwrite("Running ", 1, 8, _output_);\ - fwrite(__FUNCTION__, 1, strlen(__FUNCTION__), _output_);\ - fwrite("... ", 1, 4, _output_);\ - jmp_buf _env_; \ - if (!setjmp(_env_)) { - -/** - * Checks a test assertion. - * If the assertion is correct, the test carries on. If the assertion is not - * correct, the specified message (terminated by a dot and a line break) is - * written to the test suites output stream. - * @param condition the condition to check - * @param message the message that shall be printed out on failure - */ -#define UCX_TEST_ASSERT(condition,message) if (!(condition)) { \ - fwrite(message".\n", 1, 2+strlen(message), _output_); \ - _suite_->failure++; \ - longjmp(_env_, 1);\ - } - -/** - * Macro for a test subroutine function header. - * - * Use this to declare and/or define a subroutine that can be called by using - * UCX_TEST_CALL_SUBROUTINE(). - * - * @param name the name of the subroutine - * @param ... the parameter list - * - * @see UCX_TEST_CALL_SUBROUTINE() - */ -#define UCX_TEST_SUBROUTINE(name,...) void name(UcxTestSuite* _suite_,\ - FILE *_output_, jmp_buf _env_, __VA_ARGS__) - -/** - * Macro for calling a test subroutine. - * - * Subroutines declared with UCX_TEST_SUBROUTINE() can be called by using this - * macro. - * - * <b>Note:</b> You may <b>only</b> call subroutines within a #UCX_TEST_BEGIN- - * #UCX_TEST_END-block. - * - * @param name the name of the subroutine - * @param ... the argument list - * - * @see UCX_TEST_SUBROUTINE() - */ -#define UCX_TEST_CALL_SUBROUTINE(name,...) \ - name(_suite_,_output_,_env_,__VA_ARGS__); - -/** - * Marks the end of a test. - * <b>Note:</b> Any UCX_TEST_ASSERT() calls must be performed <b>before</b> - * #UCX_TEST_END. - * - * @see #UCX_TEST_BEGIN - */ -#define UCX_TEST_END fwrite("success.\n", 1, 9, _output_); _suite_->success++;} - #ifdef __cplusplus } #endif -#endif /* UCX_TEST_H */ +#endif /* WS_TEST_H */
--- a/src/server/test/uri.c Sat Nov 22 12:49:20 2025 +0100 +++ b/src/server/test/uri.c Sat Nov 22 14:27:01 2025 +0100 @@ -31,34 +31,34 @@ #include "../util/util.h" -UCX_TEST(test_util_uri_escape_alphanum) { +CX_TEST(test_util_uri_escape_alphanum) { char *str1 = "/test/path/abc/"; char str_enc[512]; - UCX_TEST_BEGIN; + CX_TEST_DO { - char *test = util_uri_escape(str_enc, str1); - UCX_TEST_ASSERT(test, "util_uri_escape returned NULL"); - UCX_TEST_ASSERT(!strcasecmp(test, str1), "test != str1"); - - UCX_TEST_END; + char *test = util_uri_escape(str_enc, str1); + CX_TEST_ASSERT(test); + CX_TEST_ASSERT(!strcasecmp(test, str1)); + + } } -UCX_TEST(test_util_uri_escape_space) { +CX_TEST(test_util_uri_escape_space) { char *str1 = "/test/space in path/"; char *str_enc_expected = "/test/space%20in%20path/"; char str_enc[512]; - UCX_TEST_BEGIN; + CX_TEST_DO { - char *test = util_uri_escape(str_enc, str1); - UCX_TEST_ASSERT(test, "util_uri_escape returned NULL"); - UCX_TEST_ASSERT(!strcasecmp(test, str_enc_expected), "unexpected result"); + char *test = util_uri_escape(str_enc, str1); + CX_TEST_ASSERT(test); + CX_TEST_ASSERT(!strcasecmp(test, str_enc_expected)); - UCX_TEST_END; + } } -UCX_TEST(test_util_uri_escape_latin) { +CX_TEST(test_util_uri_escape_latin) { char *str1 = "/test/path/öäütestß/"; char *str_enc_expected = "/test/path/%C3%B6%C3%A4%C3%BCtest%C3%9F/"; @@ -67,22 +67,22 @@ char str_enc[512]; - UCX_TEST_BEGIN; - - // test 1 - char *test = util_uri_escape(str_enc, str1); - UCX_TEST_ASSERT(test, "util_uri_escape returned NULL"); - UCX_TEST_ASSERT(!strcasecmp(test, str_enc_expected), "unexpected result"); + CX_TEST_DO { - // test 2 - test = util_uri_escape(str_enc, str2); - UCX_TEST_ASSERT(test, "(2) util_uri_escape returned NULL"); - UCX_TEST_ASSERT(!strcasecmp(test, str2_enc_expected), "(2) unexpected result"); + // test 1 + char *test = util_uri_escape(str_enc, str1); + CX_TEST_ASSERT(test); + CX_TEST_ASSERT(!strcasecmp(test, str_enc_expected)); + + // test 2 + test = util_uri_escape(str_enc, str2); + CX_TEST_ASSERT(test); + CX_TEST_ASSERT(!strcasecmp(test, str2_enc_expected)); - UCX_TEST_END; + } } -UCX_TEST(test_util_uri_escape_kanji) { +CX_TEST(test_util_uri_escape_kanji) { char *str1 = "æ¼¢å—"; char *str1_enc_expected = "%E6%BC%A2%E5%AD%97"; @@ -91,18 +91,18 @@ char str_enc[512]; - UCX_TEST_BEGIN; - - // test 1 - char *test = util_uri_escape(str_enc, str1); - UCX_TEST_ASSERT(test, "util_uri_escape returned NULL"); - UCX_TEST_ASSERT(!strcasecmp(test, str1_enc_expected), "unexpected result"); + CX_TEST_DO { - // test 2 - test = util_uri_escape(str_enc, str2); - UCX_TEST_ASSERT(test, "(2) util_uri_escape returned NULL"); - UCX_TEST_ASSERT(!strcasecmp(test, str2_enc_expected), "(2) unexpected result"); + // test 1 + char *test = util_uri_escape(str_enc, str1); + CX_TEST_ASSERT(test); + CX_TEST_ASSERT(!strcasecmp(test, str1_enc_expected)); + + // test 2 + test = util_uri_escape(str_enc, str2); + CX_TEST_ASSERT(test); + CX_TEST_ASSERT(!strcasecmp(test, str2_enc_expected)); - UCX_TEST_END; + } }
--- a/src/server/test/uri.h Sat Nov 22 12:49:20 2025 +0100 +++ b/src/server/test/uri.h Sat Nov 22 14:27:01 2025 +0100 @@ -38,10 +38,10 @@ extern "C" { #endif -UCX_TEST(test_util_uri_escape_alphanum); -UCX_TEST(test_util_uri_escape_space); -UCX_TEST(test_util_uri_escape_latin); -UCX_TEST(test_util_uri_escape_kanji); +CX_TEST(test_util_uri_escape_alphanum); +CX_TEST(test_util_uri_escape_space); +CX_TEST(test_util_uri_escape_latin); +CX_TEST(test_util_uri_escape_kanji); #ifdef __cplusplus }
--- a/src/server/test/vfs.c Sat Nov 22 12:49:20 2025 +0100 +++ b/src/server/test/vfs.c Sat Nov 22 14:27:01 2025 +0100 @@ -364,190 +364,190 @@ // /* ------------------------------------------------------------------------- */ -UCX_TEST(test_vfs_open) { +CX_TEST(test_vfs_open) { Session *sn = testutil_session(); Request *rq = testutil_request(sn->pool, "PUT", "/"); rq->vfs = testvfs_create(sn); VFSContext *vfs = vfs_request_context(sn, rq); - UCX_TEST_BEGIN; - - UCX_TEST_ASSERT(vfs, "vfs is NULL"); + CX_TEST_DO { - SYS_FILE f1 = vfs_open(vfs, "/file1", O_CREAT); - UCX_TEST_ASSERT(f1, "f1 not opened"); + CX_TEST_ASSERT(vfs); + + SYS_FILE f1 = vfs_open(vfs, "/file1", O_CREAT); + CX_TEST_ASSERT(f1); + + SYS_FILE f2 = vfs_open(vfs, "/file1", 0); + CX_TEST_ASSERT(f2); - SYS_FILE f2 = vfs_open(vfs, "/file1", 0); - UCX_TEST_ASSERT(f2, "f2 not opened"); - - UCX_TEST_END; + } testutil_destroy_session(sn); } -UCX_TEST(test_vfs_mkdir) { +CX_TEST(test_vfs_mkdir) { Session *sn = testutil_session(); Request *rq = testutil_request(sn->pool, "PUT", "/"); rq->vfs = testvfs_create(sn); VFSContext *vfs = vfs_request_context(sn, rq); - UCX_TEST_BEGIN; - - int err = vfs_mkdir(vfs, "/dir"); - UCX_TEST_ASSERT(err == 0, "error not 0"); + CX_TEST_DO { - SYS_FILE fd = vfs_open(vfs, "/dir", 0); - UCX_TEST_ASSERT(fd, "no fd"); + int err = vfs_mkdir(vfs, "/dir"); + CX_TEST_ASSERT(err == 0); + + SYS_FILE fd = vfs_open(vfs, "/dir", 0); + CX_TEST_ASSERT(fd); - UCX_TEST_END; + } testutil_destroy_session(sn); } -UCX_TEST(test_vfs_opendir) { +CX_TEST(test_vfs_opendir) { Session *sn = testutil_session(); Request *rq = testutil_request(sn->pool, "PUT", "/"); rq->vfs = testvfs_create(sn); VFSContext *vfs = vfs_request_context(sn, rq); - UCX_TEST_BEGIN; - - int err = vfs_mkdir(vfs, "/dir"); - UCX_TEST_ASSERT(err == 0, "error not 0"); + CX_TEST_DO { - VFSDir *dir = vfs_opendir(vfs, "/dir"); - UCX_TEST_ASSERT(dir, "no dir"); + int err = vfs_mkdir(vfs, "/dir"); + CX_TEST_ASSERT(err == 0); + + VFSDir *dir = vfs_opendir(vfs, "/dir"); + CX_TEST_ASSERT(dir); - UCX_TEST_END; + } testutil_destroy_session(sn); } -UCX_TEST(test_vfs_readdir) { +CX_TEST(test_vfs_readdir) { Session *sn = testutil_session(); Request *rq = testutil_request(sn->pool, "PUT", "/"); rq->vfs = testvfs_create(sn); VFSContext *vfs = vfs_request_context(sn, rq); - UCX_TEST_BEGIN; - - int err = vfs_mkdir(vfs, "/dir"); - UCX_TEST_ASSERT(err == 0, "error not 0"); - - // add some test file to /dir - UCX_TEST_ASSERT(vfs_open(vfs, "/dir/file1", O_CREAT), "creation of file1 failed"); - UCX_TEST_ASSERT(vfs_open(vfs, "/dir/file2", O_CREAT), "creation of file2 failed"); - UCX_TEST_ASSERT(vfs_open(vfs, "/dir/file3", O_CREAT), "creation of file3 failed"); - UCX_TEST_ASSERT(vfs_open(vfs, "/dir/file4", O_CREAT), "creation of file4 failed"); - - VFSDir *dir = vfs_opendir(vfs, "/dir"); - UCX_TEST_ASSERT(dir, "dir not opened"); + CX_TEST_DO { - CxMap *files = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 8); - - VFSEntry entry; - while(vfs_readdir(dir, &entry)) { - cxMapPut(files, cx_hash_key_str(entry.name), dir); - } + int err = vfs_mkdir(vfs, "/dir"); + CX_TEST_ASSERT(err == 0); + + // add some test file to /dir + CX_TEST_ASSERT(vfs_open(vfs, "/dir/file1", O_CREAT)); + CX_TEST_ASSERT(vfs_open(vfs, "/dir/file2", O_CREAT)); + CX_TEST_ASSERT(vfs_open(vfs, "/dir/file3", O_CREAT)); + CX_TEST_ASSERT(vfs_open(vfs, "/dir/file4", O_CREAT)); + + VFSDir *dir = vfs_opendir(vfs, "/dir"); + CX_TEST_ASSERT(dir); + + CxMap *files = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 8); + + VFSEntry entry; + while(vfs_readdir(dir, &entry)) { + cxMapPut(files, cx_hash_key_str(entry.name), dir); + } + + CX_TEST_ASSERT(cxMapSize(files)== 4); + CX_TEST_ASSERT(cxMapGet(files, cx_hash_key_str("file1"))); + CX_TEST_ASSERT(cxMapGet(files, cx_hash_key_str("file2"))); + CX_TEST_ASSERT(cxMapGet(files, cx_hash_key_str("file3"))); + CX_TEST_ASSERT(cxMapGet(files, cx_hash_key_str("file4"))); + + cxMapFree(files); - UCX_TEST_ASSERT(cxMapSize(files)== 4, "wrong files count"); - UCX_TEST_ASSERT(cxMapGet(files, cx_hash_key_str("file1")), "file1 missing"); - UCX_TEST_ASSERT(cxMapGet(files, cx_hash_key_str("file2")), "file2 missing"); - UCX_TEST_ASSERT(cxMapGet(files, cx_hash_key_str("file3")), "file3 missing"); - UCX_TEST_ASSERT(cxMapGet(files, cx_hash_key_str("file4")), "file4 missing"); - - cxMapFree(files); - - UCX_TEST_END; + } testutil_destroy_session(sn); } -UCX_TEST(test_vfs_unlink) { +CX_TEST(test_vfs_unlink) { Session *sn = testutil_session(); Request *rq = testutil_request(sn->pool, "PUT", "/"); rq->vfs = testvfs_create(sn); VFSContext *vfs = vfs_request_context(sn, rq); - UCX_TEST_BEGIN; - // prepare test - int err; - err = vfs_mkdir(vfs, "/dir1"); - UCX_TEST_ASSERT(err == 0, "mkdir 1: error not 0"); - err = vfs_mkdir(vfs, "/dir2"); - UCX_TEST_ASSERT(err == 0, "mkdir 1: error not 0"); - - SYS_FILE f1 = vfs_open(vfs, "/file1", O_CREAT); - UCX_TEST_ASSERT(f1, "f1 not opened"); - - SYS_FILE f2 = vfs_open(vfs, "/file2", O_CREAT); - UCX_TEST_ASSERT(f1, "f2 not opened"); - - SYS_FILE f3 = vfs_open(vfs, "/dir1/file3", O_CREAT); - UCX_TEST_ASSERT(f1, "f3 not opened"); + CX_TEST_DO { + // prepare test + int err; + err = vfs_mkdir(vfs, "/dir1"); + CX_TEST_ASSERT(err == 0); + err = vfs_mkdir(vfs, "/dir2"); + CX_TEST_ASSERT(err == 0); + + SYS_FILE f1 = vfs_open(vfs, "/file1", O_CREAT); + CX_TEST_ASSERT(f1); + + SYS_FILE f2 = vfs_open(vfs, "/file2", O_CREAT); + CX_TEST_ASSERT(f1); + + SYS_FILE f3 = vfs_open(vfs, "/dir1/file3", O_CREAT); + CX_TEST_ASSERT(f1); + + // test unlink + err = vfs_unlink(vfs, "/file1"); + CX_TEST_ASSERT(err == 0); + err = vfs_unlink(vfs, "/dir1/file3"); + CX_TEST_ASSERT(err == 0); + + err = vfs_unlink(vfs, "/filex"); + CX_TEST_ASSERT(err != 0); + + // check if files were removed + SYS_FILE o1 = vfs_open(vfs, "/file1", O_RDONLY); + CX_TEST_ASSERT(o1 == NULL); + SYS_FILE o3 = vfs_open(vfs, "/dir1/file3", O_RDONLY); + CX_TEST_ASSERT(o1 == NULL); + + // file2 should still be there + SYS_FILE o2 = vfs_open(vfs, "/file2", O_RDONLY); + CX_TEST_ASSERT(o2); + + // check if dir unlink fails + err = vfs_unlink(vfs, "/dir1"); + CX_TEST_ASSERT(err != 0); - // test unlink - err = vfs_unlink(vfs, "/file1"); - UCX_TEST_ASSERT(err == 0, "unlink /file1 failed"); - err = vfs_unlink(vfs, "/dir1/file3"); - UCX_TEST_ASSERT(err == 0, "unlink /dir1/file3 failed"); - - err = vfs_unlink(vfs, "/filex"); - UCX_TEST_ASSERT(err != 0, "unlink /filex should fail"); - - // check if files were removed - SYS_FILE o1 = vfs_open(vfs, "/file1", O_RDONLY); - UCX_TEST_ASSERT(o1 == NULL, "/file1 not deleted"); - SYS_FILE o3 = vfs_open(vfs, "/dir1/file3", O_RDONLY); - UCX_TEST_ASSERT(o1 == NULL, "/dir1/file3 not deleted"); - - // file2 should still be there - SYS_FILE o2 = vfs_open(vfs, "/file2", O_RDONLY); - UCX_TEST_ASSERT(o2, "/file2 deleted"); - - // check if dir unlink fails - err = vfs_unlink(vfs, "/dir1"); - UCX_TEST_ASSERT(err != 0, "unlink dir1 should fail"); - - UCX_TEST_END; + } testutil_destroy_session(sn); } -UCX_TEST(test_vfs_rmdir) { +CX_TEST(test_vfs_rmdir) { Session *sn = testutil_session(); Request *rq = testutil_request(sn->pool, "PUT", "/"); rq->vfs = testvfs_create(sn); VFSContext *vfs = vfs_request_context(sn, rq); - UCX_TEST_BEGIN; - // prepare test - int err; - err = vfs_mkdir(vfs, "/dir1"); - UCX_TEST_ASSERT(err == 0, "mkdir 1: error not 0"); - err = vfs_mkdir(vfs, "/dir2"); - UCX_TEST_ASSERT(err == 0, "mkdir 1: error not 0"); - - SYS_FILE f1 = vfs_open(vfs, "/dir1/file1", O_CREAT); - UCX_TEST_ASSERT(f1, "f1 not opened"); + CX_TEST_DO { + // prepare test + int err; + err = vfs_mkdir(vfs, "/dir1"); + CX_TEST_ASSERT(err == 0); + err = vfs_mkdir(vfs, "/dir2"); + CX_TEST_ASSERT(err == 0); + + SYS_FILE f1 = vfs_open(vfs, "/dir1/file1", O_CREAT); + CX_TEST_ASSERT(f1); + + err = vfs_rmdir(vfs, "/dir1"); + CX_TEST_ASSERT(err != 0); + err = vfs_rmdir(vfs, "/dir2"); + CX_TEST_ASSERT(err == 0); + + err = vfs_unlink(vfs, "/dir1/file1"); + CX_TEST_ASSERT(err == 0); + err = vfs_rmdir(vfs, "/dir1"); + CX_TEST_ASSERT(err == 0); - err = vfs_rmdir(vfs, "/dir1"); - UCX_TEST_ASSERT(err != 0, "rmdir /dir1 should fail"); - err = vfs_rmdir(vfs, "/dir2"); - UCX_TEST_ASSERT(err == 0, "rmdir /dir2 failed"); - - err = vfs_unlink(vfs, "/dir1/file1"); - UCX_TEST_ASSERT(err == 0, "unlink failed"); - err = vfs_rmdir(vfs, "/dir1"); - UCX_TEST_ASSERT(err == 0, "rmdir /dir1 (2) failed"); - - UCX_TEST_END; + } testutil_destroy_session(sn); }
--- a/src/server/test/vfs.h Sat Nov 22 12:49:20 2025 +0100 +++ b/src/server/test/vfs.h Sat Nov 22 14:27:01 2025 +0100 @@ -40,12 +40,12 @@ VFS* testvfs_create(Session *sn); -UCX_TEST(test_vfs_open); -UCX_TEST(test_vfs_mkdir); -UCX_TEST(test_vfs_opendir); -UCX_TEST(test_vfs_readdir); -UCX_TEST(test_vfs_unlink); -UCX_TEST(test_vfs_rmdir); +CX_TEST(test_vfs_open); +CX_TEST(test_vfs_mkdir); +CX_TEST(test_vfs_opendir); +CX_TEST(test_vfs_readdir); +CX_TEST(test_vfs_unlink); +CX_TEST(test_vfs_rmdir); #ifdef __cplusplus }
--- a/src/server/test/webdav.c Sat Nov 22 12:49:20 2025 +0100 +++ b/src/server/test/webdav.c Sat Nov 22 14:27:01 2025 +0100 @@ -329,10 +329,10 @@ } -UCX_TEST(test_webdav_plist_add) { +CX_TEST(test_webdav_plist_add) { Session *sn = testutil_session(); - UCX_TEST_BEGIN; + CX_TEST_DO { WebdavPList *begin = NULL; WebdavPList *end = NULL; @@ -345,748 +345,706 @@ r = webdav_plist_add(sn->pool, &begin, &end, &p1); - UCX_TEST_ASSERT(r == 0, "add 1 failed"); - UCX_TEST_ASSERT(begin && end, "ptrs are NULL"); - UCX_TEST_ASSERT(begin == end, "begin != end"); - UCX_TEST_ASSERT(begin->prev == NULL, "begin->prev not NULL"); - UCX_TEST_ASSERT(begin->next == NULL, "begin->next not NULL"); + CX_TEST_ASSERT(r == 0); + CX_TEST_ASSERT(begin && end); + CX_TEST_ASSERT(begin == end); + CX_TEST_ASSERT(begin->prev == NULL); + CX_TEST_ASSERT(begin->next == NULL); r = webdav_plist_add(sn->pool, &begin, &end, &p2); - UCX_TEST_ASSERT(r == 0, "add 2 failed"); - UCX_TEST_ASSERT(begin && end, "add2: ptrs are NULL"); - UCX_TEST_ASSERT(begin->next, "begin->next is NULL"); - UCX_TEST_ASSERT(begin->next == end, "begin->next != end"); - UCX_TEST_ASSERT(end->prev = begin, "end->prev != begin"); - UCX_TEST_ASSERT(begin->prev == NULL, "add2: begin->prev not NULL"); - UCX_TEST_ASSERT(end->next == NULL, "add2: end->next not NULL"); + CX_TEST_ASSERT(r == 0); + CX_TEST_ASSERT(begin && end); + CX_TEST_ASSERT(begin->next); + CX_TEST_ASSERT(begin->next == end); + CX_TEST_ASSERT(end->prev = begin); + CX_TEST_ASSERT(begin->prev == NULL); + CX_TEST_ASSERT(end->next == NULL); r = webdav_plist_add(sn->pool, &begin, &end, &p3); - UCX_TEST_ASSERT(r == 0, "add 3 failed"); - UCX_TEST_ASSERT(begin && end, "add3: ptrs are NULL"); - UCX_TEST_ASSERT(begin->next == end->prev, "begin->next != end->prev"); + CX_TEST_ASSERT(r == 0); + CX_TEST_ASSERT(begin && end); + CX_TEST_ASSERT(begin->next == end->prev); - UCX_TEST_END; + } testutil_destroy_session(sn); } -UCX_TEST(test_webdav_plist_size) { +CX_TEST(test_webdav_plist_size) { Session *sn = testutil_session(); - UCX_TEST_BEGIN; - - WebdavPList *begin = NULL; - WebdavPList *end = NULL; + CX_TEST_DO { - WebdavProperty p1, p2, p3; - ZERO(&p1, sizeof(WebdavProperty)); - ZERO(&p2, sizeof(WebdavProperty)); - ZERO(&p3, sizeof(WebdavProperty)); - int r; + WebdavPList *begin = NULL; + WebdavPList *end = NULL; + + WebdavProperty p1, p2, p3; + ZERO(&p1, sizeof(WebdavProperty)); + ZERO(&p2, sizeof(WebdavProperty)); + ZERO(&p3, sizeof(WebdavProperty)); + int r; + + CX_TEST_ASSERT(webdav_plist_size(begin) == 0); + r = webdav_plist_add(sn->pool, &begin, &end, &p1); + CX_TEST_ASSERT(webdav_plist_size(begin) == 1); + r = webdav_plist_add(sn->pool, &begin, &end, &p2); + CX_TEST_ASSERT(webdav_plist_size(begin) == 2); + r = webdav_plist_add(sn->pool, &begin, &end, &p3); + CX_TEST_ASSERT(webdav_plist_size(begin) == 3); - UCX_TEST_ASSERT(webdav_plist_size(begin) == 0, "size != 0"); - r = webdav_plist_add(sn->pool, &begin, &end, &p1); - UCX_TEST_ASSERT(webdav_plist_size(begin) == 1, "size != 1"); - r = webdav_plist_add(sn->pool, &begin, &end, &p2); - UCX_TEST_ASSERT(webdav_plist_size(begin) == 2, "size != 2"); - r = webdav_plist_add(sn->pool, &begin, &end, &p3); - UCX_TEST_ASSERT(webdav_plist_size(begin) == 3, "size != 3"); - - UCX_TEST_END; + } testutil_destroy_session(sn); } -UCX_TEST(test_propfind_parse) { +CX_TEST(test_propfind_parse) { Session *sn = testutil_session(); Request *rq = testutil_request(sn->pool, "PROPFIND", "/"); - UCX_TEST_BEGIN - - int error = 0; - - // - // ----------------- TEST_PROPFIND1 ----------------- - // test basic propfind request - WebdavPropfindRequest *p1 = propfind_parse( - sn, - rq, - TEST_PROPFIND1, - strlen(TEST_PROPFIND1), - &error); - - UCX_TEST_ASSERT(p1, "p1 is NULL"); - UCX_TEST_ASSERT(p1->properties, "p1: no props"); - UCX_TEST_ASSERT(!p1->allprop, "p1: allprop is TRUE"); - UCX_TEST_ASSERT(!p1->propname, "p1: propname is TRUE"); - UCX_TEST_ASSERT(p1->propcount == 6, "p1: wrong propcount"); - - // property 1: DAV:displayname - WebdavPList *elm = p1->properties; - UCX_TEST_ASSERT( - !strcmp(elm->property->name, "displayname"), - "p1: property 1 has wrong name"); - UCX_TEST_ASSERT( - !strcmp((char*)elm->property->namespace->href, "DAV:"), - "p1: property 1 has wrong namespace"); - - // property 2: DAV:getcontentlength - elm = elm->next; - UCX_TEST_ASSERT(elm, "p1: property 2 missing"); - UCX_TEST_ASSERT( - !strcmp(elm->property->name, "getcontentlength"), - "p1: property 2 has wrong name"); - UCX_TEST_ASSERT( - !strcmp((char*)elm->property->namespace->href, "DAV:"), - "p1: property 2 has wrong namespace"); - - elm = elm->next; - UCX_TEST_ASSERT(elm, "p1: property 3 missing"); - elm = elm->next; - UCX_TEST_ASSERT(elm, "p1: property 4 missing"); - elm = elm->next; - UCX_TEST_ASSERT(elm, "p1: property 5 missing"); - - // property 6: DAV:getetag - elm = elm->next; - UCX_TEST_ASSERT(elm, "p1: property 6 missing"); - UCX_TEST_ASSERT( - !strcmp(elm->property->name, "getetag"), - "p1: property 6 has wrong name"); - UCX_TEST_ASSERT( - !strcmp((char*)elm->property->namespace->href, "DAV:"), - "p1: property 6 has wrong namespace"); - UCX_TEST_ASSERT(!elm->next, "p1: should not have property 7"); - - // - // ----------------- TEST_PROPFIND2 ----------------- - // test with multiple namespaces - WebdavPropfindRequest *p2 = propfind_parse( - sn, - rq, - TEST_PROPFIND2, - strlen(TEST_PROPFIND2), - &error); - - UCX_TEST_ASSERT(p2, "p2 is NULL"); - UCX_TEST_ASSERT(p2->properties, "p2: no props"); - UCX_TEST_ASSERT(!p2->allprop, "p2: allprop is TRUE"); - UCX_TEST_ASSERT(!p2->propname, "p2: propname is TRUE"); - - // property 1: DAV:resourcetype - elm = p2->properties; - UCX_TEST_ASSERT( - !strcmp(elm->property->name, "resourcetype"), - "p2: property 1 has wrong name"); - UCX_TEST_ASSERT( - !strcmp((char*)elm->property->namespace->href, "DAV:"), - "p2: property 1 has wrong namespace"); - - // property 2: X:testprop - elm = elm->next; - UCX_TEST_ASSERT(elm, "p2: property 2 missing"); - UCX_TEST_ASSERT( - !strcmp(elm->property->name, "testprop"), - "p2: property 2 has wrong name"); - UCX_TEST_ASSERT( - !strcmp((char*)elm->property->namespace->href, "http://example.com/"), - "p2: property 2 has wrong namespace"); + CX_TEST_DO { - // property 3: X:name - elm = elm->next; - UCX_TEST_ASSERT(elm, "p2: property 3 missing"); - UCX_TEST_ASSERT( - !strcmp(elm->property->name, "name"), - "p2: property 3 has wrong name"); - UCX_TEST_ASSERT( - !strcmp((char*)elm->property->namespace->href, "http://example.com/"), - "p2: property 3 has wrong namespace"); - - // property 4: Z:testprop - elm = elm->next; - UCX_TEST_ASSERT(elm, "p2: property 4 missing"); - UCX_TEST_ASSERT( - !strcmp(elm->property->name, "testprop"), - "p2: property 4 has wrong name"); - UCX_TEST_ASSERT( - !strcmp((char*)elm->property->namespace->href, "testns"), - "p2: property 4 has wrong namespace"); - - - // - // ----------------- TEST_PROPFIND3 ----------------- - // test allprop - WebdavPropfindRequest *p3 = propfind_parse(sn, rq, TEST_PROPFIND3, strlen(TEST_PROPFIND3), &error); - - UCX_TEST_ASSERT(p3, "p3 is NULL"); - UCX_TEST_ASSERT(!p3->properties, "p2: has props"); - UCX_TEST_ASSERT(p3->allprop, "p2: allprop is FALSE"); - UCX_TEST_ASSERT(!p3->propname, "p2: propname is TRUE"); - UCX_TEST_ASSERT(p3->propcount == 0, "p2: wrong propcount"); - - - // - // ----------------- TEST_PROPFIND4 ----------------- - // test propname - WebdavPropfindRequest *p4 = propfind_parse(sn, rq, TEST_PROPFIND4, strlen(TEST_PROPFIND4), &error); - - UCX_TEST_ASSERT(p4, "p4 is NULL"); - UCX_TEST_ASSERT(!p4->properties, "p2: has props"); - UCX_TEST_ASSERT(!p4->allprop, "p2: allprop is TRUE"); - UCX_TEST_ASSERT(p4->propname, "p2: propname is FALSE"); - + int error = 0; + + // + // ----------------- TEST_PROPFIND1 ----------------- + // test basic propfind request + WebdavPropfindRequest *p1 = propfind_parse( + sn, + rq, + TEST_PROPFIND1, + strlen(TEST_PROPFIND1), + &error); + + CX_TEST_ASSERT(p1); + CX_TEST_ASSERT(p1->properties); + CX_TEST_ASSERT(!p1->allprop); + CX_TEST_ASSERT(!p1->propname); + CX_TEST_ASSERT(p1->propcount == 6); + + // property 1: DAV:displayname + WebdavPList *elm = p1->properties; + CX_TEST_ASSERT( + !strcmp(elm->property->name, "displayname")); + CX_TEST_ASSERT( + !strcmp((char*)elm->property->namespace->href, "DAV:")); + + // property 2: DAV:getcontentlength + elm = elm->next; + CX_TEST_ASSERT(elm); + CX_TEST_ASSERT( + !strcmp(elm->property->name, "getcontentlength")); + CX_TEST_ASSERT( + !strcmp((char*)elm->property->namespace->href, "DAV:")); + + elm = elm->next; + CX_TEST_ASSERT(elm); + elm = elm->next; + CX_TEST_ASSERT(elm); + elm = elm->next; + CX_TEST_ASSERT(elm); + + // property 6: DAV:getetag + elm = elm->next; + CX_TEST_ASSERT(elm); + CX_TEST_ASSERT( + !strcmp(elm->property->name, "getetag")); + CX_TEST_ASSERT( + !strcmp((char*)elm->property->namespace->href, "DAV:")); + CX_TEST_ASSERT(!elm->next); + + // + // ----------------- TEST_PROPFIND2 ----------------- + // test with multiple namespaces + WebdavPropfindRequest *p2 = propfind_parse( + sn, + rq, + TEST_PROPFIND2, + strlen(TEST_PROPFIND2), + &error); + + CX_TEST_ASSERT(p2); + CX_TEST_ASSERT(p2->properties); + CX_TEST_ASSERT(!p2->allprop); + CX_TEST_ASSERT(!p2->propname); + + // property 1: DAV:resourcetype + elm = p2->properties; + CX_TEST_ASSERT( + !strcmp(elm->property->name, "resourcetype")); + CX_TEST_ASSERT( + !strcmp((char*)elm->property->namespace->href, "DAV:")); + + // property 2: X:testprop + elm = elm->next; + CX_TEST_ASSERT(elm); + CX_TEST_ASSERT( + !strcmp(elm->property->name, "testprop")); + CX_TEST_ASSERT( + !strcmp((char*)elm->property->namespace->href, "http://example.com/")); + + // property 3: X:name + elm = elm->next; + CX_TEST_ASSERT(elm); + CX_TEST_ASSERT( + !strcmp(elm->property->name, "name")); + CX_TEST_ASSERT( + !strcmp((char*)elm->property->namespace->href, "http://example.com/")); + + // property 4: Z:testprop + elm = elm->next; + CX_TEST_ASSERT(elm); + CX_TEST_ASSERT( + !strcmp(elm->property->name, "testprop")); + CX_TEST_ASSERT( + !strcmp((char*)elm->property->namespace->href, "testns")); + + + // + // ----------------- TEST_PROPFIND3 ----------------- + // test allprop + WebdavPropfindRequest *p3 = propfind_parse(sn, rq, TEST_PROPFIND3, strlen(TEST_PROPFIND3), &error); + + CX_TEST_ASSERT(p3); + CX_TEST_ASSERT(!p3->properties); + CX_TEST_ASSERT(p3->allprop); + CX_TEST_ASSERT(!p3->propname); + CX_TEST_ASSERT(p3->propcount == 0); + + + // + // ----------------- TEST_PROPFIND4 ----------------- + // test propname + WebdavPropfindRequest *p4 = propfind_parse(sn, rq, TEST_PROPFIND4, strlen(TEST_PROPFIND4), &error); + + CX_TEST_ASSERT(p4); + CX_TEST_ASSERT(!p4->properties); + CX_TEST_ASSERT(!p4->allprop); + CX_TEST_ASSERT(p4->propname); + + + // + // ----------------- TEST_PROPFIND5 ----------------- + // test duplicate check + WebdavPropfindRequest *p5 = propfind_parse(sn, rq, TEST_PROPFIND5, strlen(TEST_PROPFIND5), &error); + + CX_TEST_ASSERT(p5); + CX_TEST_ASSERT(p5->properties); + CX_TEST_ASSERT(!p5->allprop); + CX_TEST_ASSERT(!p5->propname); + CX_TEST_ASSERT(p5->propcount == 4); + + // property 1: DAV:displayname + elm = p5->properties; + CX_TEST_ASSERT(elm); + CX_TEST_ASSERT( + !strcmp(elm->property->name, "displayname")); + CX_TEST_ASSERT( + !strcmp((char*)elm->property->namespace->href, "DAV:")); + + elm = elm->next; + CX_TEST_ASSERT(elm); + elm = elm->next; + CX_TEST_ASSERT(elm); + + // property 4: DAV:resourcetype + elm = elm->next; + CX_TEST_ASSERT(elm); + CX_TEST_ASSERT( + !strcmp(elm->property->name, "resourcetype")); + CX_TEST_ASSERT( + !strcmp((char*)elm->property->namespace->href, "DAV:")); + + + // + // ----------------- TEST_PROPFIND6 ----------------- + // test prop/allprop mix + WebdavPropfindRequest *p6 = propfind_parse(sn, rq, TEST_PROPFIND6, strlen(TEST_PROPFIND6), &error); + + CX_TEST_ASSERT(p6); + CX_TEST_ASSERT(!p6->properties); + CX_TEST_ASSERT(p6->allprop); + CX_TEST_ASSERT(!p6->propname); + CX_TEST_ASSERT(p6->propcount == 0); - // - // ----------------- TEST_PROPFIND5 ----------------- - // test duplicate check - WebdavPropfindRequest *p5 = propfind_parse(sn, rq, TEST_PROPFIND5, strlen(TEST_PROPFIND5), &error); - - UCX_TEST_ASSERT(p5, "p5 is NULL"); - UCX_TEST_ASSERT(p5->properties, "p5: no props"); - UCX_TEST_ASSERT(!p5->allprop, "p5: allprop is TRUE"); - UCX_TEST_ASSERT(!p5->propname, "p5: propname is TRUE"); - UCX_TEST_ASSERT(p5->propcount == 4, "p5: wrong propcount"); - - // property 1: DAV:displayname - elm = p5->properties; - UCX_TEST_ASSERT(elm, "p5: property 1 missing"); - UCX_TEST_ASSERT( - !strcmp(elm->property->name, "displayname"), - "p5: property 1 has wrong name"); - UCX_TEST_ASSERT( - !strcmp((char*)elm->property->namespace->href, "DAV:"), - "p5: property 1 has wrong namespace"); + } + + pool_destroy(sn->pool); +} + +CX_TEST(test_proppatch_parse) { + Session *sn = testutil_session(); + Request *rq = testutil_request(sn->pool, "PROPPATCH", "/"); - elm = elm->next; - UCX_TEST_ASSERT(elm, "p5: property 2 missing"); - elm = elm->next; - UCX_TEST_ASSERT(elm, "p5: property 3 missing"); + CX_TEST_DO { + int error = 0; + + WebdavProppatchRequest *p1 = proppatch_parse(sn, rq, TEST_PROPPATCH1, strlen(TEST_PROPPATCH1), &error); + + CX_TEST_ASSERT(p1->set); + CX_TEST_ASSERT(!p1->remove); + CX_TEST_ASSERT(p1->setcount == 2); + CX_TEST_ASSERT(p1->set->next); + CX_TEST_ASSERT(!p1->set->next->next); + CX_TEST_ASSERT(p1->set->property); + CX_TEST_ASSERT( + !strcmp(p1->set->property->name, "test")); + + WebdavProppatchRequest *p2 = proppatch_parse(sn, rq, TEST_PROPPATCH2, strlen(TEST_PROPPATCH2), &error); + + CX_TEST_ASSERT(p2->set); + CX_TEST_ASSERT(p2->remove); + CX_TEST_ASSERT(p2->setcount == 4); + CX_TEST_ASSERT(p2->removecount == 1); + + CX_TEST_ASSERT( + !strcmp((char*)p2->set->property->namespace->href, "http://example.com/")); + CX_TEST_ASSERT( + !strcmp(p2->set->property->name, "a")); + WSXmlNode *p2set1 = p2->set->property->value.node; + CX_TEST_ASSERT(p2set1->type == WS_NODE_TEXT); + CX_TEST_ASSERT(p2set1->content); + CX_TEST_ASSERT(!strcmp((char*)p2set1->content, "test")); + + WSXmlNode *p2set3 = p2->set->next->next->property->value.node; + CX_TEST_ASSERT(p2set3); + CX_TEST_ASSERT(p2set3->type == WS_NODE_TEXT); + CX_TEST_ASSERT(p2set3->next); + + CX_TEST_ASSERT(xmlHasProp(p2set3->next, BAD_CAST"test")); + + CX_TEST_ASSERT(xmlHasProp(p2set3->next, BAD_CAST"abc")); + + xmlChar *value1 = xmlGetProp(p2set3->next, BAD_CAST"test"); + CX_TEST_ASSERT(!strcmp((char*) value1, "test1")); + xmlFree(value1); + + xmlChar *value2 = xmlGetProp(p2set3->next, BAD_CAST"abc"); + CX_TEST_ASSERT(!strcmp((char*) value2, "def")); + xmlFree(value2); + + CX_TEST_ASSERT(!strcmp(p2->remove->property->name, "e")); - // property 4: DAV:resourcetype - elm = elm->next; - UCX_TEST_ASSERT(elm, "p5: property 4 missing"); - UCX_TEST_ASSERT( - !strcmp(elm->property->name, "resourcetype"), - "p5: property 4 has wrong name"); - UCX_TEST_ASSERT( - !strcmp((char*)elm->property->namespace->href, "DAV:"), - "p5: property 4 has wrong namespace"); - - - // - // ----------------- TEST_PROPFIND6 ----------------- - // test prop/allprop mix - WebdavPropfindRequest *p6 = propfind_parse(sn, rq, TEST_PROPFIND6, strlen(TEST_PROPFIND6), &error); - - UCX_TEST_ASSERT(p6, "p5 is NULL"); - UCX_TEST_ASSERT(!p6->properties, "p5: has props"); - UCX_TEST_ASSERT(p6->allprop, "p5: allprop is FALSE"); - UCX_TEST_ASSERT(!p6->propname, "p5: propname is TRUE"); - UCX_TEST_ASSERT(p6->propcount == 0, "p5: wrong propcount"); - - UCX_TEST_END + } pool_destroy(sn->pool); } -UCX_TEST(test_proppatch_parse) { - Session *sn = testutil_session(); - Request *rq = testutil_request(sn->pool, "PROPPATCH", "/"); - - UCX_TEST_BEGIN - int error = 0; - - WebdavProppatchRequest *p1 = proppatch_parse(sn, rq, TEST_PROPPATCH1, strlen(TEST_PROPPATCH1), &error); - - UCX_TEST_ASSERT(p1->set, "p1: missing set props"); - UCX_TEST_ASSERT(!p1->remove, "p1: has remove props"); - UCX_TEST_ASSERT(p1->setcount == 2, "p1: wrong setcount"); - UCX_TEST_ASSERT(p1->set->next, "p1: set plist broken"); - UCX_TEST_ASSERT(!p1->set->next->next, "p1: set plist has no end"); - UCX_TEST_ASSERT(p1->set->property, "p1: missing property ptr in plist"); - UCX_TEST_ASSERT( - !strcmp(p1->set->property->name, "test"), - "p1: wrong property 1 name"); - - WebdavProppatchRequest *p2 = proppatch_parse(sn, rq, TEST_PROPPATCH2, strlen(TEST_PROPPATCH2), &error); - - UCX_TEST_ASSERT(p2->set, "p2: missing set props"); - UCX_TEST_ASSERT(p2->remove, "p2: missing remove props"); - UCX_TEST_ASSERT(p2->setcount == 4, "p2: wrong setcount"); - UCX_TEST_ASSERT(p2->removecount == 1, "p2: wrong removecount"); - - UCX_TEST_ASSERT( - !strcmp((char*)p2->set->property->namespace->href, "http://example.com/"), - "p2: set property 1: wrong namespace"); - UCX_TEST_ASSERT( - !strcmp(p2->set->property->name, "a"), - "p2: set property 1: wrong name"); - WSXmlNode *p2set1 = p2->set->property->value.node; - UCX_TEST_ASSERT( - p2set1->type == WS_NODE_TEXT, - "p2: set property 1: wrong type"); - UCX_TEST_ASSERT( - p2set1->content, - "p2: set property 1: no text"); - UCX_TEST_ASSERT( - !strcmp((char*)p2set1->content, "test"), - "p2: set property 1: wrong value"); - - WSXmlNode *p2set3 = p2->set->next->next->property->value.node; - UCX_TEST_ASSERT(p2set3, "p2: set property 3 missing"); - UCX_TEST_ASSERT( - p2set3->type == WS_NODE_TEXT, - "p2: set property 3: wrong type"); - UCX_TEST_ASSERT( - p2set3->next, - "p2: set property 3: missing element X:name"); - - UCX_TEST_ASSERT( - xmlHasProp(p2set3->next, BAD_CAST"test"), - "p2: set property 3: missing attribute 'test'"); - - UCX_TEST_ASSERT( - xmlHasProp(p2set3->next, BAD_CAST"abc"), - "p2: set property 3: missing attribute 'abc"); - - xmlChar *value1 = xmlGetProp(p2set3->next, BAD_CAST"test"); - UCX_TEST_ASSERT( - !strcmp((char*) value1, "test1"), - "p2: set property 3: wrong attribute value 1"); - xmlFree(value1); - - xmlChar *value2 = xmlGetProp(p2set3->next, BAD_CAST"abc"); - UCX_TEST_ASSERT( - !strcmp((char*) value2, "def"), - "p2: set property 3: wrong attribute value 2"); - xmlFree(value2); - - UCX_TEST_ASSERT( - !strcmp(p2->remove->property->name, "e"), - "p2: wrong remove property"); - - UCX_TEST_END - - pool_destroy(sn->pool); -} - -UCX_TEST(test_lock_parse) { +CX_TEST(test_lock_parse) { Session *sn = testutil_session(); Request *rq = testutil_request(sn->pool, "LOCK", "/"); - UCX_TEST_BEGIN - int error = 0; - - WebdavLockRequest *l1 = lock_parse(sn, rq, TEST_LOCK1, strlen(TEST_LOCK1), &error); + CX_TEST_DO { + int error = 0; + + WebdavLockRequest *l1 = lock_parse(sn, rq, TEST_LOCK1, strlen(TEST_LOCK1), &error); + + CX_TEST_ASSERT(l1); + CX_TEST_ASSERT(l1->type == WEBDAV_LOCK_WRITE); + CX_TEST_ASSERT(l1->scope == WEBDAV_LOCK_SHARED); + CX_TEST_ASSERT(l1->owner); + CX_TEST_ASSERT(!strcmp((char*)l1->owner->content, "User")); - UCX_TEST_ASSERT(l1, "l1 is NULL"); - UCX_TEST_ASSERT(l1->type == WEBDAV_LOCK_WRITE, "l1: wrong type"); - UCX_TEST_ASSERT(l1->scope == WEBDAV_LOCK_SHARED, "l1: wrong scope"); - UCX_TEST_ASSERT(l1->owner, "l1: owner is NULL"); - UCX_TEST_ASSERT(!strcmp((char*)l1->owner->content, "User"), "l1: wrong owner"); - - UCX_TEST_END + } pool_destroy(sn->pool); } -UCX_TEST(test_rqbody2buffer) { +CX_TEST(test_rqbody2buffer) { Session *sn; Request *rq; - UCX_TEST_BEGIN; - // - // TEST 1 - sn = testutil_session(); - rq = testutil_request(sn->pool, "PUT", "/"); - testutil_request_body(sn, rq, "Hello World!", 12); - - CxBuffer b1; - rqbody2buffer(sn, rq, &b1); - UCX_TEST_ASSERT(b1.size == 12, "b1: wrong size"); - UCX_TEST_ASSERT(!memcmp(b1.space,"Hello World!",12), "b1: wrong content"); - - cxBufferDestroy(&b1); - testutil_destroy_session(sn); + CX_TEST_DO { + // + // TEST 1 + sn = testutil_session(); + rq = testutil_request(sn->pool, "PUT", "/"); + testutil_request_body(sn, rq, "Hello World!", 12); + + CxBuffer b1; + rqbody2buffer(sn, rq, &b1); + CX_TEST_ASSERT(b1.size == 12); + CX_TEST_ASSERT(!memcmp(b1.space,"Hello World!",12)); + + cxBufferDestroy(&b1); + testutil_destroy_session(sn); + + // + // TEST 2 + size_t len1 = 25000; + unsigned char *body1 = malloc(len1); + for(int i=0;i<len1;i++) { + body1[i] = i; + } + sn = testutil_session(); + rq = testutil_request(sn->pool, "PUT", "/"); + testutil_request_body(sn, rq, (char*)body1, len1); + + CxBuffer b2; + rqbody2buffer(sn, rq, &b2); + CX_TEST_ASSERT(b2.size == len1); + CX_TEST_ASSERT(!memcmp(b2.space, body1, len1)); + + cxBufferDestroy(&b2); + testutil_destroy_session(sn); - // - // TEST 2 - size_t len1 = 25000; - unsigned char *body1 = malloc(len1); - for(int i=0;i<len1;i++) { - body1[i] = i; } - sn = testutil_session(); - rq = testutil_request(sn->pool, "PUT", "/"); - testutil_request_body(sn, rq, (char*)body1, len1); - - CxBuffer b2; - rqbody2buffer(sn, rq, &b2); - UCX_TEST_ASSERT(b2.size == len1, "b2: wrong size"); - UCX_TEST_ASSERT(!memcmp(b2.space, body1, len1), "b2: wrong content"); - - cxBufferDestroy(&b2); - testutil_destroy_session(sn); - - UCX_TEST_END; } -UCX_TEST(test_webdav_plist_iterator) { +CX_TEST(test_webdav_plist_iterator) { Session *sn; Request *rq; WebdavPropfindRequest *propfind; - UCX_TEST_BEGIN; - UCX_TEST_ASSERT(!test_init(&sn, &rq, &propfind, TEST_PROPFIND1), "init failed"); - - WebdavPList *properties = propfind->properties; - size_t count = 0; - - WebdavPListIterator i = webdav_plist_iterator(&properties); - WebdavPList *cur; - while(webdav_plist_iterator_next(&i, &cur)) { - switch(i.index) { - case 0: { - UCX_TEST_ASSERT(!strcmp(cur->property->name, "displayname"), "wrong property 1"); - break; - } - case 1: { - UCX_TEST_ASSERT(!strcmp(cur->property->name, "getcontentlength"), "wrong property 2"); - break; + CX_TEST_DO { + CX_TEST_ASSERT(!test_init(&sn, &rq, &propfind, TEST_PROPFIND1)); + + WebdavPList *properties = propfind->properties; + size_t count = 0; + + WebdavPListIterator i = webdav_plist_iterator(&properties); + WebdavPList *cur; + while(webdav_plist_iterator_next(&i, &cur)) { + switch(i.index) { + case 0: { + CX_TEST_ASSERT(!strcmp(cur->property->name, "displayname")); + break; + } + case 1: { + CX_TEST_ASSERT(!strcmp(cur->property->name, "getcontentlength")); + break; + } + case 2: { + CX_TEST_ASSERT(!strcmp(cur->property->name, "getcontenttype")); + break; + } + case 3: { + CX_TEST_ASSERT(!strcmp(cur->property->name, "getlastmodified")); + break; + } + case 4: { + CX_TEST_ASSERT(!strcmp(cur->property->name, "resourcetype")); + break; + } + case 5: { + CX_TEST_ASSERT(!strcmp(cur->property->name, "getetag")); + break; + } } - case 2: { - UCX_TEST_ASSERT(!strcmp(cur->property->name, "getcontenttype"), "wrong property 3"); - break; - } - case 3: { - UCX_TEST_ASSERT(!strcmp(cur->property->name, "getlastmodified"), "wrong property 4"); - break; - } - case 4: { - UCX_TEST_ASSERT(!strcmp(cur->property->name, "resourcetype"), "wrong property 5"); - break; - } - case 5: { - UCX_TEST_ASSERT(!strcmp(cur->property->name, "getetag"), "wrong property 6"); - break; - } + count++; } - count++; - } - - UCX_TEST_ASSERT(count == propfind->propcount, "wrong count"); + + CX_TEST_ASSERT(count == propfind->propcount); - UCX_TEST_END; + } testutil_destroy_session(sn); } -UCX_TEST(test_webdav_plist_iterator_remove_current) { +CX_TEST(test_webdav_plist_iterator_remove_current) { Session *sn; Request *rq; WebdavPropfindRequest *propfind; - UCX_TEST_BEGIN; - UCX_TEST_ASSERT(!test_init(&sn, &rq, &propfind, TEST_PROPFIND1), "init failed"); - - WebdavPList *properties1 = webdav_plist_clone(sn->pool, propfind->properties); - WebdavPList *properties2 = webdav_plist_clone(sn->pool, propfind->properties); - WebdavPList *properties3 = webdav_plist_clone(sn->pool, propfind->properties); - WebdavPList *properties4 = webdav_plist_clone(sn->pool, propfind->properties); - - WebdavPListIterator i; - WebdavPList *cur; - - // test removal of first element - i = webdav_plist_iterator(&properties1); - while(webdav_plist_iterator_next(&i, &cur)) { - if(i.index == 0) { - webdav_plist_iterator_remove_current(&i); - } - } - - UCX_TEST_ASSERT(!properties1->prev, "test1: prev not cleared"); - UCX_TEST_ASSERT(!strcmp(properties1->property->name, "getcontentlength"), "test1: wrong property"); - UCX_TEST_ASSERT(!strcmp(properties1->next->property->name, "getcontenttype"), "test1: wrong property 2"); - UCX_TEST_ASSERT(properties1->next->prev == properties1, "test1: wrong link"); - - // test removal of second element - i = webdav_plist_iterator(&properties2); - while(webdav_plist_iterator_next(&i, &cur)) { - if(i.index == 1) { - webdav_plist_iterator_remove_current(&i); + CX_TEST_DO { + CX_TEST_ASSERT(!test_init(&sn, &rq, &propfind, TEST_PROPFIND1)); + + WebdavPList *properties1 = webdav_plist_clone(sn->pool, propfind->properties); + WebdavPList *properties2 = webdav_plist_clone(sn->pool, propfind->properties); + WebdavPList *properties3 = webdav_plist_clone(sn->pool, propfind->properties); + WebdavPList *properties4 = webdav_plist_clone(sn->pool, propfind->properties); + + WebdavPListIterator i; + WebdavPList *cur; + + // test removal of first element + i = webdav_plist_iterator(&properties1); + while(webdav_plist_iterator_next(&i, &cur)) { + if(i.index == 0) { + webdav_plist_iterator_remove_current(&i); + } } - } - - UCX_TEST_ASSERT(!strcmp(properties2->next->property->name, "getcontenttype"), "test2: wrong property"); - UCX_TEST_ASSERT(properties2->next->prev == properties2, "test2: wrong link"); - UCX_TEST_ASSERT(webdav_plist_size(properties2) == 5, "test2: wrong size"); - - // remove last element - i = webdav_plist_iterator(&properties3); - while(webdav_plist_iterator_next(&i, &cur)) { - if(i.index == 5) { - webdav_plist_iterator_remove_current(&i); + + CX_TEST_ASSERT(!properties1->prev); + CX_TEST_ASSERT(!strcmp(properties1->property->name, "getcontentlength")); + CX_TEST_ASSERT(!strcmp(properties1->next->property->name, "getcontenttype")); + CX_TEST_ASSERT(properties1->next->prev == properties1); + + // test removal of second element + i = webdav_plist_iterator(&properties2); + while(webdav_plist_iterator_next(&i, &cur)) { + if(i.index == 1) { + webdav_plist_iterator_remove_current(&i); + } } - } - - UCX_TEST_ASSERT(webdav_plist_size(properties3) == 5, "test3: wrong size"); - UCX_TEST_ASSERT(!strcmp(properties3->next->next->next->next->property->name, "resourcetype"), "test2: wrong property"); - - // remove all elements - i = webdav_plist_iterator(&properties4); - while(webdav_plist_iterator_next(&i, &cur)) { - webdav_plist_iterator_remove_current(&i); - switch(i.index) { - case 0: { - UCX_TEST_ASSERT(!strcmp(properties4->property->name, "getcontentlength"), "test4: wrong property 2"); - UCX_TEST_ASSERT(properties4->prev == NULL, "test4: prev not NULL (0)"); - break; - } - case 1: { - UCX_TEST_ASSERT(!strcmp(properties4->property->name, "getcontenttype"), "test4: wrong property 3"); - UCX_TEST_ASSERT(properties4->prev == NULL, "test4: prev not NULL (1)"); - break; - } - case 2: { - UCX_TEST_ASSERT(!strcmp(properties4->property->name, "getlastmodified"), "test4: wrong property 4"); - UCX_TEST_ASSERT(properties4->prev == NULL, "test4: prev not NULL (2)"); - break; - } - case 3: { - UCX_TEST_ASSERT(!strcmp(properties4->property->name, "resourcetype"), "test4: wrong property 5"); - UCX_TEST_ASSERT(properties4->prev == NULL, "test4: prev not NULL (3)"); - break; - } - case 4: { - UCX_TEST_ASSERT(!strcmp(properties4->property->name, "getetag"), "test4: wrong property 6"); - UCX_TEST_ASSERT(properties4->prev == NULL, "test4: prev not NULL (4)"); - break; - } - default: { - UCX_TEST_ASSERT(i.index <= 5, "fail"); + + CX_TEST_ASSERT(!strcmp(properties2->next->property->name, "getcontenttype")); + CX_TEST_ASSERT(properties2->next->prev == properties2); + CX_TEST_ASSERT(webdav_plist_size(properties2) == 5); + + // remove last element + i = webdav_plist_iterator(&properties3); + while(webdav_plist_iterator_next(&i, &cur)) { + if(i.index == 5) { + webdav_plist_iterator_remove_current(&i); } } - } + + CX_TEST_ASSERT(webdav_plist_size(properties3) == 5); + CX_TEST_ASSERT(!strcmp(properties3->next->next->next->next->property->name, "resourcetype")); + + // remove all elements + i = webdav_plist_iterator(&properties4); + while(webdav_plist_iterator_next(&i, &cur)) { + webdav_plist_iterator_remove_current(&i); + switch(i.index) { + case 0: { + CX_TEST_ASSERT(!strcmp(properties4->property->name, "getcontentlength")); + CX_TEST_ASSERT(properties4->prev == NULL); + break; + } + case 1: { + CX_TEST_ASSERT(!strcmp(properties4->property->name, "getcontenttype")); + CX_TEST_ASSERT(properties4->prev == NULL); + break; + } + case 2: { + CX_TEST_ASSERT(!strcmp(properties4->property->name, "getlastmodified")); + CX_TEST_ASSERT(properties4->prev == NULL); + break; + } + case 3: { + CX_TEST_ASSERT(!strcmp(properties4->property->name, "resourcetype")); + CX_TEST_ASSERT(properties4->prev == NULL); + break; + } + case 4: { + CX_TEST_ASSERT(!strcmp(properties4->property->name, "getetag")); + CX_TEST_ASSERT(properties4->prev == NULL); + break; + } + default: { + CX_TEST_ASSERT(i.index <= 5); + } + } + } + + CX_TEST_ASSERT(properties4 == NULL); - UCX_TEST_ASSERT(properties4 == NULL, "test4: list not NULL"); - - UCX_TEST_END; + } testutil_destroy_session(sn); } -UCX_TEST(test_msresponse_addproperty) { +CX_TEST(test_msresponse_addproperty) { Session *sn; Request *rq; - UCX_TEST_BEGIN; - - WebdavOperation *op = test_propfind_op(&sn, &rq, TEST_PROPFIND1); - UCX_TEST_ASSERT(op, "init failed"); - UCX_TEST_ASSERT(op->response, "no response"); - - Multistatus *ms = (Multistatus*)op->response; - MSResponse *r = (MSResponse*)ms->response.addresource((WebdavResponse*)ms, "/"); - - WebdavProperty p1; - WebdavProperty p[16]; - const char *names[] = {"a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9"}; - - WSNamespace ns1; - ZERO(&ns1, sizeof(WSNamespace)); - WSNamespace ns2; - ZERO(&ns2, sizeof(WSNamespace)); - ns1.prefix = (xmlChar*)"x1"; - ns1.href = (xmlChar*)"http://example.com/test/"; - ns2.prefix = (xmlChar*)"x2"; - ns2.href = (xmlChar*)"http://example.com/test/"; - - WebdavProperty dp1; - ZERO(&dp1, sizeof(WebdavProperty)); - dp1.name = "dup"; - dp1.namespace = &ns1; - dp1.value.text.str = "Hello"; - dp1.value.text.length = 5; - dp1.vtype = WS_VALUE_TEXT; - - WebdavProperty dp2; - ZERO(&dp2, sizeof(WebdavProperty)); - dp2.name = "dup"; - dp2.namespace = &ns1; - dp2.value.text.str = "Hello"; - dp2.value.text.length = 5; - dp2.vtype = WS_VALUE_TEXT; - - WebdavProperty dp3; - ZERO(&dp3, sizeof(WebdavProperty)); - dp3.name = "dup"; - dp3.namespace = &ns2; - dp3.value.text.str = "Hello"; - dp3.value.text.length = 5; - dp3.vtype = WS_VALUE_TEXT; - - // init test data - p1.namespace = webdav_dav_namespace(); - p1.lang = NULL; - p1.name = "test1"; - p1.value.data = (WSXmlData){ NULL, NULL, 0}; - p1.vtype = 0; + CX_TEST_DO { - for(int i=0;i<8;i++) { - p[i].namespace = webdav_dav_namespace(); - p[i].name = names[i]; - p[i].lang = NULL; - p[i].value.node = NULL; - p[1].vtype = 0; - } - - UCX_TEST_ASSERT(!r->plist_begin && !r->plist_end, "plist not empty"); - - r->resource.addproperty((WebdavResource*)r, &p1, 200); - UCX_TEST_ASSERT(r->plist_begin, "!plist_begin"); - UCX_TEST_ASSERT(r->plist_begin == r->plist_end, "plist begin != end"); - - r->resource.addproperty((WebdavResource*)r, &p[0], 404); - r->resource.addproperty((WebdavResource*)r, &p[1], 404); - r->resource.addproperty((WebdavResource*)r, &p[2], 403); - r->resource.addproperty((WebdavResource*)r, &p[3], 403); - r->resource.addproperty((WebdavResource*)r, &p[4], 403); - r->resource.addproperty((WebdavResource*)r, &p[5], 403); - r->resource.addproperty((WebdavResource*)r, &p[6], 500); - - UCX_TEST_ASSERT(r->plist_begin == r->plist_end, "plist begin != end"); + WebdavOperation *op = test_propfind_op(&sn, &rq, TEST_PROPFIND1); + CX_TEST_ASSERT(op); + CX_TEST_ASSERT(op->response); + + Multistatus *ms = (Multistatus*)op->response; + MSResponse *r = (MSResponse*)ms->response.addresource((WebdavResponse*)ms, "/"); + + WebdavProperty p1; + WebdavProperty p[16]; + const char *names[] = {"a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9"}; + + WSNamespace ns1; + ZERO(&ns1, sizeof(WSNamespace)); + WSNamespace ns2; + ZERO(&ns2, sizeof(WSNamespace)); + ns1.prefix = (xmlChar*)"x1"; + ns1.href = (xmlChar*)"http://example.com/test/"; + ns2.prefix = (xmlChar*)"x2"; + ns2.href = (xmlChar*)"http://example.com/test/"; + + WebdavProperty dp1; + ZERO(&dp1, sizeof(WebdavProperty)); + dp1.name = "dup"; + dp1.namespace = &ns1; + dp1.value.text.str = "Hello"; + dp1.value.text.length = 5; + dp1.vtype = WS_VALUE_TEXT; + + WebdavProperty dp2; + ZERO(&dp2, sizeof(WebdavProperty)); + dp2.name = "dup"; + dp2.namespace = &ns1; + dp2.value.text.str = "Hello"; + dp2.value.text.length = 5; + dp2.vtype = WS_VALUE_TEXT; + + WebdavProperty dp3; + ZERO(&dp3, sizeof(WebdavProperty)); + dp3.name = "dup"; + dp3.namespace = &ns2; + dp3.value.text.str = "Hello"; + dp3.value.text.length = 5; + dp3.vtype = WS_VALUE_TEXT; + + // init test data + p1.namespace = webdav_dav_namespace(); + p1.lang = NULL; + p1.name = "test1"; + p1.value.data = (WSXmlData){ NULL, NULL, 0}; + p1.vtype = 0; + + for(int i=0;i<8;i++) { + p[i].namespace = webdav_dav_namespace(); + p[i].name = names[i]; + p[i].lang = NULL; + p[i].value.node = NULL; + p[1].vtype = 0; + } + + CX_TEST_ASSERT(!r->plist_begin && !r->plist_end); + + r->resource.addproperty((WebdavResource*)r, &p1, 200); + CX_TEST_ASSERT(r->plist_begin); + CX_TEST_ASSERT(r->plist_begin == r->plist_end); + + r->resource.addproperty((WebdavResource*)r, &p[0], 404); + r->resource.addproperty((WebdavResource*)r, &p[1], 404); + r->resource.addproperty((WebdavResource*)r, &p[2], 403); + r->resource.addproperty((WebdavResource*)r, &p[3], 403); + r->resource.addproperty((WebdavResource*)r, &p[4], 403); + r->resource.addproperty((WebdavResource*)r, &p[5], 403); + r->resource.addproperty((WebdavResource*)r, &p[6], 500); + + CX_TEST_ASSERT(r->plist_begin == r->plist_end); + + CX_TEST_ASSERT(r->errors); + CX_TEST_ASSERT(r->errors->next); + CX_TEST_ASSERT(r->errors->next->next); + CX_TEST_ASSERT(!r->errors->next->next->next); + + CX_TEST_ASSERT(webdav_plist_size(r->errors->begin) == 2); + CX_TEST_ASSERT(webdav_plist_size(r->errors->next->begin) == 4); + CX_TEST_ASSERT(webdav_plist_size(r->errors->next->next->begin) == 1); + + // new resource for prop duplication tests + r = (MSResponse*)ms->response.addresource((WebdavResponse*)ms, "/test"); + CX_TEST_ASSERT(r); + + r->resource.addproperty((WebdavResource*)r, &dp1, 200); + CX_TEST_ASSERT(r->plist_begin); + CX_TEST_ASSERT(!r->plist_begin->next); + + r->resource.addproperty((WebdavResource*)r, &dp2, 200); + CX_TEST_ASSERT(!r->plist_begin->next); + + r->resource.addproperty((WebdavResource*)r, &dp2, 404); + CX_TEST_ASSERT(!r->plist_begin->next); + if(r->errors) { + CX_TEST_ASSERT(webdav_plist_size(r->errors->begin) == 0); + } + + r->resource.addproperty((WebdavResource*)r, &dp3, 200); + CX_TEST_ASSERT(!r->plist_begin->next); - UCX_TEST_ASSERT(r->errors, "no prop errors"); - UCX_TEST_ASSERT(r->errors->next, "no second error code"); - UCX_TEST_ASSERT(r->errors->next->next, "no third error code"); - UCX_TEST_ASSERT(!r->errors->next->next->next, "too many error codes"); - - UCX_TEST_ASSERT(webdav_plist_size(r->errors->begin) == 2, "404 list size != 2"); - UCX_TEST_ASSERT(webdav_plist_size(r->errors->next->begin) == 4, "403 list size != 4"); - UCX_TEST_ASSERT(webdav_plist_size(r->errors->next->next->begin) == 1, "500 list size != 1"); - - // new resource for prop duplication tests - r = (MSResponse*)ms->response.addresource((WebdavResponse*)ms, "/test"); - UCX_TEST_ASSERT(r, "cannot create second response"); - - r->resource.addproperty((WebdavResource*)r, &dp1, 200); - UCX_TEST_ASSERT(r->plist_begin, "adding dp1 failed"); - UCX_TEST_ASSERT(!r->plist_begin->next, "dp1: list size not 1"); - - r->resource.addproperty((WebdavResource*)r, &dp2, 200); - UCX_TEST_ASSERT(!r->plist_begin->next, "dp1: adding dp2 should not work"); - - r->resource.addproperty((WebdavResource*)r, &dp2, 404); - UCX_TEST_ASSERT(!r->plist_begin->next, "dp1: adding dp2 with different status should not work (1)"); - if(r->errors) { - UCX_TEST_ASSERT(webdav_plist_size(r->errors->begin) == 0, "dp1: error list not empty"); } - - r->resource.addproperty((WebdavResource*)r, &dp3, 200); - UCX_TEST_ASSERT(!r->plist_begin->next, "dp1: adding dp3 should not work"); - - UCX_TEST_END; } -UCX_TEST(test_webdav_propfind_init) { +CX_TEST(test_webdav_propfind_init) { reset_backends(); Session *sn; Request *rq; WebdavPropfindRequest *propfind; - UCX_TEST_BEGIN; - UCX_TEST_ASSERT(!test_init(&sn, &rq, &propfind, TEST_PROPFIND1), "init failed"); - - WebdavPropfindRequestList *requests = NULL; - int err = webdav_propfind_init(&backend1, propfind, "/", "/", &requests); - - UCX_TEST_ASSERT(!err, "webdav_propfind_init failed"); - UCX_TEST_ASSERT(requests, "request list is empty"); - UCX_TEST_ASSERT(cx_linked_list_size(requests, offsetof(WebdavPropfindRequestList, next)), "request list has wrong size"); - - WebdavPropfindRequest *p1 = requests->propfind; - WebdavPropfindRequest *p2 = requests->next->propfind; + CX_TEST_DO { + CX_TEST_ASSERT(!test_init(&sn, &rq, &propfind, TEST_PROPFIND1)); + + WebdavPropfindRequestList *requests = NULL; + int err = webdav_propfind_init(&backend1, propfind, "/", "/", &requests); + + CX_TEST_ASSERT(!err); + CX_TEST_ASSERT(requests); + CX_TEST_ASSERT(cx_linked_list_size(requests, offsetof(WebdavPropfindRequestList, next))); + + WebdavPropfindRequest *p1 = requests->propfind; + WebdavPropfindRequest *p2 = requests->next->propfind; + + // backend1 removes the first property from the plist + // backend2 should have one property less + + CX_TEST_ASSERT(p1 && p2); + CX_TEST_ASSERT(p1 != p2); + CX_TEST_ASSERT(p1->properties != p2->properties); + CX_TEST_ASSERT(p1->propcount == p2->propcount + 1); + + CX_TEST_ASSERT(backend1_init_called == 1); + CX_TEST_ASSERT(backend2_init_called == 1); - // backend1 removes the first property from the plist - // backend2 should have one property less - - UCX_TEST_ASSERT(p1 && p2, "missing requests objects"); - UCX_TEST_ASSERT(p1 != p2, "request objects equal"); - UCX_TEST_ASSERT(p1->properties != p2->properties, "plists equal"); - UCX_TEST_ASSERT(p1->propcount == p2->propcount + 1, "first property not removed"); - - UCX_TEST_ASSERT(backend1_init_called == 1, "backend1 init not called"); - UCX_TEST_ASSERT(backend2_init_called == 1, "backend2 init not called"); - - UCX_TEST_END; + } pool_destroy(sn->pool); } -UCX_TEST(test_webdav_op_propfind_begin) { +CX_TEST(test_webdav_op_propfind_begin) { reset_backends(); Session *sn; Request *rq; - UCX_TEST_BEGIN; - WebdavOperation *op = test_propfind_op(&sn, &rq, TEST_PROPFIND1); - UCX_TEST_ASSERT(op, "WebdavOperation not created"); + CX_TEST_DO { + WebdavOperation *op = test_propfind_op(&sn, &rq, TEST_PROPFIND1); + CX_TEST_ASSERT(op); + + int err = webdav_op_propfind_begin(op, "/", NULL, NULL); + CX_TEST_ASSERT(err == 0); + CX_TEST_ASSERT(backend1_propfind_do_count == 1); + CX_TEST_ASSERT(backend2_propfind_do_count == 1); - int err = webdav_op_propfind_begin(op, "/", NULL, NULL); - UCX_TEST_ASSERT(err == 0, "err not 0"); - UCX_TEST_ASSERT(backend1_propfind_do_count == 1, "backend1 propfind_do not called"); - UCX_TEST_ASSERT(backend2_propfind_do_count == 1, "backend2 propfind_do not called"); - - - UCX_TEST_END; + } testutil_destroy_session(sn); } -UCX_TEST(test_webdav_op_propfind_children) { +CX_TEST(test_webdav_op_propfind_children) { reset_backends(); Session *sn; Request *rq; - UCX_TEST_BEGIN; - WebdavOperation *op = test_propfind_op(&sn, &rq, TEST_PROPFIND1); - UCX_TEST_ASSERT(op, "WebdavOperation not created"); - - int err = webdav_op_propfind_begin(op, "/", NULL, NULL); - UCX_TEST_ASSERT(err == 0, "propfind_begin error"); - - // create test vfs with some files (code from test_vfs_readdir) - rq->vfs = testvfs_create(sn); - VFSContext *vfs = vfs_request_context(sn, rq); - UCX_TEST_ASSERT(vfs, "no vfs"); - - err = vfs_mkdir(vfs, "/dir"); - UCX_TEST_ASSERT(err == 0, "error not 0"); + CX_TEST_DO { + WebdavOperation *op = test_propfind_op(&sn, &rq, TEST_PROPFIND1); + CX_TEST_ASSERT(op); + + int err = webdav_op_propfind_begin(op, "/", NULL, NULL); + CX_TEST_ASSERT(err == 0); + + // create test vfs with some files (code from test_vfs_readdir) + rq->vfs = testvfs_create(sn); + VFSContext *vfs = vfs_request_context(sn, rq); + CX_TEST_ASSERT(vfs); + + err = vfs_mkdir(vfs, "/dir"); + CX_TEST_ASSERT(err == 0); + + // add some test file to /dir + CX_TEST_ASSERT(vfs_open(vfs, "/dir/file1", O_CREAT)); + CX_TEST_ASSERT(vfs_open(vfs, "/dir/file2", O_CREAT)); + CX_TEST_ASSERT(vfs_open(vfs, "/dir/file3", O_CREAT)); + CX_TEST_ASSERT(vfs_open(vfs, "/dir/file4", O_CREAT)); + + VFSDir *dir = vfs_opendir(vfs, "/dir"); + CX_TEST_ASSERT(dir); + + CX_TEST_ASSERT(backend1_propfind_do_count == 1); + CX_TEST_ASSERT(backend2_propfind_do_count == 1); + + // propfind for all children + err = webdav_op_propfind_children(op, vfs, "/", "/dir"); + CX_TEST_ASSERT(err == 0); + + // 1 dir + 4 children + CX_TEST_ASSERT(backend1_propfind_do_count == 5); + CX_TEST_ASSERT(backend2_propfind_do_count == 5); - // add some test file to /dir - UCX_TEST_ASSERT(vfs_open(vfs, "/dir/file1", O_CREAT), "creation of file1 failed"); - UCX_TEST_ASSERT(vfs_open(vfs, "/dir/file2", O_CREAT), "creation of file2 failed"); - UCX_TEST_ASSERT(vfs_open(vfs, "/dir/file3", O_CREAT), "creation of file3 failed"); - UCX_TEST_ASSERT(vfs_open(vfs, "/dir/file4", O_CREAT), "creation of file4 failed"); - - VFSDir *dir = vfs_opendir(vfs, "/dir"); - UCX_TEST_ASSERT(dir, "dir not opened"); - - UCX_TEST_ASSERT(backend1_propfind_do_count == 1, "backend1 propfind_do not called"); - UCX_TEST_ASSERT(backend2_propfind_do_count == 1, "backend1 propfind_do not called") - - // propfind for all children - err = webdav_op_propfind_children(op, vfs, "/", "/dir"); - UCX_TEST_ASSERT(err == 0, "webdav_op_propfind_children failed"); - - // 1 dir + 4 children - UCX_TEST_ASSERT(backend1_propfind_do_count == 5, "backend1 propfind_do wrong count"); - UCX_TEST_ASSERT(backend2_propfind_do_count == 5, "backend2 propfind_do wrong count"); - - UCX_TEST_END; + } testutil_destroy_session(sn); } @@ -1125,50 +1083,50 @@ *out_pb = pb; } -UCX_TEST(test_webdav_propfind) { +CX_TEST(test_webdav_propfind) { Session *sn; Request *rq; TestIOStream *st; pblock *pb; - UCX_TEST_BEGIN; - - int ret; - // Test 1 - init_test_webdav_method(&sn, &rq, &st, &pb, "PROPFIND", "/", TEST_PROPFIND1); - - ret = webdav_propfind(pb, sn, rq); - - UCX_TEST_ASSERT(ret == REQ_PROCEED, "webdav_propfind (1) failed"); - - xmlDoc *doc = xmlReadMemory( - st->buf->space, st->buf->size, NULL, NULL, 0); - UCX_TEST_ASSERT(doc, "propfind1: response is not valid xml"); - - //printf("\n\n%.*s\n", (int)st->buf->size, st->buf->space); + CX_TEST_DO { - testutil_destroy_session(sn); - xmlFreeDoc(doc); - testutil_iostream_destroy(st); - - // Test2 - init_test_webdav_method(&sn, &rq, &st, &pb, "PROPFIND", "/", TEST_PROPFIND2); - - ret = webdav_propfind(pb, sn, rq); - - UCX_TEST_ASSERT(ret == REQ_PROCEED, "webdav_propfind (2) failed"); + int ret; + // Test 1 + init_test_webdav_method(&sn, &rq, &st, &pb, "PROPFIND", "/", TEST_PROPFIND1); + + ret = webdav_propfind(pb, sn, rq); + + CX_TEST_ASSERT(ret == REQ_PROCEED); + + xmlDoc *doc = xmlReadMemory( + st->buf->space, st->buf->size, NULL, NULL, 0); + CX_TEST_ASSERT(doc); + + //printf("\n\n%.*s\n", (int)st->buf->size, st->buf->space); + + testutil_destroy_session(sn); + xmlFreeDoc(doc); + testutil_iostream_destroy(st); + + // Test2 + init_test_webdav_method(&sn, &rq, &st, &pb, "PROPFIND", "/", TEST_PROPFIND2); + + ret = webdav_propfind(pb, sn, rq); + + CX_TEST_ASSERT(ret == REQ_PROCEED); + + xmlDoc *doc2 = xmlReadMemory( + st->buf->space, st->buf->size, NULL, NULL, 0); + CX_TEST_ASSERT(doc); + + //printf("\n\n%.*s\n", (int)st->buf->size, st->buf->space); + + testutil_destroy_session(sn); + xmlFreeDoc(doc2); + testutil_iostream_destroy(st); - xmlDoc *doc2 = xmlReadMemory( - st->buf->space, st->buf->size, NULL, NULL, 0); - UCX_TEST_ASSERT(doc, "propfind2: response is not valid xml"); - - //printf("\n\n%.*s\n", (int)st->buf->size, st->buf->space); - - testutil_destroy_session(sn); - xmlFreeDoc(doc2); - testutil_iostream_destroy(st); - - UCX_TEST_END; + } } @@ -1244,7 +1202,7 @@ } -UCX_TEST(test_proppatch_msresponse) { +CX_TEST(test_proppatch_msresponse) { Session *sn; Request *rq; WebdavOperation *op; @@ -1262,36 +1220,36 @@ p[i].vtype = 0; } - UCX_TEST_BEGIN; - - op = test_proppatch_op1(&sn, &rq, TEST_PROPPATCH2); - UCX_TEST_ASSERT(op, "failed to create proppatch operation"); - - ms = (Multistatus*)op->response; - ms->proppatch = TRUE; - res = ms->response.addresource(&ms->response, "/"); - UCX_TEST_ASSERT(res, "cannot create resource 1"); + CX_TEST_DO { - UCX_TEST_ASSERT(!res->addproperty(res, &p[0], 200), "addproperty 1 failed"); - UCX_TEST_ASSERT(!res->addproperty(res, &p[1], 200), "addproperty 2 failed"); - UCX_TEST_ASSERT(!res->addproperty(res, &p[2], 200), "addproperty 3 failed"); - UCX_TEST_ASSERT(!res->addproperty(res, &p[3], 200), "addproperty 4 failed"); - - UCX_TEST_ASSERT(!res->close(res), "close failed"); + op = test_proppatch_op1(&sn, &rq, TEST_PROPPATCH2); + CX_TEST_ASSERT(op); + + ms = (Multistatus*)op->response; + ms->proppatch = TRUE; + res = ms->response.addresource(&ms->response, "/"); + CX_TEST_ASSERT(res); - MSResponse *msres = (MSResponse*)res; - UCX_TEST_ASSERT(!msres->errors, "error list not NULL"); - UCX_TEST_ASSERT(msres->plist_begin, "elm1 missing"); - UCX_TEST_ASSERT(msres->plist_begin->next, "elm2 missing"); - UCX_TEST_ASSERT(msres->plist_begin->next->next, "elm3 missing"); - UCX_TEST_ASSERT(msres->plist_begin->next->next->next, "elm4 missing"); - UCX_TEST_ASSERT(!msres->plist_begin->next->next->next->next, "count != 4"); - - UCX_TEST_END; + CX_TEST_ASSERT(!res->addproperty(res, &p[0], 200)); + CX_TEST_ASSERT(!res->addproperty(res, &p[1], 200)); + CX_TEST_ASSERT(!res->addproperty(res, &p[2], 200)); + CX_TEST_ASSERT(!res->addproperty(res, &p[3], 200)); + + CX_TEST_ASSERT(!res->close(res)); + + MSResponse *msres = (MSResponse*)res; + CX_TEST_ASSERT(!msres->errors); + CX_TEST_ASSERT(msres->plist_begin); + CX_TEST_ASSERT(msres->plist_begin->next); + CX_TEST_ASSERT(msres->plist_begin->next->next); + CX_TEST_ASSERT(msres->plist_begin->next->next->next); + CX_TEST_ASSERT(!msres->plist_begin->next->next->next->next); + + } testutil_destroy_session(sn); } -UCX_TEST(test_msresponse_addproperty_with_errors) { +CX_TEST(test_msresponse_addproperty_with_errors) { Session *sn; Request *rq; WebdavOperation *op; @@ -1309,51 +1267,51 @@ p[i].vtype = 0; } - UCX_TEST_BEGIN; - - op = test_proppatch_op1(&sn, &rq, TEST_PROPPATCH2); - UCX_TEST_ASSERT(op, "failed to create proppatch operation"); - - ms = (Multistatus*)op->response; - ms->proppatch = TRUE; - res = ms->response.addresource(&ms->response, "/"); - UCX_TEST_ASSERT(res, "cannot create resource 1"); + CX_TEST_DO { - UCX_TEST_ASSERT(!res->addproperty(res, &p[0], 200), "addproperty 1 failed"); - UCX_TEST_ASSERT(!res->addproperty(res, &p[1], 200), "addproperty 2 failed"); - UCX_TEST_ASSERT(!res->addproperty(res, &p[2], 409), "addproperty 3 failed"); - UCX_TEST_ASSERT(!res->addproperty(res, &p[3], 200), "addproperty 4 failed"); - - UCX_TEST_ASSERT(!res->close(res), "close failed"); - - // all properties should have an error status code now - // 1 x 409, 3 x 424 + op = test_proppatch_op1(&sn, &rq, TEST_PROPPATCH2); + CX_TEST_ASSERT(op); + + ms = (Multistatus*)op->response; + ms->proppatch = TRUE; + res = ms->response.addresource(&ms->response, "/"); + CX_TEST_ASSERT(res); + + CX_TEST_ASSERT(!res->addproperty(res, &p[0], 200)); + CX_TEST_ASSERT(!res->addproperty(res, &p[1], 200)); + CX_TEST_ASSERT(!res->addproperty(res, &p[2], 409)); + CX_TEST_ASSERT(!res->addproperty(res, &p[3], 200)); + + CX_TEST_ASSERT(!res->close(res)); + + // all properties should have an error status code now + // 1 x 409, 3 x 424 - MSResponse *msres = (MSResponse*)res; - - UCX_TEST_ASSERT(!msres->plist_begin, "plist not NULL"); - UCX_TEST_ASSERT(msres->errors, "error list is NULL"); - UCX_TEST_ASSERT(msres->errors->next, "second error list is missing"); - UCX_TEST_ASSERT(!msres->errors->next->next, "wrong error list size"); + MSResponse *msres = (MSResponse*)res; + + CX_TEST_ASSERT(!msres->plist_begin); + CX_TEST_ASSERT(msres->errors); + CX_TEST_ASSERT(msres->errors->next); + CX_TEST_ASSERT(!msres->errors->next->next); + + // We know that we have 2 error lists, one with status code 409 and + // the other must have 409. However we don't enforce the order of the + // error lists, therefore check both variants + if(msres->errors->status == 409) { + CX_TEST_ASSERT(msres->errors->next->status == 424); + CX_TEST_ASSERT(msres->errors->begin); + CX_TEST_ASSERT(msres->errors->next->begin); + } else { + CX_TEST_ASSERT(msres->errors->next->status == 409); + CX_TEST_ASSERT(msres->errors->begin); + CX_TEST_ASSERT(msres->errors->next->begin); + } - // We know that we have 2 error lists, one with status code 409 and - // the other must have 409. However we don't enforce the order of the - // error lists, therefore check both variants - if(msres->errors->status == 409) { - UCX_TEST_ASSERT(msres->errors->next->status == 424, "wrong status code in second err elm"); - UCX_TEST_ASSERT(msres->errors->begin, "missing 409 property"); - UCX_TEST_ASSERT(msres->errors->next->begin, "missing 424 properties"); - } else { - UCX_TEST_ASSERT(msres->errors->next->status == 409, "wrong status code in second err elm"); - UCX_TEST_ASSERT(msres->errors->begin, "missing 424 properties"); - UCX_TEST_ASSERT(msres->errors->next->begin, "missing 409 property"); - } - - UCX_TEST_END; + } testutil_destroy_session(sn); } -UCX_TEST(test_webdav_op_proppatch) { +CX_TEST(test_webdav_op_proppatch) { Session *sn; Request *rq; WebdavOperation *op; @@ -1371,57 +1329,57 @@ p[1].vtype = 0; } - UCX_TEST_BEGIN; - - // TEST_PROPPATCH2 should succeed - reset_backends(); - op = test_proppatch_op1(&sn, &rq, TEST_PROPPATCH2); - UCX_TEST_ASSERT(op, "failed to create proppatch operation"); - - int ret = webdav_op_proppatch(op, "/", "/"); - UCX_TEST_ASSERT(ret == 0, "webdav_op_proppatch failed"); - UCX_TEST_ASSERT(backend1_proppatch_commit, "backend1 no commit"); - UCX_TEST_ASSERT(backend2_proppatch_commit, "backend2 no commit"); - UCX_TEST_ASSERT(backend1_proppatch_do_count == 1, "backend1 wrong count (1)"); - UCX_TEST_ASSERT(backend2_proppatch_do_count == 1, "backend1 wrong count (1)"); - UCX_TEST_ASSERT(backend1_proppatch_finish_count == 1, "backend1 wrong finish count (1)"); - UCX_TEST_ASSERT(backend2_proppatch_finish_count == 1, "backend1 wrong finish count (1)"); + CX_TEST_DO { - // TEST_PROPPATCH3 should fail (commit == FALSE) - reset_backends(); - op = test_proppatch_op1(&sn, &rq, TEST_PROPPATCH3); - UCX_TEST_ASSERT(op, "failed to create proppatch operation 2"); - - ret = webdav_op_proppatch(op, "/", "/"); - UCX_TEST_ASSERT(ret == 0, "webdav_op_proppatch failed (2)"); - UCX_TEST_ASSERT(!backend1_proppatch_commit, "backend1 commit"); - UCX_TEST_ASSERT(!backend2_proppatch_commit, "backend2 commit"); + // TEST_PROPPATCH2 should succeed + reset_backends(); + op = test_proppatch_op1(&sn, &rq, TEST_PROPPATCH2); + CX_TEST_ASSERT(op); + + int ret = webdav_op_proppatch(op, "/", "/"); + CX_TEST_ASSERT(ret == 0); + CX_TEST_ASSERT(backend1_proppatch_commit); + CX_TEST_ASSERT(backend2_proppatch_commit); + CX_TEST_ASSERT(backend1_proppatch_do_count == 1); + CX_TEST_ASSERT(backend2_proppatch_do_count == 1); + CX_TEST_ASSERT(backend1_proppatch_finish_count == 1); + CX_TEST_ASSERT(backend2_proppatch_finish_count == 1); + + // TEST_PROPPATCH3 should fail (commit == FALSE) + reset_backends(); + op = test_proppatch_op1(&sn, &rq, TEST_PROPPATCH3); + CX_TEST_ASSERT(op); + + ret = webdav_op_proppatch(op, "/", "/"); + CX_TEST_ASSERT(ret == 0); + CX_TEST_ASSERT(!backend1_proppatch_commit); + CX_TEST_ASSERT(!backend2_proppatch_commit); + + // TEST_PROPPATCH4 should abort + reset_backends(); + op = test_proppatch_op1(&sn, &rq, TEST_PROPPATCH4); + CX_TEST_ASSERT(op); + + ret = webdav_op_proppatch(op, "/", "/"); + CX_TEST_ASSERT(ret != 0); + CX_TEST_ASSERT(backend1_proppatch_do_count == 1); + CX_TEST_ASSERT(backend2_proppatch_do_count == 1); + CX_TEST_ASSERT(backend1_proppatch_finish_count == 1); + CX_TEST_ASSERT(backend2_proppatch_finish_count == 0); - // TEST_PROPPATCH4 should abort - reset_backends(); - op = test_proppatch_op1(&sn, &rq, TEST_PROPPATCH4); - UCX_TEST_ASSERT(op, "failed to create proppatch operation 3"); - - ret = webdav_op_proppatch(op, "/", "/"); - UCX_TEST_ASSERT(ret != 0, "webdav_op_proppatch should fail"); - UCX_TEST_ASSERT(backend1_proppatch_do_count == 1, "backend1 wrong count (2)"); - UCX_TEST_ASSERT(backend2_proppatch_do_count == 1, "backend1 wrong count (2)"); - UCX_TEST_ASSERT(backend1_proppatch_finish_count == 1, "backend1 wrong finish count (2)"); - UCX_TEST_ASSERT(backend2_proppatch_finish_count == 0, "backend1 wrong finish count (2)"); - - UCX_TEST_END; + } testutil_destroy_session(sn); } #define xstreq(a, b) (!strcmp((const char*)a, (const char*)b)) -UCX_TEST(test_webdav_proppatch) { +CX_TEST(test_webdav_proppatch) { Session *sn; Request *rq; TestIOStream *st; pblock *pb; - UCX_TEST_BEGIN; + CX_TEST_DO { int ret; // Test 1 @@ -1429,16 +1387,16 @@ rq->davCollection = &backend1; ret = webdav_proppatch(pb, sn, rq); - UCX_TEST_ASSERT(ret == REQ_PROCEED, "webdav_proppatch (1) failed"); + CX_TEST_ASSERT(ret == REQ_PROCEED); xmlDoc *doc = xmlReadMemory( st->buf->space, st->buf->size, NULL, NULL, 0); - UCX_TEST_ASSERT(doc, "proppatch1: response is not valid xml"); + CX_TEST_ASSERT(doc); //printf("\n\n%.*s\n", (int)st->buf->size, st->buf->space); xmlNode *root = xmlDocGetRootElement(doc); - UCX_TEST_ASSERT(root, "proppatch1: no root"); + CX_TEST_ASSERT(root); xmlNode *nodeC = NULL; xmlNode *node = root->children; @@ -1475,15 +1433,15 @@ } } - UCX_TEST_ASSERT(nodeC, "prop c not in response"); - UCX_TEST_ASSERT(!nodeC->children, "properties must not have a value"); + CX_TEST_ASSERT(nodeC); + CX_TEST_ASSERT(!nodeC->children); testutil_destroy_session(sn); xmlFreeDoc(doc); testutil_iostream_destroy(st); - UCX_TEST_END; + } } @@ -1579,7 +1537,7 @@ } -UCX_TEST(test_webdav_vfs_op_do) { +CX_TEST(test_webdav_vfs_op_do) { Session *sn; Request *rq; TestIOStream *st; @@ -1619,54 +1577,54 @@ rq->davCollection = &dav1; - UCX_TEST_BEGIN; - - WebdavVFSOperation *op1 = webdav_vfs_op(sn, rq, &dav1, FALSE); - - int ret = webdav_vfs_op_do(op1, WEBDAV_VFS_MKDIR); - - UCX_TEST_ASSERT(!ret, "webdav_vfs_op_do failed"); - UCX_TEST_ASSERT(mkcol_count == 3, "wrong mkcol_count"); - UCX_TEST_ASSERT(mkcol_finish_count == 3, "wrong mkcol_finish_count"); - UCX_TEST_ASSERT(mkcol_err == 0, "mkcol_err"); - - // test without VFS, but set *created to TRUE to skip VFS usage - rq->vfs = NULL; - set_created = 1; - - WebdavVFSOperation *op2 = webdav_vfs_op(sn, rq, &dav1, FALSE); - ret = webdav_vfs_op_do(op2, WEBDAV_VFS_MKDIR); - - UCX_TEST_ASSERT(!ret, "op2 failed"); + CX_TEST_DO { - // test 3: abort after first backend - mkcol_count = 0; - mkcol_finish_count = 0; - dav1.opt_mkcol = test_webdav_mkcol_fail; - - WebdavVFSOperation *op3 = webdav_vfs_op(sn, rq, &dav1, FALSE); - ret = webdav_vfs_op_do(op3, WEBDAV_VFS_MKDIR); - - UCX_TEST_ASSERT(ret, "op3 should fail"); - UCX_TEST_ASSERT(mkcol_count == 1, "op3: wrong mkcol_count"); - UCX_TEST_ASSERT(mkcol_finish_count == 1, "op3: wrong mkcol_finish_count"); - - // test DELETE to make sure, delete callbacks will be used - pblock_replace("path", "/deltest", rq->vars); - rq->vfs = testvfs; - WebdavVFSOperation *op_del = webdav_vfs_op(sn, rq, &dav1, FALSE); - vfs_open(op_del->vfs, "/deltest", O_CREAT); - ret = webdav_vfs_op_do(op_del, WEBDAV_VFS_DELETE); - - UCX_TEST_ASSERT(!ret, "op_del failed"); - UCX_TEST_ASSERT(delete_count == 1, "op_del: wrong delete_count"); - UCX_TEST_ASSERT(delete_finish_count == 1, "op_del: wrong delete_finish_count"); + WebdavVFSOperation *op1 = webdav_vfs_op(sn, rq, &dav1, FALSE); + + int ret = webdav_vfs_op_do(op1, WEBDAV_VFS_MKDIR); + + CX_TEST_ASSERT(!ret); + CX_TEST_ASSERT(mkcol_count == 3); + CX_TEST_ASSERT(mkcol_finish_count == 3); + CX_TEST_ASSERT(mkcol_err == 0); + + // test without VFS, but set *created to TRUE to skip VFS usage + rq->vfs = NULL; + set_created = 1; + + WebdavVFSOperation *op2 = webdav_vfs_op(sn, rq, &dav1, FALSE); + ret = webdav_vfs_op_do(op2, WEBDAV_VFS_MKDIR); + + CX_TEST_ASSERT(!ret); + + // test 3: abort after first backend + mkcol_count = 0; + mkcol_finish_count = 0; + dav1.opt_mkcol = test_webdav_mkcol_fail; + + WebdavVFSOperation *op3 = webdav_vfs_op(sn, rq, &dav1, FALSE); + ret = webdav_vfs_op_do(op3, WEBDAV_VFS_MKDIR); + + CX_TEST_ASSERT(ret); + CX_TEST_ASSERT(mkcol_count == 1); + CX_TEST_ASSERT(mkcol_finish_count == 1); + + // test DELETE to make sure, delete callbacks will be used + pblock_replace("path", "/deltest", rq->vars); + rq->vfs = testvfs; + WebdavVFSOperation *op_del = webdav_vfs_op(sn, rq, &dav1, FALSE); + vfs_open(op_del->vfs, "/deltest", O_CREAT); + ret = webdav_vfs_op_do(op_del, WEBDAV_VFS_DELETE); + + CX_TEST_ASSERT(!ret); + CX_TEST_ASSERT(delete_count == 1); + CX_TEST_ASSERT(delete_finish_count == 1); - UCX_TEST_END; + } } -UCX_TEST(test_webdav_delete){ +CX_TEST(test_webdav_delete){ Session *sn; Request *rq; TestIOStream *st; @@ -1683,56 +1641,56 @@ delete_finish_count = 0; rq->davCollection = &dav1; - UCX_TEST_BEGIN; - - // prepare - VFSContext *vfs = vfs_request_context(sn, rq); - int err; - err = vfs_mkdir(vfs, "/dir1"); - UCX_TEST_ASSERT(err == 0, "mkdir dir1 failed"); - err = vfs_mkdir(vfs, "/dir2"); - UCX_TEST_ASSERT(err == 0, "mkdir dir2 failed"); - err = vfs_mkdir(vfs, "/dir2/dir3"); - UCX_TEST_ASSERT(err == 0, "mkdir dir3 failed"); - err = vfs_mkdir(vfs, "/dir2/dir4"); - UCX_TEST_ASSERT(err == 0, "mkdir dir4 failed"); - err = vfs_mkdir(vfs, "/dir2/dir4/dir5"); - UCX_TEST_ASSERT(err == 0, "mkdir dir5 failed"); + CX_TEST_DO { - SYS_FILE f0 = vfs_open(vfs, "/file0", O_CREAT); - UCX_TEST_ASSERT(f0, "f0 create failed"); - // no f1 - SYS_FILE f2 = vfs_open(vfs, "/dir2/file2", O_CREAT); - UCX_TEST_ASSERT(f2, "f2 create failed"); - SYS_FILE f3 = vfs_open(vfs, "/dir2/dir3/file3", O_CREAT); - UCX_TEST_ASSERT(f3, "f3 create failed"); - SYS_FILE f4 = vfs_open(vfs, "/dir2/dir4/file4", O_CREAT); - UCX_TEST_ASSERT(f4, "f4 create failed"); - SYS_FILE f5 = vfs_open(vfs, "/dir2/dir4/dir5/file5", O_CREAT); - UCX_TEST_ASSERT(f5, "f5 create failed"); + // prepare + VFSContext *vfs = vfs_request_context(sn, rq); + int err; + err = vfs_mkdir(vfs, "/dir1"); + CX_TEST_ASSERT(err == 0); + err = vfs_mkdir(vfs, "/dir2"); + CX_TEST_ASSERT(err == 0); + err = vfs_mkdir(vfs, "/dir2/dir3"); + CX_TEST_ASSERT(err == 0); + err = vfs_mkdir(vfs, "/dir2/dir4"); + CX_TEST_ASSERT(err == 0); + err = vfs_mkdir(vfs, "/dir2/dir4/dir5"); + CX_TEST_ASSERT(err == 0); + + SYS_FILE f0 = vfs_open(vfs, "/file0", O_CREAT); + CX_TEST_ASSERT(f0); + // no f1 + SYS_FILE f2 = vfs_open(vfs, "/dir2/file2", O_CREAT); + CX_TEST_ASSERT(f2); + SYS_FILE f3 = vfs_open(vfs, "/dir2/dir3/file3", O_CREAT); + CX_TEST_ASSERT(f3); + SYS_FILE f4 = vfs_open(vfs, "/dir2/dir4/file4", O_CREAT); + CX_TEST_ASSERT(f4); + SYS_FILE f5 = vfs_open(vfs, "/dir2/dir4/dir5/file5", O_CREAT); + CX_TEST_ASSERT(f5); + + // delete single file + pblock_replace("path", "/file0", rq->vars); + err = webdav_delete(NULL, sn, rq); + CX_TEST_ASSERT(err == 0); + CX_TEST_ASSERT(delete_count == 1); + + delete_count = 0; + pblock_replace("path", "/dir1", rq->vars); + err = webdav_delete(NULL, sn, rq); + CX_TEST_ASSERT(err == 0); + CX_TEST_ASSERT(delete_count == 1); + + delete_count = 0; + pblock_replace("path", "/dir2", rq->vars); + err = webdav_delete(NULL, sn, rq); + CX_TEST_ASSERT(err == 0); + CX_TEST_ASSERT(delete_count == 8); - // delete single file - pblock_replace("path", "/file0", rq->vars); - err = webdav_delete(NULL, sn, rq); - UCX_TEST_ASSERT(err == 0, "DELETE /file0 failed"); - UCX_TEST_ASSERT(delete_count == 1, "del1: wrong delete count"); - - delete_count = 0; - pblock_replace("path", "/dir1", rq->vars); - err = webdav_delete(NULL, sn, rq); - UCX_TEST_ASSERT(err == 0, "DELETE /dir1 failed"); - UCX_TEST_ASSERT(delete_count == 1, "del1: wrong delete count"); - - delete_count = 0; - pblock_replace("path", "/dir2", rq->vars); - err = webdav_delete(NULL, sn, rq); - UCX_TEST_ASSERT(err == 0, "DELETE /dir2 failed"); - UCX_TEST_ASSERT(delete_count == 8, "del2: wrong delete count"); - - UCX_TEST_END; + } } -UCX_TEST(test_webdav_put) { +CX_TEST(test_webdav_put) { Session *sn; Request *rq; TestIOStream *st; @@ -1743,27 +1701,27 @@ init_test_webdav_method(&sn, &rq, &st, &pb, "PUT", "/", content_const); rq->vfs = testvfs_create(sn); - UCX_TEST_BEGIN; - - int err; - - pblock_replace("path", "/file0", rq->vars); - err = webdav_put(NULL, sn, rq); - - UCX_TEST_ASSERT(err == REQ_PROCEED, "put failed"); + CX_TEST_DO { - VFSContext *vfs = vfs_request_context(sn, rq); - SYS_FILE f0 = vfs_open(vfs, "/file0", 0); - UCX_TEST_ASSERT(f0, "cannot open file0"); - - char buf[1024]; - int r = system_fread(f0, buf, 1024); + int err; + + pblock_replace("path", "/file0", rq->vars); + err = webdav_put(NULL, sn, rq); + + CX_TEST_ASSERT(err == REQ_PROCEED); + + VFSContext *vfs = vfs_request_context(sn, rq); + SYS_FILE f0 = vfs_open(vfs, "/file0", 0); + CX_TEST_ASSERT(f0); + + char buf[1024]; + int r = system_fread(f0, buf, 1024); + + CX_TEST_ASSERT(r == strlen(content_const)); + CX_TEST_ASSERT(!memcmp(content_const, buf, r)); + + testutil_destroy_session(sn); + testutil_iostream_destroy(st); - UCX_TEST_ASSERT(r == strlen(content_const), "wrong file size"); - UCX_TEST_ASSERT(!memcmp(content_const, buf, r), "wrong file content"); - - testutil_destroy_session(sn); - testutil_iostream_destroy(st); - - UCX_TEST_END; + } }
--- a/src/server/test/webdav.h Sat Nov 22 12:49:20 2025 +0100 +++ b/src/server/test/webdav.h Sat Nov 22 14:27:01 2025 +0100 @@ -49,36 +49,36 @@ const char *path, const char *request_body); -UCX_TEST(test_webdav_plist_add); -UCX_TEST(test_webdav_plist_size); +CX_TEST(test_webdav_plist_add); +CX_TEST(test_webdav_plist_size); -UCX_TEST(test_propfind_parse); -UCX_TEST(test_proppatch_parse); -UCX_TEST(test_lock_parse); +CX_TEST(test_propfind_parse); +CX_TEST(test_proppatch_parse); +CX_TEST(test_lock_parse); -UCX_TEST(test_rqbody2buffer); +CX_TEST(test_rqbody2buffer); -UCX_TEST(test_webdav_plist_iterator); -UCX_TEST(test_webdav_plist_iterator_remove_current); +CX_TEST(test_webdav_plist_iterator); +CX_TEST(test_webdav_plist_iterator_remove_current); -UCX_TEST(test_msresponse_addproperty); -UCX_TEST(test_msresponse_addproperty_with_errors); +CX_TEST(test_msresponse_addproperty); +CX_TEST(test_msresponse_addproperty_with_errors); -UCX_TEST(test_webdav_propfind_init); -UCX_TEST(test_webdav_op_propfind_begin); -UCX_TEST(test_webdav_op_propfind_children); +CX_TEST(test_webdav_propfind_init); +CX_TEST(test_webdav_op_propfind_begin); +CX_TEST(test_webdav_op_propfind_children); -UCX_TEST(test_webdav_propfind); +CX_TEST(test_webdav_propfind); -UCX_TEST(test_proppatch_msresponse); -UCX_TEST(test_webdav_op_proppatch); +CX_TEST(test_proppatch_msresponse); +CX_TEST(test_webdav_op_proppatch); -UCX_TEST(test_webdav_proppatch); +CX_TEST(test_webdav_proppatch); -UCX_TEST(test_webdav_vfs_op_do); +CX_TEST(test_webdav_vfs_op_do); -UCX_TEST(test_webdav_delete); -UCX_TEST(test_webdav_put); +CX_TEST(test_webdav_delete); +CX_TEST(test_webdav_put); /* --------------------------- PROPFIND --------------------------- */
--- a/src/server/test/writer.c Sat Nov 22 12:49:20 2025 +0100 +++ b/src/server/test/writer.c Sat Nov 22 14:27:01 2025 +0100 @@ -36,116 +36,112 @@ #include "writer.h" #include "testutils.h" -UCX_TEST(test_writer_putc) { +CX_TEST(test_writer_putc) { Session *sn = testutil_session(); TestIOStream *st = testutil_iostream(2048, TRUE); CxBuffer *buf = st->buf; - UCX_TEST_BEGIN; - - Writer writer; - char wbuf[1024]; - writer_init(&writer, st, wbuf, 4); - Writer *out = &writer; - - writer_putc(out, 'a'); - UCX_TEST_ASSERT(wbuf[0] == 'a', "1: wrong char at pos 0"); - UCX_TEST_ASSERT(writer.pos == 1, "1: wrong pos"); + CX_TEST_DO { - writer_putc(out, 'b'); - UCX_TEST_ASSERT(wbuf[1] == 'b', "2: wrong char at pos 1"); - UCX_TEST_ASSERT(writer.pos == 2, "2: wrong pos"); - - writer_putc(out, 'c'); - writer_putc(out, 'd'); - UCX_TEST_ASSERT(wbuf[2] == 'c', "3: wrong char at pos 2"); - UCX_TEST_ASSERT(wbuf[3] == 'd', "4: wrong char at pos 3"); + Writer writer; + char wbuf[1024]; + writer_init(&writer, st, wbuf, 4); + Writer *out = &writer; + + writer_putc(out, 'a'); + CX_TEST_ASSERT(wbuf[0] == 'a'); + CX_TEST_ASSERT(writer.pos == 1); + + writer_putc(out, 'b'); + CX_TEST_ASSERT(wbuf[1] == 'b'); + CX_TEST_ASSERT(writer.pos == 2); + + writer_putc(out, 'c'); + writer_putc(out, 'd'); + CX_TEST_ASSERT(wbuf[2] == 'c'); + CX_TEST_ASSERT(wbuf[3] == 'd'); + + writer_putc(out, 'f'); // should flush the buffer + CX_TEST_ASSERT(wbuf[0] == 'f'); + CX_TEST_ASSERT(writer.pos == 1); + CX_TEST_ASSERT(buf->space[0] == 'a'); + CX_TEST_ASSERT(buf->space[1] == 'b'); + CX_TEST_ASSERT(buf->pos == 4); - writer_putc(out, 'f'); // should flush the buffer - UCX_TEST_ASSERT(wbuf[0] == 'f', "5: wrong char at pos 0"); - UCX_TEST_ASSERT(writer.pos == 1, "5: wrong pos"); - UCX_TEST_ASSERT(buf->space[0] == 'a', "5: wrong char at UcxBuffer pos 0"); - UCX_TEST_ASSERT(buf->space[1] == 'b', "5: wrong char at UcxBuffer pos 1"); - UCX_TEST_ASSERT(buf->pos == 4, "5: wrong UcxBuffer pos"); - - UCX_TEST_END; + } testutil_iostream_destroy(st); testutil_destroy_session(sn); } -UCX_TEST(test_writer_flush) { +CX_TEST(test_writer_flush) { Session *sn = testutil_session(); TestIOStream *st = testutil_iostream(2048, TRUE); CxBuffer *buf = st->buf; - UCX_TEST_BEGIN; - - Writer writer; - char wbuf[1024]; - writer_init(&writer, st, wbuf, 4); - Writer *out = &writer; - - writer_putc(out, 'a'); - UCX_TEST_ASSERT(wbuf[0] == 'a', "1: wrong char at pos 0"); - UCX_TEST_ASSERT(writer.pos == 1, "1: wrong pos"); + CX_TEST_DO { - writer_flush(out); - UCX_TEST_ASSERT(writer.pos == 0, "wrong pos after flush"); - UCX_TEST_ASSERT(buf->space[0] == 'a', "wrong UcxBuffer content"); - UCX_TEST_ASSERT(buf->pos == 1, "wrong UcxBuffer pos"); + Writer writer; + char wbuf[1024]; + writer_init(&writer, st, wbuf, 4); + Writer *out = &writer; + + writer_putc(out, 'a'); + CX_TEST_ASSERT(wbuf[0] == 'a'); + CX_TEST_ASSERT(writer.pos == 1); + + writer_flush(out); + CX_TEST_ASSERT(writer.pos == 0); + CX_TEST_ASSERT(buf->space[0] == 'a'); + CX_TEST_ASSERT(buf->pos == 1); + + writer_putc(out, 'b'); + CX_TEST_ASSERT(wbuf[0] == 'b'); + CX_TEST_ASSERT(writer.pos == 1); - writer_putc(out, 'b'); - UCX_TEST_ASSERT(wbuf[0] == 'b', "2: wrong char at pos 0"); - UCX_TEST_ASSERT(writer.pos == 1, "2: wrong pos"); - - UCX_TEST_END; + } testutil_iostream_destroy(st); testutil_destroy_session(sn); } -UCX_TEST(test_writer_put) { +CX_TEST(test_writer_put) { Session *sn = testutil_session(); TestIOStream *st = testutil_iostream(2048, TRUE); CxBuffer *buf = st->buf; - UCX_TEST_BEGIN; - - Writer writer; - char wbuf[1024]; - writer_init(&writer, st, wbuf, 8); - Writer *out = &writer; - - writer_put(out, "abcd", 4); - UCX_TEST_ASSERT(!memcmp(wbuf, "abcd", 4), "1: wrong content"); - UCX_TEST_ASSERT(writer.pos == 4, "1: wrong pos"); - - writer_put(out, "efgh", 4); - UCX_TEST_ASSERT(!memcmp(wbuf, "abcdefgh", 8), "2: wrong content"); - UCX_TEST_ASSERT(writer.pos == 8, "2: wrong pos"); + CX_TEST_DO { - writer_put(out, "1234", 4); - UCX_TEST_ASSERT(!memcmp(wbuf, "1234", 4), "3: wrong content"); - UCX_TEST_ASSERT(writer.pos == 4, "3: wrong pos"); - UCX_TEST_ASSERT(!memcmp(buf->space, "abcdefgh", 8), "3: wrong UcxBuffer content"); - UCX_TEST_ASSERT(buf->pos == 8, "3: wrong UcxBuffer pos"); - - writer_put(out, "5678xx", 6); - UCX_TEST_ASSERT(!memcmp(wbuf, "xx", 2), "4: wrong content"); - UCX_TEST_ASSERT(writer.pos == 2, "4: wrong pos"); - UCX_TEST_ASSERT(!memcmp(buf->space, "abcdefgh12345678", 16), "4: wrong UcxBuffer content"); - UCX_TEST_ASSERT(buf->pos == 16, "4: wrong UcxBuffer pos"); + Writer writer; + char wbuf[1024]; + writer_init(&writer, st, wbuf, 8); + Writer *out = &writer; + + writer_put(out, "abcd", 4); + CX_TEST_ASSERT(!memcmp(wbuf, "abcd", 4)); + CX_TEST_ASSERT(writer.pos == 4); + + writer_put(out, "efgh", 4); + CX_TEST_ASSERT(!memcmp(wbuf, "abcdefgh", 8)); + CX_TEST_ASSERT(writer.pos == 8); + + writer_put(out, "1234", 4); + CX_TEST_ASSERT(!memcmp(wbuf, "1234", 4)); + CX_TEST_ASSERT(writer.pos == 4); + CX_TEST_ASSERT(!memcmp(buf->space, "abcdefgh", 8)); + CX_TEST_ASSERT(buf->pos == 8); + + writer_put(out, "5678xx", 6); + CX_TEST_ASSERT(!memcmp(wbuf, "xx", 2)); + CX_TEST_ASSERT(writer.pos == 2); + CX_TEST_ASSERT(!memcmp(buf->space, "abcdefgh12345678", 16)); + CX_TEST_ASSERT(buf->pos == 16); + + writer_puts(out, cx_str("345678abcdefgh12345678end.")); + CX_TEST_ASSERT(!memcmp(wbuf, "end.", 4)); + CX_TEST_ASSERT(writer.pos == 4); + CX_TEST_ASSERT(!memcmp(buf->space, "abcdefgh12345678xx345678abcdefgh12345678", 40)); + CX_TEST_ASSERT(buf->pos == 40); - writer_puts(out, cx_str("345678abcdefgh12345678end.")); - UCX_TEST_ASSERT(!memcmp(wbuf, "end.", 4), "5: wrong content"); - UCX_TEST_ASSERT(writer.pos == 4, "5: wrong pos"); - UCX_TEST_ASSERT(!memcmp( - buf->space, - "abcdefgh12345678xx345678abcdefgh12345678", - 40), - "5: wrong UcxBuffer content"); - UCX_TEST_ASSERT(buf->pos == 40, "5: wrong UcxBuffer pos"); - - UCX_TEST_END; + } testutil_iostream_destroy(st); testutil_destroy_session(sn); }
--- a/src/server/test/writer.h Sat Nov 22 12:49:20 2025 +0100 +++ b/src/server/test/writer.h Sat Nov 22 14:27:01 2025 +0100 @@ -35,9 +35,9 @@ extern "C" { #endif -UCX_TEST(test_writer_putc); -UCX_TEST(test_writer_flush); -UCX_TEST(test_writer_put); +CX_TEST(test_writer_putc); +CX_TEST(test_writer_flush); +CX_TEST(test_writer_put); #ifdef __cplusplus }
--- a/src/server/test/xml.c Sat Nov 22 12:49:20 2025 +0100 +++ b/src/server/test/xml.c Sat Nov 22 14:27:01 2025 +0100 @@ -152,57 +152,57 @@ return 0; } -UCX_TEST(test_wsxml_iterator) { +CX_TEST(test_wsxml_iterator) { Session *sn = testutil_session(); - UCX_TEST_BEGIN; - - xmlDoc *doc = xmlReadMemory( - XML_TESTDATA1, strlen(XML_TESTDATA1), NULL, NULL, 0); - xmlDoc *doc2 = xmlReadMemory( - XML_TESTDATA2, strlen(XML_TESTDATA2), NULL, NULL, 0); - xmlDoc *doc6 = xmlReadMemory( - XML_TESTDATA6, strlen(XML_TESTDATA6), NULL, NULL, 0); - UCX_TEST_ASSERT(doc, "doc is NULL"); - UCX_TEST_ASSERT(doc2, "doc2 is NULL"); - UCX_TEST_ASSERT(doc6, "doc6 is NULL"); - - xmlNode *root = xmlDocGetRootElement(doc); - - // Test 1: iterate over complete document - Test1Data testdata; - ZERO(&testdata, sizeof(Test1Data)); - int ret = wsxml_iterator(sn->pool, root, test1_begin, test1_end, &testdata); - UCX_TEST_ASSERT(ret == 0, "wsxml_iterator failed"); - UCX_TEST_ASSERT(!testdata.err, "wrong element order (begin)"); - UCX_TEST_ASSERT(!testdata.endErr, "wrong element order (end)"); - UCX_TEST_ASSERT(!testdata.textErr, "text order error"); - UCX_TEST_ASSERT(testdata.beginCounter == testdata.endCounter, "begin/end counter not equal"); + CX_TEST_DO { - // Test 2: iterate over sub-document - ZERO(&testdata, sizeof(Test1Data)); - xmlNode *root2 = xmlDocGetRootElement(doc2); - xmlNode *sub = root2->children->children; - ret = wsxml_iterator(sn->pool, sub, test1_begin, test1_end, &testdata); - UCX_TEST_ASSERT(ret == 0, "test2: wsxml_iterator failed"); - UCX_TEST_ASSERT(!testdata.err, "test2: wrong element order (begin)"); - UCX_TEST_ASSERT(!testdata.endErr, "test2: wrong element order (end)"); - UCX_TEST_ASSERT(!testdata.textErr, "test2: text order error"); - UCX_TEST_ASSERT(testdata.beginCounter == testdata.endCounter, "test2: begin/end counter not equal"); - - // Test 3: iterate over document with all kinds of node types - xmlNode *root6 = xmlDocGetRootElement(doc6); - ZERO(&testdata, sizeof(Test1Data)); - ret = wsxml_iterator(sn->pool, root6, test2_begin, test2_end, &testdata); - UCX_TEST_ASSERT(ret == 0, "test3: wsxml_iterator failed"); - UCX_TEST_ASSERT(testdata.elmCounter == testdata.endElmCounter, "test3: begin/end counter not equal"); - UCX_TEST_ASSERT(testdata.elmCounter == 12, "test3: wrong elm counter"); - UCX_TEST_ASSERT(testdata.nodesWithAttributesCounter == 5, "test3: wrong entity ref counter"); - - xmlFreeDoc(doc); - xmlFreeDoc(doc2); - xmlFreeDoc(doc6); - UCX_TEST_END; + xmlDoc *doc = xmlReadMemory( + XML_TESTDATA1, strlen(XML_TESTDATA1), NULL, NULL, 0); + xmlDoc *doc2 = xmlReadMemory( + XML_TESTDATA2, strlen(XML_TESTDATA2), NULL, NULL, 0); + xmlDoc *doc6 = xmlReadMemory( + XML_TESTDATA6, strlen(XML_TESTDATA6), NULL, NULL, 0); + CX_TEST_ASSERT(doc); + CX_TEST_ASSERT(doc2); + CX_TEST_ASSERT(doc6); + + xmlNode *root = xmlDocGetRootElement(doc); + + // Test 1: iterate over complete document + Test1Data testdata; + ZERO(&testdata, sizeof(Test1Data)); + int ret = wsxml_iterator(sn->pool, root, test1_begin, test1_end, &testdata); + CX_TEST_ASSERT(ret == 0); + CX_TEST_ASSERT(!testdata.err); + CX_TEST_ASSERT(!testdata.endErr); + CX_TEST_ASSERT(!testdata.textErr); + CX_TEST_ASSERT(testdata.beginCounter == testdata.endCounter); + + // Test 2: iterate over sub-document + ZERO(&testdata, sizeof(Test1Data)); + xmlNode *root2 = xmlDocGetRootElement(doc2); + xmlNode *sub = root2->children->children; + ret = wsxml_iterator(sn->pool, sub, test1_begin, test1_end, &testdata); + CX_TEST_ASSERT(ret == 0); + CX_TEST_ASSERT(!testdata.err); + CX_TEST_ASSERT(!testdata.endErr); + CX_TEST_ASSERT(!testdata.textErr); + CX_TEST_ASSERT(testdata.beginCounter == testdata.endCounter); + + // Test 3: iterate over document with all kinds of node types + xmlNode *root6 = xmlDocGetRootElement(doc6); + ZERO(&testdata, sizeof(Test1Data)); + ret = wsxml_iterator(sn->pool, root6, test2_begin, test2_end, &testdata); + CX_TEST_ASSERT(ret == 0); + CX_TEST_ASSERT(testdata.elmCounter == testdata.endElmCounter); + CX_TEST_ASSERT(testdata.elmCounter == 12); + CX_TEST_ASSERT(testdata.nodesWithAttributesCounter == 5); + + xmlFreeDoc(doc); + xmlFreeDoc(doc2); + xmlFreeDoc(doc6); + } testutil_destroy_session(sn); } @@ -238,193 +238,193 @@ } } -UCX_TEST(test_wsxml_get_required_namespaces) { +CX_TEST(test_wsxml_get_required_namespaces) { Session *sn = testutil_session(); - UCX_TEST_BEGIN; - - xmlDoc *doc3 = xmlReadMemory( - XML_TESTDATA3, strlen(XML_TESTDATA3), NULL, NULL, 0); - xmlDoc *doc4 = xmlReadMemory( - XML_TESTDATA4, strlen(XML_TESTDATA4), NULL, NULL, 0); - xmlDoc *doc5 = xmlReadMemory( - XML_TESTDATA5, strlen(XML_TESTDATA5), NULL, NULL, 0); - - xmlNode *node0 = xmlDocGetRootElement(doc3); - xmlNode *node1 = xmlDocGetRootElement(doc3)->children; - xmlNode *node2 = xmlDocGetRootElement(doc4)->children; - xmlNode *node3 = xmlDocGetRootElement(doc5)->children; - - UCX_TEST_ASSERT(doc3, "doc3 is NULL"); - UCX_TEST_ASSERT(doc4, "doc4 is NULL"); - UCX_TEST_ASSERT(doc5, "doc5 is NULL"); - - int err0, err1, err2, err3; - int x1 = 0; - int x2 = 0; - int x3 = 0; - int x4 = 0; - WebdavNSList *elm = NULL; - - // Test 0: - WebdavNSList *ns0 = wsxml_get_required_namespaces(sn->pool, node0, &err0); - UCX_TEST_ASSERT(!err0, "ns0 failed"); - UCX_TEST_ASSERT(!ns0, "ns0: nsdefs should be ignored"); + CX_TEST_DO { - WebdavNSList *ns1 = wsxml_get_required_namespaces(sn->pool, node1, &err1); - check_ns_list(ns1, &x1, &x2, &x3, &x4); - UCX_TEST_ASSERT(!err1, "ns1 failed"); - UCX_TEST_ASSERT(ns1, "ns1: no list"); - UCX_TEST_ASSERT(x1, "ns1: x1 missing"); - UCX_TEST_ASSERT(x2, "ns1: x2 missing"); - UCX_TEST_ASSERT(x3, "ns1: x3 missing"); - UCX_TEST_ASSERT(x4, "ns1: x4 missing"); - - WebdavNSList *ns2 = wsxml_get_required_namespaces(sn->pool, node2, &err2); - check_ns_list(ns2, &x1, &x2, &x3, &x4); - UCX_TEST_ASSERT(!err2, "ns2 failed"); - UCX_TEST_ASSERT(ns2, "ns2: no list"); - UCX_TEST_ASSERT(x1, "ns2: x1 missing"); - UCX_TEST_ASSERT(x2, "ns2: x2 missing"); - UCX_TEST_ASSERT(!x3, "ns2: x3"); - UCX_TEST_ASSERT(!x4, "ns2: x4"); - - WebdavNSList *ns3 = wsxml_get_required_namespaces(sn->pool, node3, &err3); - check_ns_list(ns3, &x1, &x2, &x3, &x4); - UCX_TEST_ASSERT(!err3, "ns3 failed"); - UCX_TEST_ASSERT(ns3, "ns3: no list"); - UCX_TEST_ASSERT(x1, "ns3: x1 missing"); - UCX_TEST_ASSERT(x2, "ns3: x2 missing"); - UCX_TEST_ASSERT(!x3, "ns3: x3"); - UCX_TEST_ASSERT(!x4, "ns3: x4"); - - xmlFreeDoc(doc3); - xmlFreeDoc(doc4); - xmlFreeDoc(doc5); - UCX_TEST_END; + xmlDoc *doc3 = xmlReadMemory( + XML_TESTDATA3, strlen(XML_TESTDATA3), NULL, NULL, 0); + xmlDoc *doc4 = xmlReadMemory( + XML_TESTDATA4, strlen(XML_TESTDATA4), NULL, NULL, 0); + xmlDoc *doc5 = xmlReadMemory( + XML_TESTDATA5, strlen(XML_TESTDATA5), NULL, NULL, 0); + + xmlNode *node0 = xmlDocGetRootElement(doc3); + xmlNode *node1 = xmlDocGetRootElement(doc3)->children; + xmlNode *node2 = xmlDocGetRootElement(doc4)->children; + xmlNode *node3 = xmlDocGetRootElement(doc5)->children; + + CX_TEST_ASSERT(doc3); + CX_TEST_ASSERT(doc4); + CX_TEST_ASSERT(doc5); + + int err0, err1, err2, err3; + int x1 = 0; + int x2 = 0; + int x3 = 0; + int x4 = 0; + WebdavNSList *elm = NULL; + + // Test 0: + WebdavNSList *ns0 = wsxml_get_required_namespaces(sn->pool, node0, &err0); + CX_TEST_ASSERT(!err0); + CX_TEST_ASSERT(!ns0); + + WebdavNSList *ns1 = wsxml_get_required_namespaces(sn->pool, node1, &err1); + check_ns_list(ns1, &x1, &x2, &x3, &x4); + CX_TEST_ASSERT(!err1); + CX_TEST_ASSERT(ns1); + CX_TEST_ASSERT(x1); + CX_TEST_ASSERT(x2); + CX_TEST_ASSERT(x3); + CX_TEST_ASSERT(x4); + + WebdavNSList *ns2 = wsxml_get_required_namespaces(sn->pool, node2, &err2); + check_ns_list(ns2, &x1, &x2, &x3, &x4); + CX_TEST_ASSERT(!err2); + CX_TEST_ASSERT(ns2); + CX_TEST_ASSERT(x1); + CX_TEST_ASSERT(x2); + CX_TEST_ASSERT(!x3); + CX_TEST_ASSERT(!x4); + + WebdavNSList *ns3 = wsxml_get_required_namespaces(sn->pool, node3, &err3); + check_ns_list(ns3, &x1, &x2, &x3, &x4); + CX_TEST_ASSERT(!err3); + CX_TEST_ASSERT(ns3); + CX_TEST_ASSERT(x1); + CX_TEST_ASSERT(x2); + CX_TEST_ASSERT(!x3); + CX_TEST_ASSERT(!x4); + + xmlFreeDoc(doc3); + xmlFreeDoc(doc4); + xmlFreeDoc(doc5); + } testutil_destroy_session(sn); } -UCX_TEST(test_wsxml_write_nodes) { +CX_TEST(test_wsxml_write_nodes) { Session *sn = testutil_session(); TestIOStream *st = testutil_iostream(2048, TRUE); - UCX_TEST_BEGIN; - xmlDoc *doc = xmlReadMemory( - XML_TESTDATA6, strlen(XML_TESTDATA6), NULL, NULL, 0); - UCX_TEST_ASSERT(doc, "xml parser error"); - xmlNode *root = xmlDocGetRootElement(doc); - - Writer writer; - char buffer[1024]; - writer_init(&writer, st, buffer, 1024); + CX_TEST_DO { + xmlDoc *doc = xmlReadMemory( + XML_TESTDATA6, strlen(XML_TESTDATA6), NULL, NULL, 0); + CX_TEST_ASSERT(doc); + xmlNode *root = xmlDocGetRootElement(doc); + + Writer writer; + char buffer[1024]; + writer_init(&writer, st, buffer, 1024); + + int err = wsxml_write_nodes(sn->pool, &writer, NULL, root); + writer_flush(&writer); + CX_TEST_ASSERT(err == 0); + CX_TEST_ASSERT(st->buf->pos > 0); + + //printf("\n\n"); + //printf("%.*s\n", (int)st->buf->size, st->buf->space); + //printf("\n\n"); + + xmlDoc *genDoc = xmlReadMemory( + st->buf->space, st->buf->size, NULL, NULL, 0); + CX_TEST_ASSERT(genDoc); + + xmlFreeDoc(doc); + xmlFreeDoc(genDoc); - int err = wsxml_write_nodes(sn->pool, &writer, NULL, root); - writer_flush(&writer); - UCX_TEST_ASSERT(err == 0, "wsxml_write_nodes error"); - UCX_TEST_ASSERT(st->buf->pos > 0, "buffer is empty"); - - //printf("\n\n"); - //printf("%.*s\n", (int)st->buf->size, st->buf->space); - //printf("\n\n"); - - xmlDoc *genDoc = xmlReadMemory( - st->buf->space, st->buf->size, NULL, NULL, 0); - UCX_TEST_ASSERT(genDoc, "generated doc is not valid xml"); - - xmlFreeDoc(doc); - xmlFreeDoc(genDoc); - - UCX_TEST_END; + } testutil_iostream_destroy(st); testutil_destroy_session(sn); } -UCX_TEST(test_wsxml_nslist2string) { +CX_TEST(test_wsxml_nslist2string) { Session *sn = testutil_session(); - UCX_TEST_BEGIN; - - WSNamespace ns1; - WSNamespace ns2; - WSNamespace ns3; - memset(&ns1, 0, sizeof(WSNamespace)); - memset(&ns2, 0, sizeof(WSNamespace)); - memset(&ns3, 0, sizeof(WSNamespace)); - ns1.prefix = (const xmlChar*)"x"; - ns1.href = (const xmlChar*)"ns1"; - ns2.prefix = (const xmlChar*)"y"; - ns2.href = (const xmlChar*)"ns2"; - ns3.prefix = (const xmlChar*)"z"; - ns3.href = (const xmlChar*)"ns3"; - - WebdavNSList elm1 = { &ns1, NULL, NULL }; - WebdavNSList elm2 = { &ns2, NULL, NULL }; - WebdavNSList elm3 = { &ns3, NULL, NULL }; + CX_TEST_DO { - // single elm test - char *str1 = wsxml_nslist2string(sn->pool, &elm1); - UCX_TEST_ASSERT(str1, "str1 is null"); - UCX_TEST_ASSERT(!strcmp(str1, "x:ns1"), "str1: wrong content"); - - // 2 elm test - elm1.next = &elm2; - char *str2 = wsxml_nslist2string(sn->pool, &elm1); - UCX_TEST_ASSERT(str2, "str2 is null"); - UCX_TEST_ASSERT(!strcmp(str2, "x:ns1\ny:ns2"), "str2: wrong content"); + WSNamespace ns1; + WSNamespace ns2; + WSNamespace ns3; + memset(&ns1, 0, sizeof(WSNamespace)); + memset(&ns2, 0, sizeof(WSNamespace)); + memset(&ns3, 0, sizeof(WSNamespace)); + ns1.prefix = (const xmlChar*)"x"; + ns1.href = (const xmlChar*)"ns1"; + ns2.prefix = (const xmlChar*)"y"; + ns2.href = (const xmlChar*)"ns2"; + ns3.prefix = (const xmlChar*)"z"; + ns3.href = (const xmlChar*)"ns3"; + + WebdavNSList elm1 = { &ns1, NULL, NULL }; + WebdavNSList elm2 = { &ns2, NULL, NULL }; + WebdavNSList elm3 = { &ns3, NULL, NULL }; + + // single elm test + char *str1 = wsxml_nslist2string(sn->pool, &elm1); + CX_TEST_ASSERT(str1); + CX_TEST_ASSERT(!strcmp(str1, "x:ns1")); + + // 2 elm test + elm1.next = &elm2; + char *str2 = wsxml_nslist2string(sn->pool, &elm1); + CX_TEST_ASSERT(str2); + CX_TEST_ASSERT(!strcmp(str2, "x:ns1\ny:ns2")); + + // 3 elm test + elm2.next = &elm3; + char *str3 = wsxml_nslist2string(sn->pool, &elm1); + CX_TEST_ASSERT(str3); + CX_TEST_ASSERT(!strcmp(str3, "x:ns1\ny:ns2\nz:ns3")); + + // empty prefix test + ns1.prefix = NULL; + char *str4 = wsxml_nslist2string(sn->pool, &elm1); + CX_TEST_ASSERT(str4); + CX_TEST_ASSERT(!strcmp(str4, ":ns1\ny:ns2\nz:ns3")); - // 3 elm test - elm2.next = &elm3; - char *str3 = wsxml_nslist2string(sn->pool, &elm1); - UCX_TEST_ASSERT(str3, "str3 is null"); - UCX_TEST_ASSERT(!strcmp(str3, "x:ns1\ny:ns2\nz:ns3"), "str3: wrong content"); - - // empty prefix test - ns1.prefix = NULL; - char *str4 = wsxml_nslist2string(sn->pool, &elm1); - UCX_TEST_ASSERT(str4, "str3 is null"); - UCX_TEST_ASSERT(!strcmp(str4, ":ns1\ny:ns2\nz:ns3"), "str4: wrong content"); - - UCX_TEST_END; + } testutil_destroy_session(sn); } -UCX_TEST(test_wsxml_string2nslist) { +CX_TEST(test_wsxml_string2nslist) { Session *sn = testutil_session(); - UCX_TEST_BEGIN; - - // empty list - WebdavNSList *list1 = wsxml_string2nslist(sn->pool, ""); - UCX_TEST_ASSERT(!list1, "list1 should be NULL"); - - // 1 elm list - WebdavNSList *list2 = wsxml_string2nslist(sn->pool, "x:ns1"); - UCX_TEST_ASSERT(list2, "list2 is NULL"); - UCX_TEST_ASSERT(list2->namespace, "list2 namespace is NULL"); - UCX_TEST_ASSERT(!strcmp((const char*)list2->namespace->prefix, "x"), "list2: wrong prefix"); - UCX_TEST_ASSERT(!strcmp((const char*)list2->namespace->href, "ns1"), "list2: wrong href"); + CX_TEST_DO { - // 2 elm list - WebdavNSList *list3 = wsxml_string2nslist(sn->pool, "x:ns1\ny:ns2"); - UCX_TEST_ASSERT(list3, "list3 is NULL"); - UCX_TEST_ASSERT(list3->namespace, "list3 namespace is NULL"); - UCX_TEST_ASSERT(!strcmp((const char*)list3->namespace->prefix, "x"), "list3: wrong prefix"); - UCX_TEST_ASSERT(!strcmp((const char*)list3->namespace->href, "ns1"), "list3: wrong href"); - UCX_TEST_ASSERT(list3->next, "list3 elm2 is NULL"); - UCX_TEST_ASSERT(list3->next->namespace, "list3 namespace 2 is NULL"); - UCX_TEST_ASSERT(!strcmp((const char*)list3->namespace->prefix, "x"), "list3: elm2 wrong prefix"); - UCX_TEST_ASSERT(!strcmp((const char*)list3->namespace->href, "ns1"), "list3: elm2 wrong href"); - - // empty prefix - WebdavNSList *list4 = wsxml_string2nslist(sn->pool, ":x\ny:ns2"); - UCX_TEST_ASSERT(list4, "list4 is NULL"); - UCX_TEST_ASSERT(list4->namespace, "list4 namespace is NULL"); - UCX_TEST_ASSERT(!list4->namespace->prefix, "list4 elm1 prefix should be NULL"); - UCX_TEST_ASSERT(!strcmp((const char*)list3->namespace->href, "ns1"), "list3: wrong href"); + // empty list + WebdavNSList *list1 = wsxml_string2nslist(sn->pool, ""); + CX_TEST_ASSERT(!list1); + + // 1 elm list + WebdavNSList *list2 = wsxml_string2nslist(sn->pool, "x:ns1"); + CX_TEST_ASSERT(list2); + CX_TEST_ASSERT(list2->namespace); + CX_TEST_ASSERT(!strcmp((const char*)list2->namespace->prefix, "x")); + CX_TEST_ASSERT(!strcmp((const char*)list2->namespace->href, "ns1")); + + // 2 elm list + WebdavNSList *list3 = wsxml_string2nslist(sn->pool, "x:ns1\ny:ns2"); + CX_TEST_ASSERT(list3); + CX_TEST_ASSERT(list3->namespace); + CX_TEST_ASSERT(!strcmp((const char*)list3->namespace->prefix, "x")); + CX_TEST_ASSERT(!strcmp((const char*)list3->namespace->href, "ns1")); + CX_TEST_ASSERT(list3->next); + CX_TEST_ASSERT(list3->next->namespace); + CX_TEST_ASSERT(!strcmp((const char*)list3->namespace->prefix, "x")); + CX_TEST_ASSERT(!strcmp((const char*)list3->namespace->href, "ns1")); + + // empty prefix + WebdavNSList *list4 = wsxml_string2nslist(sn->pool, ":x\ny:ns2"); + CX_TEST_ASSERT(list4); + CX_TEST_ASSERT(list4->namespace); + CX_TEST_ASSERT(!list4->namespace->prefix); + CX_TEST_ASSERT(!strcmp((const char*)list3->namespace->href, "ns1")); - UCX_TEST_END; + } testutil_destroy_session(sn); }
--- a/src/server/test/xml.h Sat Nov 22 12:49:20 2025 +0100 +++ b/src/server/test/xml.h Sat Nov 22 14:27:01 2025 +0100 @@ -36,11 +36,11 @@ extern "C" { #endif -UCX_TEST(test_wsxml_iterator); -UCX_TEST(test_wsxml_get_required_namespaces); -UCX_TEST(test_wsxml_write_nodes); -UCX_TEST(test_wsxml_nslist2string); -UCX_TEST(test_wsxml_string2nslist); +CX_TEST(test_wsxml_iterator); +CX_TEST(test_wsxml_get_required_namespaces); +CX_TEST(test_wsxml_write_nodes); +CX_TEST(test_wsxml_nslist2string); +CX_TEST(test_wsxml_string2nslist); #define XML_TESTDATA1 "<?xml version=\"1.0\" encoding=\"utf-8\" ?> \