You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

75 lines
1.7 KiB

  1. #include <gtest/gtest.h>
  2. #include <asyncpp.h>
  3. using namespace ::testing;
  4. using namespace ::asyncpp;
  5. TEST(result_tests, future_result___not_ready)
  6. {
  7. using result_type = future_result<int>;
  8. auto r = result_type::not_ready();
  9. EXPECT_TRUE (r.is_not_ready());
  10. EXPECT_FALSE (r.is_ready());
  11. EXPECT_FALSE (r);
  12. EXPECT_ANY_THROW(*r);
  13. }
  14. TEST(result_tests, future_result___ready)
  15. {
  16. using result_type = future_result<int&>;
  17. int i;
  18. auto r = result_type::ready(i);
  19. EXPECT_FALSE (r.is_not_ready());
  20. EXPECT_TRUE (r.is_ready());
  21. EXPECT_TRUE (r);
  22. EXPECT_EQ (&*r, &i);
  23. }
  24. TEST(result_tests, stream_result___not_ready)
  25. {
  26. using result_type = stream_result<int>;
  27. auto r = result_type::not_ready();
  28. EXPECT_EQ (result_status::not_ready, r.status());
  29. EXPECT_TRUE (r.is_not_ready());
  30. EXPECT_FALSE (r.is_ready());
  31. EXPECT_FALSE (r.is_done());
  32. EXPECT_FALSE (r);
  33. EXPECT_ANY_THROW(*r);
  34. }
  35. TEST(result_tests, stream_result___ready)
  36. {
  37. using result_type = stream_result<int&>;
  38. int i;
  39. auto r = result_type::ready(i);
  40. EXPECT_EQ (result_status::ready, r.status());
  41. EXPECT_FALSE (r.is_not_ready());
  42. EXPECT_TRUE (r.is_ready());
  43. EXPECT_FALSE (r.is_done());
  44. EXPECT_TRUE (r);
  45. EXPECT_EQ (&*r, &i);
  46. }
  47. TEST(result_tests, stream_result___done)
  48. {
  49. using result_type = stream_result<void>;
  50. auto r = result_type::done();
  51. EXPECT_EQ (result_status::done, r.status());
  52. EXPECT_FALSE (r.is_not_ready());
  53. EXPECT_FALSE (r.is_ready());
  54. EXPECT_TRUE (r.is_done());
  55. EXPECT_FALSE (r);
  56. EXPECT_ANY_THROW(*r);
  57. }