ODEAN8WriterTest.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Copyright 2017 Huy Cuong Nguyen
  3. * Copyright 2009 ZXing authors
  4. */
  5. // SPDX-License-Identifier: Apache-2.0
  6. #include "oned/ODEAN8Writer.h"
  7. #include "BitMatrixIO.h"
  8. #include "gtest/gtest.h"
  9. using namespace ZXing;
  10. using namespace ZXing::OneD;
  11. namespace {
  12. std::string Encode(const std::string& input)
  13. {
  14. auto result = ToString(EAN8Writer().encode(input, 0, 0), '1', '0', false);
  15. return result.substr(0, result.size() - 1); // remove the \n at the end
  16. }
  17. }
  18. TEST(ODEAN8WriterTest, Encode1)
  19. {
  20. std::string toEncode = "96385074";
  21. std::string expected = "0000101000101101011110111101011011101010100111011100101000100101110010100000";
  22. EXPECT_EQ(Encode(toEncode), expected);
  23. }
  24. TEST(ODEAN8WriterTest, AddChecksumAndEncode)
  25. {
  26. std::string toEncode = "9638507";
  27. std::string expected = "0000101000101101011110111101011011101010100111011100101000100101110010100000";
  28. EXPECT_EQ(Encode(toEncode), expected);
  29. }
  30. TEST(ODEAN8WriterTest, EncodeIllegalCharacters)
  31. {
  32. EXPECT_THROW({ Encode("96385abc"); }, std::invalid_argument);
  33. }