You've already forked pg_probackup
mirror of
https://github.com/postgrespro/pg_probackup.git
synced 2026-06-21 01:34:15 +02:00
PBCKP-80 More unit test improvements
This commit is contained in:
committed by
Yura Sokolov
parent
7365f24bc5
commit
f61171c12e
+2
-2
@@ -43,7 +43,7 @@ clean_basic_suite()
|
||||
#define FNAMES "abcdefghijklmnopqrstuvwxyz0123456789"
|
||||
|
||||
static int rand_init=0;
|
||||
char *
|
||||
ft_str_t
|
||||
random_path(void)
|
||||
{
|
||||
char name[MAXPGPATH];
|
||||
@@ -65,7 +65,7 @@ random_path(void)
|
||||
}
|
||||
name[i] = 0;
|
||||
|
||||
return strdup(name);
|
||||
return ft_strdupc(name);
|
||||
}
|
||||
|
||||
char *
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ extern int should_be_remote;
|
||||
|
||||
void init_test_drives(void);
|
||||
int USE_LOCAL(void);
|
||||
char *random_path(void);
|
||||
ft_str_t random_path(void);
|
||||
char *random_name(void);
|
||||
void pbk_add_tests(int (*init)(void), const char *sub_name, PBK_test_description *tests);
|
||||
void pio_write(pioDrive_i drive, path_t name, const char *data);
|
||||
|
||||
+323
-103
@@ -20,13 +20,13 @@ test_pioStat()
|
||||
{
|
||||
FOBJ_FUNC_ARP();
|
||||
err_i err = $noerr();
|
||||
char *path = random_path();
|
||||
ft_str_t path = random_path();
|
||||
|
||||
err = $i(pioWriteFile, drive, .path = path, .content = ft_bytes(TEST_STR, strlen(TEST_STR)), .binary = true);
|
||||
err = $i(pioWriteFile, drive, .path = path.ptr, .content = ft_bytes(TEST_STR, strlen(TEST_STR)), .binary = true);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
time_t now = time(NULL);
|
||||
|
||||
pio_stat_t pst = $i(pioStat, drive, .path = path, .follow_symlink = false, .err = &err);
|
||||
pio_stat_t pst = $i(pioStat, drive, .path = path.ptr, .follow_symlink = false, .err = &err);
|
||||
|
||||
CU_ASSERT(!$haserr(err));
|
||||
|
||||
@@ -34,6 +34,8 @@ test_pioStat()
|
||||
CU_ASSERT(pst.pst_mode == FILE_PERMISSION);
|
||||
CU_ASSERT(abs(now-pst.pst_mtime) < 2);
|
||||
CU_ASSERT(pst.pst_size == 5);
|
||||
|
||||
ft_str_free(&path);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -41,33 +43,17 @@ test_pioRemove()
|
||||
{
|
||||
FOBJ_FUNC_ARP();
|
||||
|
||||
char *path = random_path();
|
||||
pio_write(drive, path, TEST_STR);
|
||||
CU_ASSERT(pio_exists(drive, path));
|
||||
ft_str_t path = random_path();
|
||||
pio_write(drive, path.ptr, TEST_STR);
|
||||
CU_ASSERT(pio_exists(drive, path.ptr));
|
||||
|
||||
err_i err = $i(pioRemove, drive, .path = path, .missing_ok = false);
|
||||
err_i err = $i(pioRemove, drive, .path = path.ptr, .missing_ok = false);
|
||||
|
||||
CU_ASSERT(!$haserr(err));
|
||||
|
||||
CU_ASSERT(!pio_exists(drive, path));
|
||||
}
|
||||
CU_ASSERT(!pio_exists(drive, path.ptr));
|
||||
|
||||
static void
|
||||
test_pioRename()
|
||||
{
|
||||
FOBJ_FUNC_ARP();
|
||||
|
||||
char *name = random_path();
|
||||
char *another_name = random_path();
|
||||
|
||||
pio_write(drive, name, TEST_STR);
|
||||
CU_ASSERT(pio_exists(drive, name));
|
||||
|
||||
err_i err = $i(pioRename, dbdrive, .old_path = name, .new_path = another_name);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
|
||||
CU_ASSERT(!pio_exists(drive, name));
|
||||
CU_ASSERT(pio_exists(drive, another_name));
|
||||
ft_str_free(&path);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -80,17 +66,20 @@ test_pioExists()
|
||||
CU_ASSERT(!$haserr(err));
|
||||
CU_ASSERT(exists);
|
||||
|
||||
const char *path = random_path();
|
||||
ft_str_t path = random_path();
|
||||
err = $noerr();
|
||||
exists = $i(pioExists, drive, .path = path, .expected_kind = PIO_KIND_REGULAR, &err);
|
||||
exists = $i(pioExists, drive, .path = path.ptr, .expected_kind = PIO_KIND_REGULAR, &err);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
CU_ASSERT(!exists);
|
||||
|
||||
char *name = random_path();
|
||||
pio_write(drive, name, TEST_STR);
|
||||
exists = $i(pioExists, drive, .path = name, .expected_kind = PIO_KIND_REGULAR, &err);
|
||||
ft_str_t name = random_path();
|
||||
pio_write(drive, name.ptr, TEST_STR);
|
||||
exists = $i(pioExists, drive, .path = name.ptr, .expected_kind = PIO_KIND_REGULAR, &err);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
CU_ASSERT(exists);
|
||||
|
||||
ft_str_free(&path);
|
||||
ft_str_free(&name);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -111,23 +100,22 @@ test_pioWriteFile()
|
||||
FOBJ_FUNC_ARP();
|
||||
|
||||
err_i err = $noerr();
|
||||
char *path = random_path();
|
||||
ft_str_t path = random_path();
|
||||
|
||||
CU_ASSERT(!pio_exists(drive, path));
|
||||
CU_ASSERT(!pio_exists(drive, path.ptr));
|
||||
|
||||
err = $i(pioWriteFile, drive, .path = path, .content = ft_bytes(TEST_STR, strlen(TEST_STR)), .binary = true);
|
||||
err = $i(pioWriteFile, drive, .path = path.ptr, .content = ft_bytes(TEST_STR, strlen(TEST_STR)), .binary = true);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
|
||||
CU_ASSERT(pio_exists(drive, path));
|
||||
CU_ASSERT(pio_exists(drive, path.ptr));
|
||||
|
||||
ft_bytes_t result = $i(pioReadFile, drive, .path = path, .binary = true, &err);
|
||||
ft_bytes_t result = $i(pioReadFile, drive, .path = path.ptr, .binary = true, &err);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
CU_ASSERT(result.len==strlen(TEST_STR));
|
||||
CU_ASSERT(!strncmp(result.ptr, TEST_STR, strlen(TEST_STR)));
|
||||
|
||||
ft_bytes_free(&result);
|
||||
|
||||
free(path);
|
||||
ft_str_free(&path);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -135,12 +123,12 @@ test_pioOpenRead()
|
||||
{
|
||||
FOBJ_FUNC_ARP();
|
||||
err_i err = $noerr();
|
||||
char *path = random_path();
|
||||
pio_write(drive, path, TEST_STR);
|
||||
ft_str_t path = random_path();
|
||||
pio_write(drive, path.ptr, TEST_STR);
|
||||
|
||||
CU_ASSERT(pio_exists(drive, path));
|
||||
CU_ASSERT(pio_exists(drive, path.ptr));
|
||||
|
||||
pioReader_i reader = $i(pioOpenRead, drive, .path = path, &err);
|
||||
pioReader_i reader = $i(pioOpenRead, drive, .path = path.ptr, &err);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
char B0[8192];
|
||||
ft_bytes_t buf = ft_bytes(B0, 8192);
|
||||
@@ -159,24 +147,25 @@ test_pioOpenRead()
|
||||
|
||||
//ft_bytes_free(&result);
|
||||
|
||||
free(path);
|
||||
ft_str_free(&path);
|
||||
}
|
||||
|
||||
static void
|
||||
test_pioOpenReadStream()
|
||||
{
|
||||
// return enoent for non existent file. same for pioStat
|
||||
FOBJ_FUNC_ARP();
|
||||
err_i err = $noerr();
|
||||
char *path = random_path();
|
||||
ft_str_t path = random_path();
|
||||
|
||||
pioReadStream_i stream;
|
||||
/* Crash in pioCloudDrive */
|
||||
stream = $i(pioOpenReadStream, drive, .path = path, &err);
|
||||
stream = $i(pioOpenReadStream, drive, .path = path.ptr, &err);
|
||||
CU_ASSERT($haserr(err));
|
||||
|
||||
pio_write(drive, path, TEST_STR);
|
||||
pio_write(drive, path.ptr, TEST_STR);
|
||||
|
||||
stream = $i(pioOpenReadStream, drive, .path = path, &err);
|
||||
stream = $i(pioOpenReadStream, drive, .path = path.ptr, &err);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
|
||||
char B0[8192];
|
||||
@@ -186,7 +175,7 @@ test_pioOpenReadStream()
|
||||
CU_ASSERT(ret==strlen(TEST_STR));
|
||||
CU_ASSERT(!strncmp(buf.ptr, TEST_STR, strlen(TEST_STR)));
|
||||
$i(pioClose, stream);
|
||||
free(path);
|
||||
ft_str_free(&path);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -194,16 +183,16 @@ test_pioGetCRC32()
|
||||
{
|
||||
FOBJ_FUNC_ARP();
|
||||
err_i err = $noerr();
|
||||
char *path = random_path();
|
||||
ft_str_t path = random_path();
|
||||
pg_crc32 crc;
|
||||
|
||||
#if 0
|
||||
//crashes. should return errno in err
|
||||
crc = $i(pioGetCRC32, drive, .path = path, .compressed = false, .err = &err);
|
||||
crc = $i(pioGetCRC32, drive, .path = path.ptr, .compressed = false, .err = &err);
|
||||
CU_ASSERT($haserr(err));
|
||||
#endif
|
||||
pio_write(drive, path, TEST_STR);
|
||||
crc = $i(pioGetCRC32, drive, .path = path, .compressed = false, .err = &err);
|
||||
pio_write(drive, path.ptr, TEST_STR);
|
||||
crc = $i(pioGetCRC32, drive, .path = path.ptr, .compressed = false, .err = &err);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
CU_ASSERT(crc==0xFA94FDDF)
|
||||
}
|
||||
@@ -214,13 +203,13 @@ test_pioMakeDir()
|
||||
{
|
||||
FOBJ_FUNC_ARP();
|
||||
|
||||
char *path = random_path();
|
||||
ft_str_t path = random_path();
|
||||
|
||||
CU_ASSERT(!pio_exists(drive, path));
|
||||
err_i err = $i(pioMakeDir, drive, .path = path, .mode = DIR_PERMISSION, .strict = true);
|
||||
CU_ASSERT(!pio_exists(drive, path.ptr));
|
||||
err_i err = $i(pioMakeDir, drive, .path = path.ptr, .mode = DIR_PERMISSION, .strict = true);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
|
||||
CU_ASSERT(pio_exists_d(drive, path));
|
||||
CU_ASSERT(pio_exists_d(drive, path.ptr));
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -228,38 +217,214 @@ test_pioMakeDirWithParent()
|
||||
{
|
||||
FOBJ_FUNC_ARP();
|
||||
char child[MAXPGPATH];
|
||||
char *parent = random_path();
|
||||
CU_ASSERT(!pio_exists(drive, parent));
|
||||
snprintf(child, MAXPGPATH, "%s/TEST", parent);
|
||||
ft_str_t parent = random_path();
|
||||
CU_ASSERT(!pio_exists(drive, parent.ptr));
|
||||
snprintf(child, MAXPGPATH, "%s/TEST", parent.ptr);
|
||||
|
||||
err_i err = $i(pioMakeDir, drive, .path = child, .mode = DIR_PERMISSION, .strict = true);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
CU_ASSERT(pio_exists_d(drive, parent));
|
||||
CU_ASSERT(pio_exists_d(drive, parent.ptr));
|
||||
CU_ASSERT(pio_exists_d(drive, child));
|
||||
|
||||
free(parent);
|
||||
ft_str_free(&parent);
|
||||
}
|
||||
|
||||
static void
|
||||
test_pioListDirCanWithSlash()
|
||||
{
|
||||
FOBJ_FUNC_ARP();
|
||||
err_i err = $noerr();
|
||||
ft_str_t root = random_path();
|
||||
ft_str_t slash = ft_asprintf("%s/", root.ptr);
|
||||
ft_str_t child = ft_asprintf("%s/sample.txt", root.ptr);
|
||||
|
||||
CU_ASSERT(!pio_exists(drive, root.ptr));
|
||||
err = $i(pioMakeDir, drive, .path = root.ptr, .mode = DIR_PERMISSION, .strict = true);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
CU_ASSERT(pio_exists_d(drive, root.ptr));
|
||||
|
||||
err = $i(pioWriteFile, drive, .path = child.ptr, .content = ft_bytes(TEST_STR, strlen(TEST_STR)), .binary = true);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
|
||||
pioDirIter_i dir = $i(pioOpenDir, drive, .path = slash.ptr, .err = &err);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
|
||||
int count = 0;
|
||||
while (true)
|
||||
{
|
||||
pio_dirent_t entry = $i(pioDirNext, dir, &err);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
if (entry.stat.pst_kind == PIO_KIND_UNKNOWN) break;
|
||||
CU_ASSERT(ft_strcmp(entry.name, ft_cstr("sample.txt")) == FT_CMP_EQ);
|
||||
count++;
|
||||
}
|
||||
CU_ASSERT(count == 1);
|
||||
err = $i(pioClose, dir);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
|
||||
ft_str_free(&root);
|
||||
ft_str_free(&slash);
|
||||
ft_str_free(&child);
|
||||
}
|
||||
|
||||
static void
|
||||
test_pioListDir()
|
||||
{
|
||||
FOBJ_FUNC_ARP();
|
||||
ft_str_t root = random_path();
|
||||
ft_str_t child = ft_asprintf("%s/sample.txt", root.ptr);
|
||||
ft_str_t sub_dir = ft_asprintf("%s/subdir", root.ptr);
|
||||
ft_str_t sub_child = ft_asprintf("%s/subdir/xxx.txt", root.ptr);
|
||||
err_i err = $noerr();
|
||||
int i;
|
||||
|
||||
CU_ASSERT(!pio_exists(drive, root.ptr));
|
||||
err = $i(pioMakeDir, drive, .path = root.ptr, .mode = DIR_PERMISSION, .strict = true);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
CU_ASSERT(pio_exists_d(drive, root.ptr));
|
||||
|
||||
err = $i(pioWriteFile, drive, .path = child.ptr, .content = ft_bytes(TEST_STR, strlen(TEST_STR)), .binary = true);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
|
||||
err = $i(pioMakeDir, drive, .path = sub_dir.ptr, .mode = DIR_PERMISSION, .strict = true);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
|
||||
err = $i(pioWriteFile, drive, .path = sub_child.ptr, .content = ft_bytes(TEST_STR, strlen(TEST_STR)), .binary = true);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
|
||||
pioDirIter_i dir = $i(pioOpenDir, drive, .path = root.ptr, .err = &err);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
|
||||
#define NUM_EXPECTED 2
|
||||
const char *expected[NUM_EXPECTED] = {"sample.txt", "subdir"};
|
||||
int count = 0;
|
||||
for (count = 0; true; count++)
|
||||
{
|
||||
pio_dirent_t entry = $i(pioDirNext, dir, &err);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
|
||||
if (entry.stat.pst_kind == PIO_KIND_UNKNOWN) break;
|
||||
|
||||
for(i = 0; i < NUM_EXPECTED; ++i)
|
||||
{
|
||||
if(ft_strcmp(entry.name, ft_cstr(expected[i])) != FT_CMP_EQ)
|
||||
continue;
|
||||
expected[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
for(i = 0; i < NUM_EXPECTED; ++i)
|
||||
{
|
||||
CU_ASSERT(expected[i] == NULL);
|
||||
}
|
||||
|
||||
CU_ASSERT(count == NUM_EXPECTED);
|
||||
|
||||
err = $i(pioClose, dir);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
|
||||
dir = $i(pioOpenDir, drive, .path = sub_dir.ptr, .err = &err);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
|
||||
count = 0;
|
||||
for (count = 0; true; count++)
|
||||
{
|
||||
pio_dirent_t entry = $i(pioDirNext, dir, &err);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
|
||||
if (entry.stat.pst_kind == PIO_KIND_UNKNOWN) break;
|
||||
|
||||
CU_ASSERT(ft_strcmp(entry.name, ft_cstr("xxx.txt")) == FT_CMP_EQ);
|
||||
}
|
||||
|
||||
for(i = 0; i < NUM_EXPECTED; ++i)
|
||||
{
|
||||
CU_ASSERT(expected[i] == NULL);
|
||||
}
|
||||
|
||||
CU_ASSERT(count == 1);
|
||||
|
||||
err = $i(pioClose, dir);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
|
||||
#undef NUM_EXPECTED
|
||||
}
|
||||
|
||||
static void
|
||||
test_pioListDirMTimeAndSize()
|
||||
{
|
||||
FOBJ_FUNC_ARP();
|
||||
ft_str_t root = random_path();
|
||||
ft_str_t child = ft_asprintf("%s/sample.txt", root.ptr);
|
||||
err_i err = $noerr();
|
||||
int i;
|
||||
|
||||
CU_ASSERT(!pio_exists(drive, root.ptr));
|
||||
err = $i(pioMakeDir, drive, .path = root.ptr, .mode = DIR_PERMISSION, .strict = true);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
CU_ASSERT(pio_exists_d(drive, root.ptr));
|
||||
|
||||
err = $i(pioWriteFile, drive, .path = child.ptr, .content = ft_bytes(TEST_STR, strlen(TEST_STR)), .binary = true);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
time_t created = time(NULL);
|
||||
|
||||
pioDirIter_i dir = $i(pioOpenDir, drive, .path = root.ptr, .err = &err);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
|
||||
#define NUM_EXPECTED 1
|
||||
const char *expected[NUM_EXPECTED] = {"sample.txt"};
|
||||
int count = 0;
|
||||
for (count = 0; true; count++)
|
||||
{
|
||||
pio_dirent_t entry = $i(pioDirNext, dir, &err);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
|
||||
if (entry.stat.pst_kind == PIO_KIND_UNKNOWN) break;
|
||||
|
||||
printf("XXX mtime=%ld, size=%ld created=%ld diff=%d\n", entry.stat.pst_mtime, entry.stat.pst_size, created, (int)created-(int)entry.stat.pst_mtime);
|
||||
CU_ASSERT(entry.stat.pst_mtime == created);
|
||||
//CU_ASSERT(entry.stat.pst_mtime == (created+3600*3));
|
||||
CU_ASSERT(entry.stat.pst_size == strlen(TEST_STR));
|
||||
|
||||
for(i = 0; i < NUM_EXPECTED; ++i)
|
||||
{
|
||||
if(ft_strcmp(entry.name, ft_cstr(expected[i])) != FT_CMP_EQ)
|
||||
continue;
|
||||
expected[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
for(i = 0; i < NUM_EXPECTED; ++i)
|
||||
{
|
||||
CU_ASSERT(expected[i] == NULL);
|
||||
}
|
||||
|
||||
CU_ASSERT(count == NUM_EXPECTED);
|
||||
|
||||
err = $i(pioClose, dir);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
}
|
||||
|
||||
static void
|
||||
test_pioRemoveDir()
|
||||
{
|
||||
FOBJ_FUNC_ARP();
|
||||
char *path = random_path();
|
||||
ft_str_t path = random_path();
|
||||
err_i err = $noerr();
|
||||
char path2[8192];
|
||||
snprintf(path2, 8192, "%s/%s", path, "sample.txt");
|
||||
snprintf(path2, 8192, "%s/%s", path.ptr, "sample.txt");
|
||||
|
||||
CU_ASSERT(!pio_exists(drive, path));
|
||||
err = $i(pioMakeDir, drive, .path = path, .mode = DIR_PERMISSION, .strict = true);
|
||||
CU_ASSERT(!pio_exists(drive, path.ptr));
|
||||
err = $i(pioMakeDir, drive, .path = path.ptr, .mode = DIR_PERMISSION, .strict = true);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
CU_ASSERT(pio_exists_d(drive, path));
|
||||
CU_ASSERT(pio_exists_d(drive, path.ptr));
|
||||
|
||||
err = $i(pioWriteFile, drive, .path = path2, .content = ft_bytes(TEST_STR, strlen(TEST_STR)), .binary = true);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
CU_ASSERT(pio_exists(drive, path2));
|
||||
$i(pioRemoveDir, drive, path, .root_as_well=false);
|
||||
$i(pioRemoveDir, drive, path.ptr, .root_as_well=false);
|
||||
CU_ASSERT(!pio_exists(drive, path2));
|
||||
CU_ASSERT(pio_exists_d(drive, path));
|
||||
CU_ASSERT(pio_exists_d(drive, path.ptr));
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -268,26 +433,26 @@ test_pioFilesAreSame()
|
||||
FOBJ_FUNC_ARP();
|
||||
|
||||
err_i err = $noerr();
|
||||
char *path1 = random_path();
|
||||
char *path2 = random_path();
|
||||
ft_str_t path1 = random_path();
|
||||
ft_str_t path2 = random_path();
|
||||
|
||||
CU_ASSERT(!pio_exists(drive, path1));
|
||||
CU_ASSERT(!pio_exists(drive, path2));
|
||||
CU_ASSERT(!pio_exists(drive, path1.ptr));
|
||||
CU_ASSERT(!pio_exists(drive, path2.ptr));
|
||||
|
||||
err = $i(pioWriteFile, drive, .path = path1, .content = ft_bytes(TEST_STR, strlen(TEST_STR)), .binary = true);
|
||||
err = $i(pioWriteFile, drive, .path = path1.ptr, .content = ft_bytes(TEST_STR, strlen(TEST_STR)), .binary = true);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
CU_ASSERT(pio_exists(drive, path1));
|
||||
CU_ASSERT(pio_exists(drive, path1.ptr));
|
||||
|
||||
err = $i(pioWriteFile, drive, .path = path2, .content = ft_bytes(TEST_STR, strlen(TEST_STR)), .binary = true);
|
||||
err = $i(pioWriteFile, drive, .path = path2.ptr, .content = ft_bytes(TEST_STR, strlen(TEST_STR)), .binary = true);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
CU_ASSERT(pio_exists(drive, path2));
|
||||
CU_ASSERT(pio_exists(drive, path2.ptr));
|
||||
|
||||
ft_bytes_t result1 = $i(pioReadFile, drive, .path = path1, .binary = true, &err);
|
||||
ft_bytes_t result1 = $i(pioReadFile, drive, .path = path1.ptr, .binary = true, &err);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
CU_ASSERT(result1.len==strlen(TEST_STR));
|
||||
CU_ASSERT(!strncmp(result1.ptr, TEST_STR, strlen(TEST_STR)));
|
||||
|
||||
ft_bytes_t result2 = $i(pioReadFile, drive, .path = path2, .binary = true, &err);
|
||||
ft_bytes_t result2 = $i(pioReadFile, drive, .path = path2.ptr, .binary = true, &err);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
CU_ASSERT(result2.len==strlen(TEST_STR));
|
||||
CU_ASSERT(!strncmp(result2.ptr, TEST_STR, strlen(TEST_STR)));
|
||||
@@ -298,8 +463,8 @@ test_pioFilesAreSame()
|
||||
ft_bytes_free(&result1);
|
||||
ft_bytes_free(&result2);
|
||||
|
||||
free(path1);
|
||||
free(path2);
|
||||
ft_str_free(&path1);
|
||||
ft_str_free(&path2);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -308,23 +473,23 @@ test_pioReadFile()
|
||||
FOBJ_FUNC_ARP();
|
||||
|
||||
err_i err = $noerr();
|
||||
char *path = random_path();
|
||||
ft_str_t path = random_path();
|
||||
|
||||
CU_ASSERT(!pio_exists(drive, path));
|
||||
CU_ASSERT(!pio_exists(drive, path.ptr));
|
||||
|
||||
err = $i(pioWriteFile, drive, .path = path, .content = ft_bytes(TEST_STR, strlen(TEST_STR)), .binary = true);
|
||||
err = $i(pioWriteFile, drive, .path = path.ptr, .content = ft_bytes(TEST_STR, strlen(TEST_STR)), .binary = true);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
|
||||
CU_ASSERT(pio_exists(drive, path));
|
||||
CU_ASSERT(pio_exists(drive, path.ptr));
|
||||
|
||||
ft_bytes_t result = $i(pioReadFile, drive, .path = path, .binary = true, &err);
|
||||
ft_bytes_t result = $i(pioReadFile, drive, .path = path.ptr, .binary = true, &err);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
CU_ASSERT(result.len==strlen(TEST_STR));
|
||||
CU_ASSERT(!strncmp(result.ptr, TEST_STR, strlen(TEST_STR)));
|
||||
|
||||
ft_bytes_free(&result);
|
||||
|
||||
free(path);
|
||||
ft_str_free(&path);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -332,12 +497,12 @@ test_pioOpenRewrite()
|
||||
{
|
||||
FOBJ_FUNC_ARP();
|
||||
err_i err = $noerr();
|
||||
char *path = random_path();
|
||||
pio_write(drive, path, TEST_STR);
|
||||
ft_str_t path = random_path();
|
||||
pio_write(drive, path.ptr, TEST_STR);
|
||||
|
||||
CU_ASSERT(pio_exists(drive, path));
|
||||
CU_ASSERT(pio_exists(drive, path.ptr));
|
||||
|
||||
pioWriteCloser_i writer = $i(pioOpenRewrite, drive, .path = path,
|
||||
pioWriteCloser_i writer = $i(pioOpenRewrite, drive, .path = path.ptr,
|
||||
.permissions = FILE_PERMISSION, .binary = true,
|
||||
.use_temp=true, .sync = true, .err = &err);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
@@ -348,34 +513,89 @@ test_pioOpenRewrite()
|
||||
CU_ASSERT(!$haserr(err));
|
||||
$i(pioClose, writer);
|
||||
|
||||
ft_bytes_t result = $i(pioReadFile, drive, .path = path, .binary = true, &err);
|
||||
ft_bytes_t result = $i(pioReadFile, drive, .path = path.ptr, .binary = true, &err);
|
||||
CU_ASSERT(strlen(XXX_STR) == result.len);
|
||||
CU_ASSERT(!memcmp(XXX_STR, result.ptr, result.len));
|
||||
ft_bytes_free(&result);
|
||||
|
||||
free(path);
|
||||
ft_str_free(&path);
|
||||
}
|
||||
|
||||
static void
|
||||
test_pioSeek()
|
||||
{
|
||||
FOBJ_FUNC_ARP();
|
||||
err_i err = $noerr();
|
||||
ft_str_t path = random_path();
|
||||
pioWriteCloser_i writer = $i(pioOpenRewrite, drive, .path = path.ptr,
|
||||
.permissions = FILE_PERMISSION, .binary = true,
|
||||
.use_temp=true, .sync = true, .err = &err);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
char B0[8192];
|
||||
snprintf(B0, 8192, "012345678901234567890123012345678901234567890123");
|
||||
ft_bytes_t buf = ft_bytes(B0, strlen(B0));
|
||||
err = $i(pioWrite, writer, .buf = buf);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
$i(pioClose, writer);
|
||||
|
||||
pioReader_i reader = $i(pioOpenRead, drive, .path = path.ptr, &err);
|
||||
CU_ASSERT (!$haserr(err));
|
||||
|
||||
#define TRY_OFFT 1
|
||||
#define TRY_LEN 24
|
||||
err = $i(pioSeek, reader, TRY_OFFT);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
|
||||
ft_bytes_t read_buf = ft_bytes_alloc(TRY_LEN);
|
||||
size_t rc = $i(pioRead, reader, .buf = read_buf, .err = &err);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
CU_ASSERT(rc == TRY_LEN);
|
||||
CU_ASSERT(!memcmp(B0+TRY_OFFT, read_buf.ptr, TRY_LEN));
|
||||
}
|
||||
|
||||
/* pioDBDrive */
|
||||
static void
|
||||
test_pioRename()
|
||||
{
|
||||
FOBJ_FUNC_ARP();
|
||||
pioDBDrive_i db_drive = pioDBDriveForLocation(FIO_LOCAL_HOST);
|
||||
ft_str_t name = random_path();
|
||||
ft_str_t another_name = random_path();
|
||||
|
||||
pio_write(drive, name.ptr, TEST_STR);
|
||||
CU_ASSERT(pio_exists(drive, name.ptr));
|
||||
|
||||
err_i err = $i(pioRename, db_drive, .old_path = name.ptr, .new_path = another_name.ptr);
|
||||
CU_ASSERT(!$haserr(err));
|
||||
|
||||
CU_ASSERT(!pio_exists(drive, name.ptr));
|
||||
CU_ASSERT(pio_exists(drive, another_name.ptr));
|
||||
}
|
||||
|
||||
PBK_test_description PIO_DRIVE_TESTS[] = {
|
||||
{"Test pioOpenRead", test_pioOpenRead},
|
||||
{"Test pioOpenRead", test_pioOpenRead},
|
||||
{"Test pioOpenReadStream", test_pioOpenReadStream},
|
||||
{"Test pioStat", test_pioStat},
|
||||
{"Test pioRemove", test_pioRemove},
|
||||
{"Test pioRename", test_pioRename},
|
||||
{"Test pioExists", test_pioExists},
|
||||
{"Test pioGetCRC32", test_pioGetCRC32},
|
||||
{"Test pioIsRemote", test_pioIsRemote},
|
||||
{"Test pioMakeDir", test_pioMakeDir},
|
||||
{"Test pioStat", test_pioStat},
|
||||
{"Test pioRemove", test_pioRemove},
|
||||
{"Test pioExists", test_pioExists},
|
||||
{"Test pioGetCRC32", test_pioGetCRC32},
|
||||
{"Test pioIsRemote", test_pioIsRemote},
|
||||
{"Test pioMakeDir", test_pioMakeDir},
|
||||
{"Test pioMakeDirWithParent", test_pioMakeDirWithParent},
|
||||
{"Test pioRemoveDir", test_pioRemoveDir},
|
||||
{"Test pioListDir", test_pioListDir},
|
||||
{"Test pioListDirCanWithSlash", test_pioListDirCanWithSlash},
|
||||
{"Test pioListDirMTimeAndSize", test_pioListDirMTimeAndSize},
|
||||
{"Test pioRemoveDir", test_pioRemoveDir},
|
||||
{"Test pioFilesAreSame", test_pioFilesAreSame},
|
||||
{"Test pioReadFile", test_pioReadFile},
|
||||
{"Test pioWriteFile", test_pioWriteFile},
|
||||
{"Test pioOpenRewrite", test_pioOpenRewrite},
|
||||
{"Test pioReadFile", test_pioReadFile},
|
||||
{"Test pioWriteFile", test_pioWriteFile},
|
||||
{"Test pioOpenRewrite", test_pioOpenRewrite},
|
||||
{"Test pioSeek", test_pioSeek},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
PBK_test_description PIO_DB_DRIVE_TESTS[] = {
|
||||
{"Test pioRename", test_pioRename},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
|
||||
+11
-10
@@ -14,33 +14,34 @@ static void
|
||||
test_do_init()
|
||||
{
|
||||
FOBJ_FUNC_ARP();
|
||||
char *backup_path = random_path();
|
||||
ft_str_t backup_path = random_path();
|
||||
CatalogState *catalogState = catalog_new(backup_path.ptr);
|
||||
int rc;
|
||||
|
||||
CatalogState *catalogState = catalog_new(backup_path);
|
||||
rc = do_init(catalogState);
|
||||
|
||||
int rc = do_init(catalogState);
|
||||
CU_ASSERT(rc == 0);
|
||||
}
|
||||
|
||||
static void
|
||||
test_do_add_instance()
|
||||
{
|
||||
//FOBJ_FUNC_ARP();
|
||||
FOBJ_FUNC_ARP();
|
||||
int rc;
|
||||
char *backup_path = random_path();
|
||||
ft_str_t backup_path = random_path();
|
||||
char *instance_name = random_name();
|
||||
char *server_path = random_path();
|
||||
init_fake_server(server_path);
|
||||
ft_str_t server_path = random_path();
|
||||
init_fake_server(server_path.ptr);
|
||||
|
||||
CatalogState *catalogState = catalog_new(backup_path);
|
||||
CatalogState *catalogState = catalog_new(backup_path.ptr);
|
||||
catalogState->backup_location = drive;
|
||||
rc = do_init(catalogState);
|
||||
CU_ASSERT(rc == 0);
|
||||
|
||||
//CU_ASSERT_FATAL(pio_exists_d(drive, backup_path));
|
||||
//CU_ASSERT(pio_exists_d(drive, backup_path.ptr));
|
||||
|
||||
init_config(&instance_config, instance_name);
|
||||
instance_config.pgdata = server_path;
|
||||
instance_config.pgdata = server_path.ptr;
|
||||
InstanceState *instanceState = makeInstanceState(catalogState, instance_name);
|
||||
instanceState->database_location = drive;
|
||||
rc = do_add_instance(instanceState, &instance_config);
|
||||
|
||||
Reference in New Issue
Block a user