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 |
151 static const struct { | 158 static const struct { |
152 SkScalar fValue; | 159 SkScalar fValue; |
153 const char* fString; | 160 const char* fString; |
154 } gRec[] = { | 161 } gRec[] = { |
155 { 0, "0" }, | 162 { 0, "0" }, |
156 { SK_Scalar1, "1" }, | 163 { SK_Scalar1, "1" }, |
157 { -SK_Scalar1, "-1" }, | 164 { -SK_Scalar1, "-1" }, |
158 { SK_Scalar1/2, "0.5" }, | 165 { SK_Scalar1/2, "0.5" }, |
159 #if defined(SK_BUILD_FOR_WIN) && (_MSC_VER < 1900) | 166 #if defined(SK_BUILD_FOR_WIN) && (_MSC_VER < 1900) |
160 { 3.4028234e38f, "3.4028235e+038" }, | 167 { 3.4028234e38f, "3.4028235e+038" }, |
(...skipping 17 matching lines...) Expand all Loading... |
178 char buffer [40]; | 185 char buffer [40]; |
179 memset(buffer, 'a', 40); | 186 memset(buffer, 'a', 40); |
180 REPORTER_ASSERT(reporter, buffer[18] == 'a'); | 187 REPORTER_ASSERT(reporter, buffer[18] == 'a'); |
181 REPORTER_ASSERT(reporter, buffer[19] == 'a'); | 188 REPORTER_ASSERT(reporter, buffer[19] == 'a'); |
182 REPORTER_ASSERT(reporter, buffer[20] == 'a'); | 189 REPORTER_ASSERT(reporter, buffer[20] == 'a'); |
183 printfAnalog(buffer, 20, "%30d", 0); | 190 printfAnalog(buffer, 20, "%30d", 0); |
184 REPORTER_ASSERT(reporter, buffer[18] == ' '); | 191 REPORTER_ASSERT(reporter, buffer[18] == ' '); |
185 REPORTER_ASSERT(reporter, buffer[19] == 0); | 192 REPORTER_ASSERT(reporter, buffer[19] == 0); |
186 REPORTER_ASSERT(reporter, buffer[20] == 'a'); | 193 REPORTER_ASSERT(reporter, buffer[20] == 'a'); |
187 | 194 |
| 195 REPORTER_ASSERT(reporter, SkStringPrintf("%i", 0).equals("0")); |
| 196 |
| 197 // 2000 is larger than the static buffer size inside SkString.cpp |
| 198 a = SkStringPrintf("%2000s", " "); |
| 199 REPORTER_ASSERT(reporter, a.size() == 2000); |
| 200 for (size_t i = 0; i < a.size(); ++i) { |
| 201 if (a[i] != ' ') { |
| 202 ERRORF(reporter, "SkStringPrintf fail: a[%d] = '%c'", i, a[i]); |
| 203 break; |
| 204 } |
| 205 } |
| 206 a.reset(); |
| 207 a.printf("%2000s", " "); |
| 208 REPORTER_ASSERT(reporter, a.size() == 2000); |
| 209 for (size_t i = 0; i < a.size(); ++i) { |
| 210 if (a[i] != ' ') { |
| 211 ERRORF(reporter, "SkStringPrintf fail: a[%d] = '%c'", i, a[i]); |
| 212 break; |
| 213 } |
| 214 } |
188 } | 215 } |
189 | 216 |
190 DEF_TEST(String_SkStrSplit, r) { | 217 DEF_TEST(String_SkStrSplit, r) { |
191 SkTArray<SkString> results; | 218 SkTArray<SkString> results; |
192 | 219 |
193 SkStrSplit("a-_b_c-dee--f-_-_-g-", "-_", &results); | 220 SkStrSplit("a-_b_c-dee--f-_-_-g-", "-_", &results); |
194 REPORTER_ASSERT(r, results.count() == 6); | 221 REPORTER_ASSERT(r, results.count() == 6); |
195 REPORTER_ASSERT(r, results[0].equals("a")); | 222 REPORTER_ASSERT(r, results[0].equals("a")); |
196 REPORTER_ASSERT(r, results[1].equals("b")); | 223 REPORTER_ASSERT(r, results[1].equals("b")); |
197 REPORTER_ASSERT(r, results[2].equals("c")); | 224 REPORTER_ASSERT(r, results[2].equals("c")); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 REPORTER_ASSERT(r, results[2].equals("")); | 280 REPORTER_ASSERT(r, results[2].equals("")); |
254 | 281 |
255 results.reset(); | 282 results.reset(); |
256 SkStrSplit(",a,b,", ",", kStrict_SkStrSplitMode, &results); | 283 SkStrSplit(",a,b,", ",", kStrict_SkStrSplitMode, &results); |
257 REPORTER_ASSERT(r, results.count() == 4); | 284 REPORTER_ASSERT(r, results.count() == 4); |
258 REPORTER_ASSERT(r, results[0].equals("")); | 285 REPORTER_ASSERT(r, results[0].equals("")); |
259 REPORTER_ASSERT(r, results[1].equals("a")); | 286 REPORTER_ASSERT(r, results[1].equals("a")); |
260 REPORTER_ASSERT(r, results[2].equals("b")); | 287 REPORTER_ASSERT(r, results[2].equals("b")); |
261 REPORTER_ASSERT(r, results[3].equals("")); | 288 REPORTER_ASSERT(r, results[3].equals("")); |
262 } | 289 } |
OLD | NEW |