• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "Test.h"
2 #include "SkString.h"
3 
TestString(skiatest::Reporter * reporter)4 static 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");
51 }
52 
53 #include "TestClassDef.h"
54 DEFINE_TESTCLASS("String", StringTestClass, TestString)
55