blob: 5dbff36327c8563dd6dc96cc665bf545d73256af [file] [log] [blame]
Tom Sepez9eb811f2016-01-05 14:48:31 -08001// 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
Dan Sinclaira8a28e02016-03-23 15:41:39 -04007#include "core/fxcrt/include/fx_string.h"
Tom Sepez9eb811f2016-01-05 14:48:31 -08008#include "public/fpdf_save.h"
9#include "public/fpdfview.h"
10#include "testing/embedder_test.h"
11#include "testing/fx_string_testhelpers.h"
Tom Sepez0aec19b2016-01-07 12:22:44 -080012#include "testing/gmock/include/gmock/gmock-matchers.h"
Tom Sepez9eb811f2016-01-05 14:48:31 -080013#include "testing/gtest/include/gtest/gtest.h"
Tom Sepez0aec19b2016-01-07 12:22:44 -080014#include "testing/test_support.h"
Tom Sepez9eb811f2016-01-05 14:48:31 -080015
Tom Sepez0aec19b2016-01-07 12:22:44 -080016class FPDFSaveEmbedderTest : public EmbedderTest, public TestSaver {};
Tom Sepez9eb811f2016-01-05 14:48:31 -080017
18TEST_F(FPDFSaveEmbedderTest, SaveSimpleDoc) {
19 EXPECT_TRUE(OpenDocument("hello_world.pdf"));
Tom Sepez0aec19b2016-01-07 12:22:44 -080020 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
21 EXPECT_THAT(GetString(), testing::StartsWith("%PDF-1.7\r\n"));
Wei Li05d53f02016-03-29 16:42:53 -070022 EXPECT_EQ(843u, GetString().length());
Tom Sepez9eb811f2016-01-05 14:48:31 -080023}
24
25TEST_F(FPDFSaveEmbedderTest, SaveSimpleDocWithVersion) {
26 EXPECT_TRUE(OpenDocument("hello_world.pdf"));
Tom Sepez0aec19b2016-01-07 12:22:44 -080027 EXPECT_TRUE(FPDF_SaveWithVersion(document(), this, 0, 14));
28 EXPECT_THAT(GetString(), testing::StartsWith("%PDF-1.4\r\n"));
Wei Li05d53f02016-03-29 16:42:53 -070029 EXPECT_EQ(843u, GetString().length());
Tom Sepez9eb811f2016-01-05 14:48:31 -080030}
31
32TEST_F(FPDFSaveEmbedderTest, SaveSimpleDocWithBadVersion) {
33 EXPECT_TRUE(OpenDocument("hello_world.pdf"));
Tom Sepez0aec19b2016-01-07 12:22:44 -080034 EXPECT_TRUE(FPDF_SaveWithVersion(document(), this, 0, -1));
35 EXPECT_THAT(GetString(), testing::StartsWith("%PDF-1.7\r\n"));
36
37 ClearString();
38 EXPECT_TRUE(FPDF_SaveWithVersion(document(), this, 0, 0));
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"));
Tom Sepez9eb811f2016-01-05 14:48:31 -080044}
45
46TEST_F(FPDFSaveEmbedderTest, BUG_342) {
47 EXPECT_TRUE(OpenDocument("hello_world.pdf"));
Tom Sepez0aec19b2016-01-07 12:22:44 -080048 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
49 EXPECT_THAT(GetString(), testing::HasSubstr("0000000000 65535 f\r\n"));
50 EXPECT_THAT(GetString(),
51 testing::Not(testing::HasSubstr("0000000000 65536 f\r\n")));
Tom Sepez9eb811f2016-01-05 14:48:31 -080052}