OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 PDFium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include <string.h> | |
6 | |
7 #include "core/include/fxcrt/fx_string.h" | |
8 #include "public/fpdf_save.h" | |
9 #include "public/fpdfview.h" | |
10 #include "testing/embedder_test.h" | |
11 #include "testing/fx_string_testhelpers.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | |
13 | |
14 class FPDFSaveEmbedderTest : public EmbedderTest, public FPDF_FILEWRITE { | |
15 public: | |
16 static int WriteBlockCallback(FPDF_FILEWRITE* pFileWrite, | |
Lei Zhang
2016/01/05 22:12:14
This can be private.
Tom Sepez
2016/01/05 22:16:58
Done.
| |
17 const void* data, | |
18 unsigned long size) { | |
19 FPDFSaveEmbedderTest* pThis = | |
20 static_cast<FPDFSaveEmbedderTest*>(pFileWrite); | |
21 pThis->m_String.append(static_cast<const char*>(data), size); | |
22 return 1; | |
23 } | |
24 FPDFSaveEmbedderTest() { | |
25 FPDF_FILEWRITE::version = 1; | |
26 FPDF_FILEWRITE::WriteBlock = WriteBlockCallback; | |
27 } | |
28 bool SaveDocumentToString() { | |
29 m_String.clear(); | |
30 return FPDF_SaveAsCopy(document(), this, 0); | |
31 } | |
32 bool SaveDocumentWithVersionToString(int version) { | |
33 m_String.clear(); | |
34 return FPDF_SaveWithVersion(document(), this, 0, version); | |
35 } | |
36 std::string GetString() const { return m_String; } | |
Lei Zhang
2016/01/05 22:12:14
return const ref?
Tom Sepez
2016/01/05 22:16:58
Done.
| |
37 | |
38 private: | |
39 std::string m_String; | |
40 }; | |
41 | |
42 TEST_F(FPDFSaveEmbedderTest, SaveSimpleDoc) { | |
43 EXPECT_TRUE(OpenDocument("hello_world.pdf")); | |
44 EXPECT_TRUE(SaveDocumentToString()); | |
45 EXPECT_EQ("%PDF-1.7\r\n", GetString().substr(0, 10)); | |
46 EXPECT_EQ(843, GetString().length()); | |
47 } | |
48 | |
49 TEST_F(FPDFSaveEmbedderTest, SaveSimpleDocWithVersion) { | |
50 EXPECT_TRUE(OpenDocument("hello_world.pdf")); | |
51 EXPECT_TRUE(SaveDocumentWithVersionToString(14)); | |
52 EXPECT_EQ("%PDF-1.4\r\n", GetString().substr(0, 10)); | |
53 EXPECT_EQ(843, GetString().length()); | |
54 } | |
55 | |
56 TEST_F(FPDFSaveEmbedderTest, SaveSimpleDocWithBadVersion) { | |
57 EXPECT_TRUE(OpenDocument("hello_world.pdf")); | |
58 EXPECT_TRUE(SaveDocumentWithVersionToString(-1)); | |
59 EXPECT_EQ("%PDF-1.7\r\n", GetString().substr(0, 10)); | |
60 EXPECT_TRUE(SaveDocumentWithVersionToString(0)); | |
61 EXPECT_EQ("%PDF-1.7\r\n", GetString().substr(0, 10)); | |
62 EXPECT_TRUE(SaveDocumentWithVersionToString(18)); | |
63 EXPECT_EQ("%PDF-1.7\r\n", GetString().substr(0, 10)); | |
64 } | |
65 | |
66 TEST_F(FPDFSaveEmbedderTest, BUG_342) { | |
67 EXPECT_TRUE(OpenDocument("hello_world.pdf")); | |
68 EXPECT_TRUE(SaveDocumentToString()); | |
69 EXPECT_EQ(std::string::npos, GetString().find("0000000000 65536 f\r\n")); | |
70 EXPECT_NE(std::string::npos, GetString().find("0000000000 65535 f\r\n")); | |
71 } | |
OLD | NEW |