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

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

Issue 1556033002: Add embedder test for fpdfsave.cpp and bug 342 (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Private method, const ref return. 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 | « BUILD.gn ('k') | pdfium.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 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
43 TEST_F(FPDFSaveEmbedderTest, SaveSimpleDoc) {
44 EXPECT_TRUE(OpenDocument("hello_world.pdf"));
45 EXPECT_TRUE(SaveDocumentToString());
46 EXPECT_EQ("%PDF-1.7\r\n", GetString().substr(0, 10));
47 EXPECT_EQ(843, GetString().length());
48 }
49
50 TEST_F(FPDFSaveEmbedderTest, SaveSimpleDocWithVersion) {
51 EXPECT_TRUE(OpenDocument("hello_world.pdf"));
52 EXPECT_TRUE(SaveDocumentWithVersionToString(14));
53 EXPECT_EQ("%PDF-1.4\r\n", GetString().substr(0, 10));
54 EXPECT_EQ(843, GetString().length());
55 }
56
57 TEST_F(FPDFSaveEmbedderTest, SaveSimpleDocWithBadVersion) {
58 EXPECT_TRUE(OpenDocument("hello_world.pdf"));
59 EXPECT_TRUE(SaveDocumentWithVersionToString(-1));
60 EXPECT_EQ("%PDF-1.7\r\n", GetString().substr(0, 10));
61 EXPECT_TRUE(SaveDocumentWithVersionToString(0));
62 EXPECT_EQ("%PDF-1.7\r\n", GetString().substr(0, 10));
63 EXPECT_TRUE(SaveDocumentWithVersionToString(18));
64 EXPECT_EQ("%PDF-1.7\r\n", GetString().substr(0, 10));
65 }
66
67 TEST_F(FPDFSaveEmbedderTest, BUG_342) {
68 EXPECT_TRUE(OpenDocument("hello_world.pdf"));
69 EXPECT_TRUE(SaveDocumentToString());
70 EXPECT_EQ(std::string::npos, GetString().find("0000000000 65536 f\r\n"));
71 EXPECT_NE(std::string::npos, GetString().find("0000000000 65535 f\r\n"));
72 }
OLDNEW
« no previous file with comments | « BUILD.gn ('k') | pdfium.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698