Add CBC_DataMatrixWriterTest. Change-Id: Ib8ea55306a3320be46aebdcc1d6692214d46664c Reviewed-on: https://pdfium-review.googlesource.com/c/46512 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/fxbarcode/BUILD.gn b/fxbarcode/BUILD.gn index 8e14597..768c01e 100644 --- a/fxbarcode/BUILD.gn +++ b/fxbarcode/BUILD.gn
@@ -143,6 +143,7 @@ pdfium_unittest_source_set("unittests") { sources = [ + "datamatrix/BC_DataMatrixWriter_unittest.cpp", "oned/BC_OnedCodaBarWriter_unittest.cpp", "oned/BC_OnedCode128Writer_unittest.cpp", "oned/BC_OnedCode39Writer_unittest.cpp",
diff --git a/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp b/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp index f08992f..4ac8812 100644 --- a/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp +++ b/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp
@@ -109,9 +109,6 @@ uint8_t* CBC_DataMatrixWriter::Encode(const WideString& contents, int32_t& outWidth, int32_t& outHeight) { - if (outWidth < 0 || outHeight < 0) - return nullptr; - WideString ecLevel; WideString encoded = CBC_HighLevelEncoder::EncodeHighLevel(contents, ecLevel, false);
diff --git a/fxbarcode/datamatrix/BC_DataMatrixWriter.h b/fxbarcode/datamatrix/BC_DataMatrixWriter.h index fcda36e..f3dcc55 100644 --- a/fxbarcode/datamatrix/BC_DataMatrixWriter.h +++ b/fxbarcode/datamatrix/BC_DataMatrixWriter.h
@@ -9,10 +9,6 @@ #include "fxbarcode/BC_TwoDimWriter.h" -class CBC_CommonByteMatrix; -class CBC_DefaultPlacement; -class CBC_SymbolInfo; - class CBC_DataMatrixWriter final : public CBC_TwoDimWriter { public: CBC_DataMatrixWriter();
diff --git a/fxbarcode/datamatrix/BC_DataMatrixWriter_unittest.cpp b/fxbarcode/datamatrix/BC_DataMatrixWriter_unittest.cpp new file mode 100644 index 0000000..10bfbbe --- /dev/null +++ b/fxbarcode/datamatrix/BC_DataMatrixWriter_unittest.cpp
@@ -0,0 +1,108 @@ +// Copyright 2018 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "fxbarcode/datamatrix/BC_DataMatrixWriter.h" + +#include <memory> + +#include "core/fxcrt/fx_memory.h" +#include "testing/gtest/include/gtest/gtest.h" + +class CBC_DataMatrixWriterTest : public testing::Test { + public: + CBC_DataMatrixWriterTest() = default; + ~CBC_DataMatrixWriterTest() override = default; + + // testing::Test: + void SetUp() override { BC_Library_Init(); } + void TearDown() override { BC_Library_Destroy(); } +}; + +TEST_F(CBC_DataMatrixWriterTest, Encode) { + CBC_DataMatrixWriter writer; + int32_t width; + int32_t height; + + { + static constexpr int kExpectedDimension = 10; + std::unique_ptr<uint8_t, FxFreeDeleter> data( + writer.Encode(L"", width, height)); + ASSERT_TRUE(data); + ASSERT_EQ(kExpectedDimension, width); + ASSERT_EQ(kExpectedDimension, height); + // clang-format off + static const char kExpectedData[kExpectedDimension * kExpectedDimension] = { + 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, + 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, + 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, + 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, + 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, + 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, + 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, + 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, + 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 + }; + // clang-format on + for (size_t i = 0; i < FX_ArraySize(kExpectedData); ++i) + EXPECT_EQ(kExpectedData[i], data.get()[i]) << i; + } + { + static constexpr int kExpectedDimension = 14; + std::unique_ptr<uint8_t, FxFreeDeleter> data( + writer.Encode(L"helloworld", width, height)); + ASSERT_TRUE(data); + ASSERT_EQ(kExpectedDimension, width); + ASSERT_EQ(kExpectedDimension, height); + // clang-format off + static const char kExpectedData[kExpectedDimension * kExpectedDimension] = { + 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, + 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, + 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, + 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, + 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, + 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, + 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, + 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, + 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, + 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, + 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, + 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, + 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 + }; + // clang-format on + for (size_t i = 0; i < FX_ArraySize(kExpectedData); ++i) + EXPECT_EQ(kExpectedData[i], data.get()[i]) << i; + } + { + static constexpr int kExpectedDimension = 10; + std::unique_ptr<uint8_t, FxFreeDeleter> data( + writer.Encode(L"12345", width, height)); + ASSERT_TRUE(data); + ASSERT_EQ(kExpectedDimension, width); + ASSERT_EQ(kExpectedDimension, height); + // clang-format off + static const char kExpectedData[kExpectedDimension * kExpectedDimension] = { + 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, + 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, + 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, + 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, + 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, + 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, + 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, + 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, + 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 + }; + // clang-format on + for (size_t i = 0; i < FX_ArraySize(kExpectedData); ++i) + EXPECT_EQ(kExpectedData[i], data.get()[i]) << i; + } + { + std::unique_ptr<uint8_t, FxFreeDeleter> data( + writer.Encode(L"hello world", width, height)); + ASSERT_FALSE(data); + } +}