meta: re-organise tests

This commit is contained in:
2026-05-04 16:37:06 +01:00
parent 716b939d4f
commit 18c9d30c60
40 changed files with 161 additions and 25 deletions
+22
View File
@@ -0,0 +1,22 @@
#include <fx/io/directory.h>
#include <fx/io/path.h>
int main(int argc, const char **argv)
{
if (argc < 2) {
return -1;
}
const char *path = argv[1];
fx_directory *dir;
fx_result result = fx_directory_open(
NULL, FX_RV_PATH(path), FX_DIRECTORY_OPEN_CREATE_INTERMEDIATE, &dir);
if (fx_result_is_error(result)) {
fx_throw(result);
return -1;
}
fx_directory_unref(dir);
return 0;
}
+25
View File
@@ -0,0 +1,25 @@
#include <fx/io/directory.h>
int main(int argc, const char **argv)
{
if (argc < 2) {
return -1;
}
const char *path = argv[1];
fx_directory *dir;
fx_result result = fx_directory_open(NULL, FX_RV_PATH(path), 0, &dir);
if (fx_result_is_error(result)) {
fx_throw(result);
return -1;
}
result = fx_directory_delete(dir);
if (fx_result_is_error(result)) {
fx_throw(result);
return -1;
}
return 0;
}
+26
View File
@@ -0,0 +1,26 @@
#include <fx/core/stream.h>
#include <fx/io/file.h>
#include <fx/io/path.h>
#include <stdio.h>
int main(int argc, const char **argv)
{
fx_file *dest;
fx_path *path = fx_path_create_from_cstr("data.txt");
fx_result result = fx_file_open(
NULL, path, FX_FILE_WRITE_ONLY | FX_FILE_CREATE, &dest);
if (fx_result_is_error(result)) {
fx_throw(result);
return -1;
}
size_t nr_read = 0;
fx_stream_buffer *buf = fx_stream_buffer_create_dynamic(1024);
fx_stream_read_all_bytes_s(fx_stdin, dest, buf, &nr_read);
printf("done. read %zu bytes total.\n", nr_read);
fx_path_unref(path);
fx_file_unref(dest);
return 0;
}
+32
View File
@@ -0,0 +1,32 @@
#include <fx/io/directory.h>
#include <stdio.h>
#define NRAND_NUMBERS 12
#define NRAND_BYTES 128
#define NRAND_DOUBLES 8
int main(int argc, const char **argv)
{
if (argc < 2) {
return -1;
}
fx_directory *dir = NULL;
fx_path *path = fx_path_create_from_cstr(argv[1]);
fx_result result = fx_directory_open(FX_DIRECTORY_ROOT, path, 0, &dir);
if (fx_result_is_error(result)) {
fx_throw(result);
return -1;
}
fx_iterator *it = fx_directory_begin(dir, FX_DIRECTORY_ITERATE_PARENT_FIRST);
fx_foreach(fx_directory_entry *, entry, it)
{
printf("%s\n", fx_path_ptr(entry->filepath));
}
fx_iterator_unref(it);
return 0;
}
+35
View File
@@ -0,0 +1,35 @@
#include <CuTest.h>
#include <fx/core/stringstream.h>
#include <fx/io/path.h>
#include <stdio.h>
void test_path_1(CuTest *tc)
{
fx_path *path = fx_path_create_from_cstr("C:\\hello\\world\\");
char buf[512];
fx_stringstream *str = fx_stringstream_create_with_buffer(buf, sizeof buf);
fx_object_to_string(path, str);
printf("%s\n", buf);
fx_path *path2 = fx_path_create_from_cstr("path1\\path2\\");
fx_path *path3 = fx_path_create_from_cstr("path3\\path4\\");
const fx_path *paths[] = {path, path2, path3};
fx_path *path4 = fx_path_join(paths, sizeof paths / sizeof paths[0]);
fx_stringstream_reset_with_buffer(str, buf, sizeof buf);
fx_object_to_string(path4, str);
printf("%s\n", buf);
}
CuSuite *get_all_tests(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_path_1);
return suite;
}