Add unit test for CPDF_CalGray::TranslateImageLine()
Change-Id: Iccd2676e4e36f700f1ef3168da7c1f1889b575b7
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/84650
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_colorspace_unittest.cpp b/core/fpdfapi/page/cpdf_colorspace_unittest.cpp
index 8ff25ff..879c85f 100644
--- a/core/fpdfapi/page/cpdf_colorspace_unittest.cpp
+++ b/core/fpdfapi/page/cpdf_colorspace_unittest.cpp
@@ -10,6 +10,26 @@
#include "core/fxcrt/retain_ptr.h"
#include "testing/gtest/include/gtest/gtest.h"
+TEST(CPDF_CalGray, TranslateImageLine) {
+ const uint8_t kSrc[12] = {255, 0, 0, 0, 255, 0, 0, 0, 255, 128, 128, 128};
+ const uint8_t kExpect[12] = {255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+
+ RetainPtr<CPDF_ColorSpace> pCal = CPDF_ColorSpace::AllocateColorSpaceForID(
+ nullptr, FXBSTR_ID('C', 'a', 'l', 'G'));
+ ASSERT_TRUE(pCal);
+
+ uint8_t dst[12];
+ memset(dst, 0xbd, sizeof(dst));
+ pCal->TranslateImageLine(dst, kSrc, 4, 4, 1, true);
+ for (size_t i = 0; i < 12; ++i)
+ EXPECT_EQ(dst[i], kExpect[i]) << " at " << i;
+
+ memset(dst, 0xbd, sizeof(dst));
+ pCal->TranslateImageLine(dst, kSrc, 4, 4, 1, false);
+ for (size_t i = 0; i < 12; ++i)
+ EXPECT_EQ(dst[i], kExpect[i]) << " at " << i;
+}
+
TEST(CPDF_CalRGB, TranslateImageLine) {
const uint8_t kSrc[12] = {255, 0, 0, 0, 255, 0, 0, 0, 255, 128, 128, 128};
const uint8_t kExpectMask[12] = {255, 58, 0, 0, 255, 0,