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

Unified Diff: ui/gfx/codec/png_codec_unittest.cc

Issue 6696085: Add the ability to write comments to PNGCodec::Encode. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: strdup Created 9 years, 9 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
Index: ui/gfx/codec/png_codec_unittest.cc
diff --git a/ui/gfx/codec/png_codec_unittest.cc b/ui/gfx/codec/png_codec_unittest.cc
index 72ed67101bfd33bdd4f902bde2d396fb6d9a1afa..b31dbd2c289594c67c2d4a0f5f2bf2f1e0734f04 100644
--- a/ui/gfx/codec/png_codec_unittest.cc
+++ b/ui/gfx/codec/png_codec_unittest.cc
@@ -1,13 +1,15 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include <math.h>
+#include <algorithm>
+#include <cmath>
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkUnPreMultiply.h"
#include "ui/gfx/codec/png_codec.h"
+#include "ui/gfx/size.h"
namespace gfx {
@@ -79,8 +81,10 @@ TEST(PNGCodec, EncodeDecodeRGB) {
// encode
std::vector<unsigned char> encoded;
- EXPECT_TRUE(PNGCodec::Encode(&original[0], PNGCodec::FORMAT_RGB, w, h,
- w * 3, false, &encoded));
+ EXPECT_TRUE(PNGCodec::Encode(&original[0], PNGCodec::FORMAT_RGB,
+ Size(w, h), w * 3, false,
+ std::vector<PNGCodec::Comment>(),
+ &encoded));
// decode, it should have the same size as the original
std::vector<unsigned char> decoded;
@@ -106,8 +110,10 @@ TEST(PNGCodec, EncodeDecodeRGBA) {
// encode
std::vector<unsigned char> encoded;
- EXPECT_TRUE(PNGCodec::Encode(&original[0], PNGCodec::FORMAT_RGBA, w, h,
- w * 4, false, &encoded));
+ EXPECT_TRUE(PNGCodec::Encode(&original[0], PNGCodec::FORMAT_RGBA,
+ Size(w, h), w * 4, false,
+ std::vector<PNGCodec::Comment>(),
+ &encoded));
// decode, it should have the same size as the original
std::vector<unsigned char> decoded;
@@ -140,8 +146,10 @@ TEST(PNGCodec, DecodeCorrupted) {
// Make some compressed data.
std::vector<unsigned char> compressed;
- EXPECT_TRUE(PNGCodec::Encode(&original[0], PNGCodec::FORMAT_RGB, w, h,
- w * 3, false, &compressed));
+ EXPECT_TRUE(PNGCodec::Encode(&original[0], PNGCodec::FORMAT_RGB,
+ Size(w, h), w * 3, false,
+ std::vector<PNGCodec::Comment>(),
+ &compressed));
// Try decompressing a truncated version.
EXPECT_FALSE(PNGCodec::Decode(&compressed[0], compressed.size() / 2,
@@ -166,8 +174,10 @@ TEST(PNGCodec, EncodeDecodeBGRA) {
// Encode.
std::vector<unsigned char> encoded;
- EXPECT_TRUE(PNGCodec::Encode(&original[0], PNGCodec::FORMAT_BGRA, w, h,
- w * 4, false, &encoded));
+ EXPECT_TRUE(PNGCodec::Encode(&original[0], PNGCodec::FORMAT_BGRA,
+ Size(w, h), w * 4, false,
+ std::vector<PNGCodec::Comment>(),
+ &encoded));
// Decode, it should have the same size as the original.
std::vector<unsigned char> decoded;
@@ -194,10 +204,10 @@ TEST(PNGCodec, StripAddAlpha) {
// Encode RGBA data as RGB.
std::vector<unsigned char> encoded;
- EXPECT_TRUE(PNGCodec::Encode(&original_rgba[0],
- PNGCodec::FORMAT_RGBA,
- w, h,
- w * 4, true, &encoded));
+ EXPECT_TRUE(PNGCodec::Encode(&original_rgba[0], PNGCodec::FORMAT_RGBA,
+ Size(w, h), w * 4, true,
+ std::vector<PNGCodec::Comment>(),
+ &encoded));
// Decode the RGB to RGBA.
std::vector<unsigned char> decoded;
@@ -213,10 +223,10 @@ TEST(PNGCodec, StripAddAlpha) {
ASSERT_TRUE(original_rgba == decoded);
// Encode RGBA to RGBA.
- EXPECT_TRUE(PNGCodec::Encode(&original_rgba[0],
- PNGCodec::FORMAT_RGBA,
- w, h,
- w * 4, false, &encoded));
+ EXPECT_TRUE(PNGCodec::Encode(&original_rgba[0], PNGCodec::FORMAT_RGBA,
+ Size(w, h), w * 4, false,
+ std::vector<PNGCodec::Comment>(),
+ &encoded));
// Decode the RGBA to RGB.
EXPECT_TRUE(PNGCodec::Decode(&encoded[0], encoded.size(),
@@ -294,4 +304,39 @@ TEST(PNGCodec, EncodeBGRASkBitmapDiscardTransparency) {
}
}
+TEST(PNGCodec, EncodeWithComment) {
+ const int w = 10, h = 10;
+
+ std::vector<unsigned char> original;
+ MakeRGBImage(w, h, &original);
+
+ std::vector<unsigned char> encoded;
+ std::vector<PNGCodec::Comment> comments;
+ comments.push_back(PNGCodec::Comment("key", "text"));
+ comments.push_back(PNGCodec::Comment("test", "something"));
+ comments.push_back(PNGCodec::Comment("have some", "spaces in both"));
+ EXPECT_TRUE(PNGCodec::Encode(&original[0], PNGCodec::FORMAT_RGB,
+ Size(w, h), w * 3, false, comments, &encoded));
+
+ // Each chunk is of the form length (4 bytes), chunk type (tEXt), data,
+ // checksum (4 bytes). Make sure we find all of them in the encoded
+ // results.
+ const unsigned char kExpected1[] =
+ "\x00\x00\x00\x08tEXtkey\x00text\x9e\xe7\x66\x51";
+ const unsigned char kExpected2[] =
+ "\x00\x00\x00\x0etEXttest\x00something\x29\xba\xef\xac";
+ const unsigned char kExpected3[] =
+ "\x00\x00\x00\x18tEXthave some\x00spaces in both\x8d\x69\x34\x2d";
+
+ EXPECT_NE(search(encoded.begin(), encoded.end(), kExpected1,
+ kExpected1 + arraysize(kExpected1)),
+ encoded.end());
+ EXPECT_NE(search(encoded.begin(), encoded.end(), kExpected2,
+ kExpected2 + arraysize(kExpected2)),
+ encoded.end());
+ EXPECT_NE(search(encoded.begin(), encoded.end(), kExpected3,
+ kExpected3 + arraysize(kExpected3)),
+ encoded.end());
+}
+
} // namespace gfx

Powered by Google App Engine
This is Rietveld 408576698