File: test076.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 (56 lines) | stat: -rw-r--r-- 1,630 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
51
52
53
54
55
56
#include "test_helpers.hxx"

using namespace PGSTD;
using namespace pqxx;


// Simple test program for libpqxx.  Test string conversion routines.
namespace
{
void test_076(transaction_base &T)
{
  result RFalse = T.exec("SELECT 1=0"),
	 RTrue  = T.exec("SELECT 1=1");
  bool False, True;
  from_string(RFalse[0][0], False);
  from_string(RTrue[0][0],  True);
  PQXX_CHECK(!False, "False bool converted to true.");
  PQXX_CHECK(True, "True bool converted to false.");

  RFalse = T.exec("SELECT " + to_string(False));
  RTrue  = T.exec("SELECT " + to_string(True));
  from_string(RFalse[0][0], False);
  from_string(RTrue[0][0],  True);
  PQXX_CHECK(!False, "False bool converted to true.");
  PQXX_CHECK(True, "True bool converted to false.");

  const short svals[] = { -1, 1, 999, -32767, -32768, 32767, 0 };
  for (int i=0; svals[i]; ++i)
  {
    short s;
    from_string(to_string(svals[i]), s);
    PQXX_CHECK_EQUAL(s, svals[i], "short/string conversion not bijective.");
    from_string(T.exec("SELECT " + to_string(svals[i]))[0][0].c_str(), s);
    PQXX_CHECK_EQUAL(s, svals[i], "Roundtrip through backend changed short.");
  }

  const unsigned short uvals[] = { 1, 999, 32767, 32768, 65535, 0 };
  for (int i=0; uvals[i]; ++i)
  {
    unsigned short u;
    from_string(to_string(uvals[i]), u);
    PQXX_CHECK_EQUAL(
	u,
	uvals[i],
	"unsigned short/string conversion not bijective.");

    from_string(T.exec("SELECT " + to_string(uvals[i]))[0][0].c_str(), u);
    PQXX_CHECK_EQUAL(
	u,
	uvals[i],
	"Roundtrip through backend changed unsigned short.");
  }
}
} // namespace

PQXX_REGISTER_TEST_T(test_076, nontransaction)