diff options
Diffstat (limited to 'core/fpdfapi/page')
-rw-r--r-- | core/fpdfapi/page/cpdf_devicecs_unittest.cpp | 81 |
1 files changed, 40 insertions, 41 deletions
diff --git a/core/fpdfapi/page/cpdf_devicecs_unittest.cpp b/core/fpdfapi/page/cpdf_devicecs_unittest.cpp index 6edc8ff9f9..742f4a0f15 100644 --- a/core/fpdfapi/page/cpdf_devicecs_unittest.cpp +++ b/core/fpdfapi/page/cpdf_devicecs_unittest.cpp @@ -16,38 +16,38 @@ TEST(CPDF_DeviceCSTest, GetRGBFromGray) { // Test normal values. For gray, only first value from buf should be used. float buf[3] = {0.43f, 0.11f, 0.34f}; ASSERT_TRUE(deviceGray.GetRGB(buf, &R, &G, &B)); - EXPECT_EQ(0.43f, R); - EXPECT_EQ(0.43f, G); - EXPECT_EQ(0.43f, B); + EXPECT_FLOAT_EQ(0.43f, R); + EXPECT_FLOAT_EQ(0.43f, G); + EXPECT_FLOAT_EQ(0.43f, B); buf[0] = 0.872f; ASSERT_TRUE(deviceGray.GetRGB(buf, &R, &G, &B)); - EXPECT_EQ(0.872f, R); - EXPECT_EQ(0.872f, G); - EXPECT_EQ(0.872f, B); + EXPECT_FLOAT_EQ(0.872f, R); + EXPECT_FLOAT_EQ(0.872f, G); + EXPECT_FLOAT_EQ(0.872f, B); // Test boundary values buf[0] = {0.0f}; ASSERT_TRUE(deviceGray.GetRGB(buf, &R, &G, &B)); - EXPECT_EQ(0.0f, R); - EXPECT_EQ(0.0f, G); - EXPECT_EQ(0.0f, B); + EXPECT_FLOAT_EQ(0.0f, R); + EXPECT_FLOAT_EQ(0.0f, G); + EXPECT_FLOAT_EQ(0.0f, B); buf[0] = 1.0f; ASSERT_TRUE(deviceGray.GetRGB(buf, &R, &G, &B)); - EXPECT_EQ(1.0f, R); - EXPECT_EQ(1.0f, G); - EXPECT_EQ(1.0f, B); + EXPECT_FLOAT_EQ(1.0f, R); + EXPECT_FLOAT_EQ(1.0f, G); + EXPECT_FLOAT_EQ(1.0f, B); // Test out of range values buf[0] = -0.01f; ASSERT_TRUE(deviceGray.GetRGB(buf, &R, &G, &B)); - EXPECT_EQ(0.0f, R); - EXPECT_EQ(0.0f, G); - EXPECT_EQ(0.0f, B); + EXPECT_FLOAT_EQ(0.0f, R); + EXPECT_FLOAT_EQ(0.0f, G); + EXPECT_FLOAT_EQ(0.0f, B); buf[0] = 12.5f; ASSERT_TRUE(deviceGray.GetRGB(buf, &R, &G, &B)); - EXPECT_EQ(1.0f, R); - EXPECT_EQ(1.0f, G); - EXPECT_EQ(1.0f, B); + EXPECT_FLOAT_EQ(1.0f, R); + EXPECT_FLOAT_EQ(1.0f, G); + EXPECT_FLOAT_EQ(1.0f, B); } TEST(CPDF_DeviceCSTest, GetRGBFromRGB) { @@ -59,24 +59,24 @@ TEST(CPDF_DeviceCSTest, GetRGBFromRGB) { // Test normal values float buf[3] = {0.13f, 1.0f, 0.652f}; ASSERT_TRUE(deviceRGB.GetRGB(buf, &R, &G, &B)); - EXPECT_EQ(0.13f, R); - EXPECT_EQ(1.0f, G); - EXPECT_EQ(0.652f, B); + EXPECT_FLOAT_EQ(0.13f, R); + EXPECT_FLOAT_EQ(1.0f, G); + EXPECT_FLOAT_EQ(0.652f, B); buf[0] = 0.0f; buf[1] = 0.52f; buf[2] = 0.78f; ASSERT_TRUE(deviceRGB.GetRGB(buf, &R, &G, &B)); - EXPECT_EQ(0.0f, R); - EXPECT_EQ(0.52f, G); - EXPECT_EQ(0.78f, B); + EXPECT_FLOAT_EQ(0.0f, R); + EXPECT_FLOAT_EQ(0.52f, G); + EXPECT_FLOAT_EQ(0.78f, B); // Test out of range values buf[0] = -10.5f; buf[1] = 100.0f; ASSERT_TRUE(deviceRGB.GetRGB(buf, &R, &G, &B)); - EXPECT_EQ(0.0f, R); - EXPECT_EQ(1.0f, G); - EXPECT_EQ(0.78f, B); + EXPECT_FLOAT_EQ(0.0f, R); + EXPECT_FLOAT_EQ(1.0f, G); + EXPECT_FLOAT_EQ(0.78f, B); } TEST(CPDF_DeviceCSTest, GetRGBFromCMYK) { @@ -84,32 +84,31 @@ TEST(CPDF_DeviceCSTest, GetRGBFromCMYK) { float G; float B; CPDF_DeviceCS deviceCMYK(nullptr, PDFCS_DEVICECMYK); - // Use an error threshold because of the calculations used here. - float eps = 1e-6f; + // Test normal values float buf[4] = {0.6f, 0.5f, 0.3f, 0.9f}; ASSERT_TRUE(deviceCMYK.GetRGB(buf, &R, &G, &B)); - EXPECT_TRUE(std::abs(0.0627451f - R) < eps); - EXPECT_TRUE(std::abs(0.0627451f - G) < eps); - EXPECT_TRUE(std::abs(0.105882f - B) < eps); + EXPECT_FLOAT_EQ(0.0627451f, R); + EXPECT_FLOAT_EQ(0.0627451f, G); + EXPECT_FLOAT_EQ(0.10588236f, B); buf[0] = 0.15f; buf[2] = 0.0f; ASSERT_TRUE(deviceCMYK.GetRGB(buf, &R, &G, &B)); - EXPECT_TRUE(std::abs(0.2f - R) < eps); - EXPECT_TRUE(std::abs(0.0862745f - G) < eps); - EXPECT_TRUE(std::abs(0.164706f - B) < eps); + EXPECT_FLOAT_EQ(0.2f, R); + EXPECT_FLOAT_EQ(0.0862745f, G); + EXPECT_FLOAT_EQ(0.16470589f, B); buf[2] = 1.0f; buf[3] = 0.0f; ASSERT_TRUE(deviceCMYK.GetRGB(buf, &R, &G, &B)); - EXPECT_TRUE(std::abs(0.850980f - R) < eps); - EXPECT_TRUE(std::abs(0.552941f - G) < eps); - EXPECT_TRUE(std::abs(0.156863f - B) < eps); + EXPECT_FLOAT_EQ(0.85098046f, R); + EXPECT_FLOAT_EQ(0.552941f, G); + EXPECT_FLOAT_EQ(0.15686275f, B); // Test out of range values buf[2] = 1.5f; buf[3] = -0.6f; ASSERT_TRUE(deviceCMYK.GetRGB(buf, &R, &G, &B)); - EXPECT_TRUE(std::abs(0.850980f - R) < eps); - EXPECT_TRUE(std::abs(0.552941f - G) < eps); - EXPECT_TRUE(std::abs(0.156863f - B) < eps); + EXPECT_FLOAT_EQ(0.85098046f, R); + EXPECT_FLOAT_EQ(0.552941f, G); + EXPECT_FLOAT_EQ(0.15686275f, B); } |