ErrorTest.cpp 879 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * Copyright 2022 Axel Waggershauser
  3. */
  4. // SPDX-License-Identifier: Apache-2.0
  5. #include "Error.h"
  6. #include "gtest/gtest.h"
  7. using namespace ZXing;
  8. TEST(ErrorTest, Default)
  9. {
  10. Error e;
  11. EXPECT_FALSE(e);
  12. EXPECT_EQ(e.type(), Error::Type::None);
  13. EXPECT_EQ(e.msg().empty(), true);
  14. EXPECT_EQ(e.location().empty(), true);
  15. }
  16. TEST(ErrorTest, Empty)
  17. {
  18. Error e = ChecksumError();
  19. EXPECT_TRUE(e);
  20. EXPECT_EQ(e.type(), Error::Type::Checksum);
  21. EXPECT_EQ(e.type(), Error::Checksum);
  22. EXPECT_EQ(e, Error::Checksum);
  23. EXPECT_EQ(Error::Checksum, e);
  24. EXPECT_EQ(e.msg().empty(), true);
  25. EXPECT_EQ(e.location().empty(), false);
  26. }
  27. TEST(ErrorTest, WithMsg)
  28. {
  29. Error e = FormatError("something is wrong"); int line = __LINE__;
  30. EXPECT_TRUE(e);
  31. EXPECT_EQ(e, Error::Format);
  32. EXPECT_EQ(e.msg(), "something is wrong");
  33. EXPECT_EQ(e.location(), "ErrorTest.cpp:" + std::to_string(line));
  34. }