1 #include <pqxx/transaction>
2
3 #include "../test_helpers.hxx"
4
5 namespace
6 {
test_row()7 void test_row()
8 {
9 pqxx::connection conn;
10 pqxx::work tx{conn};
11 pqxx::result rows{tx.exec("SELECT 1, 2, 3")};
12 pqxx::row r{rows[0]};
13 PQXX_CHECK_EQUAL(std::size(r), 3, "Unexpected row size.");
14 PQXX_CHECK_EQUAL(r.at(0).as<int>(), 1, "Wrong value at index 0.");
15 PQXX_CHECK(std::begin(r) != std::end(r), "Broken row iteration.");
16 PQXX_CHECK(std::begin(r) < std::end(r), "Row begin does not precede end.");
17 PQXX_CHECK(std::cbegin(r) == std::begin(r), "Wrong cbegin.");
18 PQXX_CHECK(std::cend(r) == std::end(r), "Wrong cend.");
19 PQXX_CHECK(std::rbegin(r) != std::rend(r), "Broken reverse row iteration.");
20 PQXX_CHECK(std::crbegin(r) == std::rbegin(r), "Wrong crbegin.");
21 PQXX_CHECK(std::crend(r) == std::rend(r), "Wrong crend.");
22 PQXX_CHECK_EQUAL(r.front().as<int>(), 1, "Wrong row front().");
23 PQXX_CHECK_EQUAL(r.back().as<int>(), 3, "Wrong row back().");
24 }
25
26
test_row_iterator()27 void test_row_iterator()
28 {
29 pqxx::connection conn;
30 pqxx::work tx{conn};
31 pqxx::result rows{tx.exec("SELECT 1, 2, 3")};
32
33 auto i{std::begin(rows[0])};
34 PQXX_CHECK_EQUAL(i->as<int>(), 1, "Row iterator is wrong.");
35 auto i2{i};
36 PQXX_CHECK_EQUAL(i2->as<int>(), 1, "Row iterator copy is wrong.");
37 i2++;
38 PQXX_CHECK_EQUAL(i2->as<int>(), 2, "Row iterator increment is wrong.");
39 pqxx::row::const_iterator i3;
40 i3 = i2;
41 PQXX_CHECK_EQUAL(i3->as<int>(), 2, "Row iterator assignment is wrong.");
42
43 auto r{std::rbegin(rows[0])};
44 PQXX_CHECK_EQUAL(r->as<int>(), 3, "Row reverse iterator is wrong.");
45 auto r2{r};
46 PQXX_CHECK_EQUAL(r2->as<int>(), 3, "Row reverse iterator copy is wrong.");
47 r2++;
48 PQXX_CHECK_EQUAL(
49 r2->as<int>(), 2, "Row reverse iterator increment is wrong.");
50 pqxx::row::const_reverse_iterator r3;
51 r3 = r2;
52 PQXX_CHECK_EQUAL(
53 i3->as<int>(), 2, "Row reverse iterator assignment is wrong.");
54 }
55
56
57 PQXX_REGISTER_TEST(test_row);
58 PQXX_REGISTER_TEST(test_row_iterator);
59 } // namespace
60