OLD | NEW |
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <string.h> | 5 #include <string.h> |
6 | 6 |
7 #include "core/fxcrt/include/fx_string.h" | 7 #include "core/fxcrt/include/fx_string.h" |
8 #include "public/fpdf_save.h" | 8 #include "public/fpdf_save.h" |
9 #include "public/fpdfview.h" | 9 #include "public/fpdfview.h" |
10 #include "testing/embedder_test.h" | 10 #include "testing/embedder_test.h" |
11 #include "testing/fx_string_testhelpers.h" | 11 #include "testing/fx_string_testhelpers.h" |
12 #include "testing/gmock/include/gmock/gmock-matchers.h" | 12 #include "testing/gmock/include/gmock/gmock-matchers.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "testing/test_support.h" | 14 #include "testing/test_support.h" |
15 | 15 |
16 class FPDFSaveEmbedderTest : public EmbedderTest, public TestSaver {}; | 16 class FPDFSaveEmbedderTest : public EmbedderTest, public TestSaver {}; |
17 | 17 |
18 TEST_F(FPDFSaveEmbedderTest, SaveSimpleDoc) { | 18 TEST_F(FPDFSaveEmbedderTest, SaveSimpleDoc) { |
19 EXPECT_TRUE(OpenDocument("hello_world.pdf")); | 19 EXPECT_TRUE(OpenDocument("hello_world.pdf")); |
20 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); | 20 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); |
21 EXPECT_THAT(GetString(), testing::StartsWith("%PDF-1.7\r\n")); | 21 EXPECT_THAT(GetString(), testing::StartsWith("%PDF-1.7\r\n")); |
22 EXPECT_EQ(843, GetString().length()); | 22 EXPECT_EQ(843u, GetString().length()); |
23 } | 23 } |
24 | 24 |
25 TEST_F(FPDFSaveEmbedderTest, SaveSimpleDocWithVersion) { | 25 TEST_F(FPDFSaveEmbedderTest, SaveSimpleDocWithVersion) { |
26 EXPECT_TRUE(OpenDocument("hello_world.pdf")); | 26 EXPECT_TRUE(OpenDocument("hello_world.pdf")); |
27 EXPECT_TRUE(FPDF_SaveWithVersion(document(), this, 0, 14)); | 27 EXPECT_TRUE(FPDF_SaveWithVersion(document(), this, 0, 14)); |
28 EXPECT_THAT(GetString(), testing::StartsWith("%PDF-1.4\r\n")); | 28 EXPECT_THAT(GetString(), testing::StartsWith("%PDF-1.4\r\n")); |
29 EXPECT_EQ(843, GetString().length()); | 29 EXPECT_EQ(843u, GetString().length()); |
30 } | 30 } |
31 | 31 |
32 TEST_F(FPDFSaveEmbedderTest, SaveSimpleDocWithBadVersion) { | 32 TEST_F(FPDFSaveEmbedderTest, SaveSimpleDocWithBadVersion) { |
33 EXPECT_TRUE(OpenDocument("hello_world.pdf")); | 33 EXPECT_TRUE(OpenDocument("hello_world.pdf")); |
34 EXPECT_TRUE(FPDF_SaveWithVersion(document(), this, 0, -1)); | 34 EXPECT_TRUE(FPDF_SaveWithVersion(document(), this, 0, -1)); |
35 EXPECT_THAT(GetString(), testing::StartsWith("%PDF-1.7\r\n")); | 35 EXPECT_THAT(GetString(), testing::StartsWith("%PDF-1.7\r\n")); |
36 | 36 |
37 ClearString(); | 37 ClearString(); |
38 EXPECT_TRUE(FPDF_SaveWithVersion(document(), this, 0, 0)); | 38 EXPECT_TRUE(FPDF_SaveWithVersion(document(), this, 0, 0)); |
39 EXPECT_THAT(GetString(), testing::StartsWith("%PDF-1.7\r\n")); | 39 EXPECT_THAT(GetString(), testing::StartsWith("%PDF-1.7\r\n")); |
40 | 40 |
41 ClearString(); | 41 ClearString(); |
42 EXPECT_TRUE(FPDF_SaveWithVersion(document(), this, 0, 18)); | 42 EXPECT_TRUE(FPDF_SaveWithVersion(document(), this, 0, 18)); |
43 EXPECT_THAT(GetString(), testing::StartsWith("%PDF-1.7\r\n")); | 43 EXPECT_THAT(GetString(), testing::StartsWith("%PDF-1.7\r\n")); |
44 } | 44 } |
45 | 45 |
46 TEST_F(FPDFSaveEmbedderTest, BUG_342) { | 46 TEST_F(FPDFSaveEmbedderTest, BUG_342) { |
47 EXPECT_TRUE(OpenDocument("hello_world.pdf")); | 47 EXPECT_TRUE(OpenDocument("hello_world.pdf")); |
48 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); | 48 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); |
49 EXPECT_THAT(GetString(), testing::HasSubstr("0000000000 65535 f\r\n")); | 49 EXPECT_THAT(GetString(), testing::HasSubstr("0000000000 65535 f\r\n")); |
50 EXPECT_THAT(GetString(), | 50 EXPECT_THAT(GetString(), |
51 testing::Not(testing::HasSubstr("0000000000 65536 f\r\n"))); | 51 testing::Not(testing::HasSubstr("0000000000 65536 f\r\n"))); |
52 } | 52 } |
OLD | NEW |