feat(test): implemented new method of making tests
This commit is contained in:
parent
64535d0288
commit
69439c6178
5 changed files with 205 additions and 170 deletions
|
|
@ -1,9 +1,6 @@
|
||||||
#include "unit/file.h"
|
|
||||||
#include "unit/unit.h"
|
#include "unit/unit.h"
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
cosms_core_file_read_test();
|
COSMS_CORE_TEST_RUN()
|
||||||
cosms_core_file_write_test();
|
|
||||||
cosms_core_file_delete_test();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
38
tests/test.h
38
tests/test.h
|
|
@ -1,14 +1,42 @@
|
||||||
#ifndef COSMS_TEST
|
#ifndef COSMS_CORE_TEST
|
||||||
#define COSMS_TEST
|
#define COSMS_CORE_TEST
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#define COSMS_CORE_TEST_HEADER(test_module_name) printf("----------------------------------------\n%s\n----------------------------------------\n", test_module_name);
|
#define COSMS_CORE_TEST_FUNCTION_NAME(name) cosms_core_##name##_test
|
||||||
|
#define COSMS_CORE_TEST_DEFINE(name) void cosms_core_##name##_test(void)
|
||||||
|
|
||||||
|
#define COSMS_CORE_TEST_TEST(name, implementation) void cosms_core_##name##_test(void) { \
|
||||||
|
const char *cosms_core_test_name = #name; \
|
||||||
|
printf("----------------------------------------\n%s\n----------------------------------------\n", cosms_core_test_name); \
|
||||||
|
implementation \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define COSMS_CORE_TEST_SUB_TEST(name, implementation) { \
|
||||||
|
const char* cosms_core_sub_test_name = #name; \
|
||||||
|
printf("[*] running test %s...\n", cosms_core_sub_test_name); \
|
||||||
|
implementation \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define COSMS_CORE_TEST_EXPORT(name, ...) static const cosms_core_test cosms_core_test_##name[] = { \
|
||||||
|
__VA_ARGS__ \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define COSMS_CORE_TEST_START static const cosms_core_test *cosms_core_test_tests[] = {
|
||||||
|
#define COSMS_CORE_TEST_IMPORT(name) cosms_core_test_##name
|
||||||
|
#define COSMS_CORE_TEST_END };
|
||||||
|
|
||||||
|
#define COSMS_CORE_TEST_RUN() \
|
||||||
|
for (unsigned long long index = 0; index < sizeof(cosms_core_test_tests); index += 1) { \
|
||||||
|
for (unsigned long long test_index = 0; test_index < sizeof(cosms_core_test_tests[index]); test_index += 1) { \
|
||||||
|
cosms_core_test_tests[index][test_index](); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
#define COSMS_CORE_TEST_START(test_name) printf("[*] running test %s...\n", test_name)
|
|
||||||
#define COSMS_CORE_TEST_SUCCESS(test_name) printf("[+] test %s completed successfully!\n", test_name);
|
#define COSMS_CORE_TEST_SUCCESS(test_name) printf("[+] test %s completed successfully!\n", test_name);
|
||||||
#define COSMS_CORE_TEST_FAIL(test_name, error) printf("[-] test %s failed with error: %s\n", test_name, error)
|
|
||||||
|
typedef void (*cosms_core_test)();
|
||||||
|
|
||||||
static inline bool cosms_core_test_assert(const char *test_name, bool expression, const char *error_message) {
|
static inline bool cosms_core_test_assert(const char *test_name, bool expression, const char *error_message) {
|
||||||
if (!expression) {
|
if (!expression) {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
#include "test.h"
|
|
||||||
#include "unit/file.h"
|
#include "unit/file.h"
|
||||||
|
|
||||||
#include <cosms-core/file.h>
|
#include <cosms-core/file.h>
|
||||||
|
|
@ -6,187 +5,187 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
void cosms_core_file_read_test(void) {
|
COSMS_CORE_TEST_TEST(file_read,
|
||||||
COSMS_CORE_TEST_HEADER("file read");
|
COSMS_CORE_TEST_SUB_TEST(reading small file,
|
||||||
|
unsigned long long file_size = 0;
|
||||||
const char *current_test_name = "reading small file";
|
char *file_buffer = NULL;
|
||||||
COSMS_CORE_TEST_START(current_test_name);
|
CosmsCoreFileError error = cosms_core_file_read("tests/data/small-file.txt", &file_buffer, &file_size);
|
||||||
|
if (cosms_core_test_assert(cosms_core_sub_test_name, error == COSMS_CORE_FILE_OK, cosms_core_file_error_string(error))) {
|
||||||
unsigned long long file_size;
|
const char *expected_result = "Hello, World!";
|
||||||
char *file_buffer;
|
if (cosms_core_test_assert(cosms_core_sub_test_name, file_size == strlen(expected_result) && strcmp(expected_result, file_buffer) == 0, "result does not match expected result")) {
|
||||||
CosmsCoreFileError error = cosms_core_file_read("tests/data/small-file.txt", &file_buffer, &file_size);
|
COSMS_CORE_TEST_SUCCESS(cosms_core_sub_test_name);
|
||||||
if (cosms_core_test_assert(current_test_name, error == COSMS_CORE_FILE_OK, cosms_core_file_error_string(error))) {
|
}
|
||||||
const char *expected_result = "Hello, World!";
|
|
||||||
if (cosms_core_test_assert(current_test_name, file_size == strlen(expected_result) && strcmp(expected_result, file_buffer) == 0, "result does not match expected result")) {
|
|
||||||
COSMS_CORE_TEST_SUCCESS(current_test_name);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
free(file_buffer);
|
if (file_buffer != NULL) {
|
||||||
|
|
||||||
current_test_name = "reading large file";
|
|
||||||
COSMS_CORE_TEST_START(current_test_name);
|
|
||||||
|
|
||||||
file_size = 0;
|
|
||||||
file_buffer = NULL;
|
|
||||||
error = cosms_core_file_read("tests/data/large-file.txt", &file_buffer, &file_size);
|
|
||||||
if (cosms_core_test_assert(current_test_name, error == COSMS_CORE_FILE_OK, cosms_core_file_error_string(error))) {
|
|
||||||
unsigned long long expected_size = 5242880000ULL;
|
|
||||||
char *expected_result = (char*)malloc((expected_size + 1) * sizeof(char));
|
|
||||||
if (!expected_result) {
|
|
||||||
printf("[-] failed to allocate memory for test aborting file read tests...\n");
|
|
||||||
free(file_buffer);
|
free(file_buffer);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
COSMS_CORE_TEST_SUB_TEST(reading large file,
|
||||||
|
unsigned long long file_size = 0;
|
||||||
|
char *file_buffer = NULL;
|
||||||
|
CosmsCoreFileError error = cosms_core_file_read("tests/data/large-file.txt", &file_buffer, &file_size);
|
||||||
|
if (cosms_core_test_assert(cosms_core_sub_test_name, error == COSMS_CORE_FILE_OK, cosms_core_file_error_string(error))) {
|
||||||
|
unsigned long long expected_size = 5242880000ULL;
|
||||||
|
char *expected_result = (char*)malloc((expected_size + 1) * sizeof(char));
|
||||||
|
if (!expected_result) {
|
||||||
|
printf("[-] failed to allocate memory for test aborting file read tests...\n");
|
||||||
|
free(file_buffer);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(expected_result, 'a', expected_size);
|
||||||
|
expected_result[expected_size] = '\0';
|
||||||
|
|
||||||
|
if (cosms_core_test_assert(cosms_core_sub_test_name, file_size == expected_size && strcmp(expected_result, file_buffer) == 0, "result does not match expected result")) {
|
||||||
|
COSMS_CORE_TEST_SUCCESS(cosms_core_sub_test_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(expected_result);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file_buffer != NULL) {
|
||||||
|
free(file_buffer);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
COSMS_CORE_TEST_SUB_TEST(reading non existing file,
|
||||||
|
unsigned long long file_size = 0;
|
||||||
|
char *file_buffer = NULL;
|
||||||
|
CosmsCoreFileError error = cosms_core_file_read("non-existing-file.cosms", &file_buffer, &file_size);
|
||||||
|
if (cosms_core_test_assert(cosms_core_sub_test_name, error == COSMS_CORE_FILE_NOT_FOUND, cosms_core_file_error_string(error))) {
|
||||||
|
COSMS_CORE_TEST_SUCCESS(cosms_core_sub_test_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file_buffer != NULL) {
|
||||||
|
free(file_buffer);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
COSMS_CORE_TEST_TEST(file_write,
|
||||||
|
COSMS_CORE_TEST_SUB_TEST(writting small file,
|
||||||
|
char *file_buffer = "Hello, World!";
|
||||||
|
CosmsCoreFileError error = cosms_core_file_write("tests/data/small-write-file.txt", file_buffer, strlen(file_buffer), true);
|
||||||
|
if (cosms_core_test_assert(cosms_core_sub_test_name, error == COSMS_CORE_FILE_OK, cosms_core_file_error_string(error))) {
|
||||||
|
char *file_content = NULL;
|
||||||
|
error = cosms_core_file_read("tests/data/small-write-file.txt", &file_content, NULL);
|
||||||
|
if (cosms_core_test_assert(cosms_core_sub_test_name, error == COSMS_CORE_FILE_OK, cosms_core_file_error_string(error))) {
|
||||||
|
if (cosms_core_test_assert(cosms_core_sub_test_name, strcmp(file_buffer, file_content) == 0, "file content not what was written")) {
|
||||||
|
COSMS_CORE_TEST_SUCCESS(cosms_core_sub_test_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file_content != NULL) {
|
||||||
|
free(file_content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
COSMS_CORE_TEST_SUB_TEST(writting big file,
|
||||||
|
unsigned long long large_file_size = 5242880000ULL;
|
||||||
|
char *large_file_buffer = (char*)malloc((large_file_size + 1) * sizeof(char));
|
||||||
|
if (!large_file_buffer) {
|
||||||
|
printf("[-] failed to allocate memory for test aborting file read tests...\n");
|
||||||
|
free(large_file_buffer);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(expected_result, 'a', expected_size);
|
memset(large_file_buffer, 'a', large_file_size);
|
||||||
expected_result[expected_size] = '\0';
|
large_file_buffer[large_file_size] = '\0';
|
||||||
|
|
||||||
if (cosms_core_test_assert(current_test_name, file_size == expected_size && strcmp(expected_result, file_buffer) == 0, "result does not match expected result")) {
|
CosmsCoreFileError error = cosms_core_file_write("tests/data/large-write-file.txt", large_file_buffer, large_file_size, true);
|
||||||
COSMS_CORE_TEST_SUCCESS(current_test_name);
|
if (cosms_core_test_assert(cosms_core_sub_test_name, error == COSMS_CORE_FILE_OK, cosms_core_file_error_string(error))) {
|
||||||
}
|
char *file_content = NULL;
|
||||||
|
error = cosms_core_file_read("tests/data/large-write-file.txt", &file_content, NULL);
|
||||||
|
if (cosms_core_test_assert(cosms_core_sub_test_name, error == COSMS_CORE_FILE_OK, cosms_core_file_error_string(error))) {
|
||||||
|
if (cosms_core_test_assert(cosms_core_sub_test_name, strcmp(large_file_buffer, file_content) == 0, "file content not what was written")) {
|
||||||
|
COSMS_CORE_TEST_SUCCESS(cosms_core_sub_test_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
free(expected_result);
|
if (file_content != NULL) {
|
||||||
}
|
free(file_content);
|
||||||
|
|
||||||
free(file_buffer);
|
|
||||||
|
|
||||||
current_test_name = "reading non existing file";
|
|
||||||
COSMS_CORE_TEST_START(current_test_name);
|
|
||||||
|
|
||||||
file_size = 0;
|
|
||||||
file_buffer = NULL;
|
|
||||||
error = cosms_core_file_read("non-existing-file.cosms", &file_buffer, &file_size);
|
|
||||||
if (cosms_core_test_assert(current_test_name, error == COSMS_CORE_FILE_NOT_FOUND, cosms_core_file_error_string(error))) {
|
|
||||||
COSMS_CORE_TEST_SUCCESS(current_test_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(file_buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
void cosms_core_file_write_test(void) {
|
|
||||||
COSMS_CORE_TEST_HEADER("file write");
|
|
||||||
|
|
||||||
const char *current_test_name = "writting small file";
|
|
||||||
COSMS_CORE_TEST_START(current_test_name);
|
|
||||||
|
|
||||||
char *file_buffer = "Hello, World!";
|
|
||||||
CosmsCoreFileError error = cosms_core_file_write("tests/data/small-write-file.txt", file_buffer, strlen(file_buffer), true);
|
|
||||||
if (cosms_core_test_assert(current_test_name, error == COSMS_CORE_FILE_OK, cosms_core_file_error_string(error))) {
|
|
||||||
char *file_content;
|
|
||||||
error = cosms_core_file_read("tests/data/small-write-file.txt", &file_content, NULL);
|
|
||||||
if (cosms_core_test_assert(current_test_name, error == COSMS_CORE_FILE_OK, cosms_core_file_error_string(error))) {
|
|
||||||
if (cosms_core_test_assert(current_test_name, strcmp(file_buffer, file_content) == 0, "file content not what was written")) {
|
|
||||||
COSMS_CORE_TEST_SUCCESS(current_test_name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(file_content);
|
|
||||||
}
|
|
||||||
|
|
||||||
current_test_name = "writting big file";
|
|
||||||
COSMS_CORE_TEST_START(current_test_name);
|
|
||||||
|
|
||||||
unsigned long long large_file_size = 5242880000ULL;
|
|
||||||
char *large_file_buffer = (char*)malloc((large_file_size + 1) * sizeof(char));
|
|
||||||
if (!large_file_buffer) {
|
|
||||||
printf("[-] failed to allocate memory for test aborting file read tests...\n");
|
|
||||||
free(large_file_buffer);
|
free(large_file_buffer);
|
||||||
return;
|
)
|
||||||
}
|
|
||||||
|
|
||||||
memset(large_file_buffer, 'a', large_file_size);
|
COSMS_CORE_TEST_SUB_TEST(appending file,
|
||||||
large_file_buffer[large_file_size] = '\0';
|
char *file_buffer = "Hello, World!";
|
||||||
|
CosmsCoreFileError error = cosms_core_file_write("tests/data/small-write-file.txt", file_buffer, strlen(file_buffer), false);
|
||||||
error = cosms_core_file_write("tests/data/large-write-file.txt", large_file_buffer, large_file_size, true);
|
if (cosms_core_test_assert(cosms_core_sub_test_name, error == COSMS_CORE_FILE_OK, cosms_core_file_error_string(error))) {
|
||||||
if (cosms_core_test_assert(current_test_name, error == COSMS_CORE_FILE_OK, cosms_core_file_error_string(error))) {
|
char *file_content = NULL;
|
||||||
char *file_content;
|
error = cosms_core_file_read("tests/data/small-write-file.txt", &file_content, NULL);
|
||||||
error = cosms_core_file_read("tests/data/large-write-file.txt", &file_content, NULL);
|
if (cosms_core_test_assert(cosms_core_sub_test_name, error == COSMS_CORE_FILE_OK, cosms_core_file_error_string(error))) {
|
||||||
if (cosms_core_test_assert(current_test_name, error == COSMS_CORE_FILE_OK, cosms_core_file_error_string(error))) {
|
const char *expected_result = "Hello, World!Hello, World!";
|
||||||
if (cosms_core_test_assert(current_test_name, strcmp(large_file_buffer, file_content) == 0, "file content not what was written")) {
|
if (cosms_core_test_assert(cosms_core_sub_test_name, strcmp(expected_result, file_content) == 0, "file content not what was written")) {
|
||||||
COSMS_CORE_TEST_SUCCESS(current_test_name);
|
COSMS_CORE_TEST_SUCCESS(cosms_core_sub_test_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file_content != NULL) {
|
||||||
|
free(file_content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
|
||||||
free(file_content);
|
COSMS_CORE_TEST_SUB_TEST(appending to non existing file,
|
||||||
}
|
char *file_buffer = "Hello, World!";
|
||||||
|
CosmsCoreFileError error = cosms_core_file_write("tests/data/append-write-file.txt", file_buffer, strlen(file_buffer), false);
|
||||||
|
if (cosms_core_test_assert(cosms_core_sub_test_name, error == COSMS_CORE_FILE_OK, cosms_core_file_error_string(error))) {
|
||||||
|
char *file_content = NULL;
|
||||||
|
error = cosms_core_file_read("tests/data/append-write-file.txt", &file_content, NULL);
|
||||||
|
if (cosms_core_test_assert(cosms_core_sub_test_name, error == COSMS_CORE_FILE_OK, cosms_core_file_error_string(error))) {
|
||||||
|
if (cosms_core_test_assert(cosms_core_sub_test_name, strcmp(file_buffer, file_content) == 0, "file content not what was written")) {
|
||||||
|
COSMS_CORE_TEST_SUCCESS(cosms_core_sub_test_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
free(large_file_buffer);
|
if (file_content != NULL) {
|
||||||
|
free(file_content);
|
||||||
current_test_name = "appending file";
|
|
||||||
COSMS_CORE_TEST_START(current_test_name);
|
|
||||||
|
|
||||||
error = cosms_core_file_write("tests/data/small-write-file.txt", file_buffer, strlen(file_buffer), false);
|
|
||||||
if (cosms_core_test_assert(current_test_name, error == COSMS_CORE_FILE_OK, cosms_core_file_error_string(error))) {
|
|
||||||
char *file_content;
|
|
||||||
error = cosms_core_file_read("tests/data/small-write-file.txt", &file_content, NULL);
|
|
||||||
if (cosms_core_test_assert(current_test_name, error == COSMS_CORE_FILE_OK, cosms_core_file_error_string(error))) {
|
|
||||||
const char *expected_result = "Hello, World!Hello, World!";
|
|
||||||
if (cosms_core_test_assert(current_test_name, strcmp(expected_result, file_content) == 0, "file content not what was written")) {
|
|
||||||
COSMS_CORE_TEST_SUCCESS(current_test_name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
)
|
||||||
free(file_content);
|
)
|
||||||
}
|
|
||||||
|
|
||||||
current_test_name = "appending to non existing file";
|
COSMS_CORE_TEST_TEST(file_delete,
|
||||||
COSMS_CORE_TEST_START(current_test_name);
|
COSMS_CORE_TEST_SUB_TEST(deleting small file,
|
||||||
|
CosmsCoreFileError error = cosms_core_file_delete("tests/data/small-write-file.txt");
|
||||||
|
if (cosms_core_test_assert(cosms_core_sub_test_name, error == COSMS_CORE_FILE_OK, cosms_core_file_error_string(error))) {
|
||||||
|
char *file_content = NULL;
|
||||||
|
error = cosms_core_file_read("tests/data/small-write-file.txt", &file_content, NULL);
|
||||||
|
if (cosms_core_test_assert(cosms_core_sub_test_name, error == COSMS_CORE_FILE_NOT_FOUND, cosms_core_file_error_string(error))) {
|
||||||
|
COSMS_CORE_TEST_SUCCESS(cosms_core_sub_test_name);
|
||||||
|
}
|
||||||
|
|
||||||
error = cosms_core_file_write("tests/data/append-write-file.txt", file_buffer, strlen(file_buffer), false);
|
if (file_content != NULL) {
|
||||||
if (cosms_core_test_assert(current_test_name, error == COSMS_CORE_FILE_OK, cosms_core_file_error_string(error))) {
|
free(file_content);
|
||||||
char *file_content;
|
|
||||||
error = cosms_core_file_read("tests/data/append-write-file.txt", &file_content, NULL);
|
|
||||||
if (cosms_core_test_assert(current_test_name, error == COSMS_CORE_FILE_OK, cosms_core_file_error_string(error))) {
|
|
||||||
if (cosms_core_test_assert(current_test_name, strcmp(file_buffer, file_content) == 0, "file content not what was written")) {
|
|
||||||
COSMS_CORE_TEST_SUCCESS(current_test_name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
|
||||||
free(file_content);
|
COSMS_CORE_TEST_SUB_TEST(deleting large file,
|
||||||
}
|
CosmsCoreFileError error = cosms_core_file_delete("tests/data/append-write-file.txt");
|
||||||
}
|
if (cosms_core_test_assert(cosms_core_sub_test_name, error == COSMS_CORE_FILE_OK, cosms_core_file_error_string(error))) {
|
||||||
|
char *file_content = NULL;
|
||||||
|
error = cosms_core_file_read("tests/data/append-write-file.txt", &file_content, NULL);
|
||||||
|
if (cosms_core_test_assert(cosms_core_sub_test_name, error == COSMS_CORE_FILE_NOT_FOUND, cosms_core_file_error_string(error))) {
|
||||||
|
COSMS_CORE_TEST_SUCCESS(cosms_core_sub_test_name);
|
||||||
|
}
|
||||||
|
|
||||||
void cosms_core_file_delete_test(void) {
|
if (file_content != NULL) {
|
||||||
COSMS_CORE_TEST_HEADER("file delete");
|
free(file_content);
|
||||||
|
}
|
||||||
const char *current_test_name = "deleting small file";
|
|
||||||
COSMS_CORE_TEST_START(current_test_name);
|
|
||||||
|
|
||||||
CosmsCoreFileError error = cosms_core_file_delete("tests/data/small-write-file.txt");
|
|
||||||
if (cosms_core_test_assert(current_test_name, error == COSMS_CORE_FILE_OK, cosms_core_file_error_string(error))) {
|
|
||||||
char *file_content = NULL;
|
|
||||||
error = cosms_core_file_read("tests/data/small-write-file.txt", &file_content, NULL);
|
|
||||||
if (cosms_core_test_assert(current_test_name, error == COSMS_CORE_FILE_NOT_FOUND, cosms_core_file_error_string(error))) {
|
|
||||||
COSMS_CORE_TEST_SUCCESS(current_test_name);
|
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
|
||||||
if (file_content != NULL) {
|
COSMS_CORE_TEST_SUB_TEST(deleting non existing file,
|
||||||
free(file_content);
|
CosmsCoreFileError error = cosms_core_file_delete("non-existing-file.cosms");
|
||||||
|
if (cosms_core_test_assert(cosms_core_sub_test_name, error == COSMS_CORE_FILE_NOT_FOUND, cosms_core_file_error_string(error))) {
|
||||||
|
COSMS_CORE_TEST_SUCCESS(cosms_core_sub_test_name);
|
||||||
}
|
}
|
||||||
}
|
)
|
||||||
|
)
|
||||||
current_test_name = "deleting large file";
|
|
||||||
COSMS_CORE_TEST_START(current_test_name);
|
|
||||||
|
|
||||||
error = cosms_core_file_delete("tests/data/append-write-file.txt");
|
|
||||||
if (cosms_core_test_assert(current_test_name, error == COSMS_CORE_FILE_OK, cosms_core_file_error_string(error))) {
|
|
||||||
char *file_content = NULL;
|
|
||||||
error = cosms_core_file_read("tests/data/append-write-file.txt", &file_content, NULL);
|
|
||||||
if (cosms_core_test_assert(current_test_name, error == COSMS_CORE_FILE_NOT_FOUND, cosms_core_file_error_string(error))) {
|
|
||||||
COSMS_CORE_TEST_SUCCESS(current_test_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (file_content != NULL) {
|
|
||||||
free(file_content);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
current_test_name = "deleting non existing file";
|
|
||||||
COSMS_CORE_TEST_START(current_test_name);
|
|
||||||
|
|
||||||
error = cosms_core_file_delete("non-existing-file.cosms");
|
|
||||||
if (cosms_core_test_assert(current_test_name, error == COSMS_CORE_FILE_NOT_FOUND, cosms_core_file_error_string(error))) {
|
|
||||||
COSMS_CORE_TEST_SUCCESS(current_test_name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,16 @@
|
||||||
#ifndef COSMS_CORE_FILE_TEST
|
#ifndef COSMS_CORE_FILE_TEST
|
||||||
#define COSMS_CORE_FILE_TEST
|
#define COSMS_CORE_FILE_TEST
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include "test.h"
|
||||||
|
|
||||||
void cosms_core_file_read_test();
|
COSMS_CORE_TEST_DEFINE(file_read);
|
||||||
void cosms_core_file_write_test();
|
COSMS_CORE_TEST_DEFINE(file_write);
|
||||||
void cosms_core_file_delete_test();
|
COSMS_CORE_TEST_DEFINE(file_delete);
|
||||||
|
|
||||||
|
COSMS_CORE_TEST_EXPORT(file,
|
||||||
|
COSMS_CORE_TEST_FUNCTION_NAME(file_read),
|
||||||
|
COSMS_CORE_TEST_FUNCTION_NAME(file_write),
|
||||||
|
COSMS_CORE_TEST_FUNCTION_NAME(file_delete)
|
||||||
|
);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -1,6 +1,11 @@
|
||||||
#ifndef COSMS_UNIT
|
#ifndef COSMS_UNIT
|
||||||
#define COSMS_UNIT
|
#define COSMS_UNIT
|
||||||
|
|
||||||
|
#include "test.h"
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
|
|
||||||
|
COSMS_CORE_TEST_START
|
||||||
|
COSMS_CORE_TEST_IMPORT(file)
|
||||||
|
COSMS_CORE_TEST_END
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Loading…
Add table
Reference in a new issue