1 // Copyright 2017 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 "core/fxcrt/fx_system.h"
6 #include "public/fpdf_edit.h"
7 #include "testing/embedder_test.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 class FPDFEditPathEmbedderTest : public EmbedderTest {};
11
TEST_F(FPDFEditPathEmbedderTest,VerifyCorrectColoursReturned)12 TEST_F(FPDFEditPathEmbedderTest, VerifyCorrectColoursReturned) {
13 constexpr int kObjectCount = 256;
14 CreateEmptyDocument();
15 FPDF_PAGE page = FPDFPage_New(document(), 0, 612, 792);
16
17 for (size_t i = 0; i < kObjectCount; ++i) {
18 FPDF_PAGEOBJECT path = FPDFPageObj_CreateNewPath(400, 100);
19 EXPECT_TRUE(FPDFPageObj_SetFillColor(path, i, i, i, i));
20 EXPECT_TRUE(FPDFPageObj_SetStrokeColor(path, i, i, i, i));
21 EXPECT_TRUE(FPDFPath_SetDrawMode(path, FPDF_FILLMODE_ALTERNATE, 0));
22 EXPECT_TRUE(FPDFPath_LineTo(path, 400, 200));
23 EXPECT_TRUE(FPDFPath_LineTo(path, 300, 100));
24 EXPECT_TRUE(FPDFPath_Close(path));
25
26 FPDFPage_InsertObject(page, path);
27 }
28
29 EXPECT_TRUE(FPDFPage_GenerateContent(page));
30 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
31 FPDF_ClosePage(page);
32 page = nullptr;
33
34 ASSERT_TRUE(OpenSavedDocument());
35 page = LoadSavedPage(0);
36 ASSERT(page);
37
38 for (size_t i = 0; i < kObjectCount; ++i) {
39 FPDF_PAGEOBJECT path = FPDFPage_GetObject(page, i);
40 ASSERT_TRUE(path);
41
42 EXPECT_EQ(FPDF_PAGEOBJ_PATH, FPDFPageObj_GetType(path));
43
44 unsigned int r;
45 unsigned int g;
46 unsigned int b;
47 unsigned int a;
48 ASSERT_TRUE(FPDFPageObj_GetFillColor(path, &r, &g, &b, &a));
49 EXPECT_EQ(i, r);
50 EXPECT_EQ(i, g);
51 EXPECT_EQ(i, b);
52 EXPECT_EQ(i, a);
53
54 ASSERT_TRUE(FPDFPageObj_GetStrokeColor(path, &r, &g, &b, &a));
55 EXPECT_EQ(i, r);
56 EXPECT_EQ(i, g);
57 EXPECT_EQ(i, b);
58 EXPECT_EQ(i, a);
59 }
60
61 CloseSavedPage(page);
62 CloseSavedDocument();
63 }
64