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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « fpdfsdk/src/fpdfedit_embeddertest.cpp ('k') | testing/test_support.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fpdfsdk/src/fpdfsave_embeddertest.cpp
diff --git a/fpdfsdk/src/fpdfsave_embeddertest.cpp b/fpdfsdk/src/fpdfsave_embeddertest.cpp
index bee452beaf41385544d39de061e1a850d989ca9b..1c93f4f0e1569aa1bd4099d4472c2e55d055cf8f 100644
--- a/fpdfsdk/src/fpdfsave_embeddertest.cpp
+++ b/fpdfsdk/src/fpdfsave_embeddertest.cpp
@@ -9,64 +9,44 @@
#include "public/fpdfview.h"
#include "testing/embedder_test.h"
#include "testing/fx_string_testhelpers.h"
+#include "testing/gmock/include/gmock/gmock-matchers.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/test_support.h"
-class FPDFSaveEmbedderTest : public EmbedderTest, public FPDF_FILEWRITE {
- public:
- FPDFSaveEmbedderTest() {
- FPDF_FILEWRITE::version = 1;
- FPDF_FILEWRITE::WriteBlock = WriteBlockCallback;
- }
- bool SaveDocumentToString() {
- m_String.clear();
- return FPDF_SaveAsCopy(document(), this, 0);
- }
- bool SaveDocumentWithVersionToString(int version) {
- m_String.clear();
- return FPDF_SaveWithVersion(document(), this, 0, version);
- }
- const std::string& GetString() const { return m_String; }
-
- private:
- static int WriteBlockCallback(FPDF_FILEWRITE* pFileWrite,
- const void* data,
- unsigned long size) {
- FPDFSaveEmbedderTest* pThis =
- static_cast<FPDFSaveEmbedderTest*>(pFileWrite);
- pThis->m_String.append(static_cast<const char*>(data), size);
- return 1;
- }
-
- std::string m_String;
-};
+class FPDFSaveEmbedderTest : public EmbedderTest, public TestSaver {};
TEST_F(FPDFSaveEmbedderTest, SaveSimpleDoc) {
EXPECT_TRUE(OpenDocument("hello_world.pdf"));
- EXPECT_TRUE(SaveDocumentToString());
- EXPECT_EQ("%PDF-1.7\r\n", GetString().substr(0, 10));
+ EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
+ EXPECT_THAT(GetString(), testing::StartsWith("%PDF-1.7\r\n"));
EXPECT_EQ(843, GetString().length());
}
TEST_F(FPDFSaveEmbedderTest, SaveSimpleDocWithVersion) {
EXPECT_TRUE(OpenDocument("hello_world.pdf"));
- EXPECT_TRUE(SaveDocumentWithVersionToString(14));
- EXPECT_EQ("%PDF-1.4\r\n", GetString().substr(0, 10));
+ EXPECT_TRUE(FPDF_SaveWithVersion(document(), this, 0, 14));
+ EXPECT_THAT(GetString(), testing::StartsWith("%PDF-1.4\r\n"));
EXPECT_EQ(843, GetString().length());
}
TEST_F(FPDFSaveEmbedderTest, SaveSimpleDocWithBadVersion) {
EXPECT_TRUE(OpenDocument("hello_world.pdf"));
- EXPECT_TRUE(SaveDocumentWithVersionToString(-1));
- EXPECT_EQ("%PDF-1.7\r\n", GetString().substr(0, 10));
- EXPECT_TRUE(SaveDocumentWithVersionToString(0));
- EXPECT_EQ("%PDF-1.7\r\n", GetString().substr(0, 10));
- EXPECT_TRUE(SaveDocumentWithVersionToString(18));
- EXPECT_EQ("%PDF-1.7\r\n", GetString().substr(0, 10));
+ EXPECT_TRUE(FPDF_SaveWithVersion(document(), this, 0, -1));
+ EXPECT_THAT(GetString(), testing::StartsWith("%PDF-1.7\r\n"));
+
+ ClearString();
+ EXPECT_TRUE(FPDF_SaveWithVersion(document(), this, 0, 0));
+ EXPECT_THAT(GetString(), testing::StartsWith("%PDF-1.7\r\n"));
+
+ ClearString();
+ EXPECT_TRUE(FPDF_SaveWithVersion(document(), this, 0, 18));
+ EXPECT_THAT(GetString(), testing::StartsWith("%PDF-1.7\r\n"));
}
TEST_F(FPDFSaveEmbedderTest, BUG_342) {
EXPECT_TRUE(OpenDocument("hello_world.pdf"));
- EXPECT_TRUE(SaveDocumentToString());
- EXPECT_EQ(std::string::npos, GetString().find("0000000000 65536 f\r\n"));
- EXPECT_NE(std::string::npos, GetString().find("0000000000 65535 f\r\n"));
+ EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
+ EXPECT_THAT(GetString(), testing::HasSubstr("0000000000 65535 f\r\n"));
+ EXPECT_THAT(GetString(),
+ testing::Not(testing::HasSubstr("0000000000 65536 f\r\n")));
}
« 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