My goal is to get to writing the payload tests but getting these other unit tests figured out first will make that process easier.
These "works" unit tests are intended to be very simple at this time.
There are no checks for comments.
The NULL data is not checked, partially due to the use of getline() and string comparison.
build_sources_program test-fss-extended_list_content_read.c test-fss-extended_list_content_write.c test-fss-extended_list_object_read.c test-fss-extended_list_object_write.c
build_sources_program test-fss-payload_header_map.c
-build_sources_program test-fss.c
+build_sources_program test-fss.c data-fss.c
build_script no
build_shared yes
--- /dev/null
+b c d
+b c d
+b c d
+a b c
+b c
+d
+b c d
+b c d
+" b c d
+d
+d
+c d
+b c d
+
+c d
+{
+c d
+
+b c d
+Ȁ b c d
+"Ȁ" b c d
+" Ȁ " b c d
+" Ȁ " b `c d`
+b c d
+b c d
+b c d
+c d' e
+c d" e
+c d` e
+c d' e
+c d" e
+c d` e
+b c d e
+b c d e '
+b c d
+b c
+c d
+b c d
+b c d
--- /dev/null
+a
+a
+a
+.
+.a
+a b c
+"a
+a"
+a
+a b" c
+a b` c
+a b
+a:
+a:
+b
+a
+b
+}
+Ȁ
+Ȃ
+Ȃ
+Ȃ
+Ȃ
+Ȁ Ƞ
+Ȁ Ƞ
+Ȁ Ƞ
+'A b
+"A b
+`A b
+A b'
+A b"
+A b`
+a
+a
+a
+a
+a
+a
+a
--- /dev/null
+a b c d
+ a b c d
+ a b c d
+. a b c
+.a b c
+"a b c" d
+\"a b c d
+a" b c d
+a " b c d
+'a b" c' d
+'a b` c' d
+`a b` c d
+a: b c d
+a:
+ b c d
+a {
+ b c d
+}
+Ȁ b c d
+Ȃ Ȁ b c d
+Ȃ "Ȁ" b c d
+Ȃ " Ȁ " b c d
+Ȃ " Ȁ " b `c d`
+`Ȁ Ƞ` b c d
+"Ȁ Ƞ" b c d
+'Ȁ Ƞ' b c d
+''A b' c d' e
+""A b" c d" e
+``A b` c d` e
+'A b'' c d' e
+"A b"" c d" e
+`A b`` c d` e
+a b c d e
+a b c d e '
+ a b c d
+a b c
+ a c d
+a b c d
+a b c d
--- /dev/null
+#include "data-fss.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+FILE *data__contents_file_open__basic_all_read(void) {
+ return fopen("./data/tests/contents/basic-all_read.txt", "r");
+}
+
+FILE *data__objects_file_open__basic_all_read(void) {
+ return fopen("./data/tests/objects/basic-all_read.txt", "r");
+}
+
+FILE *data__strings_file_open__basic_all_read(void) {
+ return fopen("./data/tests/strings/basic-all_read.txt", "r");
+}
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
--- /dev/null
+/**
+ * FLL - Level 1
+ *
+ * Project: FSS
+ * API Version: 0.7
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Data for the fss project tests.
+ */
+#ifndef _DATA__FL_fss_h
+#define _DATA__FL_fss_h
+
+// Libc includes.
+#include <arpa/inet.h>
+#include <stdint.h>
+#include <stdio.h>
+
+// FLL-0 includes.
+
+// FLL-1 includes.
+#include <fll/level_1/fss.h>
+#include <fll/level_1/fss/basic.h>
+#include <fll/level_1/fss/basic_list.h>
+#include <fll/level_1/fss/embedded_list.h>
+#include <fll/level_1/fss/extended.h>
+#include <fll/level_1/fss/extended_list.h>
+#include <fll/level_1/fss/payload.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Open the "FSS basic" contents file.
+ *
+ * This assumes the following:
+ * - The file path is relative to the current working directory (tests are run from project root).
+ * - The file path is "data/tests/contents/basic-all_read.txt".
+ *
+ * @return
+ * Non-zero on success.
+ * 0 on failure.
+ *
+ * @see fopen()
+ */
+extern FILE *data__contents_file_open__basic_all_read(void);
+
+/**
+ * Open the "FSS basic" objects file.
+ *
+ * This assumes the following:
+ * - The file path is relative to the current working directory (tests are run from project root).
+ * - The file path is "data/tests/objects/basic-all_read.txt".
+ *
+ * @return
+ * Non-zero on success.
+ * 0 on failure.
+ *
+ * @see fopen()
+ */
+extern FILE *data__objects_file_open__basic_all_read(void);
+
+/**
+ * Open the "fss basic" strings file.
+ *
+ * This assumes the following:
+ * - The file path is relative to the current working directory (tests are run from project root).
+ * - The file path is "data/tests/strings/basic-all_read.txt".
+ *
+ * @return
+ * Non-zero on success.
+ * 0 on failure.
+ *
+ * @see fopen()
+ */
+extern FILE *data__strings_file_open__basic_all_read(void);
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif // _DATA__FL_fss_h
}
}
+void test__fl_fss_basic_content_read__works(void **void_state) {
+
+ {
+ // Note: These files are required to have the same number of lines and each line should probably be at max 255 characters.
+ FILE *file_strings = data__strings_file_open__basic_all_read();
+ FILE *file_contents = data__contents_file_open__basic_all_read();
+
+ assert_non_null(file_strings);
+ assert_non_null(file_contents);
+
+ size_t max = 0;
+ char *line_string = 0;
+ char *line_content = 0;
+ ssize_t result = 0;
+
+ f_string_static_t buffer_string = f_string_static_t_initialize;
+ f_string_static_t buffer_content = f_string_static_t_initialize;
+
+ f_state_t state = f_state_t_initialize;
+ f_range_t range = f_range_t_initialize;
+ f_range_t found_object = f_range_t_initialize;
+ f_ranges_t found = f_ranges_t_initialize;
+ uint8_t quote = 0;
+ f_number_unsigneds_t delimits = f_number_unsigneds_t_initialize;
+ f_string_dynamic_t result_string = f_string_dynamic_t_initialize;
+ f_string_dynamic_t delimit_string = f_string_dynamic_t_initialize;
+ f_status_t status_object = F_okay;
+
+ for (;;) {
+
+ max = 255;
+
+ result = getline(&line_string, &max, file_strings);
+ if (result == -1) break;
+
+ buffer_string.string = line_string;
+ buffer_string.used = (f_number_unsigned_t) result;
+ buffer_string.size = buffer_string.used;
+
+ max = 255;
+
+ result = getline(&line_content, &max, file_contents);
+ assert_return_code(result, 0);
+
+ buffer_content.string = line_content;
+ buffer_content.used = (f_number_unsigned_t) result;
+ buffer_content.size = buffer_content.used;
+
+ // The newline is copied by getline(), and so remove that newline before comparing.
+ buffer_content.string[--buffer_content.used] = 0;
+
+ state.status = F_none;
+ range.start = 0;
+ range.stop = buffer_string.used - 1;
+ found_object.start = 1;
+ found_object.stop = 0;
+
+ fl_fss_basic_object_read(buffer_string, &range, &found_object, "e, &delimits, &state);
+
+ assert_true(state.status == F_fss_found_object || state.status == F_fss_found_object_content_not);
+
+ status_object = state.status;
+ state.status = F_none;
+
+ fl_fss_basic_content_read(buffer_string, &range, &found, &delimits, &state);
+
+ if (status_object == F_fss_found_object) {
+ assert_int_equal(state.status, F_fss_found_content);
+ }
+ else {
+ assert_int_equal(state.status, F_data_not);
+ }
+
+ if (state.status == F_fss_found_content) {
+ assert_true(found.used);
+
+ {
+ const f_status_t status = f_string_dynamic_append(buffer_string, &delimit_string);
+ assert_int_equal(status, F_okay);
+ }
+
+ state.status = F_none;
+
+ f_fss_apply_delimit(delimits, &delimit_string, &state);
+ assert_int_equal(state.status, F_okay);
+
+ {
+ const f_status_t status = f_string_dynamic_partial_append_nulless(delimit_string, found.array[0], &result_string);
+ assert_true(status == F_okay || status == F_data_not_eos);
+ }
+
+ {
+ const f_status_t status = f_string_dynamic_terminate_after(&result_string);
+ assert_int_equal(status, F_okay);
+ }
+
+ assert_string_equal(result_string.string, line_content);
+ }
+ else {
+ assert_true(!found.used);
+ }
+
+ if (line_string) free(line_string);
+ if (line_content) free(line_content);
+ if (result_string.string) free(result_string.string);
+ if (delimit_string.string) free(delimit_string.string);
+ if (delimits.array) free(delimits.array);
+ if (found.array) free(found.array);
+
+ line_string = 0;
+ line_content = 0;
+ result_string.string = 0;
+ result_string.used = 0;
+ result_string.size = 0;
+ delimit_string.string = 0;
+ delimit_string.used = 0;
+ delimit_string.size = 0;
+ delimits.array = 0;
+ delimits.used = 0;
+ delimits.size = 0;
+ found.array = 0;
+ found.used = 0;
+ found.size = 0;
+ } // for
+
+ if (file_strings) fclose(file_strings);
+ if (file_contents) fclose(file_contents);
+
+ if (delimits.array) free(delimits.array);
+ if (found.array) free(found.array);
+ if (line_string) free(line_string);
+ if (line_content) free(line_content);
+ if (result_string.string) free(result_string.string);
+ if (delimit_string.string) free(delimit_string.string);
+ }
+}
+
#ifdef __cplusplus
} // extern "C"
#endif
*/
extern void test__fl_fss_basic_content_read__returns_data_not(void **state);
+
+/**
+ * Test that the function works.
+ *
+ * @see fl_fss_basic_content_read()
+ */
+extern void test__fl_fss_basic_content_read__works(void **state);
+
#endif // _TEST__FL_fss_basic_content_read_h
}
}
+void test__fl_fss_basic_object_read__works(void **void_state) {
+
+ {
+ // Note: These files are required to have the same number of lines and each line should probably be at max 255 characters.
+ FILE *file_strings = data__strings_file_open__basic_all_read();
+ FILE *file_objects = data__objects_file_open__basic_all_read();
+
+ assert_non_null(file_strings);
+ assert_non_null(file_objects);
+
+ size_t max = 0;
+ char *line_string = 0;
+ char *line_object = 0;
+ ssize_t result = 0;
+
+ f_string_static_t buffer_string = f_string_static_t_initialize;
+ f_string_static_t buffer_object = f_string_static_t_initialize;
+
+ f_state_t state = f_state_t_initialize;
+ f_range_t range = f_range_t_initialize;
+ f_range_t found = f_range_t_initialize;
+ uint8_t quote = 0;
+ f_number_unsigneds_t delimits = f_number_unsigneds_t_initialize;
+ f_string_dynamic_t result_string = f_string_dynamic_t_initialize;
+ f_string_dynamic_t delimit_string = f_string_dynamic_t_initialize;
+
+ for (;;) {
+
+ max = 255;
+
+ result = getline(&line_string, &max, file_strings);
+ if (result == -1) break;
+
+ buffer_string.string = line_string;
+ buffer_string.used = (f_number_unsigned_t) result;
+ buffer_string.size = buffer_string.used;
+
+ max = 255;
+
+ result = getline(&line_object, &max, file_objects);
+ assert_return_code(result, 0);
+
+ buffer_object.string = line_object;
+ buffer_object.used = (f_number_unsigned_t) result;
+ buffer_object.size = buffer_object.used;
+
+ // The newline is copied by getline(), and so remove that newline before comparing.
+ buffer_object.string[--buffer_object.used] = 0;
+
+ state.status = F_none;
+ range.start = 0;
+ range.stop = buffer_string.used - 1;
+ found.start = 1;
+ found.stop = 0;
+
+ fl_fss_basic_object_read(buffer_string, &range, &found, "e, &delimits, &state);
+
+ assert_true(state.status == F_fss_found_object || state.status == F_fss_found_object_content_not);
+ assert_true(found.start <= found.stop);
+
+ {
+ const f_status_t status = f_string_dynamic_append(buffer_string, &delimit_string);
+ assert_int_equal(status, F_okay);
+ }
+
+ state.status = F_none;
+
+ f_fss_apply_delimit(delimits, &delimit_string, &state);
+ assert_int_equal(state.status, F_okay);
+
+ {
+ const f_status_t status = f_string_dynamic_partial_append_nulless(delimit_string, found, &result_string);
+ assert_true(status == F_okay || status == F_data_not_eos);
+ }
+
+ {
+ const f_status_t status = f_string_dynamic_terminate_after(&result_string);
+ assert_int_equal(status, F_okay);
+ }
+
+ assert_string_equal(result_string.string, line_object);
+
+ if (line_string) free(line_string);
+ if (line_object) free(line_object);
+ if (result_string.string) free(result_string.string);
+ if (delimit_string.string) free(delimit_string.string);
+ if (delimits.array) free(delimits.array);
+
+ line_string = 0;
+ line_object = 0;
+ result_string.string = 0;
+ result_string.used = 0;
+ result_string.size = 0;
+ delimit_string.string = 0;
+ delimit_string.used = 0;
+ delimit_string.size = 0;
+ delimits.array = 0;
+ delimits.used = 0;
+ delimits.size = 0;
+ } // for
+
+ if (file_strings) fclose(file_strings);
+ if (file_objects) fclose(file_objects);
+
+ if (delimits.array) free(delimits.array);
+ if (line_string) free(line_string);
+ if (line_object) free(line_object);
+ if (result_string.string) free(result_string.string);
+ if (delimit_string.string) free(delimit_string.string);
+ }
+}
+
#ifdef __cplusplus
} // extern "C"
#endif
*/
extern void test__fl_fss_basic_object_read__returns_data_not(void **state);
+
+/**
+ * Test that the function works.
+ *
+ * @see fl_fss_basic_object_read()
+ */
+extern void test__fl_fss_basic_object_read__works(void **state);
+
#endif // _TEST__FL_fss_basic_object_read_h
cmocka_unit_test(test__fl_fss_basic_object_read__returns_data_not),
cmocka_unit_test(test__fl_fss_basic_object_write__returns_data_not),
+ cmocka_unit_test(test__fl_fss_basic_content_read__works),
+ cmocka_unit_test(test__fl_fss_basic_object_read__works),
+
cmocka_unit_test(test__fl_fss_basic_list_content_read__returns_data_not),
cmocka_unit_test(test__fl_fss_basic_list_content_write__returns_data_not),
cmocka_unit_test(test__fl_fss_basic_list_object_read__returns_data_not),
#include <stddef.h>
#include <setjmp.h>
#include <stdint.h>
+#include <stdio.h>
#include <string.h>
#include <unistd.h>
// Mock includes.
//#include "mock-fss.h"
+// Data includes.
+#include "data-fss.h"
+
// Test includes.
#include "test-fss-basic_content_read.h"
#include "test-fss-basic_content_write.h"