diff options
author | halcanary <halcanary@google.com> | 2014-08-13 08:07:38 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-08-13 08:07:38 -0700 |
commit | fbd3576a18799da88988ef26fa9bce09e8ebba37 (patch) | |
tree | 001c50fc4b6c3362797858f7e91f4d17de6fe252 /tests | |
parent | 2ed49a492bd7cfcfe1380476d270ce0afe0c8305 (diff) |
Flate Test tests if compression works
- Produce a compressable stream.
- Assert compression ratio > 1
- In verbose mode, print compression ratio.
R=mtklein@google.com
Author: halcanary@google.com
Review URL: https://codereview.chromium.org/464373002
Diffstat (limited to 'tests')
-rw-r--r-- | tests/FlateTest.cpp | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/tests/FlateTest.cpp b/tests/FlateTest.cpp index a49ff5fd1b..3e8e5837e1 100644 --- a/tests/FlateTest.cpp +++ b/tests/FlateTest.cpp @@ -7,7 +7,6 @@ #include "SkData.h" #include "SkFlate.h" -#include "SkRandom.h" #include "SkStream.h" #include "Test.h" @@ -26,12 +25,12 @@ public: static const size_t kGetSizeKey = 0xDEADBEEF; }; -// Returns a deterministic data of the given size. +// Returns a deterministic data of the given size that should be +// very compressible. static SkData* new_test_data(size_t dataSize) { SkAutoTMalloc<uint8_t> testBuffer(dataSize); - SkRandom random(0); for (size_t i = 0; i < dataSize; ++i) { - testBuffer[i] = random.nextU() & 0xFF; + testBuffer[i] = i % 64; } return SkData::NewFromMalloc(testBuffer.detach(), dataSize); } @@ -60,12 +59,7 @@ static void TestFlate(skiatest::Reporter* reporter, SkMemoryStream* testStream, dataSize) == 0); } - // Assume there are two test sizes, big and small. - if (dataSize < 1024) { - REPORTER_ASSERT(reporter, compressed.getOffset() < 1024); - } else { - REPORTER_ASSERT(reporter, compressed.getOffset() > 1024); - } + size_t compressedSize = compressed.getOffset(); SkAutoDataUnref compressedData(compressed.copyToData()); testStream->setData(compressedData.get()); @@ -79,7 +73,7 @@ static void TestFlate(skiatest::Reporter* reporter, SkMemoryStream* testStream, if (inputSize == 0) { inputSize = testStream->read(NULL, SkZeroSizeMemStream::kGetSizeKey); } - REPORTER_ASSERT(reporter, compressedData->size() == inputSize); + REPORTER_ASSERT(reporter, compressedSize == inputSize); if (compressedData->size() == inputSize) { REPORTER_ASSERT(reporter, memcmp(testStream->getMemoryBase(), compressedData->data(), @@ -94,6 +88,17 @@ static void TestFlate(skiatest::Reporter* reporter, SkMemoryStream* testStream, uncompressedData->data(), dataSize) == 0); } + + double compressionRatio = static_cast<double>(dataSize) / compressedSize; + // Assert that some compression took place. + REPORTER_ASSERT(reporter, compressionRatio > 1.2); + + if (reporter->verbose()) { + SkDebugf("Flate Test: \t input size: " SK_SIZE_T_SPECIFIER + "\tcompressed size: " SK_SIZE_T_SPECIFIER + "\tratio: %.4g\n", + dataSize, compressedSize, compressionRatio); + } } DEF_TEST(Flate, reporter) { |