ODDataBarExpandedBitDecoderTest.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright 2021 gitlost
  3. */
  4. // SPDX-License-Identifier: Apache-2.0
  5. #include "BitArray.h"
  6. #include "BitArrayUtility.h"
  7. #include "HRI.h"
  8. #include "oned/ODDataBarExpandedBitDecoder.h"
  9. #include "gtest/gtest.h"
  10. using namespace ZXing;
  11. static std::string parse(std::string bitStr)
  12. {
  13. return HRIFromGS1(OneD::DataBar::DecodeExpandedBits(Utility::ParseBitArray(bitStr, '1')));
  14. }
  15. TEST(ODDataBarExpandedBitDecoderTest, FNC1NumericLatch)
  16. {
  17. std::string result;
  18. // Correctly encoded (Alphanumeric FNC1 "01111" implying numeric latch)
  19. result = parse("0000000100110010101000010000001111011011000111110100001000000100");
  20. EXPECT_EQ(result, "(10)12A(422)123");
  21. // Incorrectly encoded (Alphanumeric FNC1 "01111" followed by numeric latch "000")
  22. result = parse("0000000100110010101000010000001111000011011000111110100001000000100");
  23. EXPECT_EQ(result, "(10)12A(422)123");
  24. // Correctly encoded (ISO646 FNC1 "01111" implying numeric latch)
  25. result = parse("0001000100110010101000000100111011010111101101100011111010000100000010000100");
  26. EXPECT_EQ(result, "(10)12((422)123");
  27. // Incorrectly encoded (ISO646 FNC1 "01111" followed by numeric latch "000")
  28. result = parse("0001000100110010101000000100111011010111100001101100011111010000100000010000100");
  29. EXPECT_EQ(result, "(10)12((422)123");
  30. }
  31. TEST(ODDataBarExpandedBitDecoderTest, DecodeAI01392x)
  32. {
  33. std::string result;
  34. // Parse AIs following AI01392x
  35. result = parse("00110000000000000100111010101000110111110111101000001110100111100001001");
  36. EXPECT_EQ(result, "(01)90012345678908(3920)1(20)01");
  37. result = parse("0011000000000000010011101010100011011111011110101010111101000100111100000010000010");
  38. EXPECT_EQ(result, "(01)90012345678908(3922)7955(20)01");
  39. result = parse("0100100100000000010011101010100011011111011110100110010010011100101010101101100010110111011101011001"
  40. "01010101101111100000010000011101");
  41. EXPECT_EQ(result, "(01)90012345678908(3929)12345678901234(20)01");
  42. }
  43. TEST(ODDataBarExpandedBitDecoderTest, DecodeAI01393x)
  44. {
  45. std::string result;
  46. // Parse AIs following AI01393x
  47. result = parse("0011010000000000010011101010100011011111011110100000000011000011101001111000010010010011000010000010"
  48. "000100110");
  49. EXPECT_EQ(result, "(01)90012345678908(3930)0121(20)01(10)AB1");
  50. result = parse("0011010000000000010011101010100011011111011110101000000010000010101010110111110000001000001010000000"
  51. "010110000010000100110");
  52. EXPECT_EQ(result, "(01)90012345678908(3932)0081234(20)01(10)AB1");
  53. result = parse("0011010000000000010011101010100011011111011110101111111001010010101010110110001011011101110101100101"
  54. "0101011011001001001111000010010010011000010000010000100110");
  55. EXPECT_EQ(result, "(01)90012345678908(3933)997123456789012345(20)01(10)AB1");
  56. }