OLD | NEW |
1 | |
2 /* | 1 /* |
3 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
4 * | 3 * |
5 * 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 |
6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
7 */ | 6 */ |
| 7 |
8 #include "Test.h" | 8 #include "Test.h" |
| 9 #include "TestClassDef.h" |
9 #include "SkString.h" | 10 #include "SkString.h" |
10 #include <stdarg.h> | 11 #include <stdarg.h> |
11 #include <stdio.h> | 12 #include <stdio.h> |
12 | 13 |
13 // Windows vsnprintf doesn't 0-terminate safely), but is so far | 14 // Windows vsnprintf doesn't 0-terminate safely), but is so far |
14 // encapsulated in SkString that we can't test it directly. | 15 // encapsulated in SkString that we can't test it directly. |
15 | 16 |
16 #ifdef SK_BUILD_FOR_WIN | 17 #ifdef SK_BUILD_FOR_WIN |
17 #define VSNPRINTF(buffer, size, format, args) \ | 18 #define VSNPRINTF(buffer, size, format, args) \ |
18 vsnprintf_s(buffer, size, _TRUNCATE, format, args) | 19 vsnprintf_s(buffer, size, _TRUNCATE, format, args) |
19 #else | 20 #else |
20 #define VSNPRINTF vsnprintf | 21 #define VSNPRINTF vsnprintf |
21 #endif | 22 #endif |
22 | 23 |
23 #define ARGS_TO_BUFFER(format, buffer, size) \ | 24 #define ARGS_TO_BUFFER(format, buffer, size) \ |
24 do { \ | 25 do { \ |
25 va_list args; \ | 26 va_list args; \ |
26 va_start(args, format); \ | 27 va_start(args, format); \ |
27 VSNPRINTF(buffer, size, format, args); \ | 28 VSNPRINTF(buffer, size, format, args); \ |
28 va_end(args); \ | 29 va_end(args); \ |
29 } while (0) | 30 } while (0) |
30 | 31 |
31 static void printfAnalog(char* buffer, int size, const char format[], ...) { | 32 static void printfAnalog(char* buffer, int size, const char format[], ...) { |
32 ARGS_TO_BUFFER(format, buffer, size); | 33 ARGS_TO_BUFFER(format, buffer, size); |
33 } | 34 } |
34 | 35 |
35 | 36 DEF_TEST(String, reporter) { |
36 | |
37 static void TestString(skiatest::Reporter* reporter) { | |
38 SkString a; | 37 SkString a; |
39 SkString b((size_t)0); | 38 SkString b((size_t)0); |
40 SkString c(""); | 39 SkString c(""); |
41 SkString d(NULL, 0); | 40 SkString d(NULL, 0); |
42 | 41 |
43 REPORTER_ASSERT(reporter, a.isEmpty()); | 42 REPORTER_ASSERT(reporter, a.isEmpty()); |
44 REPORTER_ASSERT(reporter, a == b && a == c && a == d); | 43 REPORTER_ASSERT(reporter, a == b && a == c && a == d); |
45 | 44 |
46 a.set("hello"); | 45 a.set("hello"); |
47 b.set("hellox", 5); | 46 b.set("hellox", 5); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 REPORTER_ASSERT(reporter, buffer[18] == 'a'); | 182 REPORTER_ASSERT(reporter, buffer[18] == 'a'); |
184 REPORTER_ASSERT(reporter, buffer[19] == 'a'); | 183 REPORTER_ASSERT(reporter, buffer[19] == 'a'); |
185 REPORTER_ASSERT(reporter, buffer[20] == 'a'); | 184 REPORTER_ASSERT(reporter, buffer[20] == 'a'); |
186 printfAnalog(buffer, 20, "%30d", 0); | 185 printfAnalog(buffer, 20, "%30d", 0); |
187 REPORTER_ASSERT(reporter, buffer[18] == ' '); | 186 REPORTER_ASSERT(reporter, buffer[18] == ' '); |
188 REPORTER_ASSERT(reporter, buffer[19] == 0); | 187 REPORTER_ASSERT(reporter, buffer[19] == 0); |
189 REPORTER_ASSERT(reporter, buffer[20] == 'a'); | 188 REPORTER_ASSERT(reporter, buffer[20] == 'a'); |
190 | 189 |
191 } | 190 } |
192 | 191 |
193 #include "TestClassDef.h" | |
194 DEFINE_TESTCLASS("String", StringTestClass, TestString) | |
195 | |
196 DEF_TEST(String_SkStrSplit, r) { | 192 DEF_TEST(String_SkStrSplit, r) { |
197 SkTArray<SkString> results; | 193 SkTArray<SkString> results; |
198 | 194 |
199 SkStrSplit("a-_b_c-dee--f-_-_-g-", "-_", &results); | 195 SkStrSplit("a-_b_c-dee--f-_-_-g-", "-_", &results); |
200 REPORTER_ASSERT(r, results.count() == 6); | 196 REPORTER_ASSERT(r, results.count() == 6); |
201 REPORTER_ASSERT(r, results[0].equals("a")); | 197 REPORTER_ASSERT(r, results[0].equals("a")); |
202 REPORTER_ASSERT(r, results[1].equals("b")); | 198 REPORTER_ASSERT(r, results[1].equals("b")); |
203 REPORTER_ASSERT(r, results[2].equals("c")); | 199 REPORTER_ASSERT(r, results[2].equals("c")); |
204 REPORTER_ASSERT(r, results[3].equals("dee")); | 200 REPORTER_ASSERT(r, results[3].equals("dee")); |
205 REPORTER_ASSERT(r, results[4].equals("f")); | 201 REPORTER_ASSERT(r, results[4].equals("f")); |
206 REPORTER_ASSERT(r, results[5].equals("g")); | 202 REPORTER_ASSERT(r, results[5].equals("g")); |
207 } | 203 } |
OLD | NEW |