Lot of code for generating code. Working on unit tests.
This commit is contained in:
parent
da45929b12
commit
8f4845d4d2
42 changed files with 1089 additions and 267 deletions
|
|
@ -1,12 +1,15 @@
|
|||
include(gtest_dependency.pri)
|
||||
|
||||
TEMPLATE = app
|
||||
CONFIG += console c++14
|
||||
CONFIG += console c++17
|
||||
CONFIG -= app_bundle
|
||||
CONFIG += thread
|
||||
CONFIG += qt
|
||||
|
||||
QT += core
|
||||
QT += core widgets
|
||||
|
||||
QMAKE_CXXFLAGS += /std:c++17
|
||||
LIBS += -LC:\VSproj\boost32\lib -LC:/PROG/LIB -lws2_32 -llibpq
|
||||
|
||||
HEADERS +=
|
||||
|
||||
|
|
@ -17,7 +20,9 @@ SOURCES += main.cpp \
|
|||
tst_scopeguard.cpp \
|
||||
tst_CsvWriter.cpp \
|
||||
tst_PasswordManager.cpp \
|
||||
tst_ParamJson.cpp
|
||||
tst_ParamJson.cpp \
|
||||
tst_CodeBuilder.cpp \
|
||||
tst_NameManglingRules.cpp
|
||||
|
||||
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
|
||||
|
|
@ -60,3 +65,16 @@ else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../../p
|
|||
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../../pglablib/release/pglablib.lib
|
||||
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../../pglablib/debug/pglablib.lib
|
||||
else:unix:!macx: PRE_TARGETDEPS += $$OUT_PWD/../../pglablib/libpglablib.a
|
||||
|
||||
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../mygtestutils/release/ -lmygtestutils
|
||||
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../mygtestutils/debug/ -lmygtestutils
|
||||
else:unix:!macx: LIBS += -L$$OUT_PWD/../mygtestutils/ -lmygtestutils
|
||||
|
||||
INCLUDEPATH += $$PWD/../mygtestutils
|
||||
DEPENDPATH += $$PWD/../mygtestutils
|
||||
|
||||
win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../mygtestutils/release/libmygtestutils.a
|
||||
else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../mygtestutils/debug/libmygtestutils.a
|
||||
else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../mygtestutils/release/mygtestutils.lib
|
||||
else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../mygtestutils/debug/mygtestutils.lib
|
||||
else:unix:!macx: PRE_TARGETDEPS += $$OUT_PWD/../mygtestutils/libmygtestutils.a
|
||||
|
|
|
|||
231
tests/pglabtests/tst_CodeBuilder.cpp
Normal file
231
tests/pglabtests/tst_CodeBuilder.cpp
Normal file
|
|
@ -0,0 +1,231 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <gmock/gmock-matchers.h>
|
||||
#include <QRegularExpression>
|
||||
#include "PgType.h"
|
||||
#include "PgTypeContainer.h"
|
||||
#include "PrintTo_Qt.h"
|
||||
#include "codebuilder/IndentationConfig.h"
|
||||
#include "codebuilder/TypeMappings.h"
|
||||
#include "Pgsql_oids.h"
|
||||
|
||||
using namespace testing;
|
||||
|
||||
|
||||
|
||||
// Test to verify my understanding of the documentation
|
||||
TEST(QRegularExpression, doIUnderstandItCorrectly)
|
||||
{
|
||||
QString text("abcdefghi");
|
||||
QRegularExpression re("c(def)g");
|
||||
QRegularExpressionMatch match;
|
||||
int pos = text.indexOf(re, 0, &match);
|
||||
|
||||
ASSERT_THAT(pos, Eq(2));
|
||||
ASSERT_THAT(match.capturedStart(), Eq(2));
|
||||
ASSERT_THAT(match.capturedEnd(), Eq(7));
|
||||
ASSERT_THAT(match.capturedStart(1), Eq(3));
|
||||
ASSERT_THAT(match.capturedEnd(1), Eq(6));
|
||||
}
|
||||
|
||||
TEST(QRegularExpression, doIUnderstandItCorrectly2)
|
||||
{
|
||||
QString text("abc/%def%/ghi");
|
||||
QRegularExpression re("(?:[^\\\\]|^)(\\/%([a-zA-Z0-9_-]+)%\\/)");
|
||||
QRegularExpressionMatch match;
|
||||
int pos = text.indexOf(re, 0, &match);
|
||||
|
||||
ASSERT_THAT(pos, Eq(2));
|
||||
ASSERT_THAT(match.capturedStart(1), Eq(3));
|
||||
ASSERT_THAT(match.capturedLength(1), Eq(7));
|
||||
ASSERT_THAT(match.capturedStart(2), Eq(5));
|
||||
ASSERT_THAT(match.capturedLength(2), Eq(3));
|
||||
}
|
||||
|
||||
#include <QTextStream>
|
||||
|
||||
void FormatToStream(QTextStream &stream, QString format, std::function<void(QTextStream &, QString)> field_callback);
|
||||
|
||||
TEST(FormatToStream, EmptyFormat)
|
||||
{
|
||||
QString result;
|
||||
QTextStream stream(&result);
|
||||
FormatToStream(stream, "", nullptr);
|
||||
stream.flush();
|
||||
|
||||
ASSERT_THAT(result, Eq(QString()));
|
||||
}
|
||||
|
||||
TEST(FormatToStream, OnlyVar)
|
||||
{
|
||||
QString result;
|
||||
QTextStream stream(&result);
|
||||
FormatToStream(stream, "/%var%/",
|
||||
[](QTextStream &stream, QString varname)
|
||||
{
|
||||
if (varname == "var")
|
||||
stream << "abc";
|
||||
});
|
||||
stream.flush();
|
||||
|
||||
ASSERT_EQ(result, QString("abc"));
|
||||
}
|
||||
|
||||
TEST(FormatToStream, StartWithVar)
|
||||
{
|
||||
QString result;
|
||||
QTextStream stream(&result);
|
||||
FormatToStream(stream, "/%var%/def",
|
||||
[](QTextStream &stream, QString varname)
|
||||
{
|
||||
if (varname == "var")
|
||||
stream << "abc";
|
||||
});
|
||||
stream.flush();
|
||||
|
||||
ASSERT_EQ(result, QString("abcdef"));
|
||||
}
|
||||
|
||||
TEST(FormatToStream, EndWithVar)
|
||||
{
|
||||
QString result;
|
||||
QTextStream stream(&result);
|
||||
FormatToStream(stream, "def/%var%/",
|
||||
[](QTextStream &stream, QString varname)
|
||||
{
|
||||
if (varname == "var")
|
||||
stream << "abc";
|
||||
});
|
||||
stream.flush();
|
||||
|
||||
ASSERT_EQ(result, QString("defabc"));
|
||||
}
|
||||
|
||||
TEST(FormatToStream, TwoVarsTogether)
|
||||
{
|
||||
QString result;
|
||||
QTextStream stream(&result);
|
||||
FormatToStream(stream, "/%var1%//%var2%/",
|
||||
[](QTextStream &stream, QString varname)
|
||||
{
|
||||
if (varname == "var1")
|
||||
stream << "abc";
|
||||
else if (varname == "var2")
|
||||
stream << "def";
|
||||
});
|
||||
stream.flush();
|
||||
|
||||
ASSERT_EQ(result, QString("abcdef"));
|
||||
}
|
||||
|
||||
TEST(FormatToStream, TwoVarsWithTextInBetween)
|
||||
{
|
||||
QString result;
|
||||
QTextStream stream(&result);
|
||||
FormatToStream(stream, "1/%var1%/2/%var2%/3",
|
||||
[](QTextStream &stream, QString varname)
|
||||
{
|
||||
if (varname == "var1")
|
||||
stream << "abc";
|
||||
else if (varname == "var2")
|
||||
stream << "def";
|
||||
});
|
||||
stream.flush();
|
||||
|
||||
ASSERT_EQ(result, QString("1abc2def3"));
|
||||
}
|
||||
|
||||
|
||||
TEST(IndentationConfig, tab8indent4true_level1)
|
||||
{
|
||||
IndentationConfig icfg(8, 4, true);
|
||||
QString result = icfg.getIndentString(1);
|
||||
ASSERT_EQ(result, " ");
|
||||
}
|
||||
|
||||
TEST(IndentationConfig, tab8indent4true_level2)
|
||||
{
|
||||
IndentationConfig icfg(8, 4, true);
|
||||
QString result = icfg.getIndentString(2);
|
||||
ASSERT_EQ(result, "\t");
|
||||
}
|
||||
|
||||
TEST(IndentationConfig, tab8indent4true_level3)
|
||||
{
|
||||
IndentationConfig icfg(8, 4, true);
|
||||
QString result = icfg.getIndentString(3);
|
||||
ASSERT_EQ(result, "\t ");
|
||||
}
|
||||
|
||||
TEST(IndentationConfig, tab8indent4false_level1)
|
||||
{
|
||||
IndentationConfig icfg(8, 4, false);
|
||||
QString result = icfg.getIndentString(1);
|
||||
ASSERT_EQ(result, " ");
|
||||
}
|
||||
|
||||
TEST(IndentationConfig, tab8indent4false_level2)
|
||||
{
|
||||
IndentationConfig icfg(8, 4, false);
|
||||
QString result = icfg.getIndentString(2);
|
||||
ASSERT_EQ(result, " ");
|
||||
}
|
||||
|
||||
|
||||
class TypeMappingsTest : public ::testing::Test {
|
||||
protected:
|
||||
void SetUp() override
|
||||
{
|
||||
def_str_type = "std::string";
|
||||
int4str = "int";
|
||||
int8str = "long long";
|
||||
tm = TypeMappings( {
|
||||
{ Pgsql::int4_oid, int4str },
|
||||
{ Pgsql::int8_oid, int8str }
|
||||
});
|
||||
tm.setDefaultStringType(def_str_type);
|
||||
tm.setDefaultContainerType("std::vector<%1>");
|
||||
}
|
||||
|
||||
// void TearDown() override {}
|
||||
|
||||
QString def_str_type;
|
||||
QString int4str;
|
||||
QString int8str;
|
||||
TypeMappings tm;
|
||||
};
|
||||
|
||||
TEST_F(TypeMappingsTest, defStringType)
|
||||
{
|
||||
QString result = tm.getTypeForOid(Pgsql::float4_oid);
|
||||
ASSERT_EQ(result, def_str_type);
|
||||
}
|
||||
|
||||
TEST_F(TypeMappingsTest, int4Type)
|
||||
{
|
||||
QString result = tm.getTypeForOid(Pgsql::int4_oid);
|
||||
ASSERT_EQ(result, int4str);
|
||||
}
|
||||
|
||||
TEST_F(TypeMappingsTest, int4overideType)
|
||||
{
|
||||
tm.set(Pgsql::int4_oid, "QString");
|
||||
QString result = tm.getTypeForOid(Pgsql::int4_oid);
|
||||
ASSERT_EQ(result, "QString");
|
||||
}
|
||||
|
||||
// Need catalogue for the next test
|
||||
// Maybe we should mock this !?
|
||||
TEST_F(TypeMappingsTest, int4arrayType)
|
||||
{
|
||||
auto types= std::make_shared<PgTypeContainer>();
|
||||
PgType int4arr;
|
||||
int4arr.oid = Pgsql::int4_array_oid;
|
||||
int4arr.elem = Pgsql::int4_oid;
|
||||
types->add(int4arr);
|
||||
|
||||
tm.setTypes(types);
|
||||
|
||||
QString result = tm.getTypeForOid(Pgsql::int4_array_oid);
|
||||
ASSERT_EQ(result, "std::vector<int>");
|
||||
}
|
||||
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
#include "CsvWriter.h"
|
||||
#include <QTextStream>
|
||||
#include <QByteArray>
|
||||
#include "PrintTo_Qt.h"
|
||||
|
||||
using namespace testing;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#include <gmock/gmock-matchers.h>
|
||||
#include "ExplainTreeModelItem.h"
|
||||
#include "json/json.h"
|
||||
#include "PrintTo_Qt.h"
|
||||
|
||||
using namespace testing;
|
||||
|
||||
|
|
|
|||
54
tests/pglabtests/tst_NameManglingRules.cpp
Normal file
54
tests/pglabtests/tst_NameManglingRules.cpp
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <gmock/gmock-matchers.h>
|
||||
#include "PrintTo_Qt.h"
|
||||
#include "codebuilder/NameManglingRules.h"
|
||||
#include "Pgsql_oids.h"
|
||||
|
||||
using namespace testing;
|
||||
|
||||
class NameManglingRulesTest : public ::testing::Test, public ::testing::WithParamInterface<
|
||||
std::tuple<QString, NameManglingRules::CaseConversion, bool> > {
|
||||
protected:
|
||||
|
||||
virtual void SetUp() override
|
||||
{
|
||||
NameManglingRules r;
|
||||
|
||||
auto p = GetParam();
|
||||
//ReplaceRules replaceRules;
|
||||
// { {"[ -_]", QRegularExpression::OptimizeOnFirstUsageOption }, "", true }
|
||||
r.replaceRules;
|
||||
|
||||
//QString replaceSpaceWith; ///< default is empty string which means remove spaces
|
||||
r.replaceSpaceWith = std::get<0>(p);
|
||||
|
||||
//CollisionHandling CollisionHandling = CollisionHandling::Restrict;
|
||||
//CaseConversion caseConversion = CaseConversion::AsIs; ///< overall case conversion rule
|
||||
r.caseConversion = std::get<1>(p);
|
||||
//CaseConversion caseFirstChar = CaseConversion::AsIs; ///< case of the first char
|
||||
r.camelCase = std::get<2>(p); ///< removes underscores and make first char after underscore uppercase
|
||||
rules = r;
|
||||
}
|
||||
NameManglingRules rules;
|
||||
};
|
||||
|
||||
|
||||
TEST_P(NameManglingRulesTest, test1)
|
||||
{
|
||||
ASSERT_EQ(rules.replaceSpaceWith, std::get<0>(GetParam()));
|
||||
}
|
||||
|
||||
TEST_P(NameManglingRulesTest, test2)
|
||||
{
|
||||
ASSERT_EQ(rules.camelCase, std::get<2>(GetParam()));
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(InstantiationName1,
|
||||
NameManglingRulesTest,
|
||||
::testing::Combine(
|
||||
::testing::Values("", "_", "+"),
|
||||
::testing::Values(NameManglingRules::CaseConversion::AsIs,
|
||||
NameManglingRules::CaseConversion::Lower,
|
||||
NameManglingRules::CaseConversion::Upper),
|
||||
::testing::Bool()
|
||||
));
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
#include <gmock/gmock-matchers.h>
|
||||
#include "ParamListModel.h"
|
||||
#include "ParamListJson.h"
|
||||
#include "PrintTo_Qt.h"
|
||||
|
||||
using namespace testing;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <gmock/gmock-matchers.h>
|
||||
#include "PasswordManager.h"
|
||||
#include "PrintTo_Qt.h"
|
||||
|
||||
using namespace testing;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <gmock/gmock-matchers.h>
|
||||
#include "SqlLexer.h"
|
||||
#include "PrintTo_Qt.h"
|
||||
|
||||
using namespace testing;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <gmock/gmock-matchers.h>
|
||||
#include "Expected.h"
|
||||
#include "PrintTo_Qt.h"
|
||||
|
||||
using namespace testing;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <gmock/gmock-matchers.h>
|
||||
#include "ScopeGuard.h"
|
||||
#include "PrintTo_Qt.h"
|
||||
|
||||
using namespace testing;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue