DMPlacementTest.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Copyright 2017 Huy Cuong Nguyen
  3. * Copyright 2006 Jeremias Maerki
  4. */
  5. // SPDX-License-Identifier: Apache-2.0
  6. #include "BitMatrixIO.h"
  7. #include "ByteArray.h"
  8. #include "datamatrix/DMBitLayout.h"
  9. #include "gtest/gtest.h"
  10. #include <algorithm>
  11. #include <iterator>
  12. #include <sstream>
  13. using namespace ZXing;
  14. using namespace ZXing::DataMatrix;
  15. namespace {
  16. ByteArray Unvisualize(const char* visualized) {
  17. std::istringstream input(visualized);
  18. ByteArray result;
  19. std::copy(std::istream_iterator<int>(input), std::istream_iterator<int>(), std::back_inserter(result));
  20. return result;
  21. }
  22. }
  23. TEST(DMPlacementTest, Placement)
  24. {
  25. auto codewords = Unvisualize("66 74 78 66 74 78 129 56 35 102 192 96 226 100 156 1 107 221"); //"AIMAIM" encoded
  26. auto matrix = BitMatrixFromCodewords(codewords, 12, 12);
  27. std::string expected =
  28. "011100001111\n"
  29. "001010101000\n"
  30. "010001010100\n"
  31. "001010100010\n"
  32. "000111000100\n"
  33. "011000010100\n"
  34. "000100001101\n"
  35. "011000010000\n"
  36. "001100001101\n"
  37. "100010010111\n"
  38. "011101011010\n"
  39. "001011001010\n";
  40. EXPECT_EQ(expected, ToString(matrix, '1', '0', false));
  41. }