Unit tests for ParamList to json.

This commit is contained in:
eelke 2017-12-09 19:39:37 +01:00
parent e9f5fff6d3
commit dec52a3829
5 changed files with 72 additions and 11 deletions

View file

@ -1,10 +1,9 @@
#include "ParamListJson.h" #include "ParamListJson.h"
#include "ParamListModel.h"
Json::Value ParamToJson(const Param &param) Json::Value ParamToJson(const Param &param)
{ {
Json::Value v; Json::Value v;
v["type"] = (int)param.type.toUtf8().data(); v["type"] = param.type.toUtf8().data();
v["value"] = param.value.toUtf8().data(); v["value"] = param.value.toUtf8().data();
return v; return v;
} }
@ -16,7 +15,7 @@ Param ParamFromJson(const Json::Value &json)
return p; return p;
} }
Json::Value ParamListModelToJson(const t_ParamList &list) Json::Value ParamListToJson(const t_ParamList &list)
{ {
Json::Value root; Json::Value root;
for (const auto &param : list) { for (const auto &param : list) {
@ -25,7 +24,7 @@ Json::Value ParamListModelToJson(const t_ParamList &list)
return root; return root;
} }
t_ParamList ParamListModelFromJson(const Json::Value &json) t_ParamList ParamListFromJson(const Json::Value &json)
{ {
t_ParamList result; t_ParamList result;
if (json.isArray()) { if (json.isArray()) {

View file

@ -2,9 +2,8 @@
#define PARAMLISTJSON_H #define PARAMLISTJSON_H
#include "json/json.h" #include "json/json.h"
#include "ParamListModel.h"
class ParamListModel; Json::Value ParamListToJson(const t_ParamList &list);
Json::Value ParamListModelToJson(const t_ParamList &list);
#endif // PARAMLISTJSON_H #endif // PARAMLISTJSON_H

View file

@ -10,7 +10,10 @@ TARGET = core
TEMPLATE = lib TEMPLATE = lib
CONFIG += staticlib c++14 CONFIG += staticlib c++14
INCLUDEPATH += C:\prog\include C:\VSproj\boost32\include\boost-1_65_1 INCLUDEPATH += C:\prog\include \
C:\Prog\include\pgsql \
C:\VSproj\boost32\include\boost-1_65_1
DEFINES += WIN32_LEAN_AND_MEAN NOMINMAX DEFINES += WIN32_LEAN_AND_MEAN NOMINMAX
#LIBS += /LIBPATH:C:\VSproj\boost_1_63_0\stage\lib /LIBPATH:c:\prog\lib\ libpq.lib fmt.lib User32.lib ws2_32.lib #LIBS += /LIBPATH:C:\VSproj\boost_1_63_0\stage\lib /LIBPATH:c:\prog\lib\ libpq.lib fmt.lib User32.lib ws2_32.lib
@ -46,7 +49,8 @@ HEADERS += PasswordManager.h \
Expected.h \ Expected.h \
ExplainTreeModelItem.h \ ExplainTreeModelItem.h \
ParamListJson.h \ ParamListJson.h \
ParamListModel.h ParamListModel.h \
json/json.h
unix { unix {
target.path = /usr/lib target.path = /usr/lib
@ -54,3 +58,16 @@ unix {
} }
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../pgsql/release/ -lpgsql
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../pgsql/debug/ -lpgsql
else:unix:!macx: LIBS += -L$$OUT_PWD/../pgsql/ -lpgsql
INCLUDEPATH += $$PWD/../pgsql
DEPENDPATH += $$PWD/../pgsql
win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../pgsql/release/libpgsql.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../pgsql/debug/libpgsql.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../pgsql/release/pgsql.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../pgsql/debug/pgsql.lib
else:unix:!macx: PRE_TARGETDEPS += $$OUT_PWD/../pgsql/libpgsql.a

View file

@ -16,12 +16,16 @@ HEADERS += \
tst_PasswordManager.h tst_PasswordManager.h
SOURCES += main.cpp \ SOURCES += main.cpp \
tst_ExplainJsonParser.cpp tst_ExplainJsonParser.cpp \
tst_ParamJson.cpp
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../../../core/release/ -lcore win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../../../core/release/ -lcore
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../../../core/debug/ -lcore else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../../../core/debug/ -lcore
INCLUDEPATH += C:\prog\include C:\VSproj\boost_1_63_0 INCLUDEPATH += C:\prog\include \
C:\Prog\include\pgsql \
C:\VSproj\boost32\include\boost-1_65_1
INCLUDEPATH += $$PWD/../../../core INCLUDEPATH += $$PWD/../../../core
DEPENDPATH += $$PWD/../../../core DEPENDPATH += $$PWD/../../../core
LIBS += c:\prog\lib\botand_imp.lib LIBS += c:\prog\lib\botand_imp.lib
@ -30,3 +34,16 @@ win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../../../c
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../../../core/debug/libcore.a else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../../../core/debug/libcore.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../../../core/release/core.lib else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../../../core/release/core.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../../../core/debug/core.lib else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../../../core/debug/core.lib
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../../../pgsql/release/ -lpgsql
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../../../pgsql/debug/ -lpgsql
else:unix:!macx: LIBS += -L$$OUT_PWD/../../../pgsql/ -lpgsql
INCLUDEPATH += $$PWD/../../../pgsql
DEPENDPATH += $$PWD/../../../pgsql
win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../../../pgsql/release/libpgsql.a
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../../../pgsql/debug/libpgsql.a
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../../../pgsql/release/pgsql.lib
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../../../pgsql/debug/pgsql.lib
else:unix:!macx: PRE_TARGETDEPS += $$OUT_PWD/../../../pgsql/libpgsql.a

View file

@ -0,0 +1,29 @@
#include <gtest/gtest.h>
#include <gmock/gmock-matchers.h>
#include "ParamListModel.h"
#include "ParamListJson.h"
using namespace testing;
TEST(ParamListToJson, test1)
{
t_ParamList params;
params.emplace_back("valuestr", "typestr");
Json::Value root = ParamListToJson(params); // will contains the root value after parsing.
ASSERT_TRUE(root.isArray());
ASSERT_EQ(root.size(), 1);
Json::Value e = root[0];
ASSERT_TRUE(e.isMember("type"));
ASSERT_TRUE(e.isMember("value"));
ASSERT_EQ(e["type"].asString(), "typestr");
ASSERT_EQ(e["value"].asString(), "valuestr");
// Json::Reader reader;
// bool parsingSuccessful = reader.parse(input, root);
// auto explain = ExplainRoot::createFromJson(root);
// ASSERT_TRUE(explain != nullptr);
}