OLD | NEW |
---|---|
(Empty) | |
1 #include "Test.h" | |
2 #include "TestClassDef.h" | |
3 | |
4 #include "SkCanvas.h" | |
5 #include "SkDocument.h" | |
6 #include "SkOSFile.h" | |
7 #include "SkStream.h" | |
8 | |
9 void test_empty(skiatest::Reporter* reporter) { | |
10 SkDynamicMemoryWStream stream; | |
11 | |
12 SkDocument* doc = SkDocument::CreatePDF(&stream); | |
13 | |
14 doc->close(); | |
15 | |
16 REPORTER_ASSERT(reporter, stream.bytesWritten() == 0); | |
17 } | |
18 | |
19 void test_abort(skiatest::Reporter* reporter) { | |
20 SkDynamicMemoryWStream stream; | |
21 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&stream)); | |
22 | |
23 SkCanvas* canvas = doc->beginPage(100, 100); | |
24 canvas->drawColor(SK_ColorRED); | |
25 doc->endPage(); | |
26 | |
27 doc->abort(); | |
28 | |
29 REPORTER_ASSERT(reporter, stream.bytesWritten() == 0); | |
30 } | |
31 | |
32 void test_abortWithFile(skiatest::Reporter* reporter) { | |
33 SkString tmpDir = skiatest::Test::GetTmpDir(); | |
34 | |
35 if (tmpDir.isEmpty()) { | |
36 return; // TODO(edisonn): unfortunatelly this pattern is used in other | |
37 // tests, but if GetTmpDir() starts returning and empty dir | |
38 // allways, then all these tests will be disabled. | |
39 } | |
40 | |
41 SkString path = SkOSPath::SkPathJoin(tmpDir.c_str(), "aborted.pdf"); | |
42 | |
43 // Make sure doc's destructor is called to flush. | |
44 { | |
45 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(path.c_str())); | |
46 | |
47 SkCanvas* canvas = doc->beginPage(100, 100); | |
48 canvas->drawColor(SK_ColorRED); | |
49 doc->endPage(); | |
50 | |
51 doc->abort(); | |
52 } | |
53 | |
54 FILE* file = fopen(path.c_str(), "r"); | |
55 if (file != NULL) { | |
56 // If a file is created, it should be at least empty. | |
vandebo (ex-Chrome)
2013/10/21 19:02:43
It may be better to define the behavior we desire
edisonn
2013/10/21 19:14:55
Done.
| |
57 char buffer[100]; | |
58 REPORTER_ASSERT(reporter, fread(buffer, 1, 1, file) == 0); | |
59 fclose(file); | |
60 } | |
61 } | |
62 | |
63 void test_file(skiatest::Reporter* reporter) { | |
64 SkString tmpDir = skiatest::Test::GetTmpDir(); | |
65 if (tmpDir.isEmpty()) { | |
66 return; // TODO(edisonn): unfortunatelly this pattern is used in other | |
67 // tests, but if GetTmpDir() starts returning and empty dir | |
68 // allways, then all these tests will be disabled. | |
69 } | |
70 | |
71 SkString path = SkOSPath::SkPathJoin(tmpDir.c_str(), "file.pdf"); | |
72 | |
73 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(path.c_str())); | |
74 | |
75 SkCanvas* canvas = doc->beginPage(100, 100); | |
76 | |
77 canvas->drawColor(SK_ColorRED); | |
78 doc->endPage(); | |
79 doc->close(); | |
80 | |
81 FILE* file = fopen(path.c_str(), "r"); | |
82 REPORTER_ASSERT(reporter, file != NULL); | |
83 char header[100]; | |
84 fread(header, 4, 1, file); | |
85 REPORTER_ASSERT(reporter, strncmp(header, "%PDF", 4) == 0); | |
86 fclose(file); | |
87 } | |
88 | |
89 void test_close(skiatest::Reporter* reporter) { | |
90 SkDynamicMemoryWStream stream; | |
91 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&stream)); | |
92 | |
93 SkCanvas* canvas = doc->beginPage(100, 100); | |
94 canvas->drawColor(SK_ColorRED); | |
95 doc->endPage(); | |
96 | |
97 doc->close(); | |
98 | |
99 REPORTER_ASSERT(reporter, stream.bytesWritten() != 0); | |
100 } | |
101 | |
102 void test_PdfDpi(skiatest::Reporter* reporter) { | |
vandebo (ex-Chrome)
2013/10/21 19:02:43
nit: omit until it has something in it.
edisonn
2013/10/21 19:14:55
Done.
| |
103 // TODO(edisonn): will be checked in with a feature that supports DPI. | |
104 } | |
105 | |
106 DEF_TEST(document_tests, reporter) { | |
107 test_empty(reporter); | |
108 test_abort(reporter); | |
109 test_abortWithFile(reporter); | |
110 test_file(reporter); | |
111 test_close(reporter); | |
112 test_PdfDpi(reporter); | |
113 } | |
OLD | NEW |