Added the test to CMakeLists.txt, all tests OK.
This commit is contained in:
parent
cb0ef0b130
commit
4c658d7811
12 changed files with 34 additions and 80 deletions
|
|
@ -1,13 +0,0 @@
|
|||
#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();
|
||||
}
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
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
|
||||
|
||||
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
|
||||
|
|
@ -1,113 +0,0 @@
|
|||
#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));
|
||||
}
|
||||
|
|
@ -1,73 +0,0 @@
|
|||
#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) );
|
||||
|
||||
}
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
#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));
|
||||
}
|
||||
|
||||
|
|
@ -1,203 +0,0 @@
|
|||
#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));
|
||||
}
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
#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_THAT(result, Eq(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));
|
||||
//}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue