blob: 1f96b89677533958240749bb7910cec494c267b1 [file] [log] [blame]
Tom Sepezd483eb42016-01-06 10:03:59 -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
Dan Sinclair85c8e7f2016-11-21 13:50:32 -05005#include <memory>
6#include <string>
7
Tom Sepezd483eb42016-01-06 10:03:59 -08008#include "public/fpdf_edit.h"
9#include "public/fpdfview.h"
10#include "testing/embedder_test.h"
Tom Sepez0aec19b2016-01-07 12:22:44 -080011#include "testing/gmock/include/gmock/gmock-matchers.h"
Tom Sepezd483eb42016-01-06 10:03:59 -080012#include "testing/gtest/include/gtest/gtest.h"
Tom Sepez0aec19b2016-01-07 12:22:44 -080013#include "testing/test_support.h"
Tom Sepezd483eb42016-01-06 10:03:59 -080014
Tom Sepez0aec19b2016-01-07 12:22:44 -080015class FPDFEditEmbeddertest : public EmbedderTest, public TestSaver {};
Tom Sepezd483eb42016-01-06 10:03:59 -080016
etienneb7712c262016-04-26 08:13:45 -070017namespace {
18const char kExpectedPDF[] =
19 "%PDF-1.7\r\n"
20 "%\xA1\xB3\xC5\xD7\r\n"
21 "1 0 obj\r\n"
22 "<</Pages 2 0 R /Type/Catalog>>\r\n"
23 "endobj\r\n"
24 "2 0 obj\r\n"
25 "<</Count 1/Kids\\[ 4 0 R \\]/Type/Pages>>\r\n"
26 "endobj\r\n"
27 "3 0 obj\r\n"
28 "<</CreationDate\\(D:.*\\)/Creator\\(PDFium\\)>>\r\n"
29 "endobj\r\n"
30 "4 0 obj\r\n"
31 "<</Contents 5 0 R /MediaBox\\[ 0 0 640 480\\]"
32 "/Parent 2 0 R /Resources<<>>/Rotate 0/Type/Page"
33 ">>\r\n"
34 "endobj\r\n"
35 "5 0 obj\r\n"
36 "<</Filter/FlateDecode/Length 8>>stream\r\n"
37 // Character '_' is matching '\0' (see comment below).
38 "x\x9C\x3____\x1\r\n"
39 "endstream\r\n"
40 "endobj\r\n"
41 "xref\r\n"
42 "0 6\r\n"
43 "0000000000 65535 f\r\n"
44 "0000000017 00000 n\r\n"
45 "0000000066 00000 n\r\n"
46 "0000000122 00000 n\r\n"
47 "0000000192 00000 n\r\n"
48 "0000000301 00000 n\r\n"
49 "trailer\r\n"
50 "<<\r\n"
51 "/Root 1 0 R\r\n"
52 "/Info 3 0 R\r\n"
53 "/Size 6/ID\\[<.*><.*>\\]>>\r\n"
54 "startxref\r\n"
55 "379\r\n"
56 "%%EOF\r\n";
57} // namespace
58
Tom Sepezd483eb42016-01-06 10:03:59 -080059TEST_F(FPDFEditEmbeddertest, EmptyCreation) {
60 EXPECT_TRUE(CreateEmptyDocument());
weili9b777de2016-08-19 16:19:46 -070061 FPDF_PAGE page = FPDFPage_New(document(), 0, 640.0, 480.0);
Tom Sepezd483eb42016-01-06 10:03:59 -080062 EXPECT_NE(nullptr, page);
63 EXPECT_TRUE(FPDFPage_GenerateContent(page));
Tom Sepez0aec19b2016-01-07 12:22:44 -080064 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
etienneb7712c262016-04-26 08:13:45 -070065
66 // The MatchesRegexp doesn't support embedded NUL ('\0') characters. They are
67 // replaced by '_' for the purpose of the test.
68 std::string result = GetString();
69 std::replace(result.begin(), result.end(), '\0', '_');
70 EXPECT_THAT(result, testing::MatchesRegex(
71 std::string(kExpectedPDF, sizeof(kExpectedPDF))));
weili9b777de2016-08-19 16:19:46 -070072 FPDF_ClosePage(page);
Tom Sepezd483eb42016-01-06 10:03:59 -080073}