more tests (need more meat in there)
authorreed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Fri, 27 Feb 2009 22:06:06 +0000 (22:06 +0000)
committerreed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Fri, 27 Feb 2009 22:06:06 +0000 (22:06 +0000)
git-svn-id: http://skia.googlecode.com/svn/trunk@97 2bbb7eff-a529-9590-31e7-b0007b416f81

16 files changed:
include/core/Sk64.h
include/core/SkGeometry.h
include/core/SkString.h
src/core/Sk64.cpp
src/core/SkGeometry.cpp
src/core/SkGraphics.cpp
src/core/SkString.cpp
tests/GeometryTest.cpp [new file with mode: 0644]
tests/MathTest.cpp
tests/MatrixTest.cpp
tests/PackBitsTest.cpp
tests/Sk64Test.cpp [new file with mode: 0644]
tests/StringTest.cpp [new file with mode: 0644]
tests/TestClassDef.h [new file with mode: 0644]
tests/TestXCode/Tests.xcodeproj/project.pbxproj
tests/UtilsTest.cpp

index 538ae7e..ff28544 100644 (file)
@@ -233,12 +233,6 @@ struct Sk64 {
 #ifdef SkLONGLONG
     SkLONGLONG getLongLong() const;
 #endif
-
-#ifdef SK_DEBUG
-  /** @cond UNIT_TEST */
-    static void UnitTest();
-  /** @endcond */
-#endif
 };
 
 #endif
index 571159f..c517855 100644 (file)
@@ -151,13 +151,4 @@ enum SkRotationDirection {
 int SkBuildQuadArc(const SkVector& unitStart, const SkVector& unitStop, SkRotationDirection,
                    const SkMatrix* matrix, SkPoint quadPoints[]);
 
-//////////////////////////////////////////////////////////////////////////////
-
-#ifdef SK_DEBUG
-    class SkGeometry {
-    public:
-        static void UnitTest();
-    };
-#endif
-
 #endif
index 743b093..ae204dc 100644 (file)
@@ -120,10 +120,6 @@ public:
         to never fail or throw.
     */
     void    swap(SkString& other);
-
-  /** @cond UNIT_TEST */
-    SkDEBUGCODE(static void UnitTest();)
-  /** @endcond */
     
 private:
     struct Rec {
index 2715d23..4381b50 100644 (file)
@@ -368,208 +368,3 @@ SkFixed Sk64::getFixedDiv(const Sk64& denom) const
     return SkApplySign(result, sign);
 }
 
-///////////////////////////////////////////////////////////////////////
-
-#ifdef SK_DEBUG
-
-#include "SkRandom.h"
-#include <math.h>
-
-#ifdef SK_SUPPORT_UNITTEST
-struct BoolTable {
-    int8_t  zero, pos, neg, toBool, sign;
-};
-
-static void bool_table_test(const Sk64& a, const BoolTable& table)
-{
-    SkASSERT(a.isZero() != a.nonZero());
-
-    SkASSERT(!a.isZero() == !table.zero);
-    SkASSERT(!a.isPos() == !table.pos);
-    SkASSERT(!a.isNeg() == !table.neg);
-    SkASSERT(a.getSign() == table.sign);
-}
-
-#ifdef SkLONGLONG
-    static SkLONGLONG asLL(const Sk64& a)
-    {
-        return ((SkLONGLONG)a.fHi << 32) | a.fLo;
-    }
-#endif
-#endif
-
-void Sk64::UnitTest()
-{
-#ifdef SK_SUPPORT_UNITTEST
-    enum BoolTests {
-        kZero_BoolTest,
-        kPos_BoolTest,
-        kNeg_BoolTest
-    };
-    static const BoolTable gBoolTable[] = {
-        { 1, 0, 0, 0, 0 },
-        { 0, 1, 0, 1, 1 },
-        { 0, 0, 1, 1, -1 }
-    };
-
-    Sk64    a, b, c;
-
-    a.fHi = a.fLo = 0;
-    b.set(0);
-    c.setZero();
-    SkASSERT(a == b);
-    SkASSERT(a == c);
-    bool_table_test(a, gBoolTable[kZero_BoolTest]);
-
-    a.fHi = 0;  a.fLo = 5;
-    b.set(5);
-    SkASSERT(a == b);
-    SkASSERT(a.is32() && a.get32() == 5 && !a.is64());
-    bool_table_test(a, gBoolTable[kPos_BoolTest]);
-
-    a.fHi = -1; a.fLo = (uint32_t)-5;
-    b.set(-5);
-    SkASSERT(a == b);
-    SkASSERT(a.is32() && a.get32() == -5 && !a.is64());
-    bool_table_test(a, gBoolTable[kNeg_BoolTest]);
-
-    a.setZero();
-    b.set(6);
-    c.set(-6);
-    SkASSERT(a != b && b != c && a != c);
-    SkASSERT(!(a == b) && !(a == b) && !(a == b));
-    SkASSERT(a < b && b > a && a <= b && b >= a);
-    SkASSERT(c < a && a > c && c <= a && a >= c);
-    SkASSERT(c < b && b > c && c <= b && b >= c);
-
-    // Now test add/sub
-
-    SkRandom    rand;
-    int         i;
-
-    for (i = 0; i < 1000; i++)
-    {
-        int aa = rand.nextS() >> 1;
-        int bb = rand.nextS() >> 1;
-        a.set(aa);
-        b.set(bb);
-        SkASSERT(a.get32() == aa && b.get32() == bb);
-        c = a; c.add(bb);
-        SkASSERT(c.get32() == aa + bb);
-        c = a; c.add(-bb);
-        SkASSERT(c.get32() == aa - bb);
-        c = a; c.add(b);
-        SkASSERT(c.get32() == aa + bb);
-        c = a; c.sub(b);
-        SkASSERT(c.get32() == aa - bb);
-    }
-
-#ifdef SkLONGLONG
-    for (i = 0; i < 1000; i++)
-    {
-        rand.next64(&a); //a.fHi >>= 1; // avoid overflow
-        rand.next64(&b); //b.fHi >>= 1; // avoid overflow
-
-        if (!(i & 3))   // want to explicitly test these cases
-        {
-            a.fLo = 0;
-            b.fLo = 0;
-        }
-        else if (!(i & 7))  // want to explicitly test these cases
-        {
-            a.fHi = 0;
-            b.fHi = 0;
-        }
-
-        SkLONGLONG aa = asLL(a);
-        SkLONGLONG bb = asLL(b);
-
-        SkASSERT((a < b) == (aa < bb));
-        SkASSERT((a <= b) == (aa <= bb));
-        SkASSERT((a > b) == (aa > bb));
-        SkASSERT((a >= b) == (aa >= bb));
-        SkASSERT((a == b) == (aa == bb));
-        SkASSERT((a != b) == (aa != bb));
-
-        c = a; c.add(b);
-        SkASSERT(asLL(c) == aa + bb);
-        c = a; c.sub(b);
-        SkASSERT(asLL(c) == aa - bb);
-        c = a; c.rsub(b);
-        SkASSERT(asLL(c) == bb - aa);
-        c = a; c.negate();
-        SkASSERT(asLL(c) == -aa);
-
-        int bits = rand.nextU() & 63;
-        c = a; c.shiftLeft(bits);
-        SkASSERT(asLL(c) == (aa << bits));
-        c = a; c.shiftRight(bits);
-        SkASSERT(asLL(c) == (aa >> bits));
-        c = a; c.roundRight(bits);
-
-        SkLONGLONG tmp;
-
-        tmp = aa;
-        if (bits > 0)
-            tmp += (SkLONGLONG)1 << (bits - 1);
-        SkASSERT(asLL(c) == (tmp >> bits));
-
-        c.setMul(a.fHi, b.fHi);
-        tmp = (SkLONGLONG)a.fHi * b.fHi;
-        SkASSERT(asLL(c) == tmp);
-    }
-
-
-    for (i = 0; i < 100000; i++)
-    {
-        Sk64    wide;
-        int32_t denom = rand.nextS();
-
-        while (denom == 0)
-            denom = rand.nextS();
-        wide.setMul(rand.nextS(), rand.nextS());
-        SkLONGLONG check = wide.getLongLong();
-
-        wide.div(denom, Sk64::kTrunc_DivOption);
-        check /= denom;
-        SkLONGLONG w = wide.getLongLong();
-
-        SkASSERT(check == w);
-
-#ifdef SK_CAN_USE_FLOATx
-        wide.setMul(rand.nextS(), rand.nextS());
-        wide.abs();
-        denom = wide.getSqrt();
-        int32_t ck = (int32_t)sqrt((double)wide.getLongLong());
-        int diff = denom - ck;
-        SkASSERT(SkAbs32(diff) <= 1);
-
-        wide.setMul(rand.nextS(), rand.nextS());
-        Sk64    dwide;
-        dwide.setMul(rand.nextS(), rand.nextS());
-        SkFixed fixdiv = wide.getFixedDiv(dwide);
-        double dnumer = (double)wide.getLongLong();
-        double ddenom = (double)dwide.getLongLong();
-        double ddiv = dnumer / ddenom;
-        SkFixed dfixdiv;
-        if (ddiv >= (double)SK_MaxS32 / (double)SK_Fixed1)
-            dfixdiv = SK_MaxS32;
-        else if (ddiv <= -(double)SK_MaxS32 / (double)SK_Fixed1)
-            dfixdiv = SK_MinS32;
-        else
-            dfixdiv = SkFloatToFixed(dnumer / ddenom);
-        diff = fixdiv - dfixdiv;
-        
-        if (SkAbs32(diff) > 1) {
-            SkDebugf(" %d === numer %g denom %g div %g xdiv %x fxdiv %x\n",
-                     i, dnumer, ddenom, ddiv, dfixdiv, fixdiv);
-        }
-//        SkASSERT(SkAbs32(diff) <= 1);
-#endif
-    }
-#endif
-#endif
-}
-
-#endif
-
index 7e2d424..229c3d8 100644 (file)
@@ -1047,26 +1047,3 @@ int SkBuildQuadArc(const SkVector& uStart, const SkVector& uStop,
     return pointCount;
 }
 
-
-/////////////////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////////////////
-
-#ifdef SK_DEBUG
-
-void SkGeometry::UnitTest()
-{
-#ifdef SK_SUPPORT_UNITTEST
-    SkPoint pts[3], dst[5];
-
-    pts[0].set(0, 0);
-    pts[1].set(100, 50);
-    pts[2].set(0, 100);
-
-    int count = SkChopQuadAtMaxCurvature(pts, dst);
-    SkASSERT(count == 1 || count == 2);
-#endif
-}
-
-#endif
-
-
index 053d9f0..b2e6cbf 100644 (file)
@@ -344,9 +344,6 @@ void SkGraphics::Init(bool runUnitTests)
         const char* fTypeName;
         void (*fUnitTest)();
     } gUnitTests[] = {
-        unittestline(Sk64),
-        unittestline(SkString),
-        unittestline(SkGeometry),
         unittestline(SkPath),
         unittestline(SkPathMeasure),
         unittestline(SkStream),
index 2e5d946..d595d51 100644 (file)
@@ -581,62 +581,3 @@ SkAutoUCS2::~SkAutoUCS2()
     delete[] fUCS2;
 }
 
-/////////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////////
-
-#ifdef SK_DEBUG
-
-void SkString::UnitTest()
-{
-#ifdef SK_SUPPORT_UNITTEST
-    SkString    a;
-    SkString    b((size_t)0);
-    SkString    c("");
-    SkString    d(NULL, 0);
-
-    SkASSERT(a.isEmpty());
-    SkASSERT(a == b && a == c && a == d);
-
-    a.set("hello");
-    b.set("hellox", 5);
-    c.set(a);
-    d.resize(5);
-    memcpy(d.writable_str(), "helloz", 5);
-
-    SkASSERT(!a.isEmpty());
-    SkASSERT(a.size() == 5);
-    SkASSERT(a == b && a == c && a == d);
-    SkASSERT(a.equals("hello", 5));
-    SkASSERT(a.equals("hello"));
-    SkASSERT(!a.equals("help"));
-
-    SkString    e(a);
-    SkString    f("hello");
-    SkString    g("helloz", 5);
-
-    SkASSERT(a == e && a == f && a == g);
-
-    b.set("world");
-    c = b;
-    SkASSERT(a != b && a != c && b == c);
-
-    a.append(" world");
-    e.append("worldz", 5);
-    e.insert(5, " ");
-    f.set("world");
-    f.prepend("hello ");
-    SkASSERT(a.equals("hello world") && a == e && a == f);
-
-    a.reset();
-    b.resize(0);
-    SkASSERT(a.isEmpty() && b.isEmpty() && a == b);
-
-    a.set("a");
-    a.set("ab");
-    a.set("abc");
-    a.set("abcd");
-#endif
-}
-
-#endif
-
diff --git a/tests/GeometryTest.cpp b/tests/GeometryTest.cpp
new file mode 100644 (file)
index 0000000..5b05952
--- /dev/null
@@ -0,0 +1,16 @@
+#include "Test.h"
+#include "SkGeometry.h"
+
+static void TestGeometry(skiatest::Reporter* reporter) {
+    SkPoint pts[3], dst[5];
+
+    pts[0].set(0, 0);
+    pts[1].set(100, 50);
+    pts[2].set(0, 100);
+
+    int count = SkChopQuadAtMaxCurvature(pts, dst);
+    REPORTER_ASSERT(reporter, count == 1 || count == 2);
+}
+
+#include "TestClassDef.h"
+DEFINE_TESTCLASS("Geometry", GeometryTestClass, TestGeometry)
index a759ab1..50d59cf 100644 (file)
@@ -213,8 +213,6 @@ static void TestMath(skiatest::Reporter* reporter) {
         REPORTER_ASSERT(reporter, x == i);
     }
     
-    REPORTER_ASSERT(reporter, !"test the reporter");
-    
     x = SkFixedSqrt(SK_Fixed1);
     REPORTER_ASSERT(reporter, x == SK_Fixed1);
     x = SkFixedSqrt(SK_Fixed1/4);
@@ -375,26 +373,5 @@ static void TestMath(skiatest::Reporter* reporter) {
 #endif
 }
 
-///////////////////////////////////////////////////////////////////////////////
-
-namespace skiatest {
-
-    class MathTest : public Test {
-    public:
-        static Test* Factory(void*) {
-            return SkNEW(MathTest);
-        }
-
-    protected:
-        virtual void onGetName(SkString* name) {
-            name->set("Math");
-        }
-        
-        virtual void onRun(Reporter* reporter) {
-            TestMath(reporter);
-        }
-    };
-
-    static TestRegistry gReg(MathTest::Factory);
-}
-
+#include "TestClassDef.h"
+DEFINE_TESTCLASS("Math", MathTestClass, TestMath)
index 1e4e341..659672a 100644 (file)
@@ -94,26 +94,5 @@ void TestMatrix(skiatest::Reporter* reporter) {
     }
 }
 
-///////////////////////////////////////////////////////////////////////////////
-
-namespace skiatest {
-
-    class MatrixTest : public Test {
-    public:
-        static Test* Factory(void*) {
-            return SkNEW(MatrixTest);
-        }
-
-    protected:
-        virtual void onGetName(SkString* name) {
-            name->set("Matrix");
-        }
-        
-        virtual void onRun(Reporter* reporter) {
-            TestMatrix(reporter);
-        }
-    };
-
-    static TestRegistry gReg(MatrixTest::Factory);
-}
-
+#include "TestClassDef.h"
+DEFINE_TESTCLASS("Matrix", MatrixTestClass, TestMatrix)
index 6e69f82..fc11fb2 100644 (file)
@@ -118,27 +118,10 @@ static void test_pack8(skiatest::Reporter* reporter) {
     }
 }
 
-///////////////////////////////////////////////////////////////////////////////
-
-namespace skiatest {
-    
-    class PackBitsTest : public Test {
-    public:
-        static Test* Factory(void*) {
-            return SkNEW(PackBitsTest);
-        }
-        
-    protected:
-        virtual void onGetName(SkString* name) {
-            name->set("PackBits");
-        }
-        
-        virtual void onRun(Reporter* reporter) {
-            test_pack8(reporter);
-            test_pack16(reporter);
-        }
-    };
-    
-    static TestRegistry gReg(PackBitsTest::Factory);
+static void TestPackBits(skiatest::Reporter* reporter) {
+    test_pack8(reporter);
+    test_pack16(reporter);
 }
 
+#include "TestClassDef.h"
+DEFINE_TESTCLASS("PackBits", PackBitsTestClass, TestPackBits)
diff --git a/tests/Sk64Test.cpp b/tests/Sk64Test.cpp
new file mode 100644 (file)
index 0000000..1829c64
--- /dev/null
@@ -0,0 +1,200 @@
+#include "Test.h"
+#include "SkRandom.h"
+#include <math.h>
+
+#ifdef SK_SUPPORT_UNITTEST
+struct BoolTable {
+    int8_t  zero, pos, neg, toBool, sign;
+};
+
+static void bool_table_test(skiatest::Reporter* reporter,
+                            const Sk64& a, const BoolTable& table)
+{
+    REPORTER_ASSERT(reporter, a.isZero() != a.nonZero());
+
+    REPORTER_ASSERT(reporter, !a.isZero() == !table.zero);
+    REPORTER_ASSERT(reporter, !a.isPos() == !table.pos);
+    REPORTER_ASSERT(reporter, !a.isNeg() == !table.neg);
+    REPORTER_ASSERT(reporter, a.getSign() == table.sign);
+}
+
+#ifdef SkLONGLONG
+    static SkLONGLONG asLL(const Sk64& a)
+    {
+        return ((SkLONGLONG)a.fHi << 32) | a.fLo;
+    }
+#endif
+#endif
+
+static void TestSk64(skiatest::Reporter* reporter) {
+    enum BoolTests {
+        kZero_BoolTest,
+        kPos_BoolTest,
+        kNeg_BoolTest
+    };
+    static const BoolTable gBoolTable[] = {
+        { 1, 0, 0, 0, 0 },
+        { 0, 1, 0, 1, 1 },
+        { 0, 0, 1, 1, -1 }
+    };
+
+    Sk64    a, b, c;
+
+    a.fHi = a.fLo = 0;
+    b.set(0);
+    c.setZero();
+    REPORTER_ASSERT(reporter, a == b);
+    REPORTER_ASSERT(reporter, a == c);
+    bool_table_test(reporter, a, gBoolTable[kZero_BoolTest]);
+
+    a.fHi = 0;  a.fLo = 5;
+    b.set(5);
+    REPORTER_ASSERT(reporter, a == b);
+    REPORTER_ASSERT(reporter, a.is32() && a.get32() == 5 && !a.is64());
+    bool_table_test(reporter, a, gBoolTable[kPos_BoolTest]);
+
+    a.fHi = -1; a.fLo = (uint32_t)-5;
+    b.set(-5);
+    REPORTER_ASSERT(reporter, a == b);
+    REPORTER_ASSERT(reporter, a.is32() && a.get32() == -5 && !a.is64());
+    bool_table_test(reporter, a, gBoolTable[kNeg_BoolTest]);
+
+    a.setZero();
+    b.set(6);
+    c.set(-6);
+    REPORTER_ASSERT(reporter, a != b && b != c && a != c);
+    REPORTER_ASSERT(reporter, !(a == b) && !(a == b) && !(a == b));
+    REPORTER_ASSERT(reporter, a < b && b > a && a <= b && b >= a);
+    REPORTER_ASSERT(reporter, c < a && a > c && c <= a && a >= c);
+    REPORTER_ASSERT(reporter, c < b && b > c && c <= b && b >= c);
+
+    // Now test add/sub
+
+    SkRandom    rand;
+    int         i;
+
+    for (i = 0; i < 1000; i++)
+    {
+        int aa = rand.nextS() >> 1;
+        int bb = rand.nextS() >> 1;
+        a.set(aa);
+        b.set(bb);
+        REPORTER_ASSERT(reporter, a.get32() == aa && b.get32() == bb);
+        c = a; c.add(bb);
+        REPORTER_ASSERT(reporter, c.get32() == aa + bb);
+        c = a; c.add(-bb);
+        REPORTER_ASSERT(reporter, c.get32() == aa - bb);
+        c = a; c.add(b);
+        REPORTER_ASSERT(reporter, c.get32() == aa + bb);
+        c = a; c.sub(b);
+        REPORTER_ASSERT(reporter, c.get32() == aa - bb);
+    }
+
+#ifdef SkLONGLONG
+    for (i = 0; i < 1000; i++)
+    {
+        rand.next64(&a); //a.fHi >>= 1; // avoid overflow
+        rand.next64(&b); //b.fHi >>= 1; // avoid overflow
+
+        if (!(i & 3))   // want to explicitly test these cases
+        {
+            a.fLo = 0;
+            b.fLo = 0;
+        }
+        else if (!(i & 7))  // want to explicitly test these cases
+        {
+            a.fHi = 0;
+            b.fHi = 0;
+        }
+
+        SkLONGLONG aa = asLL(a);
+        SkLONGLONG bb = asLL(b);
+
+        REPORTER_ASSERT(reporter, (a < b) == (aa < bb));
+        REPORTER_ASSERT(reporter, (a <= b) == (aa <= bb));
+        REPORTER_ASSERT(reporter, (a > b) == (aa > bb));
+        REPORTER_ASSERT(reporter, (a >= b) == (aa >= bb));
+        REPORTER_ASSERT(reporter, (a == b) == (aa == bb));
+        REPORTER_ASSERT(reporter, (a != b) == (aa != bb));
+
+        c = a; c.add(b);
+        REPORTER_ASSERT(reporter, asLL(c) == aa + bb);
+        c = a; c.sub(b);
+        REPORTER_ASSERT(reporter, asLL(c) == aa - bb);
+        c = a; c.rsub(b);
+        REPORTER_ASSERT(reporter, asLL(c) == bb - aa);
+        c = a; c.negate();
+        REPORTER_ASSERT(reporter, asLL(c) == -aa);
+
+        int bits = rand.nextU() & 63;
+        c = a; c.shiftLeft(bits);
+        REPORTER_ASSERT(reporter, asLL(c) == (aa << bits));
+        c = a; c.shiftRight(bits);
+        REPORTER_ASSERT(reporter, asLL(c) == (aa >> bits));
+        c = a; c.roundRight(bits);
+
+        SkLONGLONG tmp;
+
+        tmp = aa;
+        if (bits > 0)
+            tmp += (SkLONGLONG)1 << (bits - 1);
+        REPORTER_ASSERT(reporter, asLL(c) == (tmp >> bits));
+
+        c.setMul(a.fHi, b.fHi);
+        tmp = (SkLONGLONG)a.fHi * b.fHi;
+        REPORTER_ASSERT(reporter, asLL(c) == tmp);
+    }
+
+
+    for (i = 0; i < 100000; i++)
+    {
+        Sk64    wide;
+        int32_t denom = rand.nextS();
+
+        while (denom == 0)
+            denom = rand.nextS();
+        wide.setMul(rand.nextS(), rand.nextS());
+        SkLONGLONG check = wide.getLongLong();
+
+        wide.div(denom, Sk64::kTrunc_DivOption);
+        check /= denom;
+        SkLONGLONG w = wide.getLongLong();
+
+        REPORTER_ASSERT(reporter, check == w);
+
+#ifdef SK_CAN_USE_FLOAT
+        wide.setMul(rand.nextS(), rand.nextS());
+        wide.abs();
+        denom = wide.getSqrt();
+        int32_t ck = (int32_t)sqrt((double)wide.getLongLong());
+        int diff = denom - ck;
+        REPORTER_ASSERT(reporter, SkAbs32(diff) <= 1);
+
+        wide.setMul(rand.nextS(), rand.nextS());
+        Sk64    dwide;
+        dwide.setMul(rand.nextS(), rand.nextS());
+        SkFixed fixdiv = wide.getFixedDiv(dwide);
+        double dnumer = (double)wide.getLongLong();
+        double ddenom = (double)dwide.getLongLong();
+        double ddiv = dnumer / ddenom;
+        SkFixed dfixdiv;
+        if (ddiv >= (double)SK_MaxS32 / (double)SK_Fixed1)
+            dfixdiv = SK_MaxS32;
+        else if (ddiv <= -(double)SK_MaxS32 / (double)SK_Fixed1)
+            dfixdiv = SK_MinS32;
+        else
+            dfixdiv = SkFloatToFixed(dnumer / ddenom);
+        diff = fixdiv - dfixdiv;
+        
+        if (SkAbs32(diff) > 1) {
+            SkDebugf(" %d === numer %g denom %g div %g xdiv %x fxdiv %x\n",
+                     i, dnumer, ddenom, ddiv, dfixdiv, fixdiv);
+        }
+        REPORTER_ASSERT(reporter, SkAbs32(diff) <= 1);
+#endif
+    }
+#endif
+}
+
+#include "TestClassDef.h"
+DEFINE_TESTCLASS("Sk64", Sk64TestClass, TestSk64)
diff --git a/tests/StringTest.cpp b/tests/StringTest.cpp
new file mode 100644 (file)
index 0000000..344c752
--- /dev/null
@@ -0,0 +1,54 @@
+#include "Test.h"
+#include "SkString.h"
+
+static void TestString(skiatest::Reporter* reporter) {
+    SkString    a;
+    SkString    b((size_t)0);
+    SkString    c("");
+    SkString    d(NULL, 0);
+
+    REPORTER_ASSERT(reporter, a.isEmpty());
+    REPORTER_ASSERT(reporter, a == b && a == c && a == d);
+
+    a.set("hello");
+    b.set("hellox", 5);
+    c.set(a);
+    d.resize(5);
+    memcpy(d.writable_str(), "helloz", 5);
+
+    REPORTER_ASSERT(reporter, !a.isEmpty());
+    REPORTER_ASSERT(reporter, a.size() == 5);
+    REPORTER_ASSERT(reporter, a == b && a == c && a == d);
+    REPORTER_ASSERT(reporter, a.equals("hello", 5));
+    REPORTER_ASSERT(reporter, a.equals("hello"));
+    REPORTER_ASSERT(reporter, !a.equals("help"));
+
+    SkString    e(a);
+    SkString    f("hello");
+    SkString    g("helloz", 5);
+
+    REPORTER_ASSERT(reporter, a == e && a == f && a == g);
+
+    b.set("world");
+    c = b;
+    REPORTER_ASSERT(reporter, a != b && a != c && b == c);
+
+    a.append(" world");
+    e.append("worldz", 5);
+    e.insert(5, " ");
+    f.set("world");
+    f.prepend("hello ");
+    REPORTER_ASSERT(reporter, a.equals("hello world") && a == e && a == f);
+
+    a.reset();
+    b.resize(0);
+    REPORTER_ASSERT(reporter, a.isEmpty() && b.isEmpty() && a == b);
+
+    a.set("a");
+    a.set("ab");
+    a.set("abc");
+    a.set("abcd");
+}
+
+#include "TestClassDef.h"
+DEFINE_TESTCLASS("String", StringTestClass, TestString)
diff --git a/tests/TestClassDef.h b/tests/TestClassDef.h
new file mode 100644 (file)
index 0000000..77f48b3
--- /dev/null
@@ -0,0 +1,24 @@
+/*  This file is meant be including by .cpp files, so it can spew out a
+    customized class + global definition.
+    e.g.
+    #include "TestClassDef.h"
+    DEFINE_TESTCLASS("MyTest", MyTestClass, MyTestFunction)
+    where MyTestFunction is declared as
+        void MyTestFunction(skiatest::Reporter*)
+*/
+
+#define DEFINE_TESTCLASS(uiname, classname, function)                       \
+    namespace skiatest {                                                    \
+        class classname : public Test {                                     \
+        public:                                                             \
+            static Test* Factory(void*) { return SkNEW(classname); }        \
+        protected:                                                          \
+            virtual void onGetName(SkString* name) { name->set(uiname); }   \
+            virtual void onRun(Reporter* reporter) { function(reporter); }  \
+        };                                                                  \
+        static TestRegistry gReg(classname::Factory);                       \
+    }
+
index 004fb22..7d7b924 100644 (file)
@@ -15,6 +15,9 @@
                008634DC0F579B7A0044DA64 /* PackBitsTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 008634DB0F579B7A0044DA64 /* PackBitsTest.cpp */; };
                008634F10F579E410044DA64 /* MatrixTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 008634F00F579E410044DA64 /* MatrixTest.cpp */; };
                0086350F0F57A3140044DA64 /* UtilsTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0086350E0F57A3140044DA64 /* UtilsTest.cpp */; };
+               00A9BF860F584CF30091AD2D /* Sk64Test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 00A9BF850F584CF30091AD2D /* Sk64Test.cpp */; };
+               00A9BFA30F584E150091AD2D /* StringTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 00A9BFA20F584E150091AD2D /* StringTest.cpp */; };
+               00A9BFBC0F5851570091AD2D /* GeometryTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 00A9BFBB0F5851570091AD2D /* GeometryTest.cpp */; };
                8DD76F6A0486A84900D96B5E /* Tests.1 in CopyFiles */ = {isa = PBXBuildFile; fileRef = C6859E8B029090EE04C91782 /* Tests.1 */; };
 /* End PBXBuildFile section */
 
                        isa = PBXContainerItemProxy;
                        containerPortal = 00857F6B0F56F71B0078BE26 /* core.xcodeproj */;
                        proxyType = 1;
-                       remoteGlobalIDString = D2AAC045055464E500DB518D /* core */;
+                       remoteGlobalIDString = D2AAC045055464E500DB518D;
                        remoteInfo = core;
                };
                0086351E0F57A5200044DA64 /* PBXContainerItemProxy */ = {
                        isa = PBXContainerItemProxy;
                        containerPortal = 00857F890F56F9150078BE26 /* maccore.xcodeproj */;
                        proxyType = 1;
-                       remoteGlobalIDString = D2AAC045055464E500DB518D /* maccore */;
+                       remoteGlobalIDString = D2AAC045055464E500DB518D;
                        remoteInfo = maccore;
                };
 /* End PBXContainerItemProxy section */
                008634DB0F579B7A0044DA64 /* PackBitsTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = PackBitsTest.cpp; path = ../PackBitsTest.cpp; sourceTree = SOURCE_ROOT; };
                008634F00F579E410044DA64 /* MatrixTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = MatrixTest.cpp; path = ../MatrixTest.cpp; sourceTree = SOURCE_ROOT; };
                0086350E0F57A3140044DA64 /* UtilsTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = UtilsTest.cpp; path = ../UtilsTest.cpp; sourceTree = SOURCE_ROOT; };
+               00A9BF850F584CF30091AD2D /* Sk64Test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Sk64Test.cpp; path = ../Sk64Test.cpp; sourceTree = SOURCE_ROOT; };
+               00A9BFA20F584E150091AD2D /* StringTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StringTest.cpp; path = ../StringTest.cpp; sourceTree = SOURCE_ROOT; };
+               00A9BFA60F584F200091AD2D /* TestClassDef.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TestClassDef.h; path = ../TestClassDef.h; sourceTree = SOURCE_ROOT; };
+               00A9BFBB0F5851570091AD2D /* GeometryTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = GeometryTest.cpp; path = ../GeometryTest.cpp; sourceTree = SOURCE_ROOT; };
                8DD76F6C0486A84900D96B5E /* Tests */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = Tests; sourceTree = BUILT_PRODUCTS_DIR; };
                C6859E8B029090EE04C91782 /* Tests.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = Tests.1; sourceTree = "<group>"; };
 /* End PBXFileReference section */
                08FB7795FE84155DC02AAC07 /* Source */ = {
                        isa = PBXGroup;
                        children = (
+                               00A9BF850F584CF30091AD2D /* Sk64Test.cpp */,
+                               00A9BFBB0F5851570091AD2D /* GeometryTest.cpp */,
+                               00A9BFA20F584E150091AD2D /* StringTest.cpp */,
                                00857FA80F56F9620078BE26 /* Test.cpp */,
                                00857FA90F56F9620078BE26 /* main.cpp */,
                                00857F630F56F4220078BE26 /* Test.h */,
                                00857FB60F56FD340078BE26 /* MathTest.cpp */,
                                0086350E0F57A3140044DA64 /* UtilsTest.cpp */,
                                008634F00F579E410044DA64 /* MatrixTest.cpp */,
+                               00A9BFA60F584F200091AD2D /* TestClassDef.h */,
                                008634DB0F579B7A0044DA64 /* PackBitsTest.cpp */,
                        );
                        name = Source;
                                008634DC0F579B7A0044DA64 /* PackBitsTest.cpp in Sources */,
                                008634F10F579E410044DA64 /* MatrixTest.cpp in Sources */,
                                0086350F0F57A3140044DA64 /* UtilsTest.cpp in Sources */,
+                               00A9BF860F584CF30091AD2D /* Sk64Test.cpp in Sources */,
+                               00A9BFA30F584E150091AD2D /* StringTest.cpp in Sources */,
+                               00A9BFBC0F5851570091AD2D /* GeometryTest.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index 810cb51..f6b0211 100644 (file)
@@ -105,26 +105,5 @@ static void TestUTF(skiatest::Reporter* reporter) {
     test_search(reporter);
 }
 
-///////////////////////////////////////////////////////////////////////////////
-
-namespace skiatest {
-    
-    class UtfTest : public Test {
-    public:
-        static Test* Factory(void*) {
-            return SkNEW(UtfTest);
-        }
-        
-    protected:
-        virtual void onGetName(SkString* name) {
-            name->set("UTF");
-        }
-        
-        virtual void onRun(Reporter* reporter) {
-            TestUTF(reporter);
-        }
-    };
-    
-    static TestRegistry gReg(UtfTest::Factory);
-}
-
+#include "TestClassDef.h"
+DEFINE_TESTCLASS("UTF", UtfTestClass, TestUTF)