ODUPCAWriterTest.cpp 975 B

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. * Copyright 2017 Huy Cuong Nguyen
  3. * Copyright 2010 ZXing authors
  4. */
  5. // SPDX-License-Identifier: Apache-2.0
  6. #include "oned/ODUPCAWriter.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(UPCAWriter().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(ODUPCAWriterTest, Encode1)
  19. {
  20. std::string toEncode = "485963095124";
  21. std::string expected = "00001010100011011011101100010001011010111101111010101011100101110100100111011001101101100101110010100000";
  22. EXPECT_EQ(Encode(toEncode), expected);
  23. }
  24. TEST(ODUPCAWriterTest, AddChecksumAndEncode)
  25. {
  26. std::string toEncode = "12345678901";
  27. std::string expected = "00001010011001001001101111010100011011000101011110101010001001001000111010011100101100110110110010100000";
  28. EXPECT_EQ(Encode(toEncode), expected);
  29. }