Skip to content

Commit 11c6546

Browse files
committed
Tests: ArrayTest, tests for 1D collections.
1 parent 9e308a6 commit 11c6546

File tree

2 files changed

+205
-68
lines changed

2 files changed

+205
-68
lines changed

test/oatpp-postgresql/migration/ArrayTest.sql

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -24,43 +24,43 @@ CREATE TABLE test_arrays2 (
2424

2525
f_text text[][]
2626
);
27-
--
28-
-- INSERT INTO test_arrays1
29-
-- (f_real, f_double, f_int16, f_int32, f_int64, f_bool, f_text)
30-
-- VALUES
31-
-- (null, null, null, null, null, null, null);
32-
--
33-
-- INSERT INTO test_arrays1
34-
-- (f_real, f_double, f_int16, f_int32, f_int64, f_bool, f_text)
35-
-- VALUES
36-
-- ('{}', '{}', '{}', '{}', '{}', '{}', '{}');
37-
--
38-
-- INSERT INTO test_arrays1
39-
-- (f_real, f_double, f_int16, f_int32, f_int64, f_bool, f_text)
40-
-- VALUES
41-
-- ('{null, null}', '{null, null}', '{null, null}', '{null, null}', '{null, null}', '{null, null}', '{null, null}');
42-
--
43-
-- INSERT INTO test_arrays1
44-
-- (f_real, f_double, f_int16, f_int32, f_int64, f_bool, f_text)
45-
-- VALUES
46-
-- ('{0}', '{0}', '{0}', '{0}', '{0}', '{false}', '{"", ""}');
47-
--
48-
-- INSERT INTO test_arrays1
49-
-- (f_real, f_double, f_int16, f_int32, f_int64, f_bool, f_text)
50-
-- VALUES
51-
-- ('{1}', '{1}', '{1}', '{1}', '{1}', '{true}', '{"hello"}');
52-
--
53-
--
54-
-- INSERT INTO test_arrays2
55-
-- (f_real, f_double, f_int16, f_int32, f_int64, f_bool, f_text)
56-
-- VALUES
57-
-- (null, null, null, null, null, null, null);
58-
--
59-
-- INSERT INTO test_arrays2
60-
-- (f_real, f_double, f_int16, f_int32, f_int64, f_bool, f_text)
61-
-- VALUES
62-
-- ('{}', '{}', '{}', '{}', '{}', '{}', '{}');
63-
--
27+
28+
INSERT INTO test_arrays1
29+
(f_real, f_double, f_int16, f_int32, f_int64, f_bool, f_text)
30+
VALUES
31+
(null, null, null, null, null, null, null);
32+
33+
INSERT INTO test_arrays1
34+
(f_real, f_double, f_int16, f_int32, f_int64, f_bool, f_text)
35+
VALUES
36+
('{}', '{}', '{}', '{}', '{}', '{}', '{}');
37+
38+
INSERT INTO test_arrays1
39+
(f_real, f_double, f_int16, f_int32, f_int64, f_bool, f_text)
40+
VALUES
41+
('{null, null}', '{null, null}', '{null, null}', '{null, null}', '{null, null}', '{null, null}', '{null, null}');
42+
43+
INSERT INTO test_arrays1
44+
(f_real, f_double, f_int16, f_int32, f_int64, f_bool, f_text)
45+
VALUES
46+
('{0}', '{0}', '{0}', '{0}', '{0}', '{false}', '{"", ""}');
47+
48+
INSERT INTO test_arrays1
49+
(f_real, f_double, f_int16, f_int32, f_int64, f_bool, f_text)
50+
VALUES
51+
('{1}', '{1}', '{1}', '{1}', '{1}', '{true}', '{"hello"}');
52+
53+
54+
INSERT INTO test_arrays2
55+
(f_real, f_double, f_int16, f_int32, f_int64, f_bool, f_text)
56+
VALUES
57+
(null, null, null, null, null, null, null);
58+
59+
INSERT INTO test_arrays2
60+
(f_real, f_double, f_int16, f_int32, f_int64, f_bool, f_text)
61+
VALUES
62+
('{}', '{}', '{}', '{}', '{}', '{}', '{}');
63+
6464
INSERT INTO test_arrays2
6565
(f_real, f_double, f_int16, f_int32, f_int64, f_bool, f_text)
6666
VALUES

test/oatpp-postgresql/types/ArrayTest.cpp

Lines changed: 168 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,23 @@
2727
#include "oatpp-postgresql/orm.hpp"
2828
#include "oatpp/parser/json/mapping/ObjectMapper.hpp"
2929

30-
#include <limits>
31-
#include <cstdio>
32-
#include <iostream>
33-
3430
namespace oatpp { namespace test { namespace postgresql { namespace types {
3531

3632
namespace {
3733

3834
#include OATPP_CODEGEN_BEGIN(DTO)
3935

40-
class Row : public oatpp::DTO {
36+
class Row1 : public oatpp::DTO {
4137

42-
DTO_INIT(Row, DTO);
38+
DTO_INIT(Row1, DTO);
4339

4440
DTO_FIELD(Vector<Float32>, f_real);
4541
DTO_FIELD(Vector<Float64>, f_double);
4642
DTO_FIELD(Vector<Int16>, f_int16);
4743
DTO_FIELD(Vector<Int32>, f_int32);
4844
DTO_FIELD(Vector<Int64>, f_int64);
49-
DTO_FIELD(Vector<Boolean> , f_bool);
50-
DTO_FIELD(Vector<String> , f_text);
45+
DTO_FIELD(Vector<Boolean>, f_bool);
46+
DTO_FIELD(Vector<String>, f_text);
5147

5248
};
5349

@@ -73,17 +69,14 @@ class MyClient : public oatpp::orm::DbClient {
7369

7470
}
7571

76-
QUERY(insertValues,
72+
QUERY(insertValues1,
7773
"INSERT INTO test_arrays1 "
7874
"(f_real, f_double, f_int16, f_int32, f_int64, f_bool, f_text) "
7975
"VALUES "
8076
"(:row.f_real, :row.f_double, :row.f_int16, :row.f_int32, :row.f_int64, :row.f_bool, :row.f_text);",
81-
PARAM(oatpp::Object<Row>, row), PREPARE(true))
82-
83-
QUERY(deleteValues,
84-
"DELETE FROM test_floats;")
77+
PARAM(oatpp::Object<Row1>, row), PREPARE(true))
8578

86-
QUERY(selectValues, "SELECT * FROM test_arrays1;")
79+
QUERY(selectValues1, "SELECT * FROM test_arrays1;")
8780

8881
};
8982

@@ -101,16 +94,16 @@ void ArrayTest::onRun() {
10194
auto client = MyClient(executor);
10295

10396
{
104-
auto row = Row::createShared();
105-
row->f_real = {nullptr, v_float32(0), 0.32};
106-
row->f_double = {nullptr, v_float64 (0), 0.64};
107-
row->f_int16 = {nullptr, v_int16(0), 16};
108-
row->f_int32 = {nullptr, v_int16(0), 32};
109-
row->f_int64 = {nullptr, v_int16(0), 64};
110-
row->f_bool = {nullptr, true, false};
111-
row->f_text = {nullptr, "", "Hello", "World!"};
112-
113-
auto res = client.insertValues(row);
97+
auto row = Row1::createShared();
98+
row->f_real = {nullptr, v_float32(0), v_float32(1)};
99+
row->f_double = {nullptr, v_float64(0), v_float64(1)};
100+
row->f_int16 = {nullptr, v_int16(0), v_int16(16)};
101+
row->f_int32 = {nullptr, v_int32(0), v_int32(32)};
102+
row->f_int64 = {nullptr, v_int64(0), v_int64(64)};
103+
row->f_bool = {nullptr, false, true};
104+
row->f_text = {nullptr, "", "Hello"};
105+
106+
auto res = client.insertValues1(row);
114107
if(res->isSuccess()) {
115108
OATPP_LOGD(TAG, "OK, knownCount=%d, hasMore=%d", res->getKnownCount(), res->hasMoreToFetch());
116109
} else {
@@ -121,23 +114,167 @@ void ArrayTest::onRun() {
121114
}
122115

123116
{
124-
auto res = client.selectValues();
117+
auto res = client.selectValues1();
125118
if(res->isSuccess()) {
126119
OATPP_LOGD(TAG, "OK, knownCount=%d, hasMore=%d", res->getKnownCount(), res->hasMoreToFetch());
127120
} else {
128121
auto message = res->getErrorMessage();
129122
OATPP_LOGD(TAG, "Error, message=%s", message->c_str());
130123
}
131124

132-
auto dataset = res->fetch<oatpp::Vector<oatpp::Fields<oatpp::Any>>>();
125+
auto dataset = res->fetch<oatpp::Vector<oatpp::Object<Row1>>>();
126+
127+
OATPP_ASSERT(dataset->size() == 6)
128+
129+
{
130+
auto row = dataset[0];
131+
132+
OATPP_ASSERT(row->f_real == nullptr);
133+
OATPP_ASSERT(row->f_double == nullptr);
134+
OATPP_ASSERT(row->f_int16 == nullptr);
135+
OATPP_ASSERT(row->f_int32 == nullptr);
136+
OATPP_ASSERT(row->f_int64 == nullptr);
137+
OATPP_ASSERT(row->f_bool == nullptr);
138+
OATPP_ASSERT(row->f_text == nullptr);
139+
140+
}
141+
142+
{
143+
auto row = dataset[1];
144+
145+
OATPP_ASSERT(row->f_real != nullptr);
146+
OATPP_ASSERT(row->f_double != nullptr);
147+
OATPP_ASSERT(row->f_int16 != nullptr);
148+
OATPP_ASSERT(row->f_int32 != nullptr);
149+
OATPP_ASSERT(row->f_int64 != nullptr);
150+
OATPP_ASSERT(row->f_bool != nullptr);
151+
OATPP_ASSERT(row->f_text != nullptr);
152+
153+
OATPP_ASSERT(row->f_real->size() == 0);
154+
OATPP_ASSERT(row->f_double->size() == 0);
155+
OATPP_ASSERT(row->f_int16->size() == 0);
156+
OATPP_ASSERT(row->f_int32->size() == 0);
157+
OATPP_ASSERT(row->f_int64->size() == 0);
158+
OATPP_ASSERT(row->f_bool->size() == 0);
159+
OATPP_ASSERT(row->f_text->size() == 0);
133160

134-
oatpp::parser::json::mapping::ObjectMapper om;
135-
om.getSerializer()->getConfig()->useBeautifier = true;
136-
om.getSerializer()->getConfig()->enabledInterpretations = {"postgresql"};
161+
}
137162

138-
auto str = om.writeToString(dataset);
163+
{
164+
auto row = dataset[2];
165+
166+
OATPP_ASSERT(row->f_real != nullptr);
167+
OATPP_ASSERT(row->f_double != nullptr);
168+
OATPP_ASSERT(row->f_int16 != nullptr);
169+
OATPP_ASSERT(row->f_int32 != nullptr);
170+
OATPP_ASSERT(row->f_int64 != nullptr);
171+
OATPP_ASSERT(row->f_bool != nullptr);
172+
OATPP_ASSERT(row->f_text != nullptr);
173+
174+
OATPP_ASSERT(row->f_real->size() == 2);
175+
OATPP_ASSERT(row->f_double->size() == 2);
176+
OATPP_ASSERT(row->f_int16->size() == 2);
177+
OATPP_ASSERT(row->f_int32->size() == 2);
178+
OATPP_ASSERT(row->f_int64->size() == 2);
179+
OATPP_ASSERT(row->f_bool->size() == 2);
180+
OATPP_ASSERT(row->f_text->size() == 2);
181+
182+
OATPP_ASSERT(row->f_real[0] == nullptr && row->f_real[1] == nullptr);
183+
OATPP_ASSERT(row->f_double[0] == nullptr && row->f_double[1] == nullptr);
184+
OATPP_ASSERT(row->f_int16[0] == nullptr && row->f_int16[1] == nullptr);
185+
OATPP_ASSERT(row->f_int32[0] == nullptr && row->f_int32[1] == nullptr);
186+
OATPP_ASSERT(row->f_int64[0] == nullptr && row->f_int64[1] == nullptr);
187+
OATPP_ASSERT(row->f_bool[0] == nullptr && row->f_bool[1] == nullptr);
188+
OATPP_ASSERT(row->f_text[0] == nullptr && row->f_text[1] == nullptr);
139189

140-
std::cout << "\n" << str->std_str() << std::endl;
190+
}
191+
192+
{
193+
auto row = dataset[3];
194+
195+
OATPP_ASSERT(row->f_real != nullptr);
196+
OATPP_ASSERT(row->f_double != nullptr);
197+
OATPP_ASSERT(row->f_int16 != nullptr);
198+
OATPP_ASSERT(row->f_int32 != nullptr);
199+
OATPP_ASSERT(row->f_int64 != nullptr);
200+
OATPP_ASSERT(row->f_bool != nullptr);
201+
OATPP_ASSERT(row->f_text != nullptr);
202+
203+
OATPP_ASSERT(row->f_real->size() == 1);
204+
OATPP_ASSERT(row->f_double->size() == 1);
205+
OATPP_ASSERT(row->f_int16->size() == 1);
206+
OATPP_ASSERT(row->f_int32->size() == 1);
207+
OATPP_ASSERT(row->f_int64->size() == 1);
208+
OATPP_ASSERT(row->f_bool->size() == 1);
209+
OATPP_ASSERT(row->f_text->size() == 2);
210+
211+
OATPP_ASSERT(row->f_real[0] == v_float32(0));
212+
OATPP_ASSERT(row->f_double[0] == v_float64(0));
213+
OATPP_ASSERT(row->f_int16[0] == v_int16(0));
214+
OATPP_ASSERT(row->f_int32[0] == v_int32(0));
215+
OATPP_ASSERT(row->f_int64[0] == v_int64(0));
216+
OATPP_ASSERT(row->f_bool[0] == false);
217+
OATPP_ASSERT(row->f_text[0] == "" && row->f_text[1] == "");
218+
219+
}
220+
221+
{
222+
auto row = dataset[4];
223+
224+
OATPP_ASSERT(row->f_real != nullptr);
225+
OATPP_ASSERT(row->f_double != nullptr);
226+
OATPP_ASSERT(row->f_int16 != nullptr);
227+
OATPP_ASSERT(row->f_int32 != nullptr);
228+
OATPP_ASSERT(row->f_int64 != nullptr);
229+
OATPP_ASSERT(row->f_bool != nullptr);
230+
OATPP_ASSERT(row->f_text != nullptr);
231+
232+
OATPP_ASSERT(row->f_real->size() == 1);
233+
OATPP_ASSERT(row->f_double->size() == 1);
234+
OATPP_ASSERT(row->f_int16->size() == 1);
235+
OATPP_ASSERT(row->f_int32->size() == 1);
236+
OATPP_ASSERT(row->f_int64->size() == 1);
237+
OATPP_ASSERT(row->f_bool->size() == 1);
238+
OATPP_ASSERT(row->f_text->size() == 1);
239+
240+
OATPP_ASSERT(row->f_real[0] == v_float32(1));
241+
OATPP_ASSERT(row->f_double[0] == v_float64(1));
242+
OATPP_ASSERT(row->f_int16[0] == v_int16(1));
243+
OATPP_ASSERT(row->f_int32[0] == v_int32(1));
244+
OATPP_ASSERT(row->f_int64[0] == v_int64(1));
245+
OATPP_ASSERT(row->f_bool[0] == true);
246+
OATPP_ASSERT(row->f_text[0] == "hello");
247+
248+
}
249+
250+
{
251+
auto row = dataset[5];
252+
253+
OATPP_ASSERT(row->f_real != nullptr);
254+
OATPP_ASSERT(row->f_double != nullptr);
255+
OATPP_ASSERT(row->f_int16 != nullptr);
256+
OATPP_ASSERT(row->f_int32 != nullptr);
257+
OATPP_ASSERT(row->f_int64 != nullptr);
258+
OATPP_ASSERT(row->f_bool != nullptr);
259+
OATPP_ASSERT(row->f_text != nullptr);
260+
261+
OATPP_ASSERT(row->f_real->size() == 3);
262+
OATPP_ASSERT(row->f_double->size() == 3);
263+
OATPP_ASSERT(row->f_int16->size() == 3);
264+
OATPP_ASSERT(row->f_int32->size() == 3);
265+
OATPP_ASSERT(row->f_int64->size() == 3);
266+
OATPP_ASSERT(row->f_bool->size() == 3);
267+
OATPP_ASSERT(row->f_text->size() == 3);
268+
269+
OATPP_ASSERT(row->f_real[0] == nullptr && row->f_real[1] == v_float32(0) && row->f_real[2] == v_float32(1));
270+
OATPP_ASSERT(row->f_double[0] == nullptr && row->f_double[1] == v_float64(0) && row->f_double[2] == v_float64(1));
271+
OATPP_ASSERT(row->f_int16[0] == nullptr && row->f_int16[1] == v_int16(0) && row->f_int16[2] == v_int16(16));
272+
OATPP_ASSERT(row->f_int32[0] == nullptr && row->f_int32[1] == v_int32(0) && row->f_int32[2] == v_int32(32));
273+
OATPP_ASSERT(row->f_int64[0] == nullptr && row->f_int64[1] == v_int64(0) && row->f_int64[2] == v_int64(64));
274+
OATPP_ASSERT(row->f_bool[0] == nullptr && row->f_bool[1] == false && row->f_bool[2] == true);
275+
OATPP_ASSERT(row->f_text[0] == nullptr && row->f_text[1] == "" && row->f_text[2] == "Hello");
276+
277+
}
141278

142279
}
143280

0 commit comments

Comments
 (0)