Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / utility / cloud_print / pwg_encoder_unittest.cc
bloba688cef81bfd95fdf9f427052b80524261a8b719
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/files/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[] = {'\x4a', '\xd7', '\x44', '\x29', '\x98', '\xc8',
19 '\xfe', '\xae', '\x94', '\xbc', '\x9c', '\x8b',
20 '\x17', '\x7a', '\x7c', '\x94', '\x76', '\x6c',
21 '\xc9', '\xfb', '\0'};
23 const int kRasterWidth = 612;
24 const int kRasterHeight = 792;
25 const int kRasterDPI = 72;
27 scoped_ptr<BitmapImage> MakeSampleBitmap() {
28 scoped_ptr<BitmapImage> bitmap_image(
29 new BitmapImage(gfx::Size(kRasterWidth, kRasterHeight),
30 BitmapImage::RGBA));
32 uint32* bitmap_data = reinterpret_cast<uint32*>(
33 bitmap_image->pixel_data());
35 for (int i = 0; i < kRasterWidth * kRasterHeight; i++) {
36 bitmap_data[i] = 0xFFFFFF;
40 for (int i = 0; i < kRasterWidth; i++) {
41 for (int j = 200; j < 300; j++) {
42 int row_start = j * kRasterWidth;
43 uint32 red = (i * 255)/kRasterWidth;
44 bitmap_data[row_start + i] = red;
48 // To test run length encoding
49 for (int i = 0; i < kRasterWidth; i++) {
50 for (int j = 400; j < 500; j++) {
51 int row_start = j * kRasterWidth;
52 if ((i/40) % 2 == 0) {
53 bitmap_data[row_start + i] = 255 << 8;
54 } else {
55 bitmap_data[row_start + i] = 255 << 16;
60 return bitmap_image.Pass();
63 } // namespace
65 TEST(PwgRasterTest, CompareWithMaster) {
66 std::string output;
67 PwgEncoder encoder;
68 scoped_ptr<BitmapImage> image = MakeSampleBitmap();
69 PwgHeaderInfo header_info;
70 header_info.dpi = kRasterDPI;
71 header_info.total_pages = 1;
73 encoder.EncodeDocumentHeader(&output);
74 encoder.EncodePage(*image, header_info, &output);
76 EXPECT_EQ(kPWGFileSha1, base::SHA1HashString(output));
79 } // namespace cloud_print