summaryrefslogtreecommitdiffstats
path: root/printing/emf_win_unittest.cc
diff options
context:
space:
mode:
authorsanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-12 16:25:04 +0000
committersanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-12 16:25:04 +0000
commit2aa8e1835e136a1979210121cca1b68f25187a66 (patch)
tree229a5abbc11360cca47c8ed128f8d46f927c3059 /printing/emf_win_unittest.cc
parent98a94ee562ef36213099a153ca6f3fa4b3b5d09c (diff)
downloadchromium_src-2aa8e1835e136a1979210121cca1b68f25187a66.zip
chromium_src-2aa8e1835e136a1979210121cca1b68f25187a66.tar.gz
chromium_src-2aa8e1835e136a1979210121cca1b68f25187a66.tar.bz2
Added StartPage and EndPage methods to the Emf class because the GDI StartPage and EndPage APIs do not work in a metafile DC. We write custom GDICOMMENT records to designate a StartPage and EndPage.
BUG=None TEST=Unit-tests provided. Review URL: http://codereview.chromium.org/2947006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52084 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'printing/emf_win_unittest.cc')
-rw-r--r--printing/emf_win_unittest.cc41
1 files changed, 41 insertions, 0 deletions
diff --git a/printing/emf_win_unittest.cc b/printing/emf_win_unittest.cc
index fb85282..3b4c473 100644
--- a/printing/emf_win_unittest.cc
+++ b/printing/emf_win_unittest.cc
@@ -6,11 +6,13 @@
// For quick access.
#include <wingdi.h>
+#include <winspool.h>
#include "base/basictypes.h"
#include "base/file_path.h"
#include "base/file_util.h"
#include "base/path_service.h"
+#include "base/scoped_handle_win.h"
#include "printing/printing_context.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -113,3 +115,42 @@ TEST_F(EmfPrintingTest, Enumerate) {
context.DocumentDone();
}
+// Disabled if no "UnitTest printer" exists.
+TEST_F(EmfPrintingTest, PageBreak) {
+ ScopedHDC dc(CreateDC(L"WINSPOOL", L"UnitTest Printer", NULL, NULL));
+ if (!dc.Get())
+ return;
+ printing::Emf emf;
+ EXPECT_TRUE(emf.CreateDc(dc.Get(), NULL));
+ EXPECT_TRUE(emf.hdc() != NULL);
+ int pages = 3;
+ while (pages) {
+ EXPECT_TRUE(emf.StartPage());
+ ::Rectangle(emf.hdc(), 10, 10, 190, 190);
+ EXPECT_TRUE(emf.EndPage());
+ --pages;
+ }
+ EXPECT_TRUE(emf.CloseDc());
+ uint32 size = emf.GetDataSize();
+ std::vector<BYTE> data;
+ EXPECT_TRUE(emf.GetData(&data));
+ EXPECT_EQ(data.size(), size);
+ emf.CloseEmf();
+
+ // Playback the data.
+ DOCINFO di = {0};
+ di.cbSize = sizeof(DOCINFO);
+ di.lpszDocName = L"Test Job";
+ int job_id = ::StartDoc(dc.Get(), &di);
+ EXPECT_TRUE(emf.CreateFromData(&data.front(), size));
+ EXPECT_TRUE(emf.SafePlayback(dc.Get()));
+ ::EndDoc(dc.Get());
+ // Since presumably the printer is not real, let us just delete the job from
+ // the queue.
+ HANDLE printer = NULL;
+ if (::OpenPrinter(L"UnitTest Printer", &printer, NULL)) {
+ ::SetJob(printer, job_id, 0, NULL, JOB_CONTROL_DELETE);
+ ClosePrinter(printer);
+ }
+}
+