test: move all module tests to the test/ directory
This commit is contained in:
35
test/io/io-units.c
Normal file
35
test/io/io-units.c
Normal file
@@ -0,0 +1,35 @@
|
||||
#include <CuTest.h>
|
||||
#include <blue/core/stringstream.h>
|
||||
#include <blue/io/path.h>
|
||||
#include <stdio.h>
|
||||
|
||||
void test_path_1(CuTest *tc)
|
||||
{
|
||||
b_path *path = b_path_create_from_cstr("C:\\hello\\world\\");
|
||||
char buf[512];
|
||||
b_stringstream *str = b_stringstream_create_with_buffer(buf, sizeof buf);
|
||||
|
||||
b_object_to_string(path, str);
|
||||
|
||||
printf("%s\n", buf);
|
||||
|
||||
b_path *path2 = b_path_create_from_cstr("path1\\path2\\");
|
||||
b_path *path3 = b_path_create_from_cstr("path3\\path4\\");
|
||||
|
||||
const b_path *paths[] = {path, path2, path3};
|
||||
|
||||
b_path *path4 = b_path_join(paths, sizeof paths / sizeof paths[0]);
|
||||
|
||||
b_stringstream_reset_with_buffer(str, buf, sizeof buf);
|
||||
b_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;
|
||||
}
|
||||
22
test/io/mkdir.c
Normal file
22
test/io/mkdir.c
Normal file
@@ -0,0 +1,22 @@
|
||||
#include <blue/io/directory.h>
|
||||
#include <blue/io/path.h>
|
||||
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
if (argc < 2) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char *path = argv[1];
|
||||
|
||||
b_directory *dir;
|
||||
b_result result = b_directory_open(
|
||||
NULL, B_RV_PATH(path), B_DIRECTORY_OPEN_CREATE_INTERMEDIATE, &dir);
|
||||
if (b_result_is_error(result)) {
|
||||
b_throw(result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
b_directory_unref(dir);
|
||||
return 0;
|
||||
}
|
||||
25
test/io/rmdir.c
Normal file
25
test/io/rmdir.c
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <blue/io/directory.h>
|
||||
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
if (argc < 2) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char *path = argv[1];
|
||||
|
||||
b_directory *dir;
|
||||
b_result result = b_directory_open(NULL, B_RV_PATH(path), 0, &dir);
|
||||
if (b_result_is_error(result)) {
|
||||
b_throw(result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
result = b_directory_delete(dir);
|
||||
if (b_result_is_error(result)) {
|
||||
b_throw(result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
23
test/io/streams.c
Normal file
23
test/io/streams.c
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <blue/core/stream.h>
|
||||
#include <blue/io/file.h>
|
||||
#include <blue/io/path.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
b_file *dest;
|
||||
b_path *path = b_path_create_from_cstr("data.txt");
|
||||
b_result result = b_file_open(
|
||||
NULL, path, B_FILE_WRITE_ONLY | B_FILE_CREATE, &dest);
|
||||
if (b_result_is_error(result)) {
|
||||
b_throw(result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
size_t nr_read = 0;
|
||||
b_stream_buffer *buf = b_stream_buffer_create_dynamic(1024);
|
||||
b_stream_read_all_bytes_s(b_stdin, dest, buf, &nr_read);
|
||||
|
||||
printf("done. read %zu bytes total.\n", nr_read);
|
||||
return 0;
|
||||
}
|
||||
32
test/io/tree.c
Normal file
32
test/io/tree.c
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <blue/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;
|
||||
}
|
||||
|
||||
b_directory *dir = NULL;
|
||||
b_path *path = b_path_create_from_cstr(argv[1]);
|
||||
b_result result = b_directory_open(B_DIRECTORY_ROOT, path, 0, &dir);
|
||||
|
||||
if (b_result_is_error(result)) {
|
||||
b_throw(result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
b_iterator *it = b_directory_begin(dir, B_DIRECTORY_ITERATE_PARENT_FIRST);
|
||||
b_foreach(b_directory_entry *, entry, it)
|
||||
{
|
||||
printf("%s\n", b_path_ptr(entry->filepath));
|
||||
}
|
||||
|
||||
b_iterator_unref(it);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user