diff options
author | dzwdz | 2021-08-03 19:01:43 +0200 |
---|---|---|
committer | dzwdz | 2021-08-03 19:01:43 +0200 |
commit | 18380bea869c307c0ecf6fe4fa5801e5540bec4e (patch) | |
tree | b4130b82cb50629fa3f462aa5f5a064d30107100 /src/kernel | |
parent | 5d5b1d775984fe0112c0e1f60500c7d8e9850337 (diff) |
kernel: implement static_strcmp()
will be used to test functions operating on strings
Diffstat (limited to 'src/kernel')
-rw-r--r-- | src/kernel/tests/util.c | 13 | ||||
-rw-r--r-- | src/kernel/util.h | 4 |
2 files changed, 17 insertions, 0 deletions
diff --git a/src/kernel/tests/util.c b/src/kernel/tests/util.c index 5bc8656..81c36d6 100644 --- a/src/kernel/tests/util.c +++ b/src/kernel/tests/util.c @@ -21,6 +21,19 @@ TEST(memcmp) { TEST_IF(0 < memcmp("654", "555", 3)); } +TEST(static_strcmp) { + TEST_IF(0 == static_strcmp("", "")); + TEST_IF(0 == static_strcmp("same", "same")); + + TEST_IF(0 != static_strcmp("same", "diff")); + TEST_IF(0 != static_strcmp("same!", "same")); + TEST_IF(0 != static_strcmp("same", "same!")); + + TEST_IF(0 > static_strcmp("555", "654")); + TEST_IF(0 < static_strcmp("654", "555")); +} + void tests_utils() { TEST_RUN(memcmp); + TEST_RUN(static_strcmp); } diff --git a/src/kernel/util.h b/src/kernel/util.h index b50810d..0aa2c4c 100644 --- a/src/kernel/util.h +++ b/src/kernel/util.h @@ -8,3 +8,7 @@ void *memcpy(void *dest, const void *src, size_t n); void *memset(void *s, int c, size_t n); int memcmp(const void *s1, const void *s2, size_t n); + +// s1 MUST be a string known at compiletime +#define static_strcmp(s1, s2) \ + memcmp(s1, s2, sizeof(s1)) |