diff options
author | skia.committer@gmail.com <skia.committer@gmail.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-12-02 13:36:22 +0000 |
---|---|---|
committer | skia.committer@gmail.com <skia.committer@gmail.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-12-02 13:36:22 +0000 |
commit | 5b39f5ba9c339d1e4dae391fee9ec1396feec180 (patch) | |
tree | 1c9ae56ec4e8faec6f4422d7a506423425ccde6b /tests | |
parent | 742058f0ca473dd871a1235a0f30b1736b045ec9 (diff) |
Sanitizing source files in Housekeeper-Nightly
git-svn-id: http://skia.googlecode.com/svn/trunk@12427 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests')
-rw-r--r-- | tests/BitmapCopyTest.cpp | 68 | ||||
-rw-r--r-- | tests/BitmapGetColorTest.cpp | 63 | ||||
-rw-r--r-- | tests/BlitRowTest.cpp | 2 | ||||
-rw-r--r-- | tests/HashCacheTest.cpp | 11 | ||||
-rw-r--r-- | tests/ImageCacheTest.cpp | 19 | ||||
-rw-r--r-- | tests/ImageDecodingTest.cpp | 2 | ||||
-rw-r--r-- | tests/SerializationTest.cpp | 16 | ||||
-rw-r--r-- | tests/StringTest.cpp | 13 |
8 files changed, 133 insertions, 61 deletions
diff --git a/tests/BitmapCopyTest.cpp b/tests/BitmapCopyTest.cpp index f61d55e953..5cef1eb986 100644 --- a/tests/BitmapCopyTest.cpp +++ b/tests/BitmapCopyTest.cpp @@ -15,7 +15,7 @@ static const char* boolStr(bool value) { // these are in the same order as the SkBitmap::Config enum static const char* gConfigName[] = { - "None", "A8", "Index8", "565", "4444", "8888" + "None", "A1", "A8", "Index8", "565", "4444", "8888", "RLE_Index8" }; static void report_opaqueness(skiatest::Reporter* reporter, const SkBitmap& src, @@ -57,6 +57,10 @@ static void init_src(const SkBitmap& bitmap) { if (bitmap.getPixels()) { if (bitmap.getColorTable()) { sk_bzero(bitmap.getPixels(), bitmap.getSize()); + } else if (SkBitmap::kA1_Config == bitmap.config()) { + // The A1 config can have uninitialized bits at the + // end of each row if eraseColor is used + memset(bitmap.getPixels(), 0xff, bitmap.getSafeSize()); } else { bitmap.eraseColor(SK_ColorWHITE); } @@ -88,7 +92,7 @@ struct Pair { static uint32_t getPixel(int x, int y, const SkBitmap& bm) { uint32_t val = 0; uint16_t val16; - uint8_t val8; + uint8_t val8, shift; SkAutoLockPixels lock(bm); const void* rawAddr = bm.getAddr(x,y); @@ -106,6 +110,11 @@ static uint32_t getPixel(int x, int y, const SkBitmap& bm) { memcpy(&val8, rawAddr, sizeof(uint8_t)); val = val8; break; + case SkBitmap::kA1_Config: + memcpy(&val8, rawAddr, sizeof(uint8_t)); + shift = x % 8; + val = (val8 >> shift) & 0x1 ; + break; default: break; } @@ -117,7 +126,7 @@ static uint32_t getPixel(int x, int y, const SkBitmap& bm) { // converted to, but at present uint32_t can handle all formats. static void setPixel(int x, int y, uint32_t val, SkBitmap& bm) { uint16_t val16; - uint8_t val8; + uint8_t val8, shift; SkAutoLockPixels lock(bm); void* rawAddr = bm.getAddr(x,y); @@ -135,6 +144,15 @@ static void setPixel(int x, int y, uint32_t val, SkBitmap& bm) { val8 = val & 0xFF; memcpy(rawAddr, &val8, sizeof(uint8_t)); break; + case SkBitmap::kA1_Config: + shift = x % 8; // We assume we're in the right byte. + memcpy(&val8, rawAddr, sizeof(uint8_t)); + if (val & 0x1) // Turn bit on. + val8 |= (0x1 << shift); + else // Turn bit off. + val8 &= ~(0x1 << shift); + memcpy(rawAddr, &val8, sizeof(uint8_t)); + break; default: // Ignore. break; @@ -146,6 +164,7 @@ static void setPixel(int x, int y, uint32_t val, SkBitmap& bm) { static const char* getSkConfigName(const SkBitmap& bm) { switch (bm.config()) { case SkBitmap::kNo_Config: return "SkBitmap::kNo_Config"; + case SkBitmap::kA1_Config: return "SkBitmap::kA1_Config"; case SkBitmap::kA8_Config: return "SkBitmap::kA8_Config"; case SkBitmap::kIndex8_Config: return "SkBitmap::kIndex8_Config"; case SkBitmap::kRGB_565_Config: return "SkBitmap::kRGB_565_Config"; @@ -206,12 +225,13 @@ static void writeCoordPixels(SkBitmap& bm, const Coordinates& coords) { static void TestBitmapCopy(skiatest::Reporter* reporter) { static const Pair gPairs[] = { - { SkBitmap::kNo_Config, "0000000" }, - { SkBitmap::kA8_Config, "0101010" }, - { SkBitmap::kIndex8_Config, "0111010" }, - { SkBitmap::kRGB_565_Config, "0101010" }, - { SkBitmap::kARGB_4444_Config, "0101110" }, - { SkBitmap::kARGB_8888_Config, "0101110" }, + { SkBitmap::kNo_Config, "00000000" }, + { SkBitmap::kA1_Config, "01000000" }, + { SkBitmap::kA8_Config, "00101010" }, + { SkBitmap::kIndex8_Config, "00111010" }, + { SkBitmap::kRGB_565_Config, "00101010" }, + { SkBitmap::kARGB_4444_Config, "00101110" }, + { SkBitmap::kARGB_8888_Config, "00101110" }, }; static const bool isExtracted[] = { @@ -355,6 +375,12 @@ static void TestBitmapCopy(skiatest::Reporter* reporter) { case SkBitmap::kNo_Config: break; + case SkBitmap::kA1_Config: + if (safeSize.fHi != 0x470DE || + safeSize.fLo != 0x4DF82000) + sizeFail = true; + break; + case SkBitmap::kA8_Config: case SkBitmap::kIndex8_Config: if (safeSize.fHi != 0x2386F2 || @@ -385,8 +411,21 @@ static void TestBitmapCopy(skiatest::Reporter* reporter) { reporter->reportFailed(str); } - int subW = 2; - int subH = 2; + int subW, subH; + // Set sizes to be height = 2 to force the last row of the + // source to be used, thus verifying correct operation if + // the bitmap is an extracted subset. + if (gPairs[i].fConfig == SkBitmap::kA1_Config) { + // If one-bit per pixel, use 9 pixels to force more than + // one byte per row. + subW = 9; + subH = 2; + } else { + // All other configurations are at least one byte per pixel, + // and different configs will test copying different numbers + // of bytes. + subW = subH = 2; + } // Create bitmap to act as source for copies and subsets. SkBitmap src, subset; @@ -410,7 +449,12 @@ static void TestBitmapCopy(skiatest::Reporter* reporter) { // The extractedSubset() test case allows us to test copy- // ing when src and dst mave possibly different strides. SkIRect r; - r.set(1, 0, 1 + subW, subH); // 2x2 extracted bitmap + if (gPairs[i].fConfig == SkBitmap::kA1_Config) + // This config seems to need byte-alignment of + // extracted subset bits. + r.set(0, 0, subW, subH); + else + r.set(1, 0, 1 + subW, subH); // 2x2 extracted bitmap srcReady = src.extractSubset(&subset, r); } else { diff --git a/tests/BitmapGetColorTest.cpp b/tests/BitmapGetColorTest.cpp index 40aa3e26bf..11c22e6fa3 100644 --- a/tests/BitmapGetColorTest.cpp +++ b/tests/BitmapGetColorTest.cpp @@ -10,6 +10,67 @@ #include "SkRect.h" #include "SkRandom.h" +static int nextRand(SkRandom& rand, int min, int max) { + return min + (int)rand.nextRangeU(0, max - min); +} + +static void rand_irect(SkIRect* rect, int W, int H, SkRandom& rand) { + const int DX = W / 2; + const int DY = H / 2; + + rect->fLeft = nextRand(rand, -DX, W + DX); + rect->fTop = nextRand(rand, -DY, H + DY); + rect->fRight = nextRand(rand, -DX, W + DX); + rect->fBottom = nextRand(rand, -DY, H + DY); + rect->sort(); +} + +static void test_equal_A1_A8(skiatest::Reporter* reporter, + const SkBitmap& bm1, const SkBitmap& bm8) { + SkASSERT(SkBitmap::kA1_Config == bm1.config()); + SkASSERT(SkBitmap::kA8_Config == bm8.config()); + + REPORTER_ASSERT(reporter, bm1.width() == bm8.width()); + REPORTER_ASSERT(reporter, bm1.height() == bm8.height()); + for (int y = 0; y < bm1.height(); ++y) { + for (int x = 0; x < bm1.width(); ++x) { + int p1 = *bm1.getAddr1(x, y) & (1 << (7 - (x & 7))); + SkASSERT(SkIsPow2(p1)); + p1 = p1 ? 0xFF : 0; + + int p8 = *bm8.getAddr8(x, y); + SkASSERT(0 == p8 || 0xFF == p8); + + REPORTER_ASSERT(reporter, p1 == p8); + } + } +} + +static void test_eraserect_A1(skiatest::Reporter* reporter) { + const int W = 43; + const int H = 13; + + SkBitmap bm1, bm8; + + bm1.setConfig(SkBitmap::kA1_Config, W, H); + bm1.allocPixels(); + bm8.setConfig(SkBitmap::kA8_Config, W, H); + bm8.allocPixels(); + + SkRandom rand; + for (int i = 0; i < 10000; ++i) { + SkIRect area; + rand_irect(&area, W, H, rand); + + bm1.eraseColor(0); + bm8.eraseColor(0); + + bm1.eraseArea(area, SK_ColorWHITE); + bm8.eraseArea(area, SK_ColorWHITE); + test_equal_A1_A8(reporter, bm1, bm8); + } +} + static void TestGetColor(skiatest::Reporter* reporter) { static const struct Rec { SkBitmap::Config fConfig; @@ -44,6 +105,8 @@ static void TestGetColor(skiatest::Reporter* reporter) { SkColor c = bm.getColor(1, 1); REPORTER_ASSERT(reporter, c == gRec[i].fOutColor); } + + test_eraserect_A1(reporter); } #include "TestClassDef.h" diff --git a/tests/BlitRowTest.cpp b/tests/BlitRowTest.cpp index 85761104b2..3903efbfba 100644 --- a/tests/BlitRowTest.cpp +++ b/tests/BlitRowTest.cpp @@ -14,7 +14,7 @@ // these are in the same order as the SkBitmap::Config enum static const char* gConfigName[] = { - "None", "A8", "Index8", "565", "4444", "8888" + "None", "A1", "A8", "Index8", "565", "4444", "8888", "RLE_Index8" }; /** Returns -1 on success, else the x coord of the first bad pixel, return its diff --git a/tests/HashCacheTest.cpp b/tests/HashCacheTest.cpp index 1a5c4701cd..bd28c44197 100644 --- a/tests/HashCacheTest.cpp +++ b/tests/HashCacheTest.cpp @@ -39,18 +39,21 @@ public: uint32_t getHash() const { return fKey; } - static bool LessThan(const HashElement& entry, const HashKey& key) { + static bool LT(const HashElement& entry, const HashKey& key) { return entry.fKey < key.fKey; } - static bool Equals(const HashElement& entry, const HashKey& key) { + static bool EQ(const HashElement& entry, const HashKey& key) { return entry.fKey == key.fKey; } #ifdef SK_DEBUG - static bool LessThan(const HashElement& a, const HashElement& b) { + static uint32_t GetHash(const HashElement& entry) { + return entry.fKey; + } + static bool LT(const HashElement& a, const HashElement& b) { return a.fKey < b.fKey; } - static bool Equals(const HashElement& a, const HashElement& b) { + static bool EQ(const HashElement& a, const HashElement& b) { return a.fKey == b.fKey; } #endif diff --git a/tests/ImageCacheTest.cpp b/tests/ImageCacheTest.cpp index b8815a3217..877591acc7 100644 --- a/tests/ImageCacheTest.cpp +++ b/tests/ImageCacheTest.cpp @@ -63,22 +63,3 @@ static void TestImageCache(skiatest::Reporter* reporter) { #include "TestClassDef.h" DEFINE_TESTCLASS("ImageCache", TestImageCacheClass, TestImageCache) - -DEF_TEST(ImageCache_doubleAdd, r) { - // Adding the same key twice should be safe. - SkScaledImageCache cache(1024); - - SkBitmap original; - original.setConfig(SkBitmap::kARGB_8888_Config, 40, 40); - original.allocPixels(); - - SkBitmap scaled; - scaled.setConfig(SkBitmap::kARGB_8888_Config, 20, 20); - scaled.allocPixels(); - - SkScaledImageCache::ID* id1 = cache.addAndLock(original, 0.5f, 0.5f, scaled); - SkScaledImageCache::ID* id2 = cache.addAndLock(original, 0.5f, 0.5f, scaled); - // We don't really care if id1 == id2 as long as unlocking both works. - cache.unlock(id1); - cache.unlock(id2); -} diff --git a/tests/ImageDecodingTest.cpp b/tests/ImageDecodingTest.cpp index 6fcef1d315..56193f4e47 100644 --- a/tests/ImageDecodingTest.cpp +++ b/tests/ImageDecodingTest.cpp @@ -148,7 +148,7 @@ public: // the list is that each one is different, so we can test // to make sure the correct config is chosen. const SkBitmap::Config configs[] = { - SkBitmap::kA8_Config, + SkBitmap::kA1_Config, SkBitmap::kA8_Config, SkBitmap::kIndex8_Config, SkBitmap::kRGB_565_Config, diff --git a/tests/SerializationTest.cpp b/tests/SerializationTest.cpp index 9e63249c62..f49abe9106 100644 --- a/tests/SerializationTest.cpp +++ b/tests/SerializationTest.cpp @@ -173,43 +173,37 @@ static void Tests(skiatest::Reporter* reporter) { // Test rrect serialization { - // SkRRect does not initialize anything. - // An uninitialized SkRRect can be serialized, - // but will branch on uninitialized data when deserialized. SkRRect rrect; - SkRect rect = SkRect::MakeXYWH(1, 2, 20, 30); - SkVector corners[4] = { {1, 2}, {2, 3}, {3,4}, {4,5} }; - rrect.setRectRadii(rect, corners); TestAlignment(&rrect, reporter); } // Test readByteArray { - unsigned char data[kArraySize] = { 1, 2, 3 }; + unsigned char data[kArraySize] = {0}; TestArraySerialization(data, reporter); } // Test readColorArray { - SkColor data[kArraySize] = { SK_ColorBLACK, SK_ColorWHITE, SK_ColorRED }; + SkColor data[kArraySize]; TestArraySerialization(data, reporter); } // Test readIntArray { - int32_t data[kArraySize] = { 1, 2, 4, 8 }; + int32_t data[kArraySize]; TestArraySerialization(data, reporter); } // Test readPointArray { - SkPoint data[kArraySize] = { {6, 7}, {42, 128} }; + SkPoint data[kArraySize]; TestArraySerialization(data, reporter); } // Test readScalarArray { - SkScalar data[kArraySize] = { SK_Scalar1, SK_ScalarHalf, SK_ScalarMax }; + SkScalar data[kArraySize]; TestArraySerialization(data, reporter); } } diff --git a/tests/StringTest.cpp b/tests/StringTest.cpp index c8c10e1925..462fcfadaf 100644 --- a/tests/StringTest.cpp +++ b/tests/StringTest.cpp @@ -192,16 +192,3 @@ static void TestString(skiatest::Reporter* reporter) { #include "TestClassDef.h" DEFINE_TESTCLASS("String", StringTestClass, TestString) - -DEF_TEST(String_SkStrSplit, r) { - SkTArray<SkString> results; - - SkStrSplit("a-_b_c-dee--f-_-_-g-", "-_", &results); - REPORTER_ASSERT(r, results.count() == 6); - REPORTER_ASSERT(r, results[0].equals("a")); - REPORTER_ASSERT(r, results[1].equals("b")); - REPORTER_ASSERT(r, results[2].equals("c")); - REPORTER_ASSERT(r, results[3].equals("dee")); - REPORTER_ASSERT(r, results[4].equals("f")); - REPORTER_ASSERT(r, results[5].equals("g")); -} |