| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkData.h" | 8 #include "SkData.h" |
| 9 #include "SkFlate.h" | 9 #include "SkFlate.h" |
| 10 #include "SkStream.h" | 10 #include "SkStream.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 | 82 |
| 83 // Check that the uncompressed data matches the source data. | 83 // Check that the uncompressed data matches the source data. |
| 84 SkAutoDataUnref uncompressedData(uncompressed.copyToData()); | 84 SkAutoDataUnref uncompressedData(uncompressed.copyToData()); |
| 85 REPORTER_ASSERT(reporter, dataSize == uncompressedData->size()); | 85 REPORTER_ASSERT(reporter, dataSize == uncompressedData->size()); |
| 86 if (dataSize == uncompressedData->size()) { | 86 if (dataSize == uncompressedData->size()) { |
| 87 REPORTER_ASSERT(reporter, memcmp(testData->data(), | 87 REPORTER_ASSERT(reporter, memcmp(testData->data(), |
| 88 uncompressedData->data(), | 88 uncompressedData->data(), |
| 89 dataSize) == 0); | 89 dataSize) == 0); |
| 90 } | 90 } |
| 91 | 91 |
| 92 if (compressedSize < 1) { return; } |
| 93 |
| 92 double compressionRatio = static_cast<double>(dataSize) / compressedSize; | 94 double compressionRatio = static_cast<double>(dataSize) / compressedSize; |
| 93 // Assert that some compression took place. | 95 // Assert that some compression took place. |
| 94 REPORTER_ASSERT(reporter, compressionRatio > 1.2); | 96 REPORTER_ASSERT(reporter, compressionRatio > 1.2); |
| 95 | 97 |
| 96 if (reporter->verbose()) { | 98 if (reporter->verbose()) { |
| 97 SkDebugf("Flate Test: \t input size: " SK_SIZE_T_SPECIFIER | 99 SkDebugf("Flate Test: \t input size: " SK_SIZE_T_SPECIFIER |
| 98 "\tcompressed size: " SK_SIZE_T_SPECIFIER | 100 "\tcompressed size: " SK_SIZE_T_SPECIFIER |
| 99 "\tratio: %.4g\n", | 101 "\tratio: %.4g\n", |
| 100 dataSize, compressedSize, compressionRatio); | 102 dataSize, compressedSize, compressionRatio); |
| 101 } | 103 } |
| 102 } | 104 } |
| 103 | 105 |
| 104 DEF_TEST(Flate, reporter) { | 106 DEF_TEST(Flate, reporter) { |
| 105 #ifdef SK_HAS_ZLIB | 107 #ifdef SK_HAS_ZLIB |
| 106 REPORTER_ASSERT(reporter, SkFlate::HaveFlate()); | 108 REPORTER_ASSERT(reporter, SkFlate::HaveFlate()); |
| 107 #endif | 109 #endif |
| 108 if (SkFlate::HaveFlate()) { | 110 if (SkFlate::HaveFlate()) { |
| 109 SkMemoryStream memStream; | 111 SkMemoryStream memStream; |
| 110 TestFlate(reporter, &memStream, 512); | 112 TestFlate(reporter, &memStream, 512); |
| 111 TestFlate(reporter, &memStream, 10240); | 113 TestFlate(reporter, &memStream, 10240); |
| 112 | 114 |
| 113 SkZeroSizeMemStream fileStream; | 115 SkZeroSizeMemStream fileStream; |
| 114 TestFlate(reporter, &fileStream, 512); | 116 TestFlate(reporter, &fileStream, 512); |
| 115 TestFlate(reporter, &fileStream, 10240); | 117 TestFlate(reporter, &fileStream, 10240); |
| 116 } | 118 } |
| 117 } | 119 } |
| OLD | NEW |