aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/core/Sk64.h6
-rw-r--r--include/core/SkGeometry.h9
-rw-r--r--include/core/SkString.h4
-rw-r--r--src/core/Sk64.cpp205
-rw-r--r--src/core/SkGeometry.cpp23
-rw-r--r--src/core/SkGraphics.cpp3
-rw-r--r--src/core/SkString.cpp59
-rw-r--r--tests/GeometryTest.cpp16
-rw-r--r--tests/MathTest.cpp27
-rw-r--r--tests/MatrixTest.cpp25
-rw-r--r--tests/PackBitsTest.cpp27
-rw-r--r--tests/Sk64Test.cpp200
-rw-r--r--tests/StringTest.cpp54
-rw-r--r--tests/TestClassDef.h24
-rw-r--r--tests/TestXCode/Tests.xcodeproj/project.pbxproj18
-rw-r--r--tests/UtilsTest.cpp25
16 files changed, 321 insertions, 404 deletions
diff --git a/include/core/Sk64.h b/include/core/Sk64.h
index 538ae7e707..ff2854410e 100644
--- a/include/core/Sk64.h
+++ b/include/core/Sk64.h
@@ -233,12 +233,6 @@ struct Sk64 {
#ifdef SkLONGLONG
SkLONGLONG getLongLong() const;
#endif
-
-#ifdef SK_DEBUG
- /** @cond UNIT_TEST */
- static void UnitTest();
- /** @endcond */
-#endif
};
#endif
diff --git a/include/core/SkGeometry.h b/include/core/SkGeometry.h
index 571159fd07..c517855cbb 100644
--- a/include/core/SkGeometry.h
+++ b/include/core/SkGeometry.h
@@ -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
diff --git a/include/core/SkString.h b/include/core/SkString.h
index 743b093207..ae204dcd9f 100644
--- a/include/core/SkString.h
+++ b/include/core/SkString.h
@@ -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 {
diff --git a/src/core/Sk64.cpp b/src/core/Sk64.cpp
index 2715d2326c..4381b506dd 100644
--- a/src/core/Sk64.cpp
+++ b/src/core/Sk64.cpp
@@ -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
-
diff --git a/src/core/SkGeometry.cpp b/src/core/SkGeometry.cpp
index 7e2d424890..229c3d8999 100644
--- a/src/core/SkGeometry.cpp
+++ b/src/core/SkGeometry.cpp
@@ -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
-
-
diff --git a/src/core/SkGraphics.cpp b/src/core/SkGraphics.cpp
index 053d9f0ec6..b2e6cbfc3c 100644
--- a/src/core/SkGraphics.cpp
+++ b/src/core/SkGraphics.cpp
@@ -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),
diff --git a/src/core/SkString.cpp b/src/core/SkString.cpp
index 2e5d9466a1..d595d51155 100644
--- a/src/core/SkString.cpp
+++ b/src/core/SkString.cpp
@@ -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
index 0000000000..5b05952c84
--- /dev/null
+++ b/tests/GeometryTest.cpp
@@ -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)
diff --git a/tests/MathTest.cpp b/tests/MathTest.cpp
index a759ab19a1..50d59cfd19 100644
--- a/tests/MathTest.cpp
+++ b/tests/MathTest.cpp
@@ -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)
diff --git a/tests/MatrixTest.cpp b/tests/MatrixTest.cpp
index 1e4e341f2b..659672a109 100644
--- a/tests/MatrixTest.cpp
+++ b/tests/MatrixTest.cpp
@@ -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)
diff --git a/tests/PackBitsTest.cpp b/tests/PackBitsTest.cpp
index 6e69f825a4..fc11fb26a9 100644
--- a/tests/PackBitsTest.cpp
+++ b/tests/PackBitsTest.cpp
@@ -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
index 0000000000..1829c647e1
--- /dev/null
+++ b/tests/Sk64Test.cpp
@@ -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
index 0000000000..344c752c8c
--- /dev/null
+++ b/tests/StringTest.cpp
@@ -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
index 0000000000..77f48b3b46
--- /dev/null
+++ b/tests/TestClassDef.h
@@ -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); \
+ }
+
diff --git a/tests/TestXCode/Tests.xcodeproj/project.pbxproj b/tests/TestXCode/Tests.xcodeproj/project.pbxproj
index 004fb2247e..7d7b924435 100644
--- a/tests/TestXCode/Tests.xcodeproj/project.pbxproj
+++ b/tests/TestXCode/Tests.xcodeproj/project.pbxproj
@@ -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 */
@@ -37,14 +40,14 @@
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 */
@@ -72,6 +75,10 @@
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 */
@@ -120,12 +127,16 @@
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;
@@ -225,6 +236,9 @@
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;
};
diff --git a/tests/UtilsTest.cpp b/tests/UtilsTest.cpp
index 810cb51650..f6b02112f0 100644
--- a/tests/UtilsTest.cpp
+++ b/tests/UtilsTest.cpp
@@ -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)