Builds on windows again
This commit is contained in:
parent
33cf39b799
commit
bebb3391c3
160 changed files with 138 additions and 117 deletions
8
core/test/main.cpp
Normal file
8
core/test/main.cpp
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#include <gtest/gtest.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
113
core/test/tst_CsvWriter.cpp
Normal file
113
core/test/tst_CsvWriter.cpp
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_EQ(result, 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_EQ(result, 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_EQ(result, 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_EQ(result, 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_EQ(result, 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_EQ(result, 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_EQ(result, expected);
|
||||
}
|
||||
72
core/test/tst_PasswordManager.cpp
Normal file
72
core/test/tst_PasswordManager.cpp
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
#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_TRUE(res.get());
|
||||
}
|
||||
|
||||
TEST(PasswordManager, unlock_succeeds)
|
||||
{
|
||||
PasswordManager pwm;
|
||||
|
||||
std::string passphrase = "my test passphrase";
|
||||
|
||||
auto res = pwm.changeMasterPassword("", passphrase);
|
||||
ASSERT_NO_THROW( res.get() );
|
||||
ASSERT_TRUE(res.get());
|
||||
|
||||
auto res2 = pwm.unlock(passphrase);
|
||||
ASSERT_NO_THROW( res2.get() );
|
||||
ASSERT_TRUE(res2.get());
|
||||
}
|
||||
|
||||
TEST(PasswordManager, unlock_fails)
|
||||
{
|
||||
PasswordManager pwm;
|
||||
|
||||
std::string passphrase = "my test passphrase";
|
||||
|
||||
auto res = pwm.changeMasterPassword("", passphrase);
|
||||
ASSERT_NO_THROW(res.get());
|
||||
ASSERT_TRUE(res.get());
|
||||
|
||||
auto res2 = pwm.unlock(passphrase + "2");
|
||||
ASSERT_NO_THROW(res2.get());
|
||||
ASSERT_FALSE(res2.get());
|
||||
}
|
||||
|
||||
TEST(PasswordManager, test_save_get)
|
||||
{
|
||||
PasswordManager pwm;
|
||||
|
||||
std::string passphrase = "my test passphrase";
|
||||
|
||||
auto res = pwm.changeMasterPassword("", passphrase);
|
||||
ASSERT_NO_THROW( res.get() );
|
||||
ASSERT_TRUE(res.get());
|
||||
|
||||
// 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_TRUE(res2.valid());
|
||||
|
||||
std::string result;
|
||||
auto res3 = pwm.getPassword(key, result);
|
||||
ASSERT_TRUE(res3.valid());
|
||||
ASSERT_TRUE(res3.get());
|
||||
ASSERT_EQ(result, password);
|
||||
}
|
||||
38
core/test/tst_SqlLexer.cpp
Normal file
38
core/test/tst_SqlLexer.cpp
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_EQ(startpos, 1);
|
||||
ASSERT_EQ(length, 6);
|
||||
ASSERT_EQ(tokentype, BasicTokenType::Symbol);
|
||||
ASSERT_EQ( out, 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_EQ(startpos, 1);
|
||||
ASSERT_EQ(length, 10);
|
||||
ASSERT_EQ(tokentype, BasicTokenType::QuotedString);
|
||||
}
|
||||
|
||||
226
core/test/tst_expected.cpp
Normal file
226
core/test/tst_expected.cpp
Normal file
|
|
@ -0,0 +1,226 @@
|
|||
#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_TRUE(v.valid());
|
||||
}
|
||||
|
||||
TEST(expected, get_when_valid_returns_value)
|
||||
{
|
||||
Expected<int> v = getAnswerToEverything();
|
||||
ASSERT_EQ(v.get(), 42);
|
||||
}
|
||||
|
||||
TEST(expected, get_when_valid_returns_value_copycon)
|
||||
{
|
||||
Expected<int> t = getAnswerToEverything();
|
||||
Expected<int> v(t);
|
||||
ASSERT_TRUE(v.valid());
|
||||
ASSERT_EQ(v.get(), 42);
|
||||
}
|
||||
|
||||
TEST(expected, hasException_when_valid_returns_false)
|
||||
{
|
||||
Expected<int> v = getAnswerToEverything();
|
||||
ASSERT_FALSE(v.hasException<std::exception>());
|
||||
}
|
||||
|
||||
TEST(expected, T_fromException_is_not_valid)
|
||||
{
|
||||
auto e = Expected<int>::fromException(std::runtime_error("hello"));
|
||||
ASSERT_FALSE(e.valid());
|
||||
}
|
||||
|
||||
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_get_thows_copycon)
|
||||
{
|
||||
auto f = Expected<int>::fromException(std::runtime_error("hello"));
|
||||
auto e(f);
|
||||
ASSERT_THROW (e.get(), std::runtime_error);
|
||||
}
|
||||
|
||||
TEST(expected, T_fromException_has_exception_true)
|
||||
{
|
||||
auto e = Expected<int>::fromException(std::runtime_error("hello"));
|
||||
ASSERT_TRUE(e.hasException<std::runtime_error>());
|
||||
}
|
||||
|
||||
TEST(expected, T_fromException_has_exception_false)
|
||||
{
|
||||
auto e = Expected<int>::fromException(std::runtime_error("hello"));
|
||||
ASSERT_FALSE(e.hasException<std::logic_error>());
|
||||
}
|
||||
|
||||
TEST(expected, T_fromException_has_derived_exception)
|
||||
{
|
||||
auto e = Expected<int>::fromException(std::runtime_error("hello"));
|
||||
ASSERT_TRUE(e.hasException<std::exception>());
|
||||
}
|
||||
|
||||
TEST(expected, T_fromCode_is_valid)
|
||||
{
|
||||
auto e = Expected<int>::fromCode([]() -> int { return 42; });
|
||||
ASSERT_TRUE(e.valid());
|
||||
}
|
||||
|
||||
TEST(expected, T_fromCode_get)
|
||||
{
|
||||
auto e = Expected<int>::fromCode([]() -> int { return 42; });
|
||||
ASSERT_EQ(e.get(), 42);
|
||||
}
|
||||
|
||||
|
||||
TEST(expected, T_fromCode_E_is_not_valid)
|
||||
{
|
||||
auto e = Expected<int>::fromCode([]() -> int { throw std::runtime_error("hello"); });
|
||||
ASSERT_FALSE(e.valid());
|
||||
}
|
||||
|
||||
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_TRUE(e.hasException<std::runtime_error>());
|
||||
}
|
||||
|
||||
TEST(expected, T_fromCode_E_has_exception_false)
|
||||
{
|
||||
auto e = Expected<int>::fromCode([]() -> int { throw std::runtime_error("hello"); });
|
||||
ASSERT_FALSE(e.hasException<std::logic_error>());
|
||||
}
|
||||
|
||||
TEST(expected, T_fromCode_E_has_derived_exception)
|
||||
{
|
||||
auto e = Expected<int>::fromCode([]() -> int { throw std::runtime_error("hello"); });
|
||||
ASSERT_TRUE(e.hasException<std::exception>());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//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_TRUE(v.valid());
|
||||
}
|
||||
|
||||
TEST(expected_void, get_when_valid_returns_value)
|
||||
{
|
||||
Expected<void> v = getNothing();
|
||||
ASSERT_NO_THROW(v.get());
|
||||
}
|
||||
|
||||
TEST(expected_void, get_when_valid_returns_value_copycon)
|
||||
{
|
||||
Expected<void> t = getNothing();
|
||||
auto v(t);
|
||||
ASSERT_TRUE(v.valid());
|
||||
ASSERT_NO_THROW(v.get());
|
||||
}
|
||||
|
||||
TEST(expected_void, hasException_when_valid_returns_false)
|
||||
{
|
||||
Expected<void> v = getNothing();
|
||||
ASSERT_FALSE(v.hasException<std::exception>());
|
||||
}
|
||||
|
||||
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
core/test/tst_scopeguard.cpp
Normal file
63
core/test/tst_scopeguard.cpp
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_FALSE(result);
|
||||
}
|
||||
|
||||
TEST(ScopeGuard, normal_run_fun_on_destruction_2)
|
||||
{
|
||||
bool result = false;
|
||||
{
|
||||
auto sg = scopeGuard([&result]() { result = true; });
|
||||
}
|
||||
|
||||
ASSERT_TRUE(result);
|
||||
}
|
||||
|
||||
TEST(ScopeGuard, dismiss)
|
||||
{
|
||||
bool result = false;
|
||||
{
|
||||
auto sg = scopeGuard([&result]() { result = true; });
|
||||
sg.dismiss();
|
||||
}
|
||||
|
||||
ASSERT_FALSE(result);
|
||||
}
|
||||
|
||||
TEST(ScopeGuard, SCOPE_EXIT_macro_1)
|
||||
{
|
||||
bool result = false;
|
||||
{
|
||||
SCOPE_EXIT { result = true; };
|
||||
ASSERT_FALSE(result); // prove previous statement hasn't run yet
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST(ScopeGuard, SCOPE_EXIT_macro_2)
|
||||
{
|
||||
bool result = false;
|
||||
{
|
||||
SCOPE_EXIT { result = true; };
|
||||
}
|
||||
|
||||
ASSERT_TRUE(result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//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