Messy commit. Testing suff and some improvements to how data is shown.
This commit is contained in:
parent
bebb3391c3
commit
3a13b7ffb4
59 changed files with 2045 additions and 716 deletions
73
tests/PgsqlTests/.gitignore
vendored
Normal file
73
tests/PgsqlTests/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
# This file is used to ignore files which are generated
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
*~
|
||||
*.autosave
|
||||
*.a
|
||||
*.core
|
||||
*.moc
|
||||
*.o
|
||||
*.obj
|
||||
*.orig
|
||||
*.rej
|
||||
*.so
|
||||
*.so.*
|
||||
*_pch.h.cpp
|
||||
*_resource.rc
|
||||
*.qm
|
||||
.#*
|
||||
*.*#
|
||||
core
|
||||
!core/
|
||||
tags
|
||||
.DS_Store
|
||||
.directory
|
||||
*.debug
|
||||
Makefile*
|
||||
*.prl
|
||||
*.app
|
||||
moc_*.cpp
|
||||
ui_*.h
|
||||
qrc_*.cpp
|
||||
Thumbs.db
|
||||
*.res
|
||||
*.rc
|
||||
/.qmake.cache
|
||||
/.qmake.stash
|
||||
|
||||
# qtcreator generated files
|
||||
*.pro.user*
|
||||
|
||||
# xemacs temporary files
|
||||
*.flc
|
||||
|
||||
# Vim temporary files
|
||||
.*.swp
|
||||
|
||||
# Visual Studio generated files
|
||||
*.ib_pdb_index
|
||||
*.idb
|
||||
*.ilk
|
||||
*.pdb
|
||||
*.sln
|
||||
*.suo
|
||||
*.vcproj
|
||||
*vcproj.*.*.user
|
||||
*.ncb
|
||||
*.sdf
|
||||
*.opensdf
|
||||
*.vcxproj
|
||||
*vcxproj.*
|
||||
|
||||
# MinGW generated files
|
||||
*.Debug
|
||||
*.Release
|
||||
|
||||
# Python byte code
|
||||
*.pyc
|
||||
|
||||
# Binaries
|
||||
# --------
|
||||
*.dll
|
||||
*.exe
|
||||
|
||||
43
tests/PgsqlTests/PgsqlTests.pro
Normal file
43
tests/PgsqlTests/PgsqlTests.pro
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
include(gtest_dependency.pri)
|
||||
|
||||
TEMPLATE = app
|
||||
CONFIG += console c++11
|
||||
CONFIG -= app_bundle
|
||||
CONFIG += thread
|
||||
CONFIG += qt
|
||||
|
||||
QT += core
|
||||
|
||||
INCLUDEPATH += C:\prog\include C:\Prog\include\pgsql
|
||||
|
||||
HEADERS +=
|
||||
|
||||
SOURCES += main.cpp \
|
||||
tst_Value.cpp
|
||||
|
||||
|
||||
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: 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: PRE_TARGETDEPS += $$OUT_PWD/../../pgsql/libpgsql.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
|
||||
29
tests/PgsqlTests/gtest_dependency.pri
Normal file
29
tests/PgsqlTests/gtest_dependency.pri
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
isEmpty(GOOGLETEST_DIR):GOOGLETEST_DIR=$$(GOOGLETEST_DIR)
|
||||
|
||||
isEmpty(GOOGLETEST_DIR) {
|
||||
warning("Using googletest src dir specified at Qt Creator wizard")
|
||||
message("set GOOGLETEST_DIR as environment variable or qmake variable to get rid of this message")
|
||||
GOOGLETEST_DIR = C:/Prog/googletest
|
||||
}
|
||||
|
||||
!isEmpty(GOOGLETEST_DIR): {
|
||||
GTEST_SRCDIR = $$GOOGLETEST_DIR/googletest
|
||||
GMOCK_SRCDIR = $$GOOGLETEST_DIR/googlemock
|
||||
}
|
||||
|
||||
requires(exists($$GTEST_SRCDIR):exists($$GMOCK_SRCDIR))
|
||||
|
||||
!exists($$GOOGLETEST_DIR):message("No googletest src dir found - set GOOGLETEST_DIR to enable.")
|
||||
|
||||
DEFINES += \
|
||||
GTEST_LANG_CXX11
|
||||
|
||||
INCLUDEPATH *= \
|
||||
$$GTEST_SRCDIR \
|
||||
$$GTEST_SRCDIR/include \
|
||||
$$GMOCK_SRCDIR \
|
||||
$$GMOCK_SRCDIR/include
|
||||
|
||||
SOURCES += \
|
||||
$$GTEST_SRCDIR/src/gtest-all.cc \
|
||||
$$GMOCK_SRCDIR/src/gmock-all.cc
|
||||
7
tests/PgsqlTests/main.cpp
Normal file
7
tests/PgsqlTests/main.cpp
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#include <gtest/gtest.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
66
tests/PgsqlTests/tst_Value.cpp
Normal file
66
tests/PgsqlTests/tst_Value.cpp
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <gmock/gmock-matchers.h>
|
||||
#include "Pgsql_Value.h"
|
||||
#include "PrintTo_Qt.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace Pgsql;
|
||||
|
||||
TEST(Pgsql_Value, test_int4)
|
||||
{
|
||||
Pgsql::Value v("1", INT4OID);
|
||||
int i = (int)v;
|
||||
ASSERT_EQ(i, 1);
|
||||
}
|
||||
|
||||
TEST(Pgsql_Value, test_QDateTime)
|
||||
{
|
||||
Pgsql::Value v("2017-10-22 12:34:56", TIMESTAMPTZOID);
|
||||
QDateTime dt = (QDateTime)v;
|
||||
ASSERT_EQ(dt, QDateTime(QDate(2017, 10, 22), QTime(12, 34, 56)));
|
||||
}
|
||||
|
||||
|
||||
TEST(Pgsql_Value, test_QDateTime_2)
|
||||
{
|
||||
Pgsql::Value v("2017-12-01 09:38:17.339817+02", TIMESTAMPTZOID);
|
||||
QDateTime dt = (QDateTime)v;
|
||||
QDateTime exp(QDate(2017, 12, 1), QTime(9, 38, 17, 340),
|
||||
Qt::OffsetFromUTC, 2*3600);
|
||||
ASSERT_EQ(dt, exp);
|
||||
}
|
||||
|
||||
TEST(Pgsql_Value, test_QDate)
|
||||
{
|
||||
Pgsql::Value v("2017-10-22", DATEOID);
|
||||
QDate d = v;
|
||||
ASSERT_EQ(d, QDate(2017, 10, 22));
|
||||
}
|
||||
|
||||
TEST(Pgsql_Value, test_QTime)
|
||||
{
|
||||
Pgsql::Value v("12:34:56", TIMEOID);
|
||||
QTime t = v;
|
||||
ASSERT_EQ(t, QTime(12, 34, 56));
|
||||
}
|
||||
|
||||
TEST(Pgsql_Value, test_QTimeMS)
|
||||
{
|
||||
Pgsql::Value v("09:38:17.339817+02", TIMETZOID);
|
||||
QTime t = v;
|
||||
ASSERT_EQ(t, QTime(9, 38, 17, 340));
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEST(Pgsql_Value, isString_int4)
|
||||
{
|
||||
Pgsql::Value v("1", INT4OID);
|
||||
ASSERT_EQ(v.isString(), false);
|
||||
}
|
||||
|
||||
TEST(Pgsql_Value, isString_varchar)
|
||||
{
|
||||
Pgsql::Value v("1", VARCHAROID);
|
||||
ASSERT_EQ(v.isString(), true);
|
||||
}
|
||||
3
tests/auto/auto.pro
Normal file
3
tests/auto/auto.pro
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
TEMPLATE = subdirs
|
||||
|
||||
SUBDIRS += mycase
|
||||
29
tests/auto/gtest_dependency.pri
Normal file
29
tests/auto/gtest_dependency.pri
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
isEmpty(GOOGLETEST_DIR):GOOGLETEST_DIR=$$(GOOGLETEST_DIR)
|
||||
|
||||
isEmpty(GOOGLETEST_DIR) {
|
||||
warning("Using googletest src dir specified at Qt Creator wizard")
|
||||
message("set GOOGLETEST_DIR as environment variable or qmake variable to get rid of this message")
|
||||
GOOGLETEST_DIR = C:/Prog/googletest
|
||||
}
|
||||
|
||||
!isEmpty(GOOGLETEST_DIR): {
|
||||
GTEST_SRCDIR = $$GOOGLETEST_DIR/googletest
|
||||
GMOCK_SRCDIR = $$GOOGLETEST_DIR/googlemock
|
||||
}
|
||||
|
||||
requires(exists($$GTEST_SRCDIR):exists($$GMOCK_SRCDIR))
|
||||
|
||||
!exists($$GOOGLETEST_DIR):message("No googletest src dir found - set GOOGLETEST_DIR to enable.")
|
||||
|
||||
DEFINES += \
|
||||
GTEST_LANG_CXX11
|
||||
|
||||
INCLUDEPATH *= \
|
||||
$$GTEST_SRCDIR \
|
||||
$$GTEST_SRCDIR/include \
|
||||
$$GMOCK_SRCDIR \
|
||||
$$GMOCK_SRCDIR/include
|
||||
|
||||
SOURCES += \
|
||||
$$GTEST_SRCDIR/src/gtest-all.cc \
|
||||
$$GMOCK_SRCDIR/src/gmock-all.cc
|
||||
13
tests/auto/mycase/main.cpp
Normal file
13
tests/auto/mycase/main.cpp
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#include "tst_CsvWriter.h"
|
||||
#include "tst_expected.h"
|
||||
#include "tst_PasswordManager.h"
|
||||
#include "tst_scopeguard.h"
|
||||
#include "tst_SqlLexer.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
32
tests/auto/mycase/mycase.pro
Normal file
32
tests/auto/mycase/mycase.pro
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
include(../gtest_dependency.pri)
|
||||
|
||||
TEMPLATE = app
|
||||
CONFIG += console c++11
|
||||
CONFIG -= app_bundle
|
||||
CONFIG += thread
|
||||
CONFIG += qt
|
||||
|
||||
QT += core
|
||||
|
||||
HEADERS += \
|
||||
tst_expected.h \
|
||||
tst_SqlLexer.h \
|
||||
tst_scopeguard.h \
|
||||
tst_CsvWriter.h \
|
||||
tst_PasswordManager.h
|
||||
|
||||
SOURCES += main.cpp \
|
||||
tst_ExplainJsonParser.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
|
||||
|
||||
INCLUDEPATH += C:\prog\include C:\VSproj\boost_1_63_0
|
||||
INCLUDEPATH += $$PWD/../../../core
|
||||
DEPENDPATH += $$PWD/../../../core
|
||||
LIBS += c:\prog\lib\botand_imp.lib
|
||||
|
||||
win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../../../core/release/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(debug, debug|release): PRE_TARGETDEPS += $$OUT_PWD/../../../core/debug/core.lib
|
||||
113
tests/auto/mycase/tst_CsvWriter.h
Normal file
113
tests/auto/mycase/tst_CsvWriter.h
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <gmock/gmock-matchers.h>
|
||||
#include "CsvWriter.h"
|
||||
#include <QTextStream>
|
||||
#include <QByteArray>
|
||||
|
||||
using namespace testing;
|
||||
|
||||
|
||||
TEST(CsvWriter, one_row_two_numbers)
|
||||
{
|
||||
QString result;
|
||||
QTextStream stream(&result);
|
||||
CsvWriter writer(&stream);
|
||||
writer.setQuote('"');
|
||||
writer.setSeperator(',');
|
||||
writer.writeField("1");
|
||||
writer.writeField("2");
|
||||
writer.nextRow();
|
||||
|
||||
QString expected = QString::fromUtf8("1,2\n");
|
||||
ASSERT_THAT(result, Eq(expected));
|
||||
}
|
||||
|
||||
TEST(CsvWriter, one_row_one_number_one_unquoted_string)
|
||||
{
|
||||
QString result;
|
||||
QTextStream stream(&result);
|
||||
CsvWriter writer(&stream);
|
||||
writer.setQuote('"');
|
||||
writer.setSeperator(',');
|
||||
writer.writeField("1");
|
||||
writer.writeField("hello");
|
||||
writer.nextRow();
|
||||
|
||||
QString expected = QString::fromUtf8("1,hello\n");
|
||||
ASSERT_THAT(result, Eq(expected));
|
||||
}
|
||||
|
||||
TEST(CsvWriter, one_row_one_number_one_quoted_string)
|
||||
{
|
||||
QString result;
|
||||
QTextStream stream(&result);
|
||||
CsvWriter writer(&stream);
|
||||
writer.setQuote('"');
|
||||
writer.setSeperator(',');
|
||||
writer.writeField("1");
|
||||
writer.writeField("hel,lo");
|
||||
writer.nextRow();
|
||||
|
||||
QString expected = QString::fromUtf8("1,\"hel,lo\"\n");
|
||||
ASSERT_THAT(result, Eq(expected));
|
||||
}
|
||||
|
||||
TEST(CsvWriter, newline_in_field)
|
||||
{
|
||||
QString result;
|
||||
QTextStream stream(&result);
|
||||
CsvWriter writer(&stream);
|
||||
writer.setQuote('"');
|
||||
writer.setSeperator(',');
|
||||
writer.writeField("1");
|
||||
writer.writeField("hel\nlo");
|
||||
writer.nextRow();
|
||||
|
||||
QString expected = QString::fromUtf8("1,\"hel\nlo\"\n");
|
||||
ASSERT_THAT(result, Eq(expected));
|
||||
}
|
||||
|
||||
TEST(CsvWriter, escape_quote)
|
||||
{
|
||||
QString result;
|
||||
QTextStream stream(&result);
|
||||
CsvWriter writer(&stream);
|
||||
writer.setQuote('"');
|
||||
writer.setSeperator(',');
|
||||
writer.writeField("1");
|
||||
writer.writeField("hel\"lo");
|
||||
writer.nextRow();
|
||||
|
||||
QString expected = QString::fromUtf8("1,\"hel\"\"lo\"\n");
|
||||
ASSERT_THAT(result, Eq(expected));
|
||||
}
|
||||
|
||||
TEST(CsvWriter, non_default_seperator)
|
||||
{
|
||||
QString result;
|
||||
QTextStream stream(&result);
|
||||
CsvWriter writer(&stream);
|
||||
writer.setQuote('"');
|
||||
writer.setSeperator('\t');
|
||||
writer.writeField("1");
|
||||
writer.writeField("hel,lo");
|
||||
writer.nextRow();
|
||||
|
||||
QString expected = QString::fromUtf8("1\thel,lo\n");
|
||||
ASSERT_THAT(result, Eq(expected));
|
||||
}
|
||||
|
||||
TEST(CsvWriter, non_default_quote)
|
||||
{
|
||||
QString result;
|
||||
QTextStream stream(&result);
|
||||
CsvWriter writer(&stream);
|
||||
writer.setQuote('*');
|
||||
writer.setSeperator('\t');
|
||||
writer.writeField("1");
|
||||
writer.writeField("hel\tlo");
|
||||
writer.nextRow();
|
||||
|
||||
QString expected = QString::fromUtf8("1\t*hel\tlo*\n");
|
||||
ASSERT_THAT(result, Eq(expected));
|
||||
}
|
||||
80
tests/auto/mycase/tst_ExplainJsonParser.cpp
Normal file
80
tests/auto/mycase/tst_ExplainJsonParser.cpp
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <gmock/gmock-matchers.h>
|
||||
#include "ExplainTreeModelItem.h"
|
||||
#include "json/json.h"
|
||||
|
||||
using namespace testing;
|
||||
|
||||
|
||||
|
||||
|
||||
TEST(ExplainParser, verbose)
|
||||
{
|
||||
std::string input = R"__json__("[
|
||||
{
|
||||
"Plan": {
|
||||
"Node Type": "Limit",
|
||||
"Parallel Aware": false,
|
||||
"Startup Cost": 0.42,
|
||||
"Total Cost": 0.42,
|
||||
"Plan Rows": 10,
|
||||
"Plan Width": 830,
|
||||
"Output": ["fr1.callstack_crc_2", "fr1.id", "fr1.program", "fr1.version", "fr1.lic_bedrijf", "fr1.lic_plaats", "fr1.lic_number", "fr1.callstack_crc_1", "fr1.callstack_crc_3", "fr1.exception_class", "fr1.exception_message", "fr1.full_report", "fr1.screenshot_filename", "fr1.ts", "fr1.duplicate_of", "fr1.actief", "fr1.commentaar", "fr1.bugzilla", "fr1.attachment_filename", "fr1.version_according_to_datetime", "fr1.program_according_to_full_report", "fr1.date", "fr2.id", "fr2.program", "fr2.version", "fr2.lic_bedrijf", "fr2.lic_plaats", "fr2.lic_number", "fr2.callstack_crc_1", "fr2.callstack_crc_3", "fr2.exception_class", "fr2.exception_message", "fr2.full_report", "fr2.screenshot_filename", "fr2.ts", "fr2.duplicate_of", "fr2.actief", "fr2.commentaar", "fr2.bugzilla", "fr2.attachment_filename", "fr2.version_according_to_datetime", "fr2.program_according_to_full_report", "fr2.date"],
|
||||
"Plans": [
|
||||
{
|
||||
"Node Type": "Nested Loop",
|
||||
"Parent Relationship": "Outer",
|
||||
"Parallel Aware": false,
|
||||
"Join Type": "Inner",
|
||||
"Startup Cost": 0.42,
|
||||
"Total Cost": 103148.97,
|
||||
"Plan Rows": 493512899,
|
||||
"Plan Width": 830,
|
||||
"Output": ["fr1.callstack_crc_2", "fr1.id", "fr1.program", "fr1.version", "fr1.lic_bedrijf", "fr1.lic_plaats", "fr1.lic_number", "fr1.callstack_crc_1", "fr1.callstack_crc_3", "fr1.exception_class", "fr1.exception_message", "fr1.full_report", "fr1.screenshot_filename", "fr1.ts", "fr1.duplicate_of", "fr1.actief", "fr1.commentaar", "fr1.bugzilla", "fr1.attachment_filename", "fr1.version_according_to_datetime", "fr1.program_according_to_full_report", "fr1.date", "fr2.id", "fr2.program", "fr2.version", "fr2.lic_bedrijf", "fr2.lic_plaats", "fr2.lic_number", "fr2.callstack_crc_1", "fr2.callstack_crc_3", "fr2.exception_class", "fr2.exception_message", "fr2.full_report", "fr2.screenshot_filename", "fr2.ts", "fr2.duplicate_of", "fr2.actief", "fr2.commentaar", "fr2.bugzilla", "fr2.attachment_filename", "fr2.version_according_to_datetime", "fr2.program_according_to_full_report", "fr2.date"],
|
||||
"Plans": [
|
||||
{
|
||||
"Node Type": "Seq Scan",
|
||||
"Parent Relationship": "Outer",
|
||||
"Parallel Aware": false,
|
||||
"Relation Name": "foutrapport",
|
||||
"Schema": "public",
|
||||
"Alias": "fr1",
|
||||
"Startup Cost": 0.00,
|
||||
"Total Cost": 6048.89,
|
||||
"Plan Rows": 105489,
|
||||
"Plan Width": 419,
|
||||
"Output": ["fr1.id", "fr1.program", "fr1.version", "fr1.lic_bedrijf", "fr1.lic_plaats", "fr1.lic_number", "fr1.callstack_crc_1", "fr1.callstack_crc_2", "fr1.callstack_crc_3", "fr1.exception_class", "fr1.exception_message", "fr1.full_report", "fr1.screenshot_filename", "fr1.ts", "fr1.duplicate_of", "fr1.actief", "fr1.commentaar", "fr1.bugzilla", "fr1.attachment_filename", "fr1.version_according_to_datetime", "fr1.program_according_to_full_report", "fr1.date"]
|
||||
},
|
||||
{
|
||||
"Node Type": "Index Scan",
|
||||
"Parent Relationship": "Inner",
|
||||
"Parallel Aware": false,
|
||||
"Scan Direction": "Forward",
|
||||
"Index Name": "foutrapport_callstack_crc_2_idx",
|
||||
"Relation Name": "foutrapport",
|
||||
"Schema": "public",
|
||||
"Alias": "fr2",
|
||||
"Startup Cost": 0.42,
|
||||
"Total Cost": 0.81,
|
||||
"Plan Rows": 11,
|
||||
"Plan Width": 419,
|
||||
"Output": ["fr2.id", "fr2.program", "fr2.version", "fr2.lic_bedrijf", "fr2.lic_plaats", "fr2.lic_number", "fr2.callstack_crc_1", "fr2.callstack_crc_2", "fr2.callstack_crc_3", "fr2.exception_class", "fr2.exception_message", "fr2.full_report", "fr2.screenshot_filename", "fr2.ts", "fr2.duplicate_of", "fr2.actief", "fr2.commentaar", "fr2.bugzilla", "fr2.attachment_filename", "fr2.version_according_to_datetime", "fr2.program_according_to_full_report", "fr2.date"],
|
||||
"Index Cond": "(fr2.callstack_crc_2 = fr1.callstack_crc_2)"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]")__json__";
|
||||
|
||||
|
||||
|
||||
Json::Value root; // will contains the root value after parsing.
|
||||
Json::Reader reader;
|
||||
bool parsingSuccessful = reader.parse(input, root);
|
||||
ASSERT_TRUE(parsingSuccessful);
|
||||
auto explain = ExplainRoot::createFromJson(root);
|
||||
|
||||
ASSERT_TRUE(explain != nullptr);
|
||||
}
|
||||
73
tests/auto/mycase/tst_PasswordManager.h
Normal file
73
tests/auto/mycase/tst_PasswordManager.h
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <gmock/gmock-matchers.h>
|
||||
#include "PasswordManager.h"
|
||||
|
||||
using namespace testing;
|
||||
|
||||
|
||||
TEST(PasswordManager, initial_changeMasterPassword_returns_true)
|
||||
{
|
||||
PasswordManager pwm;
|
||||
|
||||
auto res = pwm.changeMasterPassword("", "my test passphrase");
|
||||
ASSERT_NO_THROW( res.get() );
|
||||
ASSERT_THAT( res.get(), Eq(true) );
|
||||
}
|
||||
|
||||
TEST(PasswordManager, unlock_succeeds)
|
||||
{
|
||||
PasswordManager pwm;
|
||||
|
||||
std::string passphrase = "my test passphrase";
|
||||
|
||||
auto res = pwm.changeMasterPassword("", passphrase);
|
||||
ASSERT_NO_THROW( res.get() );
|
||||
ASSERT_THAT( res.get(), Eq(true) );
|
||||
|
||||
auto res2 = pwm.unlock(passphrase);
|
||||
ASSERT_NO_THROW( res2.get() );
|
||||
ASSERT_THAT( res2.get(), Eq(true) );
|
||||
}
|
||||
|
||||
TEST(PasswordManager, unlock_fails)
|
||||
{
|
||||
PasswordManager pwm;
|
||||
|
||||
std::string passphrase = "my test passphrase";
|
||||
|
||||
auto res = pwm.changeMasterPassword("", passphrase);
|
||||
ASSERT_NO_THROW( res.get() );
|
||||
ASSERT_THAT( res.get(), Eq(true) );
|
||||
|
||||
auto res2 = pwm.unlock(passphrase + "2");
|
||||
ASSERT_NO_THROW( res2.get() );
|
||||
ASSERT_THAT( res2.get(), Eq(false) );
|
||||
}
|
||||
|
||||
TEST(PasswordManager, test_save_get)
|
||||
{
|
||||
PasswordManager pwm;
|
||||
|
||||
std::string passphrase = "my test passphrase";
|
||||
|
||||
auto res = pwm.changeMasterPassword("", passphrase);
|
||||
ASSERT_NO_THROW( res.get() );
|
||||
ASSERT_THAT( res.get(), Eq(true) );
|
||||
|
||||
// auto res2 = pwm.unlock(passphrase + "2");
|
||||
// ASSERT_NO_THROW( res2.get() );
|
||||
// ASSERT_THAT( res2.get(), Eq(false) );
|
||||
|
||||
const std::string password = "password123";
|
||||
const std::string key = "abc";
|
||||
|
||||
auto res2 = pwm.savePassword(key, password);
|
||||
ASSERT_THAT( res2.valid(), Eq(true) );
|
||||
|
||||
std::string result;
|
||||
auto res3 = pwm.getPassword(key, result);
|
||||
ASSERT_THAT( res3.valid(), Eq(true) );
|
||||
ASSERT_THAT( res3.get(), Eq(true) );
|
||||
ASSERT_THAT( result, Eq(password) );
|
||||
|
||||
}
|
||||
38
tests/auto/mycase/tst_SqlLexer.h
Normal file
38
tests/auto/mycase/tst_SqlLexer.h
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <gmock/gmock-matchers.h>
|
||||
#include "SqlLexer.h"
|
||||
|
||||
using namespace testing;
|
||||
|
||||
|
||||
TEST(SqlLexer, lexer)
|
||||
{
|
||||
QString input = " SELECT ";
|
||||
SqlLexer lexer(input, LexerState::Null);
|
||||
|
||||
int startpos, length;
|
||||
BasicTokenType tokentype;
|
||||
QString out;
|
||||
lexer.nextBasicToken(startpos, length, tokentype, out);
|
||||
|
||||
ASSERT_THAT(startpos, Eq(1));
|
||||
ASSERT_THAT(length, Eq(6));
|
||||
ASSERT_THAT(tokentype, Eq(BasicTokenType::Symbol));
|
||||
ASSERT_THAT( out, Eq(QString("SELECT")) );
|
||||
}
|
||||
|
||||
TEST(SqlLexer, lexer_quote_in_string)
|
||||
{
|
||||
QString input = " 'abc''def' ";
|
||||
SqlLexer lexer(input, LexerState::Null);
|
||||
|
||||
int startpos, length;
|
||||
BasicTokenType tokentype;
|
||||
QString out;
|
||||
lexer.nextBasicToken(startpos, length, tokentype, out);
|
||||
|
||||
ASSERT_THAT(startpos, Eq(1));
|
||||
ASSERT_THAT(length, Eq(10));
|
||||
ASSERT_THAT(tokentype, Eq(BasicTokenType::QuotedString));
|
||||
}
|
||||
|
||||
203
tests/auto/mycase/tst_expected.h
Normal file
203
tests/auto/mycase/tst_expected.h
Normal file
|
|
@ -0,0 +1,203 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <gmock/gmock-matchers.h>
|
||||
#include "Expected.h"
|
||||
|
||||
using namespace testing;
|
||||
|
||||
Expected<int> getAnswerToEverything() { return 42; }
|
||||
|
||||
TEST(expected, valid_when_valid_returns_true)
|
||||
{
|
||||
Expected<int> v = getAnswerToEverything();
|
||||
ASSERT_THAT(v.valid(), Eq(true));
|
||||
}
|
||||
|
||||
TEST(expected, get_when_valid_returns_value)
|
||||
{
|
||||
Expected<int> v = getAnswerToEverything();
|
||||
ASSERT_THAT(v.get(), Eq(42));
|
||||
}
|
||||
|
||||
TEST(expected, hasException_when_valid_returns_false)
|
||||
{
|
||||
Expected<int> v = getAnswerToEverything();
|
||||
ASSERT_THAT(v.hasException<std::exception>(), Eq(false));
|
||||
}
|
||||
|
||||
TEST(expected, T_fromException_is_not_valid)
|
||||
{
|
||||
auto e = Expected<int>::fromException(std::runtime_error("hello"));
|
||||
ASSERT_THAT(e.valid(), Eq(false));
|
||||
}
|
||||
|
||||
TEST(expected, T_fromException_get_thows)
|
||||
{
|
||||
auto e = Expected<int>::fromException(std::runtime_error("hello"));
|
||||
ASSERT_THROW (e.get(), std::runtime_error);
|
||||
}
|
||||
|
||||
TEST(expected, T_fromException_has_exception_true)
|
||||
{
|
||||
auto e = Expected<int>::fromException(std::runtime_error("hello"));
|
||||
ASSERT_THAT(e.hasException<std::runtime_error>(), Eq(true));
|
||||
}
|
||||
|
||||
TEST(expected, T_fromException_has_exception_false)
|
||||
{
|
||||
auto e = Expected<int>::fromException(std::runtime_error("hello"));
|
||||
ASSERT_THAT(e.hasException<std::logic_error>(), Eq(false));
|
||||
}
|
||||
|
||||
TEST(expected, T_fromException_has_derived_exception)
|
||||
{
|
||||
auto e = Expected<int>::fromException(std::runtime_error("hello"));
|
||||
ASSERT_THAT(e.hasException<std::exception>(), Eq(true));
|
||||
}
|
||||
|
||||
TEST(expected, T_fromCode_is_valid)
|
||||
{
|
||||
auto e = Expected<int>::fromCode([]() -> int { return 42; });
|
||||
ASSERT_THAT(e.valid(), Eq(true));
|
||||
}
|
||||
|
||||
TEST(expected, T_fromCode_get)
|
||||
{
|
||||
auto e = Expected<int>::fromCode([]() -> int { return 42; });
|
||||
ASSERT_THAT(e.get(), Eq(42));
|
||||
}
|
||||
|
||||
|
||||
TEST(expected, T_fromCode_E_is_not_valid)
|
||||
{
|
||||
auto e = Expected<int>::fromCode([]() -> int { throw std::runtime_error("hello"); });
|
||||
ASSERT_THAT(e.valid(), Eq(false));
|
||||
}
|
||||
|
||||
TEST(expected, T_fromCode_E_get_thows)
|
||||
{
|
||||
auto e = Expected<int>::fromCode([]() -> int { throw std::runtime_error("hello"); });
|
||||
ASSERT_THROW (e.get(), std::runtime_error);
|
||||
}
|
||||
|
||||
TEST(expected, T_fromCode_E_has_exception_true)
|
||||
{
|
||||
auto e = Expected<int>::fromCode([]() -> int { throw std::runtime_error("hello"); });
|
||||
ASSERT_THAT(e.hasException<std::runtime_error>(), Eq(true));
|
||||
}
|
||||
|
||||
TEST(expected, T_fromCode_E_has_exception_false)
|
||||
{
|
||||
auto e = Expected<int>::fromCode([]() -> int { throw std::runtime_error("hello"); });
|
||||
ASSERT_THAT(e.hasException<std::logic_error>(), Eq(false));
|
||||
}
|
||||
|
||||
TEST(expected, T_fromCode_E_has_derived_exception)
|
||||
{
|
||||
auto e = Expected<int>::fromCode([]() -> int { throw std::runtime_error("hello"); });
|
||||
ASSERT_THAT(e.hasException<std::exception>(), Eq(true));
|
||||
}
|
||||
|
||||
//Expected<int> getIntWithStdRuntimeError() { return Expected<void>(); }
|
||||
|
||||
Expected<void> getNothing() { return Expected<void>(); }
|
||||
|
||||
|
||||
TEST(expected_void, valid_when_valid_returns_true)
|
||||
{
|
||||
Expected<void> v = getNothing();
|
||||
ASSERT_THAT(v.valid(), Eq(true));
|
||||
}
|
||||
|
||||
TEST(expected_void, get_when_valid_returns_value)
|
||||
{
|
||||
Expected<void> v = getNothing();
|
||||
ASSERT_NO_THROW(v.get());
|
||||
}
|
||||
|
||||
TEST(expected_void, hasException_when_valid_returns_false)
|
||||
{
|
||||
Expected<void> v = getNothing();
|
||||
ASSERT_THAT(v.hasException<std::exception>(), Eq(false));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
TEST(expected_void, void_fromException_is_not_valid)
|
||||
{
|
||||
auto e = Expected<void>::fromException(std::runtime_error("hello"));
|
||||
ASSERT_THAT(e.valid(), Eq(false));
|
||||
}
|
||||
|
||||
TEST(expected_void, void_fromException_get_thows)
|
||||
{
|
||||
auto e = Expected<void>::fromException(std::runtime_error("hello"));
|
||||
ASSERT_THROW (e.get(), std::runtime_error);
|
||||
}
|
||||
|
||||
TEST(expected_void, void_fromException_has_exception_true)
|
||||
{
|
||||
auto e = Expected<void>::fromException(std::runtime_error("hello"));
|
||||
ASSERT_THAT(e.hasException<std::runtime_error>(), Eq(true));
|
||||
}
|
||||
|
||||
TEST(expected_void, void_fromException_has_exception_false)
|
||||
{
|
||||
auto e = Expected<void>::fromException(std::runtime_error("hello"));
|
||||
ASSERT_THAT(e.hasException<std::logic_error>(), Eq(false));
|
||||
}
|
||||
|
||||
TEST(expected_void, void_fromException_has_derived_exception)
|
||||
{
|
||||
auto e = Expected<void>::fromException(std::runtime_error("hello"));
|
||||
ASSERT_THAT(e.hasException<std::exception>(), Eq(true));
|
||||
}
|
||||
|
||||
TEST(expected_void, void_fromCode_is_valid)
|
||||
{
|
||||
auto e = Expected<void>::fromCode([]() -> void { });
|
||||
ASSERT_THAT(e.valid(), Eq(true));
|
||||
}
|
||||
|
||||
TEST(expected_void, void_fromCode_get)
|
||||
{
|
||||
auto e = Expected<void>::fromCode([]() -> void { });
|
||||
ASSERT_NO_THROW(e.get());
|
||||
}
|
||||
|
||||
void expected_void_throws_func()
|
||||
{
|
||||
throw std::runtime_error("hello");
|
||||
}
|
||||
|
||||
TEST(expected_void, void_fromCode_E_is_not_valid)
|
||||
{
|
||||
auto e = Expected<void>::fromCode(expected_void_throws_func);
|
||||
ASSERT_THAT(e.valid(), Eq(false));
|
||||
}
|
||||
|
||||
TEST(expected_void, void_fromCode_E_get_thows)
|
||||
{
|
||||
auto e = Expected<void>::fromCode(expected_void_throws_func);
|
||||
ASSERT_THROW (e.get(), std::runtime_error);
|
||||
}
|
||||
|
||||
TEST(expected_void, void_fromCode_E_has_exception_true)
|
||||
{
|
||||
auto e = Expected<void>::fromCode(expected_void_throws_func);
|
||||
ASSERT_THAT(e.hasException<std::runtime_error>(), Eq(true));
|
||||
}
|
||||
|
||||
TEST(expected_void, void_fromCode_E_has_exception_false)
|
||||
{
|
||||
auto e = Expected<void>::fromCode(expected_void_throws_func);
|
||||
ASSERT_THAT(e.hasException<std::logic_error>(), Eq(false));
|
||||
}
|
||||
|
||||
TEST(expected_void, void_fromCode_E_has_derived_exception)
|
||||
{
|
||||
auto e = Expected<void>::fromCode(expected_void_throws_func);
|
||||
ASSERT_THAT(e.hasException<std::exception>(), Eq(true));
|
||||
}
|
||||
63
tests/auto/mycase/tst_scopeguard.h
Normal file
63
tests/auto/mycase/tst_scopeguard.h
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <gmock/gmock-matchers.h>
|
||||
#include "ScopeGuard.h"
|
||||
|
||||
using namespace testing;
|
||||
|
||||
|
||||
TEST(ScopeGuard, normal_run_fun_on_destruction_1)
|
||||
{
|
||||
bool result = false;
|
||||
auto sg = scopeGuard([&result]() { result = true; });
|
||||
ASSERT_THAT(result, Eq(false));
|
||||
}
|
||||
|
||||
TEST(ScopeGuard, normal_run_fun_on_destruction_2)
|
||||
{
|
||||
bool result = false;
|
||||
{
|
||||
auto sg = scopeGuard([&result]() { result = true; });
|
||||
}
|
||||
|
||||
ASSERT_EQ(result, true);
|
||||
}
|
||||
|
||||
TEST(ScopeGuard, dismiss)
|
||||
{
|
||||
bool result = false;
|
||||
{
|
||||
auto sg = scopeGuard([&result]() { result = true; });
|
||||
sg.dismiss();
|
||||
}
|
||||
|
||||
ASSERT_THAT(result, Eq(false));
|
||||
}
|
||||
|
||||
TEST(ScopeGuard, SCOPE_EXIT_macro_1)
|
||||
{
|
||||
bool result = false;
|
||||
{
|
||||
SCOPE_EXIT { result = true; };
|
||||
ASSERT_THAT(result, Eq(false)); // prove previous statement hasn't run yet
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST(ScopeGuard, SCOPE_EXIT_macro_2)
|
||||
{
|
||||
bool result = false;
|
||||
{
|
||||
SCOPE_EXIT { result = true; };
|
||||
}
|
||||
|
||||
ASSERT_THAT(result, Eq(true));
|
||||
}
|
||||
|
||||
|
||||
|
||||
//TEST(expected, get_when_valid_returns_value)
|
||||
//{
|
||||
// Expected<int> v = getAnswerToEverything();
|
||||
// ASSERT_THAT(v.get(), Eq(42));
|
||||
//}
|
||||
|
||||
9
tests/mygtestutils/PrintTo_Qt.cpp
Normal file
9
tests/mygtestutils/PrintTo_Qt.cpp
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#include "PrintTo_Qt.h"
|
||||
|
||||
void PrintTo(const QDateTime &dt, ::std::ostream* os) {
|
||||
*os << dt.toString(Qt::ISODateWithMs).toUtf8().toStdString();
|
||||
}
|
||||
|
||||
void PrintTo(const QString &s, ::std::ostream* os) {
|
||||
*os << s.toUtf8().toStdString();
|
||||
}
|
||||
11
tests/mygtestutils/PrintTo_Qt.h
Normal file
11
tests/mygtestutils/PrintTo_Qt.h
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#ifndef PRINTTO_QT_H
|
||||
#define PRINTTO_QT_H
|
||||
|
||||
#include <ostream>
|
||||
#include <QDateTime>
|
||||
#include <QString>
|
||||
|
||||
void PrintTo(const QDateTime &dt, ::std::ostream* os);
|
||||
void PrintTo(const QString &s, ::std::ostream* os);
|
||||
|
||||
#endif // PRINTTO_QT_H
|
||||
32
tests/mygtestutils/mygtestutils.pro
Normal file
32
tests/mygtestutils/mygtestutils.pro
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2017-12-01T10:07:31
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT -= gui
|
||||
|
||||
TARGET = mygtestutils
|
||||
TEMPLATE = lib
|
||||
CONFIG += staticlib
|
||||
|
||||
# The following define makes your compiler emit warnings if you use
|
||||
# any feature of Qt which has been marked as deprecated (the exact warnings
|
||||
# depend on your compiler). Please consult the documentation of the
|
||||
# deprecated API in order to know how to port your code away from it.
|
||||
DEFINES += QT_DEPRECATED_WARNINGS
|
||||
|
||||
# You can also make your code fail to compile if you use deprecated APIs.
|
||||
# In order to do so, uncomment the following line.
|
||||
# You can also select to disable deprecated APIs only up to a certain version of Qt.
|
||||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||
|
||||
SOURCES += \
|
||||
PrintTo_Qt.cpp
|
||||
|
||||
HEADERS += \
|
||||
PrintTo_Qt.h
|
||||
unix {
|
||||
target.path = /usr/lib
|
||||
INSTALLS += target
|
||||
}
|
||||
5
tests/tests.pro
Normal file
5
tests/tests.pro
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
TEMPLATE = subdirs
|
||||
|
||||
SUBDIRS += auto \
|
||||
PgsqlTests \
|
||||
mygtestutils
|
||||
Loading…
Add table
Add a link
Reference in a new issue