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

Side by Side Diff: fpdfsdk/src/fpdfsave_embeddertest.cpp

Issue 1561303002: Disentangle fpdfsave_embeddertest's FPDF_FILEWRITE, use gmock matchers. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Blank line Created 4 years, 11 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 unified diff | Download patch
« no previous file with comments | « fpdfsdk/src/fpdfedit_embeddertest.cpp ('k') | testing/test_support.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/include/fxcrt/fx_string.h" 7 #include "core/include/fxcrt/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/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "testing/test_support.h"
13 15
14 class FPDFSaveEmbedderTest : public EmbedderTest, public FPDF_FILEWRITE { 16 class FPDFSaveEmbedderTest : public EmbedderTest, public TestSaver {};
15 public:
16 FPDFSaveEmbedderTest() {
17 FPDF_FILEWRITE::version = 1;
18 FPDF_FILEWRITE::WriteBlock = WriteBlockCallback;
19 }
20 bool SaveDocumentToString() {
21 m_String.clear();
22 return FPDF_SaveAsCopy(document(), this, 0);
23 }
24 bool SaveDocumentWithVersionToString(int version) {
25 m_String.clear();
26 return FPDF_SaveWithVersion(document(), this, 0, version);
27 }
28 const std::string& GetString() const { return m_String; }
29
30 private:
31 static int WriteBlockCallback(FPDF_FILEWRITE* pFileWrite,
32 const void* data,
33 unsigned long size) {
34 FPDFSaveEmbedderTest* pThis =
35 static_cast<FPDFSaveEmbedderTest*>(pFileWrite);
36 pThis->m_String.append(static_cast<const char*>(data), size);
37 return 1;
38 }
39
40 std::string m_String;
41 };
42 17
43 TEST_F(FPDFSaveEmbedderTest, SaveSimpleDoc) { 18 TEST_F(FPDFSaveEmbedderTest, SaveSimpleDoc) {
44 EXPECT_TRUE(OpenDocument("hello_world.pdf")); 19 EXPECT_TRUE(OpenDocument("hello_world.pdf"));
45 EXPECT_TRUE(SaveDocumentToString()); 20 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
46 EXPECT_EQ("%PDF-1.7\r\n", GetString().substr(0, 10)); 21 EXPECT_THAT(GetString(), testing::StartsWith("%PDF-1.7\r\n"));
47 EXPECT_EQ(843, GetString().length()); 22 EXPECT_EQ(843, GetString().length());
48 } 23 }
49 24
50 TEST_F(FPDFSaveEmbedderTest, SaveSimpleDocWithVersion) { 25 TEST_F(FPDFSaveEmbedderTest, SaveSimpleDocWithVersion) {
51 EXPECT_TRUE(OpenDocument("hello_world.pdf")); 26 EXPECT_TRUE(OpenDocument("hello_world.pdf"));
52 EXPECT_TRUE(SaveDocumentWithVersionToString(14)); 27 EXPECT_TRUE(FPDF_SaveWithVersion(document(), this, 0, 14));
53 EXPECT_EQ("%PDF-1.4\r\n", GetString().substr(0, 10)); 28 EXPECT_THAT(GetString(), testing::StartsWith("%PDF-1.4\r\n"));
54 EXPECT_EQ(843, GetString().length()); 29 EXPECT_EQ(843, GetString().length());
55 } 30 }
56 31
57 TEST_F(FPDFSaveEmbedderTest, SaveSimpleDocWithBadVersion) { 32 TEST_F(FPDFSaveEmbedderTest, SaveSimpleDocWithBadVersion) {
58 EXPECT_TRUE(OpenDocument("hello_world.pdf")); 33 EXPECT_TRUE(OpenDocument("hello_world.pdf"));
59 EXPECT_TRUE(SaveDocumentWithVersionToString(-1)); 34 EXPECT_TRUE(FPDF_SaveWithVersion(document(), this, 0, -1));
60 EXPECT_EQ("%PDF-1.7\r\n", GetString().substr(0, 10)); 35 EXPECT_THAT(GetString(), testing::StartsWith("%PDF-1.7\r\n"));
61 EXPECT_TRUE(SaveDocumentWithVersionToString(0)); 36
62 EXPECT_EQ("%PDF-1.7\r\n", GetString().substr(0, 10)); 37 ClearString();
63 EXPECT_TRUE(SaveDocumentWithVersionToString(18)); 38 EXPECT_TRUE(FPDF_SaveWithVersion(document(), this, 0, 0));
64 EXPECT_EQ("%PDF-1.7\r\n", GetString().substr(0, 10)); 39 EXPECT_THAT(GetString(), testing::StartsWith("%PDF-1.7\r\n"));
40
41 ClearString();
42 EXPECT_TRUE(FPDF_SaveWithVersion(document(), this, 0, 18));
43 EXPECT_THAT(GetString(), testing::StartsWith("%PDF-1.7\r\n"));
65 } 44 }
66 45
67 TEST_F(FPDFSaveEmbedderTest, BUG_342) { 46 TEST_F(FPDFSaveEmbedderTest, BUG_342) {
68 EXPECT_TRUE(OpenDocument("hello_world.pdf")); 47 EXPECT_TRUE(OpenDocument("hello_world.pdf"));
69 EXPECT_TRUE(SaveDocumentToString()); 48 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
70 EXPECT_EQ(std::string::npos, GetString().find("0000000000 65536 f\r\n")); 49 EXPECT_THAT(GetString(), testing::HasSubstr("0000000000 65535 f\r\n"));
71 EXPECT_NE(std::string::npos, GetString().find("0000000000 65535 f\r\n")); 50 EXPECT_THAT(GetString(),
51 testing::Not(testing::HasSubstr("0000000000 65536 f\r\n")));
72 } 52 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/fpdfedit_embeddertest.cpp ('k') | testing/test_support.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698