Enable PPAPI tests for non-SFI mode.
[chromium-blink-merge.git] / chrome / utility / cloud_print / pwg_encoder_unittest.cc
blobc455f35caf658bc484b68fb4d93abaf1142512f6
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/file_util.h"
6 #include "base/memory/scoped_ptr.h"
7 #include "base/sha1.h"
8 #include "chrome/utility/cloud_print/bitmap_image.h"
9 #include "chrome/utility/cloud_print/pwg_encoder.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 namespace cloud_print {
14 namespace {
16 // SHA-1 of golden master for this test, plus null terminating character.
17 // File is in chrome/test/data/printing/test_pwg_generator.pwg.
18 const char kPWGFileSha1[] = {
19 '\xda', '\x5c', '\xca', '\x36', '\x10', '\xb9', '\xa4', '\x16',
20 '\x2f', '\x98', '\x1b', '\xa6', '\x5f', '\x43', '\x24', '\x33',
21 '\x60', '\x43', '\x67', '\x34', '\0'
24 const int kRasterWidth = 612;
25 const int kRasterHeight = 792;
26 const int kRasterDPI = 72;
28 scoped_ptr<BitmapImage> MakeSampleBitmap() {
29 scoped_ptr<BitmapImage> bitmap_image(
30 new BitmapImage(gfx::Size(kRasterWidth, kRasterHeight),
31 BitmapImage::RGBA));
33 uint32* bitmap_data = reinterpret_cast<uint32*>(
34 bitmap_image->pixel_data());
36 for (int i = 0; i < kRasterWidth * kRasterHeight; i++) {
37 bitmap_data[i] = 0xFFFFFF;
41 for (int i = 0; i < kRasterWidth; i++) {
42 for (int j = 200; j < 300; j++) {
43 int row_start = j * kRasterWidth;
44 uint32 red = (i * 255)/kRasterWidth;
45 bitmap_data[row_start + i] = red;
49 // To test run length encoding
50 for (int i = 0; i < kRasterWidth; i++) {
51 for (int j = 400; j < 500; j++) {
52 int row_start = j * kRasterWidth;
53 if ((i/40) % 2 == 0) {
54 bitmap_data[row_start + i] = 255 << 8;
55 } else {
56 bitmap_data[row_start + i] = 255 << 16;
61 return bitmap_image.Pass();
64 } // namespace
66 // TODO(noamsml): Add tests for rotated cases.
67 TEST(PwgRasterTest, CompareWithMaster) {
68 std::string output;
69 PwgEncoder encoder;
70 scoped_ptr<BitmapImage> image = MakeSampleBitmap();
72 encoder.EncodeDocumentHeader(&output);
73 encoder.EncodePage(*image, kRasterDPI, 1, &output, false);
75 EXPECT_EQ(kPWGFileSha1, base::SHA1HashString(output));
78 } // namespace cloud_print