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