Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

test-main.cpp 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include <iostream>
  2. #include <string.h>
  3. #include <gtest/gtest.h>
  4. #include "DBO/Result.h"
  5. template <class T>
  6. void testStream(const T& data, const std::string& ref) {
  7. std::ostringstream stream;
  8. stream << data;
  9. ASSERT_EQ(stream.str(), ref);
  10. }
  11. TEST(Result, ok)
  12. {
  13. testStream(ResultInt::ok(42), "Success: 42");
  14. testStream(ResultInt::ok(0), "Success: 0");
  15. testStream(ResultBool::ok(true), "Success: 1");
  16. testStream(ResultBool::ok(false), "Success: 0");
  17. testStream(ResultDouble::ok(0.42), "Success: 0.42");
  18. testStream(ResultDouble::ok(-0.42), "Success: -0.42");
  19. }
  20. TEST(Result, error)
  21. {
  22. testStream(ResultInt::error("My error label"), "Error: My error label");
  23. testStream(ResultInt::error(""), "Error: Unknown error");
  24. }
  25. TEST(Result, strerror)
  26. {
  27. errno = 0;
  28. testStream(ResultInt::strerror(), "Error: Success");
  29. errno = EACCES;
  30. testStream(ResultInt::strerror(), "Error: Permission denied");
  31. errno = 0;
  32. }
  33. int main(int argc, char* argv[])
  34. {
  35. // std::cout << IResult::ok(42) << std::endl;
  36. // std::cout << IResult::error("Test. error") << std::endl;
  37. // errno = EACCES;
  38. // std::cout << IResult::strerror() << std::endl;
  39. // errno = 0;
  40. ::testing::InitGoogleTest(&argc, argv);
  41. return RUN_ALL_TESTS();
  42. }