Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Unified Diff: tests/FlateTest.cpp

Issue 464373002: Flate Test tests if compression works (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/FlateTest.cpp
diff --git a/tests/FlateTest.cpp b/tests/FlateTest.cpp
index a49ff5fd1b6af074e0c52dbfda0cc95d40c01694..3e8e5837e104d4cea58e2f1f40a959df1113f17d 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) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698