ODCode39ReaderTest.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright 2022 gitlost
  3. */
  4. // SPDX-License-Identifier: Apache-2.0
  5. #include "oned/ODCode39Reader.h"
  6. #include "ReaderOptions.h"
  7. #include "Barcode.h"
  8. #include "gtest/gtest.h"
  9. using namespace ZXing;
  10. using namespace ZXing::OneD;
  11. // Helper to call decodePattern()
  12. static Barcode parse(PatternRow row, ReaderOptions opts = {})
  13. {
  14. Code39Reader reader(opts);
  15. row.insert(row.begin(), { 0, 1, 2, 1, 1, 2, 1, 2, 1, 1, 0 });
  16. row.insert(row.end(), { 0, 1, 2, 1, 1, 2, 1, 2, 1, 1, 0 });
  17. std::unique_ptr<RowReader::DecodingState> state;
  18. PatternView next(row);
  19. return reader.decodePattern(0, next, state);
  20. }
  21. TEST(ODCode39ReaderTest, SymbologyIdentifier)
  22. {
  23. {
  24. // Plain "A"
  25. PatternRow row({ 2, 1, 1, 1, 1, 2, 1, 1, 2 });
  26. auto result = parse(row);
  27. EXPECT_EQ(result.symbologyIdentifier(), "]A0");
  28. EXPECT_EQ(result.text(), "A");
  29. }
  30. {
  31. // "A" with checksum
  32. PatternRow row({ 2, 1, 1, 1, 1, 2, 1, 1, 2, 0, 2, 1, 1, 1, 1, 2, 1, 1, 2 });
  33. auto result = parse(row);
  34. EXPECT_EQ(result.symbologyIdentifier(), "]A1");
  35. EXPECT_EQ(result.text(), "AA");
  36. }
  37. {
  38. // Extended "a"
  39. PatternRow row({ 1, 2, 1, 1, 1, 2, 1, 2, 1, 0, 2, 1, 1, 1, 1, 2, 1, 1, 2 });
  40. auto result = parse(row);
  41. EXPECT_EQ(result.symbologyIdentifier(), "]A4");
  42. EXPECT_EQ(result.text(), "a");
  43. }
  44. {
  45. // Extended "a" with checksum
  46. PatternRow row({ 1, 2, 1, 1, 1, 2, 1, 2, 1, 0, 2, 1, 1, 1, 1, 2, 1, 1, 2, 0, 2, 1, 1, 2, 1, 1, 2, 1, 1 });
  47. auto result = parse(row);
  48. EXPECT_EQ(result.symbologyIdentifier(), "]A5");
  49. EXPECT_EQ(result.text(), "a8");
  50. }
  51. }