forked from Green-Sky/tomato
Green Sky
a3126d581b
82460b212 feat: add ngc events 24b54722a fix: Ensure we have allocators available for the error paths. 48dbcfebc cleanup: Remove redundant `-DSODIUM_EXPORT` from definitions. 0cef46ee9 cleanup: Fix a few more clang-tidy warnings. 0c5b918e9 cleanup: Fix a few more clang-tidy warnings. 4d3c97f49 cleanup: Enforce stricter identifier naming using clang-tidy. a549807df refactor: Add `mem` module to allow tests to override allocators. 6133fb153 chore: Add devcontainer setup for codespaces. 620e07ecd chore: Set a timeout for tests started using Conan c0ec33b16 chore: Migrate Windows CI from Appveyor to Azure DevOps 8ed47f3ef fix incorrect documentation a1e245841 docs: Fix doxygen config and remove some redundant comments. b0f633185 chore: Fix the Android CI job 7469a529b fix: Add missing `#include <array>`. 2b1a6b0d2 add missing ngc constants getter declarations and definitions 2e02d5637 chore: Add missing module dependencies. REVERT: 67badf694 feat: add ngc events git-subtree-dir: external/toxcore/c-toxcore git-subtree-split: 82460b2124216af1ac9d63060de310a682a2fd15
166 lines
5.2 KiB
C
166 lines
5.2 KiB
C
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include "../testing/misc_tools.h"
|
|
#include "check_compat.h"
|
|
|
|
typedef enum {
|
|
NEGATIVE,
|
|
ZERO,
|
|
POSITIVE
|
|
} Comparison;
|
|
|
|
static const char *comparison_str[] = { "NEGATIVE", "ZERO", "POSITIVE" };
|
|
|
|
static void verify(const char *s1, const char *s2, size_t n, Comparison expected)
|
|
{
|
|
int r = tox_strncasecmp(s1, s2, n);
|
|
Comparison actual = r < 0 ? NEGATIVE : r == 0 ? ZERO : POSITIVE;
|
|
|
|
ck_assert_msg(actual == expected,
|
|
"tox_strncasecmp(\"%s\", \"%s\", %u) == %s, but expected %s.",
|
|
s1, s2, (unsigned)n, comparison_str[actual], comparison_str[expected]);
|
|
}
|
|
|
|
static void test_general(void)
|
|
{
|
|
// empty strings are equal
|
|
verify("", "", 100, ZERO);
|
|
verify("", "", -1, ZERO);
|
|
|
|
// ====== Same Case Test Cases ======
|
|
|
|
// equal strings with n=0 are equal
|
|
verify("", "", 0, ZERO);
|
|
verify("AAA", "AAA", 0, ZERO);
|
|
|
|
// unequal strings with n=0 are equal
|
|
verify("A", "B", 0, ZERO);
|
|
verify("AAA", "BBB", 0, ZERO);
|
|
verify("AAA", "BBBBBB", 0, ZERO);
|
|
verify("AAAAAA", "BBB", 0, ZERO);
|
|
|
|
// equal strings are equal
|
|
verify("AAA", "AAA", 0, ZERO);
|
|
verify("AAA", "AAA", 1, ZERO);
|
|
verify("AAA", "AAA", 2, ZERO);
|
|
verify("AAA", "AAA", 3, ZERO);
|
|
verify("AAA", "AAA", 4, ZERO);
|
|
verify("AAA", "AAA", 5, ZERO);
|
|
verify("AAA", "AAA", -1, ZERO);
|
|
|
|
verify("AAA", "AAAAAA", 0, ZERO);
|
|
verify("AAA", "AAAAAA", 1, ZERO);
|
|
verify("AAA", "AAAAAA", 2, ZERO);
|
|
verify("AAA", "AAAAAA", 3, ZERO);
|
|
verify("AAA", "AAAAAA", 4, NEGATIVE);
|
|
verify("AAA", "AAAAAA", 5, NEGATIVE);
|
|
verify("AAA", "AAAAAA", -1, NEGATIVE);
|
|
|
|
verify("AAAAAA", "AAA", 0, ZERO);
|
|
verify("AAAAAA", "AAA", 1, ZERO);
|
|
verify("AAAAAA", "AAA", 2, ZERO);
|
|
verify("AAAAAA", "AAA", 3, ZERO);
|
|
verify("AAAAAA", "AAA", 4, POSITIVE);
|
|
verify("AAAAAA", "AAA", 5, POSITIVE);
|
|
verify("AAAAAA", "AAA", -1, POSITIVE);
|
|
|
|
verify("I'm eating wafers and drinking tea.", "I'm eating wafers and drinking tea.", -1, ZERO);
|
|
|
|
// unequal strings are equal only up to n
|
|
verify("AAAB", "AAAA", 0, ZERO);
|
|
verify("AAAB", "AAAA", 1, ZERO);
|
|
verify("AAAB", "AAAA", 2, ZERO);
|
|
verify("AAAB", "AAAA", 3, ZERO);
|
|
verify("AAAB", "AAAA", 4, POSITIVE);
|
|
verify("AAAB", "AAAA", 5, POSITIVE);
|
|
verify("AAAB", "AAAA", -1, POSITIVE);
|
|
|
|
verify("AAAA", "AAAB", 0, ZERO);
|
|
verify("AAAA", "AAAB", 1, ZERO);
|
|
verify("AAAA", "AAAB", 2, ZERO);
|
|
verify("AAAA", "AAAB", 3, ZERO);
|
|
verify("AAAA", "AAAB", 4, NEGATIVE);
|
|
verify("AAAA", "AAAB", 5, NEGATIVE);
|
|
verify("AAAA", "AAAB", -1, NEGATIVE);
|
|
|
|
verify("The wafers are salty.", "The wafers are sweet.", 16, ZERO);
|
|
verify("The wafers are salty.", "The wafers are sweet.", 17, NEGATIVE);
|
|
verify("The wafers are salty.", "The wafers are sweet.", -1, NEGATIVE);
|
|
|
|
// the comparison should stop at first mismatch
|
|
verify("AAABA", "AAAAB", -1, POSITIVE);
|
|
verify("AAAAB", "AAABA", -1, NEGATIVE);
|
|
|
|
// ====== Different Case Test Cases ======
|
|
|
|
// equal strings with n=0 are equal
|
|
verify("", "", 0, ZERO);
|
|
verify("aaa", "AAA", 0, ZERO);
|
|
|
|
// unequal strings with n=0 are equal
|
|
verify("a", "B", 0, ZERO);
|
|
verify("aaa", "BBB", 0, ZERO);
|
|
verify("aaa", "BBBBBB", 0, ZERO);
|
|
verify("aaaaaa", "BBB", 0, ZERO);
|
|
|
|
// equal strings are equal
|
|
verify("aaa", "AAA", 0, ZERO);
|
|
verify("AAA", "aaa", 1, ZERO);
|
|
verify("aaa", "AAA", 2, ZERO);
|
|
verify("aaa", "AAA", 3, ZERO);
|
|
verify("AAA", "aaa", 4, ZERO);
|
|
verify("AAA", "aaa", 5, ZERO);
|
|
verify("AAA", "aaa", -1, ZERO);
|
|
|
|
verify("aaa", "AAAAAA", 0, ZERO);
|
|
verify("AAA", "AAAaaa", 1, ZERO);
|
|
verify("aaA", "aaaAAA", 2, ZERO);
|
|
verify("AaA", "aAAAAA", 3, ZERO);
|
|
verify("AAA", "AAAAAA", 4, NEGATIVE);
|
|
verify("Aaa", "AAaaAA", 5, NEGATIVE);
|
|
verify("AAA", "AAAAAa", -1, NEGATIVE);
|
|
|
|
verify("AAAAAA", "aaa", 0, ZERO);
|
|
verify("AAAaaa", "AAA", 1, ZERO);
|
|
verify("aaaAAA", "aaA", 2, ZERO);
|
|
verify("aAAAAA", "AaA", 3, ZERO);
|
|
verify("AAAAAA", "AAA", 4, POSITIVE);
|
|
verify("AAaaAA", "Aaa", 5, POSITIVE);
|
|
verify("AAAAAa", "AAA", -1, POSITIVE);
|
|
|
|
verify("I'm Eating Wafers And Drinking Tea.", "I'm eating wafers and drinking tea.", -1, ZERO);
|
|
|
|
// unequal strings are equal only up to n
|
|
verify("aaaB", "AAAA", 0, ZERO);
|
|
verify("AaAB", "aAAA", 1, ZERO);
|
|
verify("aAAB", "AaAA", 2, ZERO);
|
|
verify("AAAB", "AAaA", 3, ZERO);
|
|
verify("AAAB", "AAAA", 4, POSITIVE);
|
|
verify("AAAb", "AAAA", 5, POSITIVE);
|
|
verify("AAAB", "AAAa", -1, POSITIVE);
|
|
|
|
verify("AAAA", "aaaB", 0, ZERO);
|
|
verify("aAAA", "AaAB", 1, ZERO);
|
|
verify("AaAA", "aAAB", 2, ZERO);
|
|
verify("AAaA", "AAAB", 3, ZERO);
|
|
verify("AAAA", "AAAB", 4, NEGATIVE);
|
|
verify("AAAA", "AAAb", 5, NEGATIVE);
|
|
verify("AAAa", "AAAB", -1, NEGATIVE);
|
|
|
|
verify("The Wafers Are Salty.", "The wafers are sweet.", 16, ZERO);
|
|
verify("The Wafers Are Salty.", "The wafers are sweet.", 17, NEGATIVE);
|
|
verify("The Wafers Are Salty.", "The wafers are sweet.", -1, NEGATIVE);
|
|
|
|
// the comparison should stop at first mismatch
|
|
verify("aAaBA", "AAAAb", -1, POSITIVE);
|
|
verify("AAAAb", "aAaBA", -1, NEGATIVE);
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
setvbuf(stdout, nullptr, _IONBF, 0);
|
|
test_general();
|
|
return 0;
|
|
}
|