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

Unified Diff: printing/emf_win_unittest.cc

Issue 6544028: Create a Factory for NativeMetafile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 10 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: printing/emf_win_unittest.cc
diff --git a/printing/emf_win_unittest.cc b/printing/emf_win_unittest.cc
index 4312b2ca7c389549ab40b3626f1e2a6eff086edd..080fea8243049f3006c2fbe997758219866699f5 100644
--- a/printing/emf_win_unittest.cc
+++ b/printing/emf_win_unittest.cc
@@ -15,6 +15,7 @@
#include "base/scoped_ptr.h"
#include "base/scoped_temp_dir.h"
#include "base/win/scoped_hdc.h"
+#include "printing/metafile_factory.h"
#include "printing/printing_context.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -195,3 +196,31 @@ TEST(EmfTest, FileBackedDC) {
emf.CloseEmf();
}
+TEST(EmfTest, DCFactory) {
+ // Simplest use case.
+ scoped_ptr<printing::NativeMetafile> emf_ptr(
+ printing::MetafileFactory::GetMetafile());
+ RECT rect = {100, 100, 200, 200};
+ HDC hdc = CreateCompatibleDC(NULL);
+ EXPECT_TRUE(hdc != NULL);
+ EXPECT_TRUE(emf_ptr->CreateDc(hdc, &rect));
+ EXPECT_TRUE(emf_ptr->hdc() != NULL);
+ // In theory, you'd use the HDC with GDI functions here.
+ EXPECT_TRUE(emf_ptr->CloseDc());
+ uint32 size = emf_ptr->GetDataSize();
+ EXPECT_EQ(size, EMF_HEADER_SIZE);
+ std::vector<BYTE> data;
+ EXPECT_TRUE(emf_ptr->GetData(&data));
+ EXPECT_EQ(data.size(), size);
+ emf_ptr->CloseEmf();
+ EXPECT_TRUE(DeleteDC(hdc));
+
+ // Playback the data.
+ hdc = CreateCompatibleDC(NULL);
+ EXPECT_TRUE(hdc);
+ EXPECT_TRUE(emf_ptr->Init(&data.front(), size));
+ RECT output_rect = {0, 0, 10, 10};
+ EXPECT_TRUE(emf_ptr->Playback(hdc, &output_rect));
+ EXPECT_TRUE(DeleteDC(hdc));
+}
+

Powered by Google App Engine
This is Rietveld 408576698