Line data Source code
1 : #define CLOVE_SUITE_NAME UtilSuite
2 :
3 : #include "clove-unit.h"
4 : #include "../src/util/strings.h"
5 :
6 : // ========================== globals ========================//
7 : char str[100] = {0};
8 : int setup_once_count = 0;
9 : int teardown_once_count = 0;
10 : int setup_count = 0;
11 : int teardown_count = 0;
12 :
13 : // ====================== setup(), teardown() ========================//
14 1 : CLOVE_SUITE_SETUP_ONCE()
15 : {
16 1 : setup_once_count++;
17 1 : }
18 :
19 1 : CLOVE_SUITE_TEARDOWN_ONCE()
20 : {
21 1 : teardown_once_count++;
22 1 : }
23 :
24 41 : CLOVE_SUITE_SETUP()
25 : {
26 41 : setup_count++;
27 41 : }
28 :
29 41 : CLOVE_SUITE_TEARDOWN()
30 : {
31 41 : teardown_count++;
32 41 : }
33 :
34 : // ====================== lengthString() ========================//
35 2 : CLOVE_TEST(lengthStringNULL)
36 : {
37 1 : char* string = NULL;
38 1 : uint32_t length = lengthString(string);
39 1 : CLOVE_UINT_EQ(0, length);
40 : }
41 :
42 2 : CLOVE_TEST(lengthStringCharPointer)
43 : {
44 1 : char* string = "test";
45 1 : uint32_t length = lengthString(string);
46 1 : CLOVE_UINT_EQ(4, length);
47 : }
48 :
49 2 : CLOVE_TEST(lengthStringArray)
50 : {
51 1 : char string[2] = "ha";
52 1 : uint32_t length = lengthString(string);
53 1 : CLOVE_UINT_EQ(2, length);
54 : }
55 :
56 : // ====================== sliceOfString() ========================//
57 2 : CLOVE_TEST(sliceOfStringEmpty)
58 : {
59 1 : }
60 :
61 2 : CLOVE_TEST(sliceOfStringCharPointr)
62 : {
63 1 : }
64 :
65 2 : CLOVE_TEST(sliceOfStringArray)
66 : {
67 1 : }
68 :
69 2 : CLOVE_TEST(sliceOfStringOrdinaryString)
70 : {
71 1 : }
72 :
73 : // ====================== intToString() ========================//
74 2 : CLOVE_TEST(intToStringZero)
75 : {
76 1 : }
77 :
78 2 : CLOVE_TEST(intToStringNegative)
79 : {
80 1 : }
81 :
82 2 : CLOVE_TEST(intToStringPositive)
83 : {
84 1 : }
85 :
86 : // ====================== floatToString() ========================//
87 2 : CLOVE_TEST(floatToString1Digit1Fraction)
88 : {
89 1 : floatToString(1.1, str);
90 1 : CLOVE_NOT_NULL(str);
91 1 : CLOVE_STRING_EQ("1.1", str);
92 : }
93 :
94 2 : CLOVE_TEST(floatToString2Digit2Fraction)
95 : {
96 1 : floatToString(23.67, str);
97 1 : CLOVE_NOT_NULL(str);
98 1 : CLOVE_STRING_EQ("23.67", str);
99 : }
100 :
101 2 : CLOVE_TEST(floatToString3Digit2Fractions)
102 : {
103 1 : floatToString(927.12, str);
104 1 : CLOVE_NOT_NULL(str);
105 1 : CLOVE_STRING_EQ("927.12", str);
106 : }
107 :
108 2 : CLOVE_TEST(floatToString3DigitNegative)
109 : {
110 1 : floatToString(-261, str);
111 1 : CLOVE_NOT_NULL(str);
112 1 : CLOVE_STRING_EQ("-261", str);
113 : }
114 :
115 2 : CLOVE_TEST(floatToString3Digit4FractionNegative)
116 : {
117 1 : floatToString(-927.1201, str);
118 1 : CLOVE_NOT_NULL(str);
119 1 : CLOVE_STRING_EQ("-927.1201", str);
120 : }
121 :
122 2 : CLOVE_TEST(floatToString0Digit2Fractional)
123 : {
124 1 : floatToString(0.08, str);
125 1 : CLOVE_NOT_NULL(str);
126 1 : CLOVE_STRING_EQ("0.08", str);
127 : }
128 :
129 2 : CLOVE_TEST(floatToString0Digit2FractionalNegative)
130 : {
131 1 : floatToString(-0.08, str);
132 1 : CLOVE_NOT_NULL(str);
133 1 : CLOVE_STRING_EQ("0.08", str);
134 : }
135 :
136 : // ====================== hexToString() ========================//
137 2 : CLOVE_TEST(hexToString1Digit)
138 : {
139 1 : hexToString(0x1, str);
140 1 : CLOVE_NOT_NULL(str);
141 1 : CLOVE_STRING_EQ("0x1", str);
142 : }
143 :
144 2 : CLOVE_TEST(hexToString2Digit)
145 : {
146 1 : hexToString(0x89, str);
147 1 : CLOVE_NOT_NULL(str);
148 1 : CLOVE_STRING_EQ("0x89", str);
149 : }
150 :
151 2 : CLOVE_TEST(hexToString3Digit)
152 : {
153 1 : hexToString(0x8AF, str);
154 1 : CLOVE_NOT_NULL(str);
155 1 : CLOVE_STRING_EQ("0x8AF", str);
156 : }
157 :
158 2 : CLOVE_TEST(hexToString4DigitPlusA)
159 : {
160 1 : hexToString(0xFFAC, str);
161 1 : CLOVE_NOT_NULL(str);
162 1 : CLOVE_STRING_EQ("0xFFAC", str);
163 : }
|