Add unit test for reversed WeightTable::CalculateWeights()
Passing the negative of the actual length is expected to
produce a mirror image of the output. Ensure that this doesn't
affect the weight calculations summing to a fixed point 1.
-- use signed arguments to allow negation.
Change-Id: I9bc4483e3f850493df7ff5a361759ccb7d213c84
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/82170
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxge/dib/cstretchengine_unittest.cpp b/core/fxge/dib/cstretchengine_unittest.cpp
index a64024d..6db7667 100644
--- a/core/fxge/dib/cstretchengine_unittest.cpp
+++ b/core/fxge/dib/cstretchengine_unittest.cpp
@@ -24,26 +24,41 @@
return sum;
}
-void ExecuteOneStretchTest(uint32_t dest_width,
- uint32_t src_width,
+void ExecuteOneStretchTest(int32_t dest_width,
+ int32_t src_width,
const FXDIB_ResampleOptions& options) {
constexpr uint32_t kExpectedSum = CStretchEngine::kFixedPointOne;
CStretchEngine::WeightTable table;
ASSERT_TRUE(table.CalculateWeights(dest_width, 0, dest_width, src_width, 0,
src_width, options));
- for (uint32_t i = 0; i < dest_width; ++i) {
+ for (int32_t i = 0; i < dest_width; ++i) {
EXPECT_EQ(kExpectedSum, PixelWeightSum(table.GetPixelWeight(i)))
<< "for { " << src_width << ", " << dest_width << " } at " << i;
}
}
+void ExecuteOneReversedStretchTest(int32_t dest_width,
+ int32_t src_width,
+ const FXDIB_ResampleOptions& options) {
+ constexpr uint32_t kExpectedSum = CStretchEngine::kFixedPointOne;
+ CStretchEngine::WeightTable table;
+ ASSERT_TRUE(table.CalculateWeights(-dest_width, 0, dest_width, src_width, 0,
+ src_width, options));
+ for (int32_t i = 0; i < dest_width; ++i) {
+ EXPECT_EQ(kExpectedSum, PixelWeightSum(table.GetPixelWeight(i)))
+ << "for { " << src_width << ", " << dest_width << " } at " << i
+ << " (reversed)";
+ }
+}
+
void ExecuteStretchTests(const FXDIB_ResampleOptions& options) {
// Can't test everything, few random values chosen.
- constexpr uint32_t kDestWidths[] = {1, 2, 337, 512, 808, 2550};
- constexpr uint32_t kSrcWidths[] = {1, 2, 187, 256, 809, 1110};
- for (uint32_t src_width : kSrcWidths) {
- for (uint32_t dest_width : kDestWidths) {
+ constexpr int32_t kDestWidths[] = {1, 2, 337, 512, 808, 2550};
+ constexpr int32_t kSrcWidths[] = {1, 2, 187, 256, 809, 1110};
+ for (int32_t src_width : kSrcWidths) {
+ for (int32_t dest_width : kDestWidths) {
ExecuteOneStretchTest(dest_width, src_width, options);
+ ExecuteOneReversedStretchTest(dest_width, src_width, options);
}
}
}