2021-07-31 19:05:04 +02:00
|
|
|
#include <ksr/files.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
2023-02-12 16:38:21 +01:00
|
|
|
int main(void)
|
2021-07-31 19:05:04 +02:00
|
|
|
{
|
|
|
|
// delete test directory if it exists.
|
|
|
|
system("rm -Rf ksrtesttesttmp");
|
|
|
|
|
|
|
|
// create a new buffer and write it in a file.
|
|
|
|
ksrbuffer *buffer = ksrbuffer_new_from_content(12, "Hello World!");
|
|
|
|
write_file("ksrtesttesttmp/tmp/test.tmp", buffer);
|
|
|
|
|
|
|
|
// try to read the previously written file, and checking that the buffer has been read properly.
|
2023-02-12 16:50:33 +01:00
|
|
|
ksrbuffer *read_buffer = read_file_from_path("ksrtesttesttmp/tmp/test.tmp");
|
|
|
|
assert(read_buffer->length == 12);
|
2021-07-31 19:05:04 +02:00
|
|
|
assert(read_buffer->bytes[0] == 'H');
|
|
|
|
assert(read_buffer->bytes[3] == 'l');
|
|
|
|
assert(read_buffer->bytes[7] == 'o');
|
|
|
|
assert(read_buffer->bytes[11] == '!');
|
|
|
|
|
|
|
|
// delete test directory.
|
|
|
|
system("rm -Rf ksrtesttesttmp");
|
|
|
|
|
|
|
|
// try to write a file where it is not writable.
|
|
|
|
assert(write_file("/dev/test/test.tmp", buffer) == false);
|
|
|
|
// try to read a non-existing file.
|
|
|
|
assert(read_file_from_path("/dev/test.tmp") == NULL);
|
|
|
|
// try to read a NULL file.
|
|
|
|
assert(read_file(NULL) == NULL);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|