aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@users.noreply.github.com>2020-05-24 13:25:01 -0400
committerGitHub <noreply@github.com>2020-05-24 13:25:01 -0400
commitc205840e737b23614a686a9675b896106cee5c64 (patch)
treef2eb9d93edb1540221daea3682bf13254d28128c /tests
parent03e39ae5dcd4002ac9657a550c48b8e9f85c449c (diff)
parenta38fbb5766b48a9695ea139f79634fc746642bdd (diff)
downloadspmc-c205840e737b23614a686a9675b896106cee5c64.tar.gz
Merge pull request #37 from jhunkeler/version-fixups
Version fixups
Diffstat (limited to 'tests')
-rw-r--r--tests/framework.h4
-rw-r--r--tests/test_str_isdigit_s.c21
-rw-r--r--tests/test_str_tolower_s.c25
-rw-r--r--tests/test_version.c95
4 files changed, 143 insertions, 2 deletions
diff --git a/tests/framework.h b/tests/framework.h
index aefdef2..c9170b6 100644
--- a/tests/framework.h
+++ b/tests/framework.h
@@ -153,8 +153,8 @@ char *mock_size(size_t size, const char *fill_byte) {
char *mock_image(int img_type, const char *img_name, char **_extra_compiler_args, int *exit_code) {
char libsuffix[10] = {0,};
char code[255] = {0,};
- char code_filename[FILENAME_MAX] = {0,};
- char img_filename[FILENAME_MAX] = {0,};
+ char code_filename[255] = {0,};
+ char img_filename[255] = {0,};
char cmd[PATH_MAX] = {0,};
char *extra_compiler_args = NULL;
Process *proc = NULL;
diff --git a/tests/test_str_isdigit_s.c b/tests/test_str_isdigit_s.c
new file mode 100644
index 0000000..5dd729c
--- /dev/null
+++ b/tests/test_str_isdigit_s.c
@@ -0,0 +1,21 @@
+#include "spm.h"
+#include "framework.h"
+
+const char *testFmt = "case '%s': returned '%d', expected '%d'\n";
+struct TestCase testCase[] = {
+ {.caseValue.str = "1234", .truthValue.signed_int = 1},
+ {.caseValue.str = "1234000000000", .truthValue.signed_int = 1},
+ {.caseValue.str = "1234aa", .truthValue.signed_int = 0},
+ {.caseValue.str = "z1234a", .truthValue.signed_int = 0},
+ {.caseValue.str = "gabcde", .truthValue.signed_int = 0},
+};
+size_t numCases = sizeof(testCase) / sizeof(struct TestCase);
+
+int main(int argc, char *argv[]) {
+ for (size_t i = 0; i < numCases; i++) {
+ int result = isdigit_s(testCase[i].caseValue.str);
+ int truth = testCase[i].truthValue.signed_int;
+ myassert(result == truth, testFmt, testCase[i].caseValue.str, result, truth);
+ }
+ return 0;
+} \ No newline at end of file
diff --git a/tests/test_str_tolower_s.c b/tests/test_str_tolower_s.c
new file mode 100644
index 0000000..f36b23d
--- /dev/null
+++ b/tests/test_str_tolower_s.c
@@ -0,0 +1,25 @@
+#include "spm.h"
+#include "framework.h"
+
+const char *testFmt = "case '%s': returned '%d', expected '%d'\n";
+struct TestCase testCase[] = {
+ {.caseValue.str = "ThE", .truthValue.sptr = "the"},
+ {.caseValue.str = "KIdS", .truthValue.sptr = "kids"},
+ {.caseValue.str = "AREn'T", .truthValue.sptr= "aren't"},
+ {.caseValue.str = "aLL", .truthValue.sptr = "all"},
+ {.caseValue.str = "RiGHt", .truthValue.sptr = "right"},
+ {.caseValue.str = "By", .truthValue.sptr = "by"},
+ {.caseValue.str = "THe oFfSpRiNg", .truthValue.sptr = "the offspring"},
+};
+size_t numCases = sizeof(testCase) / sizeof(struct TestCase);
+
+int main(int argc, char *argv[]) {
+ for (size_t i = 0; i < numCases; i++) {
+ char *orig = strdup(testCase[i].caseValue.str);
+ char *result = tolower_s(testCase[i].caseValue.str);
+ const char *truth = testCase[i].truthValue.sptr;
+ myassert(strcmp(result, truth) == 0, testFmt, orig, result, truth);
+ free(orig);
+ }
+ return 0;
+} \ No newline at end of file
diff --git a/tests/test_version.c b/tests/test_version.c
new file mode 100644
index 0000000..79c02d0
--- /dev/null
+++ b/tests/test_version.c
@@ -0,0 +1,95 @@
+#include "spm.h"
+#include "framework.h"
+
+
+const char *testFmt = "case %s: returned %llu (0x%llX), expected >%llu (0x%llX)\n";
+struct TestCase testCase[] = {
+ {},
+};
+size_t numCases = sizeof(testCase) / sizeof(struct TestCase);
+
+char *versions[] = {
+ "0.0.1", "0.0.2", "0.0.3", "0.0.4", "0.0.5", "0.0.6", "0.0.7", "0.0.8", "0.0.9", "0.0.10",
+ "0.1", "0.1.1", "0.1.2", "0.1.3", "0.1.4", "0.1.5", "0.1.6", "0.1.7", "0.1.8", "0.1.9", "0.1.10",
+ "0.2", "0.2.1", "0.2.2", "0.2.3", "0.2.4", "0.2.5", "0.2.6", "0.2.7", "0.2.8", "0.2.9", "0.2.10",
+ "0.9", "0.9.1", "0.9.2", "0.9.3", "0.9.4", "0.9.5", "0.9.6", "0.9.7", "0.9.8", "0.9.9", "0.9.10",
+ "0.10.0", "0.10.1", "0.10.2", "0.10.3", "0.10.4", "0.10.5", "0.10.6", "0.10.7", "0.10.8", "0.10.9",
+ "0.10.10",
+ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
+ "100.1a", "100.1a2", "100.3a10", "101", "101.1",
+ "2019.1", "2019.2a", "2019.3",
+ "2020.1", "2020.2a", "2020.3", "2020.4.1",
+};
+char *nonsense[] = {
+ "big_fat_sausage_waffles+glass_of_juice",
+ "big_fat_sausage_waffles.1+cup_of_fresh_broken_glass",
+};
+
+int main(int argc, char *argv[]) {
+ struct Version *prev = NULL;
+
+ for (size_t i = 0; i < (sizeof(versions) / sizeof(char *)); i++) {
+ struct Version *version = version_init();
+ version_read(&version, versions[i]);
+
+ myassert(spmerrno == 0, "Unexpected error: %s\n", spm_strerror(spmerrno));
+
+ if (prev != NULL) {
+ myassert(version->asInt > prev->asInt,
+ testFmt, versions[i],
+ version->asInt, version->asInt,
+ prev->asInt, prev->asInt);
+ }
+
+ prev = version;
+ }
+
+ prev = NULL;
+ for (size_t i = 0; i < (sizeof(nonsense) / sizeof(char *)); i++) {
+ struct Version *version = version_init();
+ version_read(&version, nonsense[i]);
+
+ myassert(spmerrno == 0, "Unexpected error: %s\n", spm_strerror(spmerrno));
+
+ if (prev != NULL) {
+ myassert(version->asInt > prev->asInt,
+ testFmt, nonsense[i],
+ version->asInt, version->asInt,
+ prev->asInt, prev->asInt);
+ }
+
+ prev = version;
+ }
+
+ // Check the wrapper, version_from(), produces the same results as "the long way" above
+ uint64_t prev_i = 0;
+ for (size_t i = 0; i < (sizeof(versions) / sizeof(char *)); i++) {
+ myassert(spmerrno == 0, "Unexpected error: %s\n", spm_strerror(spmerrno));
+
+ uint64_t result = version_from(versions[i]);
+ if (prev_i > 0) {
+ myassert(result > prev_i,
+ testFmt, versions[i],
+ result, result,
+ prev_i, prev_i);
+ }
+
+ prev_i = result;
+ }
+
+ prev_i = 0;
+ for (size_t i = 0; i < (sizeof(nonsense) / sizeof(char *)); i++) {
+ myassert(spmerrno == 0, "Unexpected error: %s\n", spm_strerror(spmerrno));
+
+ uint64_t result = version_from(nonsense[i]);
+ if (prev_i > 0) {
+ myassert(result > prev_i,
+ testFmt, nonsense[i],
+ result, result,
+ prev_i, prev_i);
+ }
+
+ prev_i = result;
+ }
+ return 0;
+}