ODITFWriterTest.cpp 844 B

12345678910111213141516171819202122232425262728293031323334
  1. /*
  2. * Copyright 2017 Huy Cuong Nguyen
  3. * Copyright 2016 ZXing authors
  4. */
  5. // SPDX-License-Identifier: Apache-2.0
  6. #include "oned/ODITFWriter.h"
  7. #include "BitMatrixIO.h"
  8. #include "gtest/gtest.h"
  9. #include <stdexcept>
  10. using namespace ZXing;
  11. using namespace ZXing::OneD;
  12. namespace {
  13. std::string Encode(const std::wstring& input)
  14. {
  15. auto result = ToString(ITFWriter().encode(input, 0, 0), '1', '0', false);
  16. return result.substr(0, result.size() - 1); // remove the \n at the end
  17. }
  18. }
  19. TEST(ODITFWriterTest, Encode)
  20. {
  21. EXPECT_EQ(Encode(L"00123456789012"),
  22. "0000010101010111000111000101110100010101110001110111010001010001110100011"
  23. "100010101000101011100011101011101000111000101110100010101110001110100000");
  24. }
  25. TEST(ODITFWriterTest, EncodeIllegalCharacters)
  26. {
  27. EXPECT_THROW({ Encode(L"00123456789abc"); }, std::invalid_argument);
  28. }