PDF417ScanningDecoderTest.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright 2022 gitlost
  3. */
  4. // SPDX-License-Identifier: Apache-2.0
  5. #include "DecoderResult.h"
  6. #include "pdf417/PDFScanningDecoder.h"
  7. #include "gtest/gtest.h"
  8. using namespace ZXing;
  9. using namespace ZXing::Pdf417;
  10. // Shorthand for DecodeCodewords()
  11. static DecoderResult decode(std::vector<int>& codewords)
  12. {
  13. std::vector<int> erasures;
  14. auto result = DecodeCodewords(codewords, NumECCodeWords(0));
  15. return result;
  16. }
  17. TEST(PDF417ScanningDecoderTest, BadSymbolLengthDescriptor)
  18. {
  19. {
  20. std::vector<int> codewords = { 4, 1, 449, 394 }; // 4 should be 2
  21. auto result = decode(codewords);
  22. EXPECT_TRUE(result.isValid());
  23. EXPECT_EQ(result.text(), L"AB");
  24. EXPECT_EQ(codewords[0], 2);
  25. }
  26. {
  27. std::vector<int> codewords = { 1, 1, 800, 351 }; // 1 should be 2
  28. auto result = decode(codewords);
  29. EXPECT_TRUE(result.isValid());
  30. EXPECT_EQ(result.text(), L"AB");
  31. EXPECT_EQ(codewords[0], 2);
  32. }
  33. {
  34. std::vector<int> codewords = { 0, 1, 917, 27 }; // 0 should be 2
  35. auto result = decode(codewords);
  36. EXPECT_TRUE(result.isValid());
  37. EXPECT_EQ(result.text(), L"AB");
  38. EXPECT_EQ(codewords[0], 2);
  39. }
  40. }