BarcodeFormatTest.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * Copyright 2020 Axel Waggershauser
  3. */
  4. // SPDX-License-Identifier: Apache-2.0
  5. #include "BarcodeFormat.h"
  6. #include "gtest/gtest.h"
  7. #include <stdexcept>
  8. #include <vector>
  9. using namespace ZXing;
  10. TEST(BarcodeFormatTest, BarcodeFormat)
  11. {
  12. using namespace std::literals;
  13. EXPECT_EQ(ToString(BarcodeFormat::QRCode), "QRCode"s);
  14. EXPECT_EQ(ToString(BarcodeFormat::None), "None"s);
  15. EXPECT_EQ(ToString(BarcodeFormat::DataMatrix | BarcodeFormat::EAN13), "DataMatrix|EAN-13");
  16. EXPECT_EQ(BarcodeFormat::EAN8, BarcodeFormatFromString("EAN_8"));
  17. EXPECT_EQ(BarcodeFormat::EAN8, BarcodeFormatFromString("EAN-8"));
  18. EXPECT_EQ(BarcodeFormat::EAN8, BarcodeFormatFromString("EAN8"));
  19. EXPECT_EQ(BarcodeFormat::EAN8, BarcodeFormatFromString("ean8"));
  20. EXPECT_EQ(BarcodeFormat::None, BarcodeFormatFromString("invalid-string"));
  21. EXPECT_EQ(BarcodeFormat::None, BarcodeFormatsFromString(""));
  22. auto formats = BarcodeFormat::EAN8 | BarcodeFormat::ITF;
  23. EXPECT_EQ(formats, BarcodeFormatsFromString("EAN-8,ITF"));
  24. EXPECT_EQ(formats, BarcodeFormatsFromString("EAN-8, ITF"));
  25. EXPECT_EQ(formats, BarcodeFormatsFromString("EAN-8 ITF"));
  26. EXPECT_EQ(formats, BarcodeFormatsFromString("ean8|itf"));
  27. auto f1 = std::vector<BarcodeFormat>(formats.begin(), formats.end());
  28. auto f2 = std::vector<BarcodeFormat>{BarcodeFormat::EAN8, BarcodeFormat::ITF};
  29. EXPECT_EQ(f1, f2);
  30. EXPECT_THROW(BarcodeFormatsFromString("ITF, invalid-string"), std::invalid_argument);
  31. }