Skip to content

Commit e5c8d1a

Browse files
committed
Tests. Arrays. Multidimensional arrays test.
1 parent 11c6546 commit e5c8d1a

File tree

2 files changed

+208
-2
lines changed

2 files changed

+208
-2
lines changed

test/oatpp-postgresql/migration/ArrayTest.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ CREATE TABLE test_arrays1 (
1414
);
1515

1616
CREATE TABLE test_arrays2 (
17-
f_real real[][][],
17+
f_real real[][],
1818
f_double double precision[][],
1919

2020
f_int16 smallint[][],
@@ -64,4 +64,4 @@ VALUES
6464
INSERT INTO test_arrays2
6565
(f_real, f_double, f_int16, f_int32, f_int64, f_bool, f_text)
6666
VALUES
67-
('{ {{0, 1}, {10, 11}}, {{0, 1}, {10, 11}} }', '{{0, 1}, {0, 1}}', '{{0, 1}, {0, 1}}', '{{0, 1}, {0, 1}}', '{{0, 1}, {0, 1}}', '{{true, false}, {true, false}}', '{{"Hello_1", "World_1"}, {Hello_2, World_2}}');
67+
('{{0, 1}, {2, 3}}', '{{0, 1}, {2, 3}}', '{{0, 1}, {2, 3}}', '{{0, 1}, {2, 3}}', '{{0, 1}, {2, 3}}', '{{false, true}, {true, false}}', '{{"Hello_1", "World_1"}, {Hello_2, World_2}}');

test/oatpp-postgresql/types/ArrayTest.cpp

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ class Row1 : public oatpp::DTO {
4747

4848
};
4949

50+
class Row2 : public oatpp::DTO {
51+
52+
DTO_INIT(Row2, DTO);
53+
54+
DTO_FIELD(Vector<Vector<Float32>>, f_real);
55+
DTO_FIELD(Vector<Vector<Float64>>, f_double);
56+
DTO_FIELD(Vector<Vector<Int16>>, f_int16);
57+
DTO_FIELD(Vector<Vector<Int32>>, f_int32);
58+
DTO_FIELD(Vector<Vector<Int64>>, f_int64);
59+
DTO_FIELD(Vector<Vector<Boolean>>, f_bool);
60+
DTO_FIELD(Vector<Vector<String>>, f_text);
61+
62+
};
63+
5064
#include OATPP_CODEGEN_END(DTO)
5165

5266
#include OATPP_CODEGEN_BEGIN(DbClient)
@@ -78,6 +92,15 @@ class MyClient : public oatpp::orm::DbClient {
7892

7993
QUERY(selectValues1, "SELECT * FROM test_arrays1;")
8094

95+
QUERY(insertValues2,
96+
"INSERT INTO test_arrays2 "
97+
"(f_real, f_double, f_int16, f_int32, f_int64, f_bool, f_text) "
98+
"VALUES "
99+
"(:row.f_real, :row.f_double, :row.f_int16, :row.f_int32, :row.f_int64, :row.f_bool, :row.f_text);",
100+
PARAM(oatpp::Object<Row2>, row), PREPARE(true))
101+
102+
QUERY(selectValues2, "SELECT * FROM test_arrays2;")
103+
81104
};
82105

83106
#include OATPP_CODEGEN_END(DbClient)
@@ -278,6 +301,189 @@ void ArrayTest::onRun() {
278301

279302
}
280303

304+
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
305+
// Array 2
306+
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
307+
308+
{
309+
auto row = Row2::createShared();
310+
row->f_real = {{nullptr, v_float32(0), v_float32(1)}};
311+
row->f_double = {{nullptr, v_float64(0), v_float64(1)}};
312+
row->f_int16 = {{nullptr, v_int16(0), v_int16(16)}};
313+
row->f_int32 = {{nullptr, v_int32(0), v_int32(32)}};
314+
row->f_int64 = {{nullptr, v_int64(0), v_int64(64)}};
315+
row->f_bool = {{nullptr, false, true}};
316+
row->f_text = {{nullptr, "", "Hello"}};
317+
318+
auto res = client.insertValues2(row);
319+
if(res->isSuccess()) {
320+
OATPP_LOGD(TAG, "OK, knownCount=%d, hasMore=%d", res->getKnownCount(), res->hasMoreToFetch());
321+
} else {
322+
auto message = res->getErrorMessage();
323+
OATPP_LOGD(TAG, "Error, message=%s", message->c_str());
324+
}
325+
326+
}
327+
328+
{
329+
auto res = client.selectValues2();
330+
if(res->isSuccess()) {
331+
OATPP_LOGD(TAG, "OK, knownCount=%d, hasMore=%d", res->getKnownCount(), res->hasMoreToFetch());
332+
} else {
333+
auto message = res->getErrorMessage();
334+
OATPP_LOGD(TAG, "Error, message=%s", message->c_str());
335+
}
336+
337+
auto dataset = res->fetch<oatpp::Vector<oatpp::Object<Row2>>>();
338+
339+
OATPP_ASSERT(dataset->size() == 4)
340+
341+
{
342+
auto row = dataset[0];
343+
344+
OATPP_ASSERT(row->f_real == nullptr);
345+
OATPP_ASSERT(row->f_double == nullptr);
346+
OATPP_ASSERT(row->f_int16 == nullptr);
347+
OATPP_ASSERT(row->f_int32 == nullptr);
348+
OATPP_ASSERT(row->f_int64 == nullptr);
349+
OATPP_ASSERT(row->f_bool == nullptr);
350+
OATPP_ASSERT(row->f_text == nullptr);
351+
352+
}
353+
354+
{
355+
auto row = dataset[1];
356+
357+
OATPP_ASSERT(row->f_real != nullptr);
358+
OATPP_ASSERT(row->f_double != nullptr);
359+
OATPP_ASSERT(row->f_int16 != nullptr);
360+
OATPP_ASSERT(row->f_int32 != nullptr);
361+
OATPP_ASSERT(row->f_int64 != nullptr);
362+
OATPP_ASSERT(row->f_bool != nullptr);
363+
OATPP_ASSERT(row->f_text != nullptr);
364+
365+
OATPP_ASSERT(row->f_real->size() == 0);
366+
OATPP_ASSERT(row->f_double->size() == 0);
367+
OATPP_ASSERT(row->f_int16->size() == 0);
368+
OATPP_ASSERT(row->f_int32->size() == 0);
369+
OATPP_ASSERT(row->f_int64->size() == 0);
370+
OATPP_ASSERT(row->f_bool->size() == 0);
371+
OATPP_ASSERT(row->f_text->size() == 0);
372+
373+
}
374+
375+
{
376+
auto row = dataset[2];
377+
378+
OATPP_ASSERT(row->f_real != nullptr);
379+
OATPP_ASSERT(row->f_double != nullptr);
380+
OATPP_ASSERT(row->f_int16 != nullptr);
381+
OATPP_ASSERT(row->f_int32 != nullptr);
382+
OATPP_ASSERT(row->f_int64 != nullptr);
383+
OATPP_ASSERT(row->f_bool != nullptr);
384+
OATPP_ASSERT(row->f_text != nullptr);
385+
386+
OATPP_ASSERT(row->f_real->size() == 2);
387+
OATPP_ASSERT(row->f_double->size() == 2);
388+
OATPP_ASSERT(row->f_int16->size() == 2);
389+
OATPP_ASSERT(row->f_int32->size() == 2);
390+
OATPP_ASSERT(row->f_int64->size() == 2);
391+
OATPP_ASSERT(row->f_bool->size() == 2);
392+
OATPP_ASSERT(row->f_text->size() == 2);
393+
394+
OATPP_ASSERT(row->f_real[0]->size() == 2);
395+
OATPP_ASSERT(row->f_double[0]->size() == 2);
396+
OATPP_ASSERT(row->f_int16[0]->size() == 2);
397+
OATPP_ASSERT(row->f_int32[0]->size() == 2);
398+
OATPP_ASSERT(row->f_int64[0]->size() == 2);
399+
OATPP_ASSERT(row->f_bool[0]->size() == 2);
400+
OATPP_ASSERT(row->f_text[0]->size() == 2);
401+
402+
OATPP_ASSERT(row->f_real[1]->size() == 2);
403+
OATPP_ASSERT(row->f_double[1]->size() == 2);
404+
OATPP_ASSERT(row->f_int16[1]->size() == 2);
405+
OATPP_ASSERT(row->f_int32[1]->size() == 2);
406+
OATPP_ASSERT(row->f_int64[1]->size() == 2);
407+
OATPP_ASSERT(row->f_bool[1]->size() == 2);
408+
OATPP_ASSERT(row->f_text[1]->size() == 2);
409+
410+
OATPP_ASSERT(row->f_real[0][0] == v_float32(0) &&
411+
row->f_real[0][1] == v_float32(1) &&
412+
row->f_real[1][0] == v_float32(2) &&
413+
row->f_real[1][1] == v_float32(3));
414+
415+
OATPP_ASSERT(row->f_double[0][0] == v_float64(0) &&
416+
row->f_double[0][1] == v_float64(1) &&
417+
row->f_double[1][0] == v_float64(2) &&
418+
row->f_double[1][1] == v_float64(3));
419+
420+
OATPP_ASSERT(row->f_int16[0][0] == v_int16(0) &&
421+
row->f_int16[0][1] == v_int16(1) &&
422+
row->f_int16[1][0] == v_int16(2) &&
423+
row->f_int16[1][1] == v_int16(3));
424+
425+
OATPP_ASSERT(row->f_int32[0][0] == v_int32(0) &&
426+
row->f_int32[0][1] == v_int32(1) &&
427+
row->f_int32[1][0] == v_int32(2) &&
428+
row->f_int32[1][1] == v_int32(3));
429+
430+
OATPP_ASSERT(row->f_int64[0][0] == v_int64(0) &&
431+
row->f_int64[0][1] == v_int64(1) &&
432+
row->f_int64[1][0] == v_int64(2) &&
433+
row->f_int64[1][1] == v_int64(3));
434+
435+
OATPP_ASSERT(row->f_bool[0][0] == false &&
436+
row->f_bool[0][1] == true &&
437+
row->f_bool[1][0] == true &&
438+
row->f_bool[1][1] == false);
439+
440+
OATPP_ASSERT(row->f_text[0][0] == "Hello_1" &&
441+
row->f_text[0][1] == "World_1" &&
442+
row->f_text[1][0] == "Hello_2" &&
443+
row->f_text[1][1] == "World_2");
444+
445+
}
446+
447+
{
448+
auto row = dataset[3];
449+
450+
OATPP_ASSERT(row->f_real != nullptr);
451+
OATPP_ASSERT(row->f_double != nullptr);
452+
OATPP_ASSERT(row->f_int16 != nullptr);
453+
OATPP_ASSERT(row->f_int32 != nullptr);
454+
OATPP_ASSERT(row->f_int64 != nullptr);
455+
OATPP_ASSERT(row->f_bool != nullptr);
456+
OATPP_ASSERT(row->f_text != nullptr);
457+
458+
OATPP_ASSERT(row->f_real->size() == 1);
459+
OATPP_ASSERT(row->f_double->size() == 1);
460+
OATPP_ASSERT(row->f_int16->size() == 1);
461+
OATPP_ASSERT(row->f_int32->size() == 1);
462+
OATPP_ASSERT(row->f_int64->size() == 1);
463+
OATPP_ASSERT(row->f_bool->size() == 1);
464+
OATPP_ASSERT(row->f_text->size() == 1);
465+
466+
OATPP_ASSERT(row->f_real[0]->size() == 3);
467+
OATPP_ASSERT(row->f_double[0]->size() == 3);
468+
OATPP_ASSERT(row->f_int16[0]->size() == 3);
469+
OATPP_ASSERT(row->f_int32[0]->size() == 3);
470+
OATPP_ASSERT(row->f_int64[0]->size() == 3);
471+
OATPP_ASSERT(row->f_bool[0]->size() == 3);
472+
OATPP_ASSERT(row->f_text[0]->size() == 3);
473+
474+
OATPP_ASSERT(row->f_real[0][0] == nullptr && row->f_real[0][1] == v_float32(0) && row->f_real[0][2] == v_float32(1));
475+
OATPP_ASSERT(row->f_double[0][0] == nullptr && row->f_double[0][1] == v_float64(0) && row->f_double[0][2] == v_float64(1));
476+
OATPP_ASSERT(row->f_int16[0][0] == nullptr && row->f_int16[0][1] == v_int16(0) && row->f_int16[0][2] == v_int16(16));
477+
OATPP_ASSERT(row->f_int32[0][0] == nullptr && row->f_int32[0][1] == v_int32(0) && row->f_int32[0][2] == v_int32(32));
478+
OATPP_ASSERT(row->f_int64[0][0] == nullptr && row->f_int64[0][1] == v_int64(0) && row->f_int64[0][2] == v_int64(64));
479+
OATPP_ASSERT(row->f_bool[0][0] == nullptr && row->f_bool[0][1] == false && row->f_bool[0][2] == true);
480+
OATPP_ASSERT(row->f_text[0][0] == nullptr && row->f_text[0][1] == "" && row->f_text[0][2] == "Hello");
481+
482+
}
483+
484+
}
485+
486+
281487

282488
}
283489

0 commit comments

Comments
 (0)