add endian tests (reviewed by bungeman)
authorreed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Fri, 3 May 2013 18:06:31 +0000 (18:06 +0000)
committerreed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Fri, 3 May 2013 18:06:31 +0000 (18:06 +0000)
git-svn-id: http://skia.googlecode.com/svn/trunk@8993 2bbb7eff-a529-9590-31e7-b0007b416f81

tests/MathTest.cpp

index 5f694f5..fe54594 100644 (file)
@@ -648,3 +648,46 @@ static void TestMath(skiatest::Reporter* reporter) {
 
 #include "TestClassDef.h"
 DEFINE_TESTCLASS("Math", MathTestClass, TestMath)
+
+///////////////////////////////////////////////////////////////////////////////
+
+#include "SkEndian.h"
+
+template <typename T> struct PairRec {
+    T   fYin;
+    T   fYang;
+};
+
+static void TestEndian(skiatest::Reporter* reporter) {
+    static const PairRec<uint16_t> g16[] = {
+        { 0x0,      0x0     },
+        { 0xFFFF,   0xFFFF  },
+        { 0x1122,   0x2211  },
+    };
+    static const PairRec<uint32_t> g32[] = {
+        { 0x0,          0x0         },
+        { 0xFFFFFFFF,   0xFFFFFFFF  },
+        { 0x11223344,   0x44332211  },
+    };
+    static const PairRec<uint64_t> g64[] = {
+        { 0x0,      0x0                             },
+        { 0xFFFFFFFFFFFFFFFFULL,  0xFFFFFFFFFFFFFFFFULL  },
+        { 0x1122334455667788ULL,  0x8877665544332211ULL  },
+    };
+
+    REPORTER_ASSERT(reporter, 0x1122 == SkTEndianSwap16<0x2211>::value);
+    REPORTER_ASSERT(reporter, 0x11223344 == SkTEndianSwap32<0x44332211>::value);
+    REPORTER_ASSERT(reporter, 0x1122334455667788ULL == SkTEndianSwap64<0x8877665544332211ULL>::value);
+
+    for (size_t i = 0; i < SK_ARRAY_COUNT(g16); ++i) {
+        REPORTER_ASSERT(reporter, g16[i].fYang == SkEndianSwap16(g16[i].fYin));
+    }
+    for (size_t i = 0; i < SK_ARRAY_COUNT(g32); ++i) {
+        REPORTER_ASSERT(reporter, g32[i].fYang == SkEndianSwap32(g32[i].fYin));
+    }
+    for (size_t i = 0; i < SK_ARRAY_COUNT(g64); ++i) {
+        REPORTER_ASSERT(reporter, g64[i].fYang == SkEndianSwap64(g64[i].fYin));
+    }
+}
+
+DEFINE_TESTCLASS("Endian", EndianTestClass, TestEndian)