aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/MathTest.cpp
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-05-03 18:06:31 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-05-03 18:06:31 +0000
commitc9f81661c17b6315df45440541ac799c8034f849 (patch)
treef1a05b7ebf0a3df3e2c56dcfab2c2e3eeee5a4c5 /tests/MathTest.cpp
parentb4ca46d748364236e82fdaccc08022dd89e29d40 (diff)
add endian tests (reviewed by bungeman)
git-svn-id: http://skia.googlecode.com/svn/trunk@8993 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests/MathTest.cpp')
-rw-r--r--tests/MathTest.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/MathTest.cpp b/tests/MathTest.cpp
index 5f694f5c36..fe54594100 100644
--- a/tests/MathTest.cpp
+++ b/tests/MathTest.cpp
@@ -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)