reed@android.com | d8730ea | 2009-02-27 22:06:06 +0000 | [diff] [blame] | 1 | #include "Test.h" |
| 2 | #include "SkString.h" |
| 3 | |
| 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"); |
vandebo@chromium.org | d877fdb | 2010-10-12 23:08:13 +0000 | [diff] [blame^] | 51 | |
| 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@android.com | d8730ea | 2009-02-27 22:06:06 +0000 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | #include "TestClassDef.h" |
| 70 | DEFINE_TESTCLASS("String", StringTestClass, TestString) |