aboutsummaryrefslogtreecommitdiffstats
path: root/fxbarcode
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2019-03-05 20:06:25 +0000
committerChromium commit bot <commit-bot@chromium.org>2019-03-05 20:06:25 +0000
commita1982d50f04c3e300185f2389624953247208d00 (patch)
tree4735a6a1ff620a84dd0797fd8d6b140a5627dd92 /fxbarcode
parent15c0b1e6fd1cd43812b7519d77f3c1d1d5dbcc63 (diff)
downloadplatform_external_pdfium-a1982d50f04c3e300185f2389624953247208d00.tar.gz
platform_external_pdfium-a1982d50f04c3e300185f2389624953247208d00.tar.bz2
platform_external_pdfium-a1982d50f04c3e300185f2389624953247208d00.zip
Add CBC_DataMatrixWriterTest tests for encoding limits.
Data Matrix barcodes have a maximum size. Test the boundary condition and see the encoder fail once the input gets to be too big. BUG=chromium:930394 Change-Id: I76e5e923249b6756d7c1fd29e72ed25117a3dac2 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/51490 Reviewed-by: Lei Zhang <thestig@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'fxbarcode')
-rw-r--r--fxbarcode/datamatrix/BC_DataMatrixWriter_unittest.cpp64
1 files changed, 62 insertions, 2 deletions
diff --git a/fxbarcode/datamatrix/BC_DataMatrixWriter_unittest.cpp b/fxbarcode/datamatrix/BC_DataMatrixWriter_unittest.cpp
index ef5c00b96..fa5d26c18 100644
--- a/fxbarcode/datamatrix/BC_DataMatrixWriter_unittest.cpp
+++ b/fxbarcode/datamatrix/BC_DataMatrixWriter_unittest.cpp
@@ -21,8 +21,8 @@ class CBC_DataMatrixWriterTest : public testing::Test {
TEST_F(CBC_DataMatrixWriterTest, Encode) {
CBC_DataMatrixWriter writer;
- int32_t width;
- int32_t height;
+ int32_t width = -1;
+ int32_t height = -1;
{
static constexpr int kExpectedDimension = 10;
@@ -134,3 +134,63 @@ TEST_F(CBC_DataMatrixWriterTest, Encode) {
ASSERT_TRUE(data.empty());
}
}
+
+TEST_F(CBC_DataMatrixWriterTest, EncodeLimitAlphaNumeric) {
+ CBC_DataMatrixWriter writer;
+ int32_t width = -1;
+ int32_t height = -1;
+
+ static constexpr int kMaxInputLength = 2335; // Per spec.
+ WideString input;
+ for (size_t i = 0; i < kMaxInputLength; ++i)
+ input.InsertAtBack(L'a');
+
+ {
+ static constexpr int kExpectedDimension = 144;
+ std::vector<uint8_t> data = writer.Encode(input.c_str(), &width, &height);
+ EXPECT_EQ(20736u, data.size());
+ EXPECT_EQ(kExpectedDimension, width);
+ EXPECT_EQ(kExpectedDimension, height);
+ }
+
+ // Go over the limit.
+ input.InsertAtBack(L'a');
+ {
+ width = -1;
+ height = -1;
+ std::vector<uint8_t> data = writer.Encode(input.c_str(), &width, &height);
+ EXPECT_EQ(0u, data.size());
+ EXPECT_EQ(-1, width);
+ EXPECT_EQ(-1, height);
+ }
+}
+
+TEST_F(CBC_DataMatrixWriterTest, EncodeLimitNumbers) {
+ CBC_DataMatrixWriter writer;
+ int32_t width = -1;
+ int32_t height = -1;
+
+ static constexpr int kMaxInputLength = 3116; // Per spec.
+ WideString input;
+ for (size_t i = 0; i < kMaxInputLength; ++i)
+ input.InsertAtBack(L'1');
+
+ {
+ static constexpr int kExpectedDimension = 144;
+ std::vector<uint8_t> data = writer.Encode(input.c_str(), &width, &height);
+ EXPECT_EQ(20736u, data.size());
+ EXPECT_EQ(kExpectedDimension, width);
+ EXPECT_EQ(kExpectedDimension, height);
+ }
+
+ // Go over the limit.
+ input.InsertAtBack(L'1');
+ {
+ width = -1;
+ height = -1;
+ std::vector<uint8_t> data = writer.Encode(input.c_str(), &width, &height);
+ EXPECT_EQ(0u, data.size());
+ EXPECT_EQ(-1, width);
+ EXPECT_EQ(-1, height);
+ }
+}