summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Pena <npm@chromium.org>2017-03-16 11:19:04 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-03-16 17:26:17 +0000
commitc9819a972830e9d1210d9d8f5c81d9f03f7c90a9 (patch)
tree5884652bd91df250392ae1d1977f8717319ff1db
parentfbd9ea1db2f1bb7fa006e7304a1202afc683c142 (diff)
downloadpdfium-c9819a972830e9d1210d9d8f5c81d9f03f7c90a9.tar.xz
Use EXPECT_FLOAT_EQ in cpdf_devicecs_unittest
Change-Id: I2e4eba78c5764de108c203b0e0efcd4e81b7bab2 Reviewed-on: https://pdfium-review.googlesource.com/3068 Commit-Queue: dsinclair <dsinclair@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
-rw-r--r--core/fpdfapi/page/cpdf_devicecs_unittest.cpp81
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);
}