diff options
author | Tom Sepez <tsepez@chromium.org> | 2017-04-27 14:58:53 -0700 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-04-27 22:11:36 +0000 |
commit | 5628fd71197c0d476a89cf3a00810aaf9fdfc086 (patch) | |
tree | 776174625f009e1b421596366bd919e7659a44f9 /xfa/fwl/cfx_barcode_unittest.cpp | |
parent | 6714ff81237e36ce0a21dbbff3e0a549dfc561a7 (diff) | |
download | pdfium-5628fd71197c0d476a89cf3a00810aaf9fdfc086.tar.xz |
Add barcode test skeleton
Individual tests need some more fleshing out.
Fix spelling of "Destroy" while we're at it.
Bug: pdfium:699
Change-Id: I05f1da8654bfdf92cb264adae16e1b3209587a31
Reviewed-on: https://pdfium-review.googlesource.com/4550
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'xfa/fwl/cfx_barcode_unittest.cpp')
-rw-r--r-- | xfa/fwl/cfx_barcode_unittest.cpp | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/xfa/fwl/cfx_barcode_unittest.cpp b/xfa/fwl/cfx_barcode_unittest.cpp new file mode 100644 index 0000000000..07d74eef81 --- /dev/null +++ b/xfa/fwl/cfx_barcode_unittest.cpp @@ -0,0 +1,123 @@ +// Copyright 2017 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 "xfa/fwl/cfx_barcode.h" + +#include <memory> +#include <utility> + +#include "core/fxcrt/fx_coordinates.h" +#include "core/fxcrt/fx_string.h" +#include "core/fxge/cfx_renderdevice.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "testing/mock_ifx_renderdevicedriver.h" +#include "testing/test_support.h" +#include "third_party/base/ptr_util.h" + +using testing::_; +using testing::AtLeast; + +class BarcodeTest : public testing::Test { + public: + void SetUp() override { + BC_Library_Init(); + barcode_ = pdfium::MakeUnique<CFX_Barcode>(); + device_ = pdfium::MakeUnique<CFX_RenderDevice>(); + driver_ = pdfium::MakeUnique<MockIFXRenderDeviceDriver>(); + } + + void TearDown() override { + driver_.reset(); + device_.reset(); + barcode_.reset(); + BC_Library_Destroy(); + } + + CFX_Barcode* barcode() const { return barcode_.get(); } + CFX_RenderDevice* device() const { return device_.get(); } + MockIFXRenderDeviceDriver* driver() const { return driver_.get(); } + + bool Create(BC_TYPE type) { + if (!barcode_->Create(type)) + return false; + + barcode_->SetModuleHeight(300); + barcode_->SetModuleWidth(420); + barcode_->SetHeight(298); + barcode_->SetWidth(418); + return true; + } + + void HandoffDriverToDevice() { device_->SetDeviceDriver(std::move(driver_)); } + bool RenderDevice() { + return barcode_->RenderDevice(device_.get(), &matrix_); + } + + protected: + CFX_Matrix matrix_; + std::unique_ptr<CFX_Barcode> barcode_; + std::unique_ptr<CFX_RenderDevice> device_; + std::unique_ptr<MockIFXRenderDeviceDriver> driver_; +}; + +TEST_F(BarcodeTest, Code39) { + EXPECT_TRUE(Create(BC_CODE39)); + EXPECT_TRUE(barcode()->Encode(L"clams", false)); + + EXPECT_CALL(*driver(), GetDeviceCaps(_)).Times(AtLeast(1)); + EXPECT_CALL(*driver(), GetClipBox(_)).Times(AtLeast(1)); + EXPECT_CALL(*driver(), DrawPath(_, _, _, _, _, _, _)).Times(AtLeast(1)); + HandoffDriverToDevice(); + RenderDevice(); +} + +TEST_F(BarcodeTest, CodaBar) { + EXPECT_TRUE(Create(BC_CODABAR)); + EXPECT_TRUE(barcode()->Encode(L"clams", false)); +} + +TEST_F(BarcodeTest, Code128) { + EXPECT_TRUE(Create(BC_CODE128)); + EXPECT_TRUE(barcode()->Encode(L"clams", false)); +} + +TEST_F(BarcodeTest, Code128_B) { + EXPECT_TRUE(Create(BC_CODE128_B)); + EXPECT_TRUE(barcode()->Encode(L"clams", false)); +} + +TEST_F(BarcodeTest, Code128_C) { + EXPECT_TRUE(Create(BC_CODE128_C)); + EXPECT_TRUE(barcode()->Encode(L"clams", false)); +} + +TEST_F(BarcodeTest, Ean8) { + EXPECT_TRUE(Create(BC_EAN8)); + EXPECT_TRUE(barcode()->Encode(L"clams", false)); +} + +TEST_F(BarcodeTest, UPCA) { + EXPECT_TRUE(Create(BC_UPCA)); + EXPECT_TRUE(barcode()->Encode(L"clams", false)); +} + +TEST_F(BarcodeTest, Ean13) { + EXPECT_TRUE(Create(BC_EAN13)); + EXPECT_TRUE(barcode()->Encode(L"clams", false)); +} + +TEST_F(BarcodeTest, Pdf417) { + EXPECT_TRUE(Create(BC_PDF417)); + EXPECT_TRUE(barcode()->Encode(L"clams", false)); +} + +TEST_F(BarcodeTest, DataMatrix) { + EXPECT_TRUE(Create(BC_DATAMATRIX)); + EXPECT_TRUE(barcode()->Encode(L"clams", false)); +} + +TEST_F(BarcodeTest, QrCode) { + EXPECT_TRUE(Create(BC_QR_CODE)); + EXPECT_TRUE(barcode()->Encode(L"clams", false)); +} |