diff options
author | Nadim Taha <ntaha@google.com> | 2017-02-02 18:48:03 -0800 |
---|---|---|
committer | Nadim Taha <ntaha@chromium.org> | 2017-02-17 01:46:31 +0000 |
commit | 69c3fc2378ee9026277c1cbaf6e8aff0b99ecf46 (patch) | |
tree | 548d9660cb450bdb29cb08be0fdaff740854d276 /test | |
parent | 61a5649e302915c617f4f70a1b3211805f363ed8 (diff) | |
download | chrome-ec-69c3fc2378ee9026277c1cbaf6e8aff0b99ecf46.tar.gz |
builtin: Expands string.h / stdint.h
Declares UINT8_MAX, INT8_MAX and defines strnlen(), strncpy(), strncmp() &
memchr(). Needed by a module I'm integrating into cr51.
BRANCH=none
BUG=none
TEST=make buildall -j
Change-Id: I894b0297216df1b945b36fc77cd3bc5c4ef8aa2b
Signed-off-by: Nadim Taha <ntaha@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/436786
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'test')
-rw-r--r-- | test/utils.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/test/utils.c b/test/utils.c index e7de7f8b3d..293c1507c4 100644 --- a/test/utils.c +++ b/test/utils.c @@ -231,6 +231,17 @@ static int test_memset(void) return EC_SUCCESS; } +static int test_memchr(void) +{ + char *buf = "1234"; + + TEST_ASSERT(memchr("123", '4', 8) == NULL); + TEST_ASSERT(memchr("123", '3', 2) == NULL); + TEST_ASSERT(memchr(buf, '3', 8) == buf + 2); + TEST_ASSERT(memchr(buf, '4', 4) == buf + 3); + return EC_SUCCESS; +} + static int test_strzcpy(void) { char dest[10]; @@ -245,11 +256,43 @@ static int test_strzcpy(void) return EC_SUCCESS; } +static int test_strncpy(void) +{ + char dest[10]; + + strncpy(dest, "test", 10); + TEST_ASSERT_ARRAY_EQ("test", dest, 5); + strncpy(dest, "12345", 6); + TEST_ASSERT_ARRAY_EQ("12345", dest, 6); + strncpy(dest, "testtesttest", 10); + TEST_ASSERT_ARRAY_EQ("testtestte", dest, 10); + + return EC_SUCCESS; +} + +static int test_strncmp(void) +{ + TEST_ASSERT(strncmp("123", "123", 8) == 0); + TEST_ASSERT(strncmp("789", "456", 8) > 0); + TEST_ASSERT(strncmp("abc", "abd", 4) < 0); + TEST_ASSERT(strncmp("abc", "abd", 2) == 0); + return EC_SUCCESS; +} + static int test_strlen(void) { TEST_CHECK(strlen("this is a string") == 16); } +static int test_strnlen(void) +{ + TEST_ASSERT(strnlen("this is a string", 17) == 16); + TEST_ASSERT(strnlen("this is a string", 16) == 16); + TEST_ASSERT(strnlen("this is a string", 5) == 5); + + return EC_SUCCESS; +} + static int test_strcasecmp(void) { TEST_CHECK((strcasecmp("test string", "TEST strIng") == 0) && @@ -453,8 +496,12 @@ void run_test(void) RUN_TEST(test_memmove); RUN_TEST(test_memcpy); RUN_TEST(test_memset); + RUN_TEST(test_memchr); RUN_TEST(test_strzcpy); + RUN_TEST(test_strncpy); + RUN_TEST(test_strncmp); RUN_TEST(test_strlen); + RUN_TEST(test_strnlen); RUN_TEST(test_strcasecmp); RUN_TEST(test_strncasecmp); RUN_TEST(test_atoi); |