Value::getAsArray function to parse array convert to correct type and
uses inserter to fill container. Unit tests included.
This commit is contained in:
parent
ec930218cd
commit
2ad4a2601f
3 changed files with 55 additions and 9 deletions
|
|
@ -8,12 +8,16 @@ CONFIG += qt
|
|||
|
||||
QT += core
|
||||
|
||||
QMAKE_CXXFLAGS += /std:c++17
|
||||
|
||||
INCLUDEPATH += C:\prog\include C:\Prog\include\pgsql
|
||||
|
||||
HEADERS +=
|
||||
|
||||
SOURCES += main.cpp \
|
||||
tst_Value.cpp
|
||||
tst_Value.cpp \
|
||||
tst_ArrayParser.cpp \
|
||||
tst_Pgsql_oids.cpp
|
||||
|
||||
|
||||
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../../pgsql/release/ -lpgsql
|
||||
|
|
|
|||
|
|
@ -2,6 +2,9 @@
|
|||
#include <gmock/gmock-matchers.h>
|
||||
#include "Pgsql_Value.h"
|
||||
#include "PrintTo_Qt.h"
|
||||
#include <iterator>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
using namespace testing;
|
||||
using namespace Pgsql;
|
||||
|
|
@ -64,3 +67,23 @@ TEST(Pgsql_Value, isString_varchar)
|
|||
Pgsql::Value v("1", VARCHAROID);
|
||||
ASSERT_EQ(v.isString(), true);
|
||||
}
|
||||
|
||||
TEST(Pgsql_Value, getAsArray_Ints)
|
||||
{
|
||||
Pgsql::Value v("{1,2}", TEXTARRAYOID);
|
||||
std::vector<int> r;
|
||||
v.getAsArray<int>(std::back_inserter(r));
|
||||
|
||||
ASSERT_EQ(r.size(), 2);
|
||||
ASSERT_EQ(r[0], 1);
|
||||
ASSERT_EQ(r[1], 2);
|
||||
}
|
||||
|
||||
TEST(Pgsql_Value, getAsArray_QDateTime)
|
||||
{
|
||||
Pgsql::Value v("{\"2017-12-11 10:11:22\",\"2017-12-13 12:00:11\"}", TEXTARRAYOID);
|
||||
std::set<QDateTime> r;
|
||||
v.getAsArray<QDateTime>(std::inserter(r, r.end()));
|
||||
|
||||
ASSERT_EQ(r.size(), 2);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue