From 70cbbe34121dc5679961df711e70724f13104489 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Tue, 23 Jan 2024 23:57:55 -0600 Subject: [PATCH] Progress: Add "works" unit tests for several FSS object and content reads. This is a follow up to the commit cb7fc88118cefd6756e1ae7aab83891d887cfb4c. Writing these unit tests exposed some bugs, such as: - The one solve in commit ba257a8b8385ec8dedfc9bc9bb596e420ca552f8. - The FSS extended read is not handling unterminated single quote correctly. An unterminated single quote in an extended requires that the quotes be treated as normal text, as per the standard. This means that the quote should be broken up into unquoted content. This is not the case and is considered a bug. For example, consider the following line: a " b c d. That line is currently being interpreted by extended read as a single content called: [0] = " b c d. Instead, this should end up being 4 contents: [0] = " [1] = b [2] = c [3] = d. The unit tests files that I created here should expect this and therefore the extended read tests currently fail. I am also adding the basic list tests but I did not get to implementing the basic list content read tests yet. The test data files exist but I need to review them and write the appropriate code. The extended list and the embedded list tests are not yet written. --- .../fl_fss/data/tests/contents/basic-all_read.txt | 86 +++++---- .../data/tests/contents/basic_list-all_read-0.txt | 1 + .../data/tests/contents/basic_list-all_read-1.txt | 0 .../data/tests/contents/basic_list-all_read-10.txt | 2 + .../data/tests/contents/basic_list-all_read-11.txt | 1 + .../data/tests/contents/basic_list-all_read-12.txt | 0 .../data/tests/contents/basic_list-all_read-2.txt | 2 + .../data/tests/contents/basic_list-all_read-3.txt | 6 + .../data/tests/contents/basic_list-all_read-4.txt | 2 + .../data/tests/contents/basic_list-all_read-5.txt | 4 + .../data/tests/contents/basic_list-all_read-6.txt | 1 + .../data/tests/contents/basic_list-all_read-7.txt | 4 + .../data/tests/contents/basic_list-all_read-8.txt | 2 + .../data/tests/contents/basic_list-all_read-9.txt | 3 + .../data/tests/contents/extended-all_read-0.txt | 53 ++++++ .../data/tests/contents/extended-all_read-1.txt | 53 ++++++ .../data/tests/contents/extended-all_read-2.txt | 53 ++++++ .../data/tests/contents/extended-all_read-3.txt | 53 ++++++ .../data/tests/contents/extended-all_read-4.txt | 53 ++++++ .../data/tests/contents/extended-all_read-5.txt | 53 ++++++ .../fl_fss/data/tests/objects/basic-all_read.txt | 14 ++ .../data/tests/objects/basic_list-all_read.txt | 13 ++ .../data/tests/objects/extended-all_read.txt | 53 ++++++ .../fl_fss/data/tests/strings/basic-all_read.txt | 86 +++++---- .../data/tests/strings/basic_list-all_read.txt | 43 +++++ .../data/tests/strings/extended-all_read.txt | 53 ++++++ level_1/fl_fss/tests/unit/c/data-fss.c | 22 ++- level_1/fl_fss/tests/unit/c/data-fss.h | 44 +++-- .../tests/unit/c/test-fss-basic_content_read.c | 11 +- .../tests/unit/c/test-fss-basic_content_read.h | 1 - .../tests/unit/c/test-fss-basic_list_object_read.c | 111 ++++++++++++ .../tests/unit/c/test-fss-basic_list_object_read.h | 7 + .../tests/unit/c/test-fss-basic_object_read.c | 11 +- .../tests/unit/c/test-fss-basic_object_read.h | 1 - .../tests/unit/c/test-fss-extended_content_read.c | 197 +++++++++++++++++++++ .../tests/unit/c/test-fss-extended_content_read.h | 7 + .../tests/unit/c/test-fss-extended_object_read.c | 107 +++++++++++ .../tests/unit/c/test-fss-extended_object_read.h | 7 + level_1/fl_fss/tests/unit/c/test-fss.c | 6 + 39 files changed, 1105 insertions(+), 121 deletions(-) create mode 100644 level_1/fl_fss/data/tests/contents/basic_list-all_read-0.txt create mode 100644 level_1/fl_fss/data/tests/contents/basic_list-all_read-1.txt create mode 100644 level_1/fl_fss/data/tests/contents/basic_list-all_read-10.txt create mode 100644 level_1/fl_fss/data/tests/contents/basic_list-all_read-11.txt create mode 100644 level_1/fl_fss/data/tests/contents/basic_list-all_read-12.txt create mode 100644 level_1/fl_fss/data/tests/contents/basic_list-all_read-2.txt create mode 100644 level_1/fl_fss/data/tests/contents/basic_list-all_read-3.txt create mode 100644 level_1/fl_fss/data/tests/contents/basic_list-all_read-4.txt create mode 100644 level_1/fl_fss/data/tests/contents/basic_list-all_read-5.txt create mode 100644 level_1/fl_fss/data/tests/contents/basic_list-all_read-6.txt create mode 100644 level_1/fl_fss/data/tests/contents/basic_list-all_read-7.txt create mode 100644 level_1/fl_fss/data/tests/contents/basic_list-all_read-8.txt create mode 100644 level_1/fl_fss/data/tests/contents/basic_list-all_read-9.txt create mode 100644 level_1/fl_fss/data/tests/contents/extended-all_read-0.txt create mode 100644 level_1/fl_fss/data/tests/contents/extended-all_read-1.txt create mode 100644 level_1/fl_fss/data/tests/contents/extended-all_read-2.txt create mode 100644 level_1/fl_fss/data/tests/contents/extended-all_read-3.txt create mode 100644 level_1/fl_fss/data/tests/contents/extended-all_read-4.txt create mode 100644 level_1/fl_fss/data/tests/contents/extended-all_read-5.txt create mode 100644 level_1/fl_fss/data/tests/objects/basic_list-all_read.txt create mode 100644 level_1/fl_fss/data/tests/objects/extended-all_read.txt create mode 100644 level_1/fl_fss/data/tests/strings/basic_list-all_read.txt create mode 100644 level_1/fl_fss/data/tests/strings/extended-all_read.txt diff --git a/level_1/fl_fss/data/tests/contents/basic-all_read.txt b/level_1/fl_fss/data/tests/contents/basic-all_read.txt index b9f0d78..3f4319b 100644 --- a/level_1/fl_fss/data/tests/contents/basic-all_read.txt +++ b/level_1/fl_fss/data/tests/contents/basic-all_read.txt @@ -1,39 +1,53 @@ -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 +b c d 1 +b c d 2 +b c d 3 +a b c 4 +b c 5 +d 6 +b c d 7 +b c d 8 +" b c d 9 +d 10 +d 11 +c d 12 +b c d 13 -c d +c d 14 { -c d +c d 15 -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 +b c d 16 +Ȁ b c d 17 +"Ȁ" b c d 18 +" Ȁ " b c d 19 +" Ȁ " b `c d` 20 +b c d 21 +b c d 22 +b c d 23 +c d' e 24 +c d" e 25 +c d` e 26 +c d' e 27 +c d" e 28 +c d` e 29 +b c d e 30 +b c d e 31 ' +b c d 32 +b c 33 +c d 34 +b c d 35 +b c d 36 +d zero​width 37 +мир 38 +e␠ +space! <-- should have the word 'space!' 39 +a comment...should have no slashes. 40 +a comment either...should have one slash. 41 +a comment either...should have two slashes. 42 +"b c d" "e f g" +"b c' d" "e' f g" +"b c` d" "e` f g" +'b c d' 'e f g' +'b c" d' 'e" f g' +`b c" d` `e" f g` +\'b c' d diff --git a/level_1/fl_fss/data/tests/contents/basic_list-all_read-0.txt b/level_1/fl_fss/data/tests/contents/basic_list-all_read-0.txt new file mode 100644 index 0000000..51c850e --- /dev/null +++ b/level_1/fl_fss/data/tests/contents/basic_list-all_read-0.txt @@ -0,0 +1 @@ + content. diff --git a/level_1/fl_fss/data/tests/contents/basic_list-all_read-1.txt b/level_1/fl_fss/data/tests/contents/basic_list-all_read-1.txt new file mode 100644 index 0000000..e69de29 diff --git a/level_1/fl_fss/data/tests/contents/basic_list-all_read-10.txt b/level_1/fl_fss/data/tests/contents/basic_list-all_read-10.txt new file mode 100644 index 0000000..8dbc0e5 --- /dev/null +++ b/level_1/fl_fss/data/tests/contents/basic_list-all_read-10.txt @@ -0,0 +1,2 @@ + Has UTF-8 characters. + diff --git a/level_1/fl_fss/data/tests/contents/basic_list-all_read-11.txt b/level_1/fl_fss/data/tests/contents/basic_list-all_read-11.txt new file mode 100644 index 0000000..5bbb0cc --- /dev/null +++ b/level_1/fl_fss/data/tests/contents/basic_list-all_read-11.txt @@ -0,0 +1 @@ + Has UTF-8: привет мир diff --git a/level_1/fl_fss/data/tests/contents/basic_list-all_read-12.txt b/level_1/fl_fss/data/tests/contents/basic_list-all_read-12.txt new file mode 100644 index 0000000..e69de29 diff --git a/level_1/fl_fss/data/tests/contents/basic_list-all_read-2.txt b/level_1/fl_fss/data/tests/contents/basic_list-all_read-2.txt new file mode 100644 index 0000000..fd49844 --- /dev/null +++ b/level_1/fl_fss/data/tests/contents/basic_list-all_read-2.txt @@ -0,0 +1,2 @@ + content as well. + With multiple lines. diff --git a/level_1/fl_fss/data/tests/contents/basic_list-all_read-3.txt b/level_1/fl_fss/data/tests/contents/basic_list-all_read-3.txt new file mode 100644 index 0000000..4feeaae --- /dev/null +++ b/level_1/fl_fss/data/tests/contents/basic_list-all_read-3.txt @@ -0,0 +1,6 @@ +Not tabbed over. + + +Has empty lines before and after. + + diff --git a/level_1/fl_fss/data/tests/contents/basic_list-all_read-4.txt b/level_1/fl_fss/data/tests/contents/basic_list-all_read-4.txt new file mode 100644 index 0000000..8e49978 --- /dev/null +++ b/level_1/fl_fss/data/tests/contents/basic_list-all_read-4.txt @@ -0,0 +1,2 @@ +This: is not a list. + diff --git a/level_1/fl_fss/data/tests/contents/basic_list-all_read-5.txt b/level_1/fl_fss/data/tests/contents/basic_list-all_read-5.txt new file mode 100644 index 0000000..7d091ee --- /dev/null +++ b/level_1/fl_fss/data/tests/contents/basic_list-all_read-5.txt @@ -0,0 +1,4 @@ + + just: + Add a slash. + diff --git a/level_1/fl_fss/data/tests/contents/basic_list-all_read-6.txt b/level_1/fl_fss/data/tests/contents/basic_list-all_read-6.txt new file mode 100644 index 0000000..9976c8b --- /dev/null +++ b/level_1/fl_fss/data/tests/contents/basic_list-all_read-6.txt @@ -0,0 +1 @@ + a slash. diff --git a/level_1/fl_fss/data/tests/contents/basic_list-all_read-7.txt b/level_1/fl_fss/data/tests/contents/basic_list-all_read-7.txt new file mode 100644 index 0000000..8f08fc0 --- /dev/null +++ b/level_1/fl_fss/data/tests/contents/basic_list-all_read-7.txt @@ -0,0 +1,4 @@ + slashes. +Has Slashes but is not a list\: + This is part of the previous one. + diff --git a/level_1/fl_fss/data/tests/contents/basic_list-all_read-8.txt b/level_1/fl_fss/data/tests/contents/basic_list-all_read-8.txt new file mode 100644 index 0000000..686da75 --- /dev/null +++ b/level_1/fl_fss/data/tests/contents/basic_list-all_read-8.txt @@ -0,0 +1,2 @@ + The object name is an empty string. + diff --git a/level_1/fl_fss/data/tests/contents/basic_list-all_read-9.txt b/level_1/fl_fss/data/tests/contents/basic_list-all_read-9.txt new file mode 100644 index 0000000..bf63add --- /dev/null +++ b/level_1/fl_fss/data/tests/contents/basic_list-all_read-9.txt @@ -0,0 +1,3 @@ + Quotes aren't supported here, so this is not an empty object. +: + diff --git a/level_1/fl_fss/data/tests/contents/extended-all_read-0.txt b/level_1/fl_fss/data/tests/contents/extended-all_read-0.txt new file mode 100644 index 0000000..6975f68 --- /dev/null +++ b/level_1/fl_fss/data/tests/contents/extended-all_read-0.txt @@ -0,0 +1,53 @@ +b +b +b +a +b +d +b +b +" +d +d +c +b + +c +{ +c + +b +Ȁ +Ȁ + Ȁ + Ȁ +b +b +b +c +c +c +c +c +c +b +b +b +b +c +b +b +d +мир +e␠ +space! +a +a +a +b c d +b c' d +b c` d +b c d +b c" d +b c" d +'b diff --git a/level_1/fl_fss/data/tests/contents/extended-all_read-1.txt b/level_1/fl_fss/data/tests/contents/extended-all_read-1.txt new file mode 100644 index 0000000..6b25560 --- /dev/null +++ b/level_1/fl_fss/data/tests/contents/extended-all_read-1.txt @@ -0,0 +1,53 @@ +c +c +c +b +c +6 +c +c +b +10 +11 +d +c + +d + +d + +c +b +b +b +b +c +c +c +d' +d" +d` +d' +d" +d` +c +c +c +c +d +c +c +zero​width +38 + +<-- +comment...should +comment +comment +e f g +e' f g +e` f g +e f g +e" f g +e" f g +c' diff --git a/level_1/fl_fss/data/tests/contents/extended-all_read-2.txt b/level_1/fl_fss/data/tests/contents/extended-all_read-2.txt new file mode 100644 index 0000000..c438882 --- /dev/null +++ b/level_1/fl_fss/data/tests/contents/extended-all_read-2.txt @@ -0,0 +1,53 @@ +d +d +d +c +5 + +d +d +c + + +12 +d + +14 + +15 + +d +c +c +c +c d +d +d +d +e +e +e +e +e +e +d +d +d +33 +34 +d +d +37 + + +should +have +either...should +either...should + + + + + + +d diff --git a/level_1/fl_fss/data/tests/contents/extended-all_read-3.txt b/level_1/fl_fss/data/tests/contents/extended-all_read-3.txt new file mode 100644 index 0000000..3f63162 --- /dev/null +++ b/level_1/fl_fss/data/tests/contents/extended-all_read-3.txt @@ -0,0 +1,53 @@ +1 +2 +3 +4 + + +7 +8 + + + + +13 + + + + + +16 +d +d +d +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +e +e +32 + + +35 +36 + + + +have +no +have +have + + + + + + + diff --git a/level_1/fl_fss/data/tests/contents/extended-all_read-4.txt b/level_1/fl_fss/data/tests/contents/extended-all_read-4.txt new file mode 100644 index 0000000..23633ef --- /dev/null +++ b/level_1/fl_fss/data/tests/contents/extended-all_read-4.txt @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + +17 +18 +19 + + + + + + + + + + +30 +31 + + + + + + + + +the +slashes. +one +two + + + + + + + diff --git a/level_1/fl_fss/data/tests/contents/extended-all_read-5.txt b/level_1/fl_fss/data/tests/contents/extended-all_read-5.txt new file mode 100644 index 0000000..88e9613 --- /dev/null +++ b/level_1/fl_fss/data/tests/contents/extended-all_read-5.txt @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +' + + + + + + + + +word +40 +slash. +slashes. + + + + + + + diff --git a/level_1/fl_fss/data/tests/objects/basic-all_read.txt b/level_1/fl_fss/data/tests/objects/basic-all_read.txt index 1194a09..ecad368 100644 --- a/level_1/fl_fss/data/tests/objects/basic-all_read.txt +++ b/level_1/fl_fss/data/tests/objects/basic-all_read.txt @@ -37,3 +37,17 @@ a a a a +c +привет +мир +UTF +#not +\#not +\\#not +a +a +a +a +a +a +a diff --git a/level_1/fl_fss/data/tests/objects/basic_list-all_read.txt b/level_1/fl_fss/data/tests/objects/basic_list-all_read.txt new file mode 100644 index 0000000..022a5a7 --- /dev/null +++ b/level_1/fl_fss/data/tests/objects/basic_list-all_read.txt @@ -0,0 +1,13 @@ +first +empty +third +fourth +spaces around +To "disable" +Has\ +Also Has\\ + +"" +привет +Content also' +Comments diff --git a/level_1/fl_fss/data/tests/objects/extended-all_read.txt b/level_1/fl_fss/data/tests/objects/extended-all_read.txt new file mode 100644 index 0000000..ecad368 --- /dev/null +++ b/level_1/fl_fss/data/tests/objects/extended-all_read.txt @@ -0,0 +1,53 @@ +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 +c +привет +мир +UTF +#not +\#not +\\#not +a +a +a +a +a +a +a diff --git a/level_1/fl_fss/data/tests/strings/basic-all_read.txt b/level_1/fl_fss/data/tests/strings/basic-all_read.txt index bf11853..5100089 100644 --- a/level_1/fl_fss/data/tests/strings/basic-all_read.txt +++ b/level_1/fl_fss/data/tests/strings/basic-all_read.txt @@ -1,39 +1,53 @@ -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 1 + a b c d 2 + a b c d 3 +. a b c 4 +.a b c 5 +"a b c" d 6 +\"a b c d 7 +a" b c d 8 +a " b c d 9 +'a b" c' d 10 +'a b` c' d 11 +`a b` c d 12 +a: b c d 13 a: - b c d + b c d 14 a { - b c d + b c d 15 } -Ȁ 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 +Ȁ b c d 16 +Ȃ Ȁ b c d 17 +Ȃ "Ȁ" b c d 18 +Ȃ " Ȁ " b c d 19 +Ȃ " Ȁ " b `c d` 20 +`Ȁ Ƞ` b c d 21 +"Ȁ Ƞ" b c d 22 +'Ȁ Ƞ' b c d 23 +''A b' c d' e 24 +""A b" c d" e 25 +``A b` c d` e 26 +'A b'' c d' e 27 +"A b"" c d" e 28 +`A b`` c d` e 29 +a b c d e 30 +a b c d e 31 ' + a b c d 32 +a b c 33 + a c d 34 +a b c d 35 +a b c d 36 +c d zero​width 37 +привет мир 38 +мир e␠ + UTF space! <-- should have the word 'space!' 39 +\#not a comment...should have no slashes. 40 +\\#not a comment either...should have one slash. 41 +\\\#not a comment either...should have two slashes. 42 +a "b c d" "e f g" +a "b c' d" "e' f g" +a "b c` d" "e` f g" +a 'b c d' 'e f g' +a 'b c" d' 'e" f g' +a `b c" d` `e" f g` +a \'b c' d diff --git a/level_1/fl_fss/data/tests/strings/basic_list-all_read.txt b/level_1/fl_fss/data/tests/strings/basic_list-all_read.txt new file mode 100644 index 0000000..c6d24e9 --- /dev/null +++ b/level_1/fl_fss/data/tests/strings/basic_list-all_read.txt @@ -0,0 +1,43 @@ +first: + content. +empty: +third: + content as well. + With multiple lines. +fourth: +Not tabbed over. + + +Has empty lines before and after. + + + spaces around : +This: is not a list. + +To "disable": + + just\: + Add a slash. + +Has\\: + a slash. +Also Has\\\\: + slashes. +Has Slashes but is not a list\\\: + This is part of the previous one. + +: + The object name is an empty string. + +"": + Quotes aren't supported here, so this is not an empty object. +\: + +привет: + Has UTF-8 characters. + +Content also': + Has UTF-8: привет мир +Comments: +# Are + #### ignored. diff --git a/level_1/fl_fss/data/tests/strings/extended-all_read.txt b/level_1/fl_fss/data/tests/strings/extended-all_read.txt new file mode 100644 index 0000000..5100089 --- /dev/null +++ b/level_1/fl_fss/data/tests/strings/extended-all_read.txt @@ -0,0 +1,53 @@ +a b c d 1 + a b c d 2 + a b c d 3 +. a b c 4 +.a b c 5 +"a b c" d 6 +\"a b c d 7 +a" b c d 8 +a " b c d 9 +'a b" c' d 10 +'a b` c' d 11 +`a b` c d 12 +a: b c d 13 +a: + b c d 14 +a { + b c d 15 +} +Ȁ b c d 16 +Ȃ Ȁ b c d 17 +Ȃ "Ȁ" b c d 18 +Ȃ " Ȁ " b c d 19 +Ȃ " Ȁ " b `c d` 20 +`Ȁ Ƞ` b c d 21 +"Ȁ Ƞ" b c d 22 +'Ȁ Ƞ' b c d 23 +''A b' c d' e 24 +""A b" c d" e 25 +``A b` c d` e 26 +'A b'' c d' e 27 +"A b"" c d" e 28 +`A b`` c d` e 29 +a b c d e 30 +a b c d e 31 ' + a b c d 32 +a b c 33 + a c d 34 +a b c d 35 +a b c d 36 +c d zero​width 37 +привет мир 38 +мир e␠ + UTF space! <-- should have the word 'space!' 39 +\#not a comment...should have no slashes. 40 +\\#not a comment either...should have one slash. 41 +\\\#not a comment either...should have two slashes. 42 +a "b c d" "e f g" +a "b c' d" "e' f g" +a "b c` d" "e` f g" +a 'b c d' 'e f g' +a 'b c" d' 'e" f g' +a `b c" d` `e" f g` +a \'b c' d diff --git a/level_1/fl_fss/tests/unit/c/data-fss.c b/level_1/fl_fss/tests/unit/c/data-fss.c index ca1601d..458e52b 100644 --- a/level_1/fl_fss/tests/unit/c/data-fss.c +++ b/level_1/fl_fss/tests/unit/c/data-fss.c @@ -4,16 +4,24 @@ extern "C" { #endif -FILE *data__contents_file_open__basic_all_read(void) { - return fopen("./data/tests/contents/basic-all_read.txt", "r"); -} +FILE *data__file_open__named__all_read(const f_string_t set, const f_string_t name) { + char path[255]; + + memset(path, 0, 255); + + snprintf(path, 254, "./data/tests/%s/%s-all_read.txt", set, name); -FILE *data__objects_file_open__basic_all_read(void) { - return fopen("./data/tests/objects/basic-all_read.txt", "r"); + return fopen(path, "r"); } -FILE *data__strings_file_open__basic_all_read(void) { - return fopen("./data/tests/strings/basic-all_read.txt", "r"); +FILE *data__file_open__named_at__all_read(const f_string_t set, const f_string_t name, const uint8_t at) { + char path[255]; + + memset(path, 0, 255); + + snprintf(path, 254, "./data/tests/%s/%s-all_read-%d.txt", set, name, at); + + return fopen(path, "r"); } #ifdef __cplusplus diff --git a/level_1/fl_fss/tests/unit/c/data-fss.h b/level_1/fl_fss/tests/unit/c/data-fss.h index 6a7446a..e6e3fe9 100644 --- a/level_1/fl_fss/tests/unit/c/data-fss.h +++ b/level_1/fl_fss/tests/unit/c/data-fss.h @@ -31,26 +31,16 @@ extern "C" { #endif /** - * Open the "FSS basic" contents file. + * Open the test data file for the given set with the given name. * - * 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". + * This requires the following: + * - The file path is relative to the current working directory (tests are run from project root). + * - The file path is "data/tests/${set}/${name}-all_read.txt". + * - Where "${set}" represents the directory set, like "contents", "objects", or "strings". + * - Where "${name}" represents the standard name, such as "basic" or "extended". * - * @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". + * @param at + * A number representing the specific content index position. * * @return * Non-zero on success. @@ -58,14 +48,20 @@ extern FILE *data__contents_file_open__basic_all_read(void); * * @see fopen() */ -extern FILE *data__objects_file_open__basic_all_read(void); +extern FILE *data__file_open__named__all_read(const f_string_t set, const f_string_t name); /** - * Open the "fss basic" strings file. + * Open the test data file for the given set with the given name and the given at index. + * + * This requires the following: + * - The file path is relative to the current working directory (tests are run from project root). + * - The file path is "data/tests/${set}/${name}-all_read-${at}.txt". + * - Where "${at}" represents the index. + * - Where "${set}" represents the directory set, like "contents", "objects", or "strings". + * - Where "${name}" represents the standard name, such as "basic" or "extended". * - * 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". + * @param at + * A number representing the specific content index position. * * @return * Non-zero on success. @@ -73,7 +69,7 @@ extern FILE *data__objects_file_open__basic_all_read(void); * * @see fopen() */ -extern FILE *data__strings_file_open__basic_all_read(void); +extern FILE *data__file_open__named_at__all_read(const f_string_t set, const f_string_t name, const uint8_t at); #ifdef __cplusplus } // extern "C" diff --git a/level_1/fl_fss/tests/unit/c/test-fss-basic_content_read.c b/level_1/fl_fss/tests/unit/c/test-fss-basic_content_read.c index dec2333..b97d9aa 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-basic_content_read.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-basic_content_read.c @@ -89,8 +89,8 @@ 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(); + FILE *file_strings = data__file_open__named__all_read("strings", "basic"); + FILE *file_contents = data__file_open__named__all_read("contents", "basic"); assert_non_null(file_strings); assert_non_null(file_contents); @@ -101,7 +101,6 @@ void test__fl_fss_basic_content_read__works(void **void_state) { 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; @@ -129,12 +128,8 @@ void test__fl_fss_basic_content_read__works(void **void_state) { 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; + line_content[result - 1] = 0; state.status = F_none; range.start = 0; diff --git a/level_1/fl_fss/tests/unit/c/test-fss-basic_content_read.h b/level_1/fl_fss/tests/unit/c/test-fss-basic_content_read.h index be4c584..6eb08e0 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-basic_content_read.h +++ b/level_1/fl_fss/tests/unit/c/test-fss-basic_content_read.h @@ -24,7 +24,6 @@ extern void test__fl_fss_basic_content_read__parameter_checking(void **state); */ extern void test__fl_fss_basic_content_read__returns_data_not(void **state); - /** * Test that the function works. * diff --git a/level_1/fl_fss/tests/unit/c/test-fss-basic_list_object_read.c b/level_1/fl_fss/tests/unit/c/test-fss-basic_list_object_read.c index 5b17c23..a58b676 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-basic_list_object_read.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-basic_list_object_read.c @@ -85,6 +85,117 @@ void test__fl_fss_basic_list_object_read__returns_data_not(void **void_state) { } } +void test__fl_fss_basic_list_object_read__works(void **void_state) { + + { + FILE *file_strings = data__file_open__named__all_read("strings", "basic_list"); + FILE *file_objects = data__file_open__named__all_read("objects", "basic_list"); + + 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_state_t state = f_state_t_initialize; + f_range_t range = f_range_t_initialize; + f_range_t found = f_range_t_initialize; + 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 (int line = 1;; ++line) { + + 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; + + state.status = F_none; + range.start = 0; + range.stop = buffer_string.used - 1; + found.start = 1; + found.stop = 0; + + fl_fss_basic_list_object_read(buffer_string, &range, &found, &delimits, &state); + + assert_true(state.status == F_fss_found_object || state.status == F_fss_found_object_not); + + if (state.status == F_fss_found_object) { + max = 255; + + result = getline(&line_object, &max, file_objects); + assert_return_code(result, 0); + + // The newline is copied by getline(), and so remove that newline before comparing. + line_object[result - 1] = 0; + + if (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); + } + else { + assert_int_equal(line_object[0], 0); + } + } + + 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 diff --git a/level_1/fl_fss/tests/unit/c/test-fss-basic_list_object_read.h b/level_1/fl_fss/tests/unit/c/test-fss-basic_list_object_read.h index 52ee19b..d76c6f9 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-basic_list_object_read.h +++ b/level_1/fl_fss/tests/unit/c/test-fss-basic_list_object_read.h @@ -24,4 +24,11 @@ extern void test__fl_fss_basic_list_object_read__parameter_checking(void **state */ extern void test__fl_fss_basic_list_object_read__returns_data_not(void **state); +/** + * Test that the function works. + * + * @see fl_fss_basic_list_object_read() + */ +extern void test__fl_fss_basic_list_object_read__works(void **state); + #endif // _TEST__FL_fss_basic_list_object_read_list_h diff --git a/level_1/fl_fss/tests/unit/c/test-fss-basic_object_read.c b/level_1/fl_fss/tests/unit/c/test-fss-basic_object_read.c index f0f1fb1..51b86ab 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-basic_object_read.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-basic_object_read.c @@ -139,8 +139,8 @@ 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(); + FILE *file_strings = data__file_open__named__all_read("strings", "basic"); + FILE *file_objects = data__file_open__named__all_read("objects", "basic"); assert_non_null(file_strings); assert_non_null(file_objects); @@ -151,7 +151,6 @@ void test__fl_fss_basic_object_read__works(void **void_state) { 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; @@ -177,12 +176,8 @@ void test__fl_fss_basic_object_read__works(void **void_state) { 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; + line_object[result - 1] = 0; state.status = F_none; range.start = 0; diff --git a/level_1/fl_fss/tests/unit/c/test-fss-basic_object_read.h b/level_1/fl_fss/tests/unit/c/test-fss-basic_object_read.h index feeaee0..33e6111 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-basic_object_read.h +++ b/level_1/fl_fss/tests/unit/c/test-fss-basic_object_read.h @@ -24,7 +24,6 @@ extern void test__fl_fss_basic_object_read__parameter_checking(void **state); */ extern void test__fl_fss_basic_object_read__returns_data_not(void **state); - /** * Test that the function works. * diff --git a/level_1/fl_fss/tests/unit/c/test-fss-extended_content_read.c b/level_1/fl_fss/tests/unit/c/test-fss-extended_content_read.c index 46fef01..2e6cdaa 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-extended_content_read.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-extended_content_read.c @@ -135,6 +135,203 @@ void test__fl_fss_extended_content_read__returns_data_not(void **void_state) { } } +void test__fl_fss_extended_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__file_open__named__all_read("strings", "extended"); + + FILE *file_contents[] = { + data__file_open__named_at__all_read("contents", "extended", 0), + data__file_open__named_at__all_read("contents", "extended", 1), + data__file_open__named_at__all_read("contents", "extended", 2), + data__file_open__named_at__all_read("contents", "extended", 3), + data__file_open__named_at__all_read("contents", "extended", 4), + data__file_open__named_at__all_read("contents", "extended", 5), + }; + + assert_non_null(file_strings); + assert_non_null(file_contents[0]); + assert_non_null(file_contents[1]); + assert_non_null(file_contents[2]); + assert_non_null(file_contents[3]); + assert_non_null(file_contents[4]); + assert_non_null(file_contents[5]); + + size_t max = 0; + char *line_string = 0; + char *line_content[] = { + 0, + 0, + 0, + 0, + 0, + 0, + }; + ssize_t result = 0; + const uint8_t total_content = 6; + + f_string_static_t buffer_string = 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_uint8s_t quotes = f_uint8s_t_initialize; + 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; + + for (uint8_t i = 0; i < total_content; ++i) { + + result = getline(&line_content[i], &max, file_contents[i]); + assert_return_code(result, 0); + + // The newline is copied by getline(), and so remove that newline before comparing. + line_content[i][result - 1] = 0; + } // or + + state.status = F_none; + range.start = 0; + range.stop = buffer_string.used - 1; + found_object.start = 1; + found_object.stop = 0; + + fl_fss_extended_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_extended_content_read(buffer_string, &range, &found, "es, &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); + assert_true(found.used < total_content); + + { + 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); + + { + uint8_t i = 0; + + for (; i < found.used; ++i) { + + result_string.used = 0; + + { + const f_status_t status = f_string_dynamic_partial_append_nulless(delimit_string, found.array[i], &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[i]); + } // for + + // All remaining positions in the file need to be a zero length string. + for (; i < total_content; ++i) { + assert_int_equal(line_content[i][0], 0); + } + } + } + else { + assert_true(!found.used); + } + + if (line_string) free(line_string); + if (line_content[0]) free(line_content[0]); + if (line_content[1]) free(line_content[1]); + if (line_content[2]) free(line_content[2]); + if (line_content[3]) free(line_content[3]); + if (line_content[4]) free(line_content[4]); + if (line_content[5]) free(line_content[5]); + 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); + if (quotes.array) free(quotes.array); + + line_string = 0; + line_content[0] = 0; + line_content[1] = 0; + line_content[2] = 0; + line_content[3] = 0; + line_content[4] = 0; + line_content[5] = 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; + quotes.array = 0; + quotes.used = 0; + quotes.size = 0; + } // for + + if (file_strings) fclose(file_strings); + if (file_contents[0]) fclose(file_contents[0]); + if (file_contents[1]) fclose(file_contents[1]); + if (file_contents[2]) fclose(file_contents[2]); + if (file_contents[3]) fclose(file_contents[3]); + if (file_contents[4]) fclose(file_contents[4]); + if (file_contents[5]) fclose(file_contents[5]); + + if (delimits.array) free(delimits.array); + if (found.array) free(found.array); + if (quotes.array) free(quotes.array); + if (line_string) free(line_string); + if (line_content[0]) free(line_content[0]); + if (line_content[1]) free(line_content[1]); + if (line_content[2]) free(line_content[2]); + if (line_content[3]) free(line_content[3]); + if (line_content[4]) free(line_content[4]); + if (line_content[5]) free(line_content[5]); + if (result_string.string) free(result_string.string); + if (delimit_string.string) free(delimit_string.string); + } +} + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_1/fl_fss/tests/unit/c/test-fss-extended_content_read.h b/level_1/fl_fss/tests/unit/c/test-fss-extended_content_read.h index 75ee0de..42d79e4 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-extended_content_read.h +++ b/level_1/fl_fss/tests/unit/c/test-fss-extended_content_read.h @@ -24,4 +24,11 @@ extern void test__fl_fss_extended_content_read__parameter_checking(void **state) */ extern void test__fl_fss_extended_content_read__returns_data_not(void **state); +/** + * Test that the function works. + * + * @see fl_fss_extended_content_read() + */ +extern void test__fl_fss_extended_content_read__works(void **state); + #endif // _TEST__FL_fss_extended_content_read_h diff --git a/level_1/fl_fss/tests/unit/c/test-fss-extended_object_read.c b/level_1/fl_fss/tests/unit/c/test-fss-extended_object_read.c index 3bb97b5..50b86c8 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-extended_object_read.c +++ b/level_1/fl_fss/tests/unit/c/test-fss-extended_object_read.c @@ -151,6 +151,113 @@ void test__fl_fss_extended_object_read__returns_data_not(void **void_state) { } } +void test__fl_fss_extended_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__file_open__named__all_read("strings", "extended"); + FILE *file_objects = data__file_open__named__all_read("objects", "extended"); + + 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_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 (int line = 0; ; ++line) { + + 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); + + // The newline is copied by getline(), and so remove that newline before comparing. + line_object[result - 1] = 0; + + state.status = F_none; + range.start = 0; + range.stop = buffer_string.used - 1; + found.start = 1; + found.stop = 0; + + fl_fss_extended_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 diff --git a/level_1/fl_fss/tests/unit/c/test-fss-extended_object_read.h b/level_1/fl_fss/tests/unit/c/test-fss-extended_object_read.h index d92c6b0..3add807 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss-extended_object_read.h +++ b/level_1/fl_fss/tests/unit/c/test-fss-extended_object_read.h @@ -24,4 +24,11 @@ extern void test__fl_fss_extended_object_read__parameter_checking(void **state); */ extern void test__fl_fss_extended_object_read__returns_data_not(void **state); +/** + * Test that the function works. + * + * @see fl_fss_extended_object_read() + */ +extern void test__fl_fss_extended_object_read__works(void **state); + #endif // _TEST__FL_fss_extended_object_read_h diff --git a/level_1/fl_fss/tests/unit/c/test-fss.c b/level_1/fl_fss/tests/unit/c/test-fss.c index 505c554..a220c8e 100644 --- a/level_1/fl_fss/tests/unit/c/test-fss.c +++ b/level_1/fl_fss/tests/unit/c/test-fss.c @@ -32,6 +32,9 @@ int main(void) { cmocka_unit_test(test__fl_fss_basic_list_object_read__returns_data_not), cmocka_unit_test(test__fl_fss_basic_list_object_write__returns_data_not), + //cmocka_unit_test(test__fl_fss_basic_list_content_read__works), + cmocka_unit_test(test__fl_fss_basic_list_object_read__works), + cmocka_unit_test(test__fl_fss_embedded_list_content_read__returns_data_not), cmocka_unit_test(test__fl_fss_embedded_list_content_write__returns_data_not), cmocka_unit_test(test__fl_fss_embedded_list_object_read__returns_data_not), @@ -42,6 +45,9 @@ int main(void) { cmocka_unit_test(test__fl_fss_extended_object_read__returns_data_not), cmocka_unit_test(test__fl_fss_extended_object_write__returns_data_not), + cmocka_unit_test(test__fl_fss_extended_content_read__works), + cmocka_unit_test(test__fl_fss_extended_object_read__works), + cmocka_unit_test(test__fl_fss_extended_list_content_read__returns_data_not), cmocka_unit_test(test__fl_fss_extended_list_content_write__returns_data_not), cmocka_unit_test(test__fl_fss_extended_list_object_read__returns_data_not), -- 1.8.3.1