OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include <stdarg.h> | 8 #include <stdarg.h> |
9 #include <stdio.h> | 9 #include <stdio.h> |
10 #include "SkString.h" | 10 #include "SkString.h" |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 a.set(""); | 141 a.set(""); |
142 a.appendU64(0x8000000000000001ULL, 0); | 142 a.appendU64(0x8000000000000001ULL, 0); |
143 REPORTER_ASSERT(reporter, a.equals("9223372036854775809")); | 143 REPORTER_ASSERT(reporter, a.equals("9223372036854775809")); |
144 a.set(""); | 144 a.set(""); |
145 a.appendU64(0xFFFFFFFFFFFFFFFFULL, 0); | 145 a.appendU64(0xFFFFFFFFFFFFFFFFULL, 0); |
146 REPORTER_ASSERT(reporter, a.equals("18446744073709551615")); | 146 REPORTER_ASSERT(reporter, a.equals("18446744073709551615")); |
147 a.set(""); | 147 a.set(""); |
148 a.appendU64(0x0000000001000000ULL, 15); | 148 a.appendU64(0x0000000001000000ULL, 15); |
149 REPORTER_ASSERT(reporter, a.equals("000000016777216")); | 149 REPORTER_ASSERT(reporter, a.equals("000000016777216")); |
150 | 150 |
151 a.printf("%i", 0); | |
152 REPORTER_ASSERT(reporter, a.equals("0")); | |
153 a.printf("%g", 3.14); | |
154 REPORTER_ASSERT(reporter, a.equals("3.14")); | |
155 a.printf("hello %s", "skia"); | |
156 REPORTER_ASSERT(reporter, a.equals("hello skia")); | |
157 | |
158 static const struct { | 151 static const struct { |
159 SkScalar fValue; | 152 SkScalar fValue; |
160 const char* fString; | 153 const char* fString; |
161 } gRec[] = { | 154 } gRec[] = { |
162 { 0, "0" }, | 155 { 0, "0" }, |
163 { SK_Scalar1, "1" }, | 156 { SK_Scalar1, "1" }, |
164 { -SK_Scalar1, "-1" }, | 157 { -SK_Scalar1, "-1" }, |
165 { SK_Scalar1/2, "0.5" }, | 158 { SK_Scalar1/2, "0.5" }, |
166 #if defined(SK_BUILD_FOR_WIN) && (_MSC_VER < 1900) | 159 #if defined(SK_BUILD_FOR_WIN) && (_MSC_VER < 1900) |
167 { 3.4028234e38f, "3.4028235e+038" }, | 160 { 3.4028234e38f, "3.4028235e+038" }, |
(...skipping 17 matching lines...) Expand all Loading... |
185 char buffer [40]; | 178 char buffer [40]; |
186 memset(buffer, 'a', 40); | 179 memset(buffer, 'a', 40); |
187 REPORTER_ASSERT(reporter, buffer[18] == 'a'); | 180 REPORTER_ASSERT(reporter, buffer[18] == 'a'); |
188 REPORTER_ASSERT(reporter, buffer[19] == 'a'); | 181 REPORTER_ASSERT(reporter, buffer[19] == 'a'); |
189 REPORTER_ASSERT(reporter, buffer[20] == 'a'); | 182 REPORTER_ASSERT(reporter, buffer[20] == 'a'); |
190 printfAnalog(buffer, 20, "%30d", 0); | 183 printfAnalog(buffer, 20, "%30d", 0); |
191 REPORTER_ASSERT(reporter, buffer[18] == ' '); | 184 REPORTER_ASSERT(reporter, buffer[18] == ' '); |
192 REPORTER_ASSERT(reporter, buffer[19] == 0); | 185 REPORTER_ASSERT(reporter, buffer[19] == 0); |
193 REPORTER_ASSERT(reporter, buffer[20] == 'a'); | 186 REPORTER_ASSERT(reporter, buffer[20] == 'a'); |
194 | 187 |
195 REPORTER_ASSERT(reporter, SkStringPrintf("%i", 0).equals("0")); | |
196 | |
197 a = SkStringPrintf("%2000s", " "); | |
198 REPORTER_ASSERT(reporter, a.size() == 2000); | |
199 for (size_t i = 0; i < a.size(); ++i) { | |
200 if (a[i] != ' ') { | |
201 ERRORF(reporter, "SkStringPrintf fail: a[%d] = '%c'", i, a[i]); | |
202 break; | |
203 } | |
204 } | |
205 a.reset(); | |
206 a.printf("%2000s", " "); | |
207 REPORTER_ASSERT(reporter, a.size() == 2000); | |
208 for (size_t i = 0; i < a.size(); ++i) { | |
209 if (a[i] != ' ') { | |
210 ERRORF(reporter, "SkStringPrintf fail: a[%d] = '%c'", i, a[i]); | |
211 break; | |
212 } | |
213 } | |
214 } | 188 } |
215 | 189 |
216 DEF_TEST(String_SkStrSplit, r) { | 190 DEF_TEST(String_SkStrSplit, r) { |
217 SkTArray<SkString> results; | 191 SkTArray<SkString> results; |
218 | 192 |
219 SkStrSplit("a-_b_c-dee--f-_-_-g-", "-_", &results); | 193 SkStrSplit("a-_b_c-dee--f-_-_-g-", "-_", &results); |
220 REPORTER_ASSERT(r, results.count() == 6); | 194 REPORTER_ASSERT(r, results.count() == 6); |
221 REPORTER_ASSERT(r, results[0].equals("a")); | 195 REPORTER_ASSERT(r, results[0].equals("a")); |
222 REPORTER_ASSERT(r, results[1].equals("b")); | 196 REPORTER_ASSERT(r, results[1].equals("b")); |
223 REPORTER_ASSERT(r, results[2].equals("c")); | 197 REPORTER_ASSERT(r, results[2].equals("c")); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 REPORTER_ASSERT(r, results[2].equals("")); | 253 REPORTER_ASSERT(r, results[2].equals("")); |
280 | 254 |
281 results.reset(); | 255 results.reset(); |
282 SkStrSplit(",a,b,", ",", kStrict_SkStrSplitMode, &results); | 256 SkStrSplit(",a,b,", ",", kStrict_SkStrSplitMode, &results); |
283 REPORTER_ASSERT(r, results.count() == 4); | 257 REPORTER_ASSERT(r, results.count() == 4); |
284 REPORTER_ASSERT(r, results[0].equals("")); | 258 REPORTER_ASSERT(r, results[0].equals("")); |
285 REPORTER_ASSERT(r, results[1].equals("a")); | 259 REPORTER_ASSERT(r, results[1].equals("a")); |
286 REPORTER_ASSERT(r, results[2].equals("b")); | 260 REPORTER_ASSERT(r, results[2].equals("b")); |
287 REPORTER_ASSERT(r, results[3].equals("")); | 261 REPORTER_ASSERT(r, results[3].equals("")); |
288 } | 262 } |
OLD | NEW |