File: test069.cxx

package info (click to toggle)
libpqxx 4.0.1%2Bdfsg3-8
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 16,012 kB
  • ctags: 9,469
  • sloc: sh: 11,289; cpp: 10,801; xml: 1,256; makefile: 287; ansic: 195; python: 159
file content (50 lines) | stat: -rw-r--r-- 1,139 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>

#include "test_helpers.hxx"

using namespace PGSTD;
using namespace pqxx;


// Test program for libpqxx.  Issue a query repeatedly through a pipeline, and
// compare results.
namespace
{
void TestPipeline(pipeline &P, int numqueries)
{
  const string Q("SELECT count(*) FROM pg_tables");

  for (int i=numqueries; i; --i) P.insert(Q);

  PQXX_CHECK(!numqueries || !P.empty(), "pipeline::empty() is broken.");

  int res = 0;
  for (int i=numqueries; i; --i)
  {
    PQXX_CHECK(!P.empty(), "Got wrong number of queries from pipeline.");

    pair<pipeline::query_id, result> R = P.retrieve();

    cout << "Query #" << R.first << ": " << R.second.at(0).at(0) << endl;
    if (res)
      PQXX_CHECK_EQUAL(
	R.second[0][0].as<int>(),
	res,
	"Got unexpected result out of pipeline.");

    res = R.second[0][0].as<int>();
  }

  PQXX_CHECK(P.empty(), "Pipeline not empty after retrieval.");
}


void test_069(transaction_base &W)
{
  pipeline P(W);
  PQXX_CHECK(P.empty(), "Pipeline is not empty initially.");
  for (int i=0; i<5; ++i) TestPipeline(P, i);
}
} // namespace

PQXX_REGISTER_TEST_C(test_069, asyncconnection)