1#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"); 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")); 67 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#ifdef SK_SCALAR_IS_FLOAT 77 { 3.4028234e38f, "3.4028235e+38" }, 78 { -3.4028234e38f, "-3.4028235e+38" }, 79#endif 80 }; 81 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) { 82 a.reset(); 83 a.appendScalar(gRec[i].fValue); 84 REPORTER_ASSERT(reporter, a.size() <= SkStrAppendScalar_MaxSize); 85// SkDebugf(" received <%s> expected <%s>\n", a.c_str(), gRec[i].fString); 86 REPORTER_ASSERT(reporter, a.equals(gRec[i].fString)); 87 } 88} 89 90#include "TestClassDef.h" 91DEFINE_TESTCLASS("String", StringTestClass, TestString) 92