test69.cxx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include <iostream>
  2. #include <pqxx/pipeline>
  3. #include <pqxx/transaction>
  4. #include "test_helpers.hxx"
  5. using namespace pqxx;
  6. // Test program for libpqxx. Issue a query repeatedly through a pipeline, and
  7. // compare results.
  8. namespace
  9. {
  10. void TestPipeline(pipeline &P, int numqueries)
  11. {
  12. std::string const Q{"SELECT 99"};
  13. for (int i{numqueries}; i > 0; --i) P.insert(Q);
  14. PQXX_CHECK(
  15. (numqueries == 0) or not std::empty(P), "pipeline::empty() is broken.");
  16. int res{0};
  17. for (int i{numqueries}; i > 0; --i)
  18. {
  19. PQXX_CHECK(
  20. not std::empty(P), "Got wrong number of queries from pipeline.");
  21. auto R{P.retrieve()};
  22. if (res != 0)
  23. PQXX_CHECK_EQUAL(
  24. R.second[0][0].as<int>(), res,
  25. "Got unexpected result out of pipeline.");
  26. res = R.second[0][0].as<int>();
  27. }
  28. PQXX_CHECK(std::empty(P), "Pipeline not empty after retrieval.");
  29. }
  30. void test_069()
  31. {
  32. connection conn;
  33. work tx{conn};
  34. pipeline P(tx);
  35. PQXX_CHECK(std::empty(P), "Pipeline is not empty initially.");
  36. for (int i{0}; i < 5; ++i) TestPipeline(P, i);
  37. }
  38. PQXX_REGISTER_TEST(test_069);
  39. } // namespace