summaryrefslogtreecommitdiffstats
path: root/printing/pdf_ps_metafile_cairo_unittest.cc
diff options
context:
space:
mode:
authorpvalchev@google.com <pvalchev@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-04 04:19:35 +0000
committerpvalchev@google.com <pvalchev@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-04 04:19:35 +0000
commit60b2c071b12334b8b70e65c528588fbdf310b8ca (patch)
treea9fd7a7b86c4499b3ccc79e7e77c506a73cebb07 /printing/pdf_ps_metafile_cairo_unittest.cc
parentf6dc8961a5a6dae4bdd32f43d28b3c8efadb8b25 (diff)
downloadchromium_src-60b2c071b12334b8b70e65c528588fbdf310b8ca.zip
chromium_src-60b2c071b12334b8b70e65c528588fbdf310b8ca.tar.gz
chromium_src-60b2c071b12334b8b70e65c528588fbdf310b8ca.tar.bz2
OpenBSD/FreeBSD GYP changes (most of the remaining ones)
Review URL: http://codereview.chromium.org/565043 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38079 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'printing/pdf_ps_metafile_cairo_unittest.cc')
-rw-r--r--printing/pdf_ps_metafile_cairo_unittest.cc110
1 files changed, 110 insertions, 0 deletions
diff --git a/printing/pdf_ps_metafile_cairo_unittest.cc b/printing/pdf_ps_metafile_cairo_unittest.cc
new file mode 100644
index 0000000..6dfd70a
--- /dev/null
+++ b/printing/pdf_ps_metafile_cairo_unittest.cc
@@ -0,0 +1,110 @@
+// Copyright (c) 2009 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 "printing/pdf_ps_metafile_cairo.h"
+
+#include <fcntl.h>
+#include <string>
+#include <vector>
+
+#include "base/file_descriptor_posix.h"
+#include "base/file_util.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+typedef struct _cairo cairo_t;
+
+class PdfPsTest : public testing::Test {
+ protected:
+ base::FileDescriptor DevNullFD() {
+ return base::FileDescriptor(open("/dev/null", O_WRONLY), true);
+ }
+};
+
+TEST_F(PdfPsTest, Pdf) {
+ // Tests in-renderer constructor.
+ printing::PdfPsMetafile pdf(printing::PdfPsMetafile::PDF);
+ EXPECT_TRUE(pdf.Init());
+
+ // Renders page 1.
+ cairo_t* context = pdf.StartPage(72, 72);
+ EXPECT_TRUE(context != NULL);
+ // In theory, we should use Cairo to draw something on |context|.
+ EXPECT_TRUE(pdf.FinishPage(1.5));
+
+ // Renders page 2.
+ context = pdf.StartPage(64, 64);
+ EXPECT_TRUE(context != NULL);
+ // In theory, we should use Cairo to draw something on |context|.
+ EXPECT_TRUE(pdf.FinishPage(0.5));
+
+ // Closes the file.
+ pdf.Close();
+
+ // Checks data size.
+ unsigned int size = pdf.GetDataSize();
+ EXPECT_GT(size, 0u);
+
+ // Gets resulting data.
+ std::vector<char> buffer(size, 0x00);
+ pdf.GetData(&buffer.front(), size);
+
+ // Tests another constructor.
+ printing::PdfPsMetafile pdf2(printing::PdfPsMetafile::PDF);
+ EXPECT_TRUE(pdf2.Init(&buffer.front(), size));
+
+ // Tries to get the first 4 characters from pdf2.
+ std::vector<char> buffer2(4, 0x00);
+ pdf2.GetData(&buffer2.front(), 4);
+
+ // Tests if the header begins with "%PDF".
+ std::string header(&buffer2.front(), 4);
+ EXPECT_EQ(header.find("%PDF", 0), 0u);
+
+ // Tests if we can save data.
+ EXPECT_TRUE(pdf.SaveTo(DevNullFD()));
+}
+
+TEST_F(PdfPsTest, Ps) {
+ // Tests in-renderer constructor.
+ printing::PdfPsMetafile ps(printing::PdfPsMetafile::PS);
+ EXPECT_TRUE(ps.Init());
+
+ // Renders page 1.
+ cairo_t* context = ps.StartPage(72, 72);
+ EXPECT_TRUE(context != NULL);
+ // In theory, we should use Cairo to draw something on |context|.
+ EXPECT_TRUE(ps.FinishPage(1.5));
+
+ // Renders page 2.
+ context = ps.StartPage(64, 64);
+ EXPECT_TRUE(context != NULL);
+ // In theory, we should use Cairo to draw something on |context|.
+ EXPECT_TRUE(ps.FinishPage(0.5));
+
+ // Closes the file.
+ ps.Close();
+
+ // Checks data size.
+ unsigned int size = ps.GetDataSize();
+ EXPECT_GT(size, 0u);
+
+ // Gets resulting data.
+ std::vector<char> buffer(size, 0x00);
+ ps.GetData(&buffer.front(), size);
+
+ // Tests another constructor.
+ printing::PdfPsMetafile ps2(printing::PdfPsMetafile::PS);
+ EXPECT_TRUE(ps2.Init(&buffer.front(), size));
+
+ // Tries to get the first 4 characters from ps2.
+ std::vector<char> buffer2(4, 0x00);
+ ps2.GetData(&buffer2.front(), 4);
+
+ // Tests if the header begins with "%!PS".
+ std::string header(&buffer2.front(), 4);
+ EXPECT_EQ(header.find("%!PS", 0), 0u);
+
+ // Tests if we can save data.
+ EXPECT_TRUE(ps.SaveTo(DevNullFD()));
+}