|
| 1 | +/******************************************************************************* |
| 2 | + * |
| 3 | + * Copyright (c) 2025 GARDENA GmbH |
| 4 | + * |
| 5 | + * All rights reserved. This program and the accompanying materials |
| 6 | + * are made available under the terms of the Eclipse Public License v2.0 |
| 7 | + * and Eclipse Distribution License v1.0 which accompany this distribution. |
| 8 | + * |
| 9 | + * The Eclipse Public License is available at |
| 10 | + * http://www.eclipse.org/legal/epl-v20.html |
| 11 | + * The Eclipse Distribution License is available at |
| 12 | + * http://www.eclipse.org/org/documents/edl-v10.php. |
| 13 | + * |
| 14 | + * Contributors: |
| 15 | + * Lukas Woodtli, GARDENA GmbH - Please refer to git log |
| 16 | + * |
| 17 | + *******************************************************************************/ |
| 18 | +#include "CUnit/Basic.h" |
| 19 | +#include "tests.h" |
| 20 | +#include "utils.h" |
| 21 | + |
| 22 | +void test_strnlen_null(void) { |
| 23 | + size_t len = utils_strnlen(NULL, 10); |
| 24 | + CU_ASSERT_EQUAL(len, 0); |
| 25 | +} |
| 26 | + |
| 27 | +void test_strnlen_0(void) { |
| 28 | + const char *string = ""; |
| 29 | + size_t len = utils_strnlen(string, 10); |
| 30 | + CU_ASSERT_EQUAL(len, 0); |
| 31 | +} |
| 32 | + |
| 33 | +void test_strnlen_1(void) { |
| 34 | + const char *string = "a"; |
| 35 | + size_t len = utils_strnlen(string, 10); |
| 36 | + CU_ASSERT_EQUAL(len, 1); |
| 37 | +} |
| 38 | + |
| 39 | +void test_strnlen_2(void) { |
| 40 | + const char *string = "ab"; |
| 41 | + size_t len = utils_strnlen(string, 10); |
| 42 | + CU_ASSERT_EQUAL(len, 2); |
| 43 | +} |
| 44 | + |
| 45 | +void test_strnlen_max_len_0(void) { |
| 46 | + const char *string = "abc"; |
| 47 | + size_t len = utils_strnlen(string, 0); |
| 48 | + CU_ASSERT_EQUAL(len, 0); |
| 49 | +} |
| 50 | + |
| 51 | +void test_strnlen_max_len_1(void) { |
| 52 | + const char *string = "abc"; |
| 53 | + size_t len = utils_strnlen(string, 1); |
| 54 | + CU_ASSERT_EQUAL(len, 1); |
| 55 | +} |
| 56 | + |
| 57 | +void test_strnlen_max_len_2(void) { |
| 58 | + const char *string = "abc"; |
| 59 | + size_t len = utils_strnlen(string, 2); |
| 60 | + CU_ASSERT_EQUAL(len, 2); |
| 61 | +} |
| 62 | + |
| 63 | +void test_strnlen_max_len_3(void) { |
| 64 | + const char *string = "abc"; |
| 65 | + size_t len = utils_strnlen(string, 3); |
| 66 | + CU_ASSERT_EQUAL(len, 3); |
| 67 | +} |
| 68 | + |
| 69 | +void test_strnlen_max_len_4(void) { |
| 70 | + const char *string = "abc"; |
| 71 | + size_t len = utils_strnlen(string, 4); |
| 72 | + CU_ASSERT_EQUAL(len, 3); |
| 73 | +} |
| 74 | + |
| 75 | +void test_strnlen_max_len_5(void) { |
| 76 | + const char *string = "abc"; |
| 77 | + size_t len = utils_strnlen(string, 5); |
| 78 | + CU_ASSERT_EQUAL(len, 3); |
| 79 | +} |
| 80 | + |
| 81 | +static struct TestTable table[] = { |
| 82 | + {"test_strnlen_null()", test_strnlen_null}, |
| 83 | + {"test_strnlen_0()", test_strnlen_0}, |
| 84 | + {"test_strnlen_1()", test_strnlen_1}, |
| 85 | + {"test_strnlen_2()", test_strnlen_2}, |
| 86 | + {"test_strnlen_max_len_0()", test_strnlen_max_len_0}, |
| 87 | + {"test_strnlen_max_len_1()", test_strnlen_max_len_1}, |
| 88 | + {"test_strnlen_max_len_2()", test_strnlen_max_len_2}, |
| 89 | + {"test_strnlen_max_len_3()", test_strnlen_max_len_3}, |
| 90 | + {"test_strnlen_max_len_4()", test_strnlen_max_len_4}, |
| 91 | + {"test_strnlen_max_len_5()", test_strnlen_max_len_5}, |
| 92 | + {NULL, NULL}, |
| 93 | +}; |
| 94 | + |
| 95 | +CU_ErrorCode create_utils_suit(void) { |
| 96 | + CU_pSuite pSuite = NULL; |
| 97 | + |
| 98 | + pSuite = CU_add_suite("Suite_utils", NULL, NULL); |
| 99 | + if (NULL == pSuite) { |
| 100 | + return CU_get_error(); |
| 101 | + } |
| 102 | + |
| 103 | + return add_tests(pSuite, table); |
| 104 | +} |
0 commit comments