summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMeco Man <[email protected]>2024-12-23 17:46:49 -0500
committerRbb666 <[email protected]>2024-12-24 13:42:04 +0800
commit8c762b42cafa54c215900395ecfa9ccd489f8eaf (patch)
tree9ec871ae87be9142fc5c4618a6b351f873c65b45 /src
parenta803c20bd7e4a97feb869eac5c53e64b14caf704 (diff)
[utest] implement rt_memcmp test cases
Diffstat (limited to 'src')
-rw-r--r--src/klibc/utest/TC_rt_memcmp.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/klibc/utest/TC_rt_memcmp.c b/src/klibc/utest/TC_rt_memcmp.c
new file mode 100644
index 0000000000..80839007cb
--- /dev/null
+++ b/src/klibc/utest/TC_rt_memcmp.c
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2006-2024, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2020-05-06 Phillip Johnston the first version
+ * 2024-12-24 Meco Man port to utest
+ */
+
+#include <rtklibc.h>
+#include <utest.h>
+
+static rt_err_t utest_tc_init(void)
+{
+ return RT_EOK;
+}
+
+static rt_err_t utest_tc_cleanup(void)
+{
+ return RT_EOK;
+}
+
+static void TC_rt_memcmp_str(void)
+{
+ const char* s = "abc 123";
+
+ uassert_int_equal(rt_memcmp("abc", "abc", 4), 0);
+ uassert_int_equal(rt_memcmp(s, "abc", 3), 0);
+ uassert_int_equal(rt_memcmp("abc", s, 3), 0);
+
+ /* The following tests intentionally use a length > 3 */
+ /* To test what rt_memcmp does in such a situation */
+ uassert_int_equal(!!(rt_memcmp(s, "abc", 6) > 0), 1);
+ uassert_int_equal(!!(rt_memcmp("abc", s, 6) < 0), 1);
+
+ /* Check RT_NULL input handling */
+ uassert_int_not_equal(rt_memcmp("abc", RT_NULL, 3), 0);
+ uassert_int_not_equal(rt_memcmp(RT_NULL, "abc", 3), 0);
+
+ /* Check that two RT_NULL strings will match */
+ uassert_int_equal(rt_memcmp(RT_NULL, RT_NULL, 0), 0);
+}
+
+static void utest_do_tc(void)
+{
+ UTEST_UNIT_RUN(TC_rt_memcmp_str);
+}
+
+UTEST_TC_EXPORT(utest_do_tc, "klibc.rt_memcmp", utest_tc_init, utest_tc_cleanup, 1000);