blob: 781fed8bf74373eb7928c05495cfb4e9c229854e [file] [log] [blame]
reed@android.comd8730ea2009-02-27 22:06:06 +00001#include "Test.h"
2#include "SkString.h"
3
4static void TestString(skiatest::Reporter* reporter) {
5 SkString a;
6 SkString b((size_t)0);
7 SkString c("");
8 SkString d(NULL, 0);
9
10 REPORTER_ASSERT(reporter, a.isEmpty());
11 REPORTER_ASSERT(reporter, a == b && a == c && a == d);
12
13 a.set("hello");
14 b.set("hellox", 5);
15 c.set(a);
16 d.resize(5);
17 memcpy(d.writable_str(), "helloz", 5);
18
19 REPORTER_ASSERT(reporter, !a.isEmpty());
20 REPORTER_ASSERT(reporter, a.size() == 5);
21 REPORTER_ASSERT(reporter, a == b && a == c && a == d);
22 REPORTER_ASSERT(reporter, a.equals("hello", 5));
23 REPORTER_ASSERT(reporter, a.equals("hello"));
24 REPORTER_ASSERT(reporter, !a.equals("help"));
25
26 SkString e(a);
27 SkString f("hello");
28 SkString g("helloz", 5);
29
30 REPORTER_ASSERT(reporter, a == e && a == f && a == g);
31
32 b.set("world");
33 c = b;
34 REPORTER_ASSERT(reporter, a != b && a != c && b == c);
35
36 a.append(" world");
37 e.append("worldz", 5);
38 e.insert(5, " ");
39 f.set("world");
40 f.prepend("hello ");
41 REPORTER_ASSERT(reporter, a.equals("hello world") && a == e && a == f);
42
43 a.reset();
44 b.resize(0);
45 REPORTER_ASSERT(reporter, a.isEmpty() && b.isEmpty() && a == b);
46
47 a.set("a");
48 a.set("ab");
49 a.set("abc");
50 a.set("abcd");
vandebo@chromium.orgd877fdb2010-10-12 23:08:13 +000051
52 a.set("");
53 a.appendS64(72036854775808LL, 0);
54 REPORTER_ASSERT(reporter, a.equals("72036854775808"));
55
56 a.set("");
57 a.appendS64(-1844674407370LL, 0);
58 REPORTER_ASSERT(reporter, a.equals("-1844674407370"));
59
60 a.set("");
61 a.appendS64(73709551616LL, 15);
62 REPORTER_ASSERT(reporter, a.equals("000073709551616"));
63
64 a.set("");
65 a.appendS64(-429496729612LL, 15);
66 REPORTER_ASSERT(reporter, a.equals("-000429496729612"));
reed@google.comfa06e522011-02-28 21:29:58 +000067
68 static const struct {
69 SkScalar fValue;
70 const char* fString;
71 } gRec[] = {
72 { 0, "0" },
73 { SK_Scalar1, "1" },
74 { -SK_Scalar1, "-1" },
75 { SK_Scalar1/2, "0.5" },
76 };
77 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) {
78 a.reset();
79 a.appendScalar(gRec[i].fValue);
80 REPORTER_ASSERT(reporter, a.equals(gRec[i].fString));
81 }
reed@android.comd8730ea2009-02-27 22:06:06 +000082}
83
84#include "TestClassDef.h"
85DEFINE_TESTCLASS("String", StringTestClass, TestString)