File: test074.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 (82 lines) | stat: -rw-r--r-- 1,878 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <cmath>

#include "test_helpers.hxx"

using namespace PGSTD;
using namespace pqxx;


// Test program for libpqxx.  Test fieldstream.
namespace
{
void test_074(transaction_base &W)
{
  result R = W.exec("SELECT * FROM pg_tables");
  const string sval = R.at(0).at(1).c_str();
  string sval2;
  fieldstream fs1(R.front()[1]);
  fs1 >> sval2;
  PQXX_CHECK_EQUAL(sval2, sval, "fieldstream returned wrong value.");

  R = W.exec("SELECT count(*) FROM pg_tables");
  int ival;
  fieldstream fs2(R.at(0).at(0));
  fs2 >> ival;
  PQXX_CHECK_EQUAL(
	ival,
	R.front().front().as<int>(),
	"fieldstream::front() is broken.");

  double dval;
  (fieldstream(R.at(0).at(0))) >> dval;
  PQXX_CHECK_BOUNDS(
	dval,
	R[0][0].as<double>() - 0.1,
	R[0][0].as<double>() + 0.1,
	"Got wrong double from fieldstream.");

  const float roughpi = static_cast<float>(3.1415926435);
  R = W.exec("SELECT " + to_string(roughpi));
  float pival;
  (fieldstream(R.at(0).at(0))) >> pival;
  PQXX_CHECK_BOUNDS(
	pival,
	roughpi - 0.001,
	roughpi + 0.001,
	"Pi approximation came back wrong from fieldstream.");

  PQXX_CHECK_EQUAL(
	to_string(R[0][0]),
	R[0][0].c_str(),
	"to_string(result::field) is inconsistent with c_str().");

  float float_pi;
  from_string(to_string(roughpi), float_pi);
  PQXX_CHECK_BOUNDS(
	float_pi,
	roughpi - 0.00001,
	roughpi + 0.00001,
	"Float changed in conversion.");

  double double_pi;
  from_string(to_string(double(roughpi)), double_pi);
  PQXX_CHECK_BOUNDS(
	double_pi,
	roughpi - 0.00001,
	roughpi + 0.00001,
	"Double changed in conversion.");

#if defined(PQXX_HAVE_LONG_DOUBLE)
  const long double ld = roughpi;
  long double long_double_pi;
  from_string(to_string(ld), long_double_pi);
  PQXX_CHECK_BOUNDS(
	long_double_pi,
	roughpi - 0.00001,
	roughpi + 0.00001,
	"long double changed in conversion.");
#endif
}
} // namespace

PQXX_REGISTER_TEST(test_074)