Index: cc/resources/texture_compressor_unittest.cc |
diff --git a/cc/resources/texture_compressor_unittest.cc b/cc/resources/texture_compressor_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..cfbfa2146ed3533f93e7dbb6161446f1198c5aa1 |
--- /dev/null |
+++ b/cc/resources/texture_compressor_unittest.cc |
@@ -0,0 +1,64 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
reveman
2015/05/05 15:30:11
If this is supposed to contain generic texture com
|
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "cc/resources/texture_compressor.h" |
+ |
+#include "cc/base/util.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace cc { |
+namespace { |
+ |
+#define TEST_IMAGE_WIDTH 256 |
+#define TEST_IMAGE_HEIGHT 256 |
+#define TEST_IMAGE_CHANNELS 4 |
+#define TEST_IMAGE_SIZE \ |
+ (TEST_IMAGE_WIDTH * TEST_IMAGE_HEIGHT * TEST_IMAGE_CHANNELS) |
+ |
+#define TEST_IMAGE_POISON 0xDEADBEEF |
+#define TEST_PIXEL_LIMIT 256 |
reveman
2015/05/05 15:30:11
please use constants instead of defines. and maybe
|
+ |
+TEST(TextureCompressorTest, CreateETC1) { |
+ scoped_ptr<TextureCompressor> compressor = |
+ TextureCompressor::Create(TextureCompressor::kFormatETC1); |
+ EXPECT_NE(nullptr, compressor); |
+} |
+ |
+TEST(TextureCompressorTest, CompressRatioETC1) { |
+ scoped_ptr<TextureCompressor> compressor = |
+ TextureCompressor::Create(TextureCompressor::kFormatETC1); |
+ uint8_t src[TEST_IMAGE_SIZE]; |
+ uint8_t dst[TEST_IMAGE_SIZE]; |
+ int compressed_size = 0; |
+ |
+ /* Poison destination bytes */ |
+ uint32_t* dst_32 = reinterpret_cast<uint32_t*>(dst); |
+ for (int i = 0; i < TEST_IMAGE_WIDTH * TEST_IMAGE_HEIGHT; i++) { |
+ dst_32[i] = TEST_IMAGE_POISON; |
+ } |
+ |
+ /* Generate test texture */ |
+ for (int i = 0; i < TEST_IMAGE_SIZE; i++) { |
+ src[i] = i % TEST_PIXEL_LIMIT; |
+ } |
+ |
+ compressor->Compress(src, dst, TEST_IMAGE_WIDTH, TEST_IMAGE_HEIGHT, |
+ (TextureCompressor::Quality)0); |
+ for (compressed_size = 0; |
+ compressed_size < TEST_IMAGE_WIDTH * TEST_IMAGE_HEIGHT; |
+ compressed_size++) { |
+ if (dst_32[compressed_size] == TEST_IMAGE_POISON) { |
+ compressed_size = |
+ compressed_size * 4; /* size in bytes of the compressed block */ |
+ break; |
+ } |
+ } |
+ |
+ /* Check if compression ratio is 8:1 for RGBA or BGRA images, after discarding |
+ * alpha channel */ |
+ EXPECT_EQ(compressed_size * 8, TEST_IMAGE_SIZE); |
+} |
+ |
+} // namespace |
+} // namespace cc |