ODCode93WriterTest.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright 2017 Huy Cuong Nguyen
  3. * Copyright 2016 ZXing authors
  4. */
  5. // SPDX-License-Identifier: Apache-2.0
  6. #include "oned/ODCode93Writer.h"
  7. #include "BitMatrixIO.h"
  8. #include "gtest/gtest.h"
  9. namespace ZXing { namespace OneD {
  10. std::string Code93ConvertToExtended(const std::wstring& contents);
  11. }}
  12. using namespace ZXing;
  13. using namespace ZXing::OneD;
  14. namespace {
  15. std::string Encode(const std::wstring& input)
  16. {
  17. auto result = ToString(Code93Writer().encode(input, 0, 0), '1', '0', false);
  18. return result.substr(0, result.size() - 1); // remove the \n at the end
  19. }
  20. }
  21. TEST(ODCode93WriterTest, Encode)
  22. {
  23. EXPECT_EQ(Encode(L"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"),
  24. "000001010111101101010001101001001101000101100101001100100101100010101011010001011001"
  25. "001011000101001101001000110101010110001010011001010001101001011001000101101101101001"
  26. "101100101101011001101001101100101101100110101011011001011001101001101101001110101000"
  27. "101001010010001010001001010000101001010001001001001001000101010100001000100101000010"
  28. "10100111010101000010101011110100000");
  29. }
  30. TEST(ODCode93WriterTest, EncodeExtended)
  31. {
  32. auto encoded = Encode(std::wstring(L"\x00\x01\x1a\x1b\x1f $%+!,09:;@AZ[_`az{\x7f", 25));
  33. auto expected =
  34. "00000" "101011110"
  35. "111011010" "110010110" "100100110" "110101000" // bU aA
  36. "100100110" "100111010" "111011010" "110101000" // aZ bA
  37. "111011010" "110010010" "111010010" "111001010" // bE space $
  38. "110101110" "101110110" "111010110" "110101000" // % + cA
  39. "111010110" "101011000" "100010100" "100001010" // cL 0 9
  40. "111010110" "100111010" "111011010" "110001010" // cZ bF
  41. "111011010" "110011010" "110101000" "100111010" // bV A Z
  42. "111011010" "100011010" "111011010" "100101100" // bK bO
  43. "111011010" "101101100" "100110010" "110101000" // bW dA
  44. "100110010" "100111010" "111011010" "100010110" // dZ bP
  45. "111011010" "110100110" // bT
  46. "110100010" "110101100" // checksum: 12 28
  47. "101011110" "100000";
  48. EXPECT_EQ(encoded, expected);
  49. }
  50. TEST(ODCode93WriterTest, ConvertToExtended)
  51. {
  52. // non-extended chars are not changed.
  53. std::string src = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%";
  54. std::string dst = Code93ConvertToExtended(std::wstring(src.begin(), src.end()));
  55. EXPECT_EQ(src, dst);
  56. }