| OLD | NEW |
| 1 #include "Test.h" | 1 #include "Test.h" |
| 2 | 2 |
| 3 #include "SkCanvas.h" | 3 #include "SkCanvas.h" |
| 4 #include "SkDocument.h" | 4 #include "SkDocument.h" |
| 5 #include "SkOSFile.h" | 5 #include "SkOSFile.h" |
| 6 #include "SkStream.h" | 6 #include "SkStream.h" |
| 7 | 7 |
| 8 static void test_empty(skiatest::Reporter* reporter) { | 8 static void test_empty(skiatest::Reporter* reporter) { |
| 9 SkDynamicMemoryWStream stream; | 9 SkDynamicMemoryWStream stream; |
| 10 | 10 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 static void test_abortWithFile(skiatest::Reporter* reporter) { | 31 static void test_abortWithFile(skiatest::Reporter* reporter) { |
| 32 SkString tmpDir = skiatest::Test::GetTmpDir(); | 32 SkString tmpDir = skiatest::Test::GetTmpDir(); |
| 33 | 33 |
| 34 if (tmpDir.isEmpty()) { | 34 if (tmpDir.isEmpty()) { |
| 35 return; // TODO(edisonn): unfortunatelly this pattern is used in other | 35 return; // TODO(edisonn): unfortunatelly this pattern is used in other |
| 36 // tests, but if GetTmpDir() starts returning and empty dir | 36 // tests, but if GetTmpDir() starts returning and empty dir |
| 37 // allways, then all these tests will be disabled. | 37 // allways, then all these tests will be disabled. |
| 38 } | 38 } |
| 39 | 39 |
| 40 SkString path = SkOSPath::SkPathJoin(tmpDir.c_str(), "aborted.pdf"); | 40 SkString path = SkOSPath::Join(tmpDir.c_str(), "aborted.pdf"); |
| 41 | 41 |
| 42 // Make sure doc's destructor is called to flush. | 42 // Make sure doc's destructor is called to flush. |
| 43 { | 43 { |
| 44 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(path.c_str())); | 44 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(path.c_str())); |
| 45 | 45 |
| 46 SkCanvas* canvas = doc->beginPage(100, 100); | 46 SkCanvas* canvas = doc->beginPage(100, 100); |
| 47 canvas->drawColor(SK_ColorRED); | 47 canvas->drawColor(SK_ColorRED); |
| 48 doc->endPage(); | 48 doc->endPage(); |
| 49 | 49 |
| 50 doc->abort(); | 50 doc->abort(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 FILE* file = fopen(path.c_str(), "r"); | 53 FILE* file = fopen(path.c_str(), "r"); |
| 54 // The created file should be empty. | 54 // The created file should be empty. |
| 55 char buffer[100]; | 55 char buffer[100]; |
| 56 REPORTER_ASSERT(reporter, fread(buffer, 1, 1, file) == 0); | 56 REPORTER_ASSERT(reporter, fread(buffer, 1, 1, file) == 0); |
| 57 fclose(file); | 57 fclose(file); |
| 58 } | 58 } |
| 59 | 59 |
| 60 static void test_file(skiatest::Reporter* reporter) { | 60 static void test_file(skiatest::Reporter* reporter) { |
| 61 SkString tmpDir = skiatest::Test::GetTmpDir(); | 61 SkString tmpDir = skiatest::Test::GetTmpDir(); |
| 62 if (tmpDir.isEmpty()) { | 62 if (tmpDir.isEmpty()) { |
| 63 return; // TODO(edisonn): unfortunatelly this pattern is used in other | 63 return; // TODO(edisonn): unfortunatelly this pattern is used in other |
| 64 // tests, but if GetTmpDir() starts returning and empty dir | 64 // tests, but if GetTmpDir() starts returning and empty dir |
| 65 // allways, then all these tests will be disabled. | 65 // allways, then all these tests will be disabled. |
| 66 } | 66 } |
| 67 | 67 |
| 68 SkString path = SkOSPath::SkPathJoin(tmpDir.c_str(), "file.pdf"); | 68 SkString path = SkOSPath::Join(tmpDir.c_str(), "file.pdf"); |
| 69 | 69 |
| 70 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(path.c_str())); | 70 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(path.c_str())); |
| 71 | 71 |
| 72 SkCanvas* canvas = doc->beginPage(100, 100); | 72 SkCanvas* canvas = doc->beginPage(100, 100); |
| 73 | 73 |
| 74 canvas->drawColor(SK_ColorRED); | 74 canvas->drawColor(SK_ColorRED); |
| 75 doc->endPage(); | 75 doc->endPage(); |
| 76 doc->close(); | 76 doc->close(); |
| 77 | 77 |
| 78 FILE* file = fopen(path.c_str(), "r"); | 78 FILE* file = fopen(path.c_str(), "r"); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 96 REPORTER_ASSERT(reporter, stream.bytesWritten() != 0); | 96 REPORTER_ASSERT(reporter, stream.bytesWritten() != 0); |
| 97 } | 97 } |
| 98 | 98 |
| 99 DEF_TEST(document_tests, reporter) { | 99 DEF_TEST(document_tests, reporter) { |
| 100 test_empty(reporter); | 100 test_empty(reporter); |
| 101 test_abort(reporter); | 101 test_abort(reporter); |
| 102 test_abortWithFile(reporter); | 102 test_abortWithFile(reporter); |
| 103 test_file(reporter); | 103 test_file(reporter); |
| 104 test_close(reporter); | 104 test_close(reporter); |
| 105 } | 105 } |
| OLD | NEW |