add password hash test (#4528)
* clangify tests * add password hash test * properly use googletest semantics
This commit is contained in:
parent
f6634de18d
commit
1e70989f38
8 changed files with 125 additions and 81 deletions
|
@ -1,11 +1,13 @@
|
||||||
enable_testing()
|
enable_testing()
|
||||||
add_test(NAME dummy_test COMMAND dummy_test)
|
add_test(NAME dummy_test COMMAND dummy_test)
|
||||||
add_test(NAME expression_test COMMAND expression_test)
|
add_test(NAME expression_test COMMAND expression_test)
|
||||||
|
add_test(NAME password_hash_test COMMAND password_hash_test)
|
||||||
|
|
||||||
# Find GTest
|
# Find GTest
|
||||||
|
|
||||||
add_executable(dummy_test dummy_test.cpp)
|
add_executable(dummy_test dummy_test.cpp)
|
||||||
add_executable(expression_test expression_test.cpp)
|
add_executable(expression_test expression_test.cpp)
|
||||||
|
add_executable(password_hash_test password_hash_test.cpp)
|
||||||
|
|
||||||
find_package(GTest)
|
find_package(GTest)
|
||||||
|
|
||||||
|
@ -35,6 +37,7 @@ if(NOT GTEST_FOUND)
|
||||||
SET(GTEST_BOTH_LIBRARIES gtest)
|
SET(GTEST_BOTH_LIBRARIES gtest)
|
||||||
add_dependencies(dummy_test gtest)
|
add_dependencies(dummy_test gtest)
|
||||||
add_dependencies(expression_test gtest)
|
add_dependencies(expression_test gtest)
|
||||||
|
add_dependencies(password_hash_test gtest)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
find_package(Qt5 COMPONENTS Widgets REQUIRED)
|
find_package(Qt5 COMPONENTS Widgets REQUIRED)
|
||||||
|
@ -44,6 +47,7 @@ set(TEST_QT_MODULES Qt5::Widgets)
|
||||||
include_directories(${GTEST_INCLUDE_DIRS})
|
include_directories(${GTEST_INCLUDE_DIRS})
|
||||||
target_link_libraries(dummy_test Threads::Threads ${GTEST_BOTH_LIBRARIES})
|
target_link_libraries(dummy_test Threads::Threads ${GTEST_BOTH_LIBRARIES})
|
||||||
target_link_libraries(expression_test cockatrice_common Threads::Threads ${GTEST_BOTH_LIBRARIES} ${TEST_QT_MODULES})
|
target_link_libraries(expression_test cockatrice_common Threads::Threads ${GTEST_BOTH_LIBRARIES} ${TEST_QT_MODULES})
|
||||||
|
target_link_libraries(password_hash_test cockatrice_common Threads::Threads ${GTEST_BOTH_LIBRARIES} ${TEST_QT_MODULES})
|
||||||
|
|
||||||
add_subdirectory(carddatabase)
|
add_subdirectory(carddatabase)
|
||||||
add_subdirectory(loading_from_clipboard)
|
add_subdirectory(loading_from_clipboard)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "gtest/gtest.h"
|
|
||||||
|
|
||||||
#include "mocks.h"
|
#include "mocks.h"
|
||||||
|
|
||||||
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -1,23 +1,25 @@
|
||||||
#include "gtest/gtest.h"
|
|
||||||
#include "../../cockatrice/src/filter_string.h"
|
#include "../../cockatrice/src/filter_string.h"
|
||||||
#include "mocks.h"
|
#include "mocks.h"
|
||||||
|
|
||||||
|
#include "gtest/gtest.h"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
CardDatabase *db;
|
CardDatabase *db;
|
||||||
|
|
||||||
#define Query(name, card, query, match) \
|
#define QUERY(name, card, query, match) \
|
||||||
TEST_F(CardQuery, name) {\
|
TEST_F(CardQuery, name) \
|
||||||
ASSERT_EQ(FilterString(query).check(card), match);\
|
{ \
|
||||||
}
|
ASSERT_EQ(FilterString(query).check(card), match); \
|
||||||
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
class CardQuery : public ::testing::Test {
|
class CardQuery : public ::testing::Test
|
||||||
protected:
|
{
|
||||||
void SetUp() override {
|
protected:
|
||||||
|
void SetUp() override
|
||||||
|
{
|
||||||
cat = db->getCardBySimpleName("Cat");
|
cat = db->getCardBySimpleName("Cat");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,32 +28,32 @@ class CardQuery : public ::testing::Test {
|
||||||
CardData cat;
|
CardData cat;
|
||||||
};
|
};
|
||||||
|
|
||||||
Query(Empty, cat, "", true)
|
QUERY(Empty, cat, "", true)
|
||||||
Query(Typing, cat, "t", true)
|
QUERY(Typing, cat, "t", true)
|
||||||
|
|
||||||
Query(NonMatchingType, cat, "t:kithkin", false)
|
QUERY(NonMatchingType, cat, "t:kithkin", false)
|
||||||
Query(MatchingType, cat, "t:creature", true)
|
QUERY(MatchingType, cat, "t:creature", true)
|
||||||
Query(Not1, cat, "not t:kithkin", true)
|
QUERY(Not1, cat, "not t:kithkin", true)
|
||||||
Query(Not2, cat, "not t:creature", false)
|
QUERY(Not2, cat, "not t:creature", false)
|
||||||
Query(Case, cat, "t:cReAtUrE", true)
|
QUERY(Case, cat, "t:cReAtUrE", true)
|
||||||
|
|
||||||
Query(And, cat, "t:creature t:creature", true)
|
QUERY(And, cat, "t:creature t:creature", true)
|
||||||
Query(And2, cat, "t:creature t:sorcery", false)
|
QUERY(And2, cat, "t:creature t:sorcery", false)
|
||||||
|
|
||||||
Query(Or, cat, "t:bat or t:creature", true)
|
QUERY(Or, cat, "t:bat or t:creature", true)
|
||||||
|
|
||||||
Query(Cmc1, cat, "cmc=2", true)
|
QUERY(Cmc1, cat, "cmc=2", true)
|
||||||
Query(Cmc2, cat, "cmc>3", false)
|
QUERY(Cmc2, cat, "cmc>3", false)
|
||||||
Query(Cmc3, cat, "cmc>1", true)
|
QUERY(Cmc3, cat, "cmc>1", true)
|
||||||
|
|
||||||
Query(Quotes, cat, "t:\"creature\"", true);
|
QUERY(Quotes, cat, "t:\"creature\"", true)
|
||||||
|
|
||||||
Query(Field, cat, "pt:\"3/3\"", true)
|
QUERY(Field, cat, "pt:\"3/3\"", true)
|
||||||
|
|
||||||
Query(Color1, cat, "c:g", true);
|
QUERY(Color1, cat, "c:g", true)
|
||||||
Query(Color2, cat, "c:gw", true);
|
QUERY(Color2, cat, "c:gw", true)
|
||||||
Query(Color3, cat, "c!g", true);
|
QUERY(Color3, cat, "c!g", true)
|
||||||
Query(Color4, cat, "c!gw", false);
|
QUERY(Color4, cat, "c!gw", false)
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
|
|
@ -41,14 +41,9 @@ QString SettingsCache::getSafeConfigFilePath(QString /* configEntry */, QString
|
||||||
return defaultPath;
|
return defaultPath;
|
||||||
}
|
}
|
||||||
SettingsCache::SettingsCache()
|
SettingsCache::SettingsCache()
|
||||||
: settings{new QSettings("global.ini", QSettings::IniFormat, this)},
|
: settings{new QSettings("global.ini", QSettings::IniFormat, this)}, shortcutsSettings{nullptr},
|
||||||
shortcutsSettings{nullptr},
|
cardDatabaseSettings{new CardDatabaseSettings("", this)}, serversSettings{nullptr}, messageSettings{nullptr},
|
||||||
cardDatabaseSettings{new CardDatabaseSettings("", this)},
|
gameFiltersSettings{nullptr}, layoutsSettings{nullptr}, downloadSettings{nullptr},
|
||||||
serversSettings{nullptr},
|
|
||||||
messageSettings{nullptr},
|
|
||||||
gameFiltersSettings{nullptr},
|
|
||||||
layoutsSettings{nullptr},
|
|
||||||
downloadSettings{nullptr},
|
|
||||||
cardDatabasePath{QString("%1/cards.xml").arg(CARDDB_DATADIR)},
|
cardDatabasePath{QString("%1/cards.xml").arg(CARDDB_DATADIR)},
|
||||||
customCardDatabasePath{QString("%1/customsets/").arg(CARDDB_DATADIR)},
|
customCardDatabasePath{QString("%1/customsets/").arg(CARDDB_DATADIR)},
|
||||||
spoilerDatabasePath{QString("%1/spoiler.xml").arg(CARDDB_DATADIR)},
|
spoilerDatabasePath{QString("%1/spoiler.xml").arg(CARDDB_DATADIR)},
|
||||||
|
@ -58,13 +53,13 @@ SettingsCache::SettingsCache()
|
||||||
void SettingsCache::setUseTearOffMenus(bool /* _useTearOffMenus */)
|
void SettingsCache::setUseTearOffMenus(bool /* _useTearOffMenus */)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void SettingsCache::setKnownMissingFeatures(const QString &/* _knownMissingFeatures */)
|
void SettingsCache::setKnownMissingFeatures(const QString & /* _knownMissingFeatures */)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void SettingsCache::setCardInfoViewMode(const int /* _viewMode */)
|
void SettingsCache::setCardInfoViewMode(const int /* _viewMode */)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void SettingsCache::setHighlightWords(const QString &/* _highlightWords */)
|
void SettingsCache::setHighlightWords(const QString & /* _highlightWords */)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void SettingsCache::setMasterVolume(int /* _masterVolume */)
|
void SettingsCache::setMasterVolume(int /* _masterVolume */)
|
||||||
|
@ -85,40 +80,40 @@ void SettingsCache::setShowMentionPopups(const int /* _showMentionPopus */)
|
||||||
void SettingsCache::setRoomHistory(const int /* _roomHistory */)
|
void SettingsCache::setRoomHistory(const int /* _roomHistory */)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void SettingsCache::setLang(const QString &/* _lang */)
|
void SettingsCache::setLang(const QString & /* _lang */)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void SettingsCache::setShowTipsOnStartup(bool /* _showTipsOnStartup */)
|
void SettingsCache::setShowTipsOnStartup(bool /* _showTipsOnStartup */)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void SettingsCache::setSeenTips(const QList<int> &/* _seenTips */)
|
void SettingsCache::setSeenTips(const QList<int> & /* _seenTips */)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void SettingsCache::setDeckPath(const QString &/* _deckPath */)
|
void SettingsCache::setDeckPath(const QString & /* _deckPath */)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void SettingsCache::setReplaysPath(const QString &/* _replaysPath */)
|
void SettingsCache::setReplaysPath(const QString & /* _replaysPath */)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void SettingsCache::setThemesPath(const QString &/* _themesPath */)
|
void SettingsCache::setThemesPath(const QString & /* _themesPath */)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void SettingsCache::setPicsPath(const QString &/* _picsPath */)
|
void SettingsCache::setPicsPath(const QString & /* _picsPath */)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void SettingsCache::setCardDatabasePath(const QString &/* _cardDatabasePath */)
|
void SettingsCache::setCardDatabasePath(const QString & /* _cardDatabasePath */)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void SettingsCache::setCustomCardDatabasePath(const QString &/* _customCardDatabasePath */)
|
void SettingsCache::setCustomCardDatabasePath(const QString & /* _customCardDatabasePath */)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void SettingsCache::setSpoilerDatabasePath(const QString &/* _spoilerDatabasePath */)
|
void SettingsCache::setSpoilerDatabasePath(const QString & /* _spoilerDatabasePath */)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void SettingsCache::setTokenDatabasePath(const QString &/* _tokenDatabasePath */)
|
void SettingsCache::setTokenDatabasePath(const QString & /* _tokenDatabasePath */)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void SettingsCache::setThemeName(const QString &/* _themeName */)
|
void SettingsCache::setThemeName(const QString & /* _themeName */)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void SettingsCache::setPicDownload(int /* _picDownload */)
|
void SettingsCache::setPicDownload(int /* _picDownload */)
|
||||||
|
@ -145,7 +140,7 @@ void SettingsCache::setStartingHandSize(int /* _startingHandSize */)
|
||||||
void SettingsCache::setAnnotateTokens(int /* _annotateTokens */)
|
void SettingsCache::setAnnotateTokens(int /* _annotateTokens */)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void SettingsCache::setTabGameSplitterSizes(const QByteArray &/* _tabGameSplitterSizes */)
|
void SettingsCache::setTabGameSplitterSizes(const QByteArray & /* _tabGameSplitterSizes */)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void SettingsCache::setDisplayCardNames(int /* _displayCardNames */)
|
void SettingsCache::setDisplayCardNames(int /* _displayCardNames */)
|
||||||
|
@ -175,10 +170,10 @@ void SettingsCache::setChatMentionForeground(int /* _chatMentionForeground */)
|
||||||
void SettingsCache::setChatHighlightForeground(int /* _chatHighlightForeground */)
|
void SettingsCache::setChatHighlightForeground(int /* _chatHighlightForeground */)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void SettingsCache::setChatMentionColor(const QString &/* _chatMentionColor */)
|
void SettingsCache::setChatMentionColor(const QString & /* _chatMentionColor */)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void SettingsCache::setChatHighlightColor(const QString &/* _chatHighlightColor */)
|
void SettingsCache::setChatHighlightColor(const QString & /* _chatHighlightColor */)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void SettingsCache::setZoneViewSortByName(int /* _zoneViewSortByName */)
|
void SettingsCache::setZoneViewSortByName(int /* _zoneViewSortByName */)
|
||||||
|
@ -193,7 +188,7 @@ void SettingsCache::setZoneViewPileView(int /* _zoneViewPileView */)
|
||||||
void SettingsCache::setSoundEnabled(int /* _soundEnabled */)
|
void SettingsCache::setSoundEnabled(int /* _soundEnabled */)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void SettingsCache::setSoundThemeName(const QString &/* _soundThemeName */)
|
void SettingsCache::setSoundThemeName(const QString & /* _soundThemeName */)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void SettingsCache::setIgnoreUnregisteredUsers(int /* _ignoreUnregisteredUsers */)
|
void SettingsCache::setIgnoreUnregisteredUsers(int /* _ignoreUnregisteredUsers */)
|
||||||
|
@ -202,19 +197,19 @@ void SettingsCache::setIgnoreUnregisteredUsers(int /* _ignoreUnregisteredUsers *
|
||||||
void SettingsCache::setIgnoreUnregisteredUserMessages(int /* _ignoreUnregisteredUserMessages */)
|
void SettingsCache::setIgnoreUnregisteredUserMessages(int /* _ignoreUnregisteredUserMessages */)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void SettingsCache::setMainWindowGeometry(const QByteArray &/* _mainWindowGeometry */)
|
void SettingsCache::setMainWindowGeometry(const QByteArray & /* _mainWindowGeometry */)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void SettingsCache::setTokenDialogGeometry(const QByteArray &/* _tokenDialogGeometry */)
|
void SettingsCache::setTokenDialogGeometry(const QByteArray & /* _tokenDialogGeometry */)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void SettingsCache::setPixmapCacheSize(const int /* _pixmapCacheSize */)
|
void SettingsCache::setPixmapCacheSize(const int /* _pixmapCacheSize */)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void SettingsCache::setClientID(const QString &/* _clientID */)
|
void SettingsCache::setClientID(const QString & /* _clientID */)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void SettingsCache::setClientVersion(const QString &/* _clientVersion */)
|
void SettingsCache::setClientVersion(const QString & /* _clientVersion */)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
QStringList SettingsCache::getCountries() const
|
QStringList SettingsCache::getCountries() const
|
||||||
|
@ -277,7 +272,7 @@ void PictureLoader::clearPixmapCache(CardInfoPtr /* card */)
|
||||||
|
|
||||||
SettingsCache *settingsCache;
|
SettingsCache *settingsCache;
|
||||||
|
|
||||||
SettingsCache& SettingsCache::instance()
|
SettingsCache &SettingsCache::instance()
|
||||||
{
|
{
|
||||||
return *settingsCache;
|
return *settingsCache;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,25 +1,27 @@
|
||||||
#include "gtest/gtest.h"
|
|
||||||
#include "../common/expression.h"
|
#include "../common/expression.h"
|
||||||
|
|
||||||
|
#include "gtest/gtest.h"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
#define TEST_EXPR(name,a,b) TEST(name, Works) { \
|
#define TEST_EXPR(name, a, b) \
|
||||||
|
TEST(ExpressionTest, name) \
|
||||||
|
{ \
|
||||||
Expression exp(8); \
|
Expression exp(8); \
|
||||||
ASSERT_EQ(exp.parse(a), b) << a; \
|
ASSERT_EQ(exp.parse(a), b) << a; \
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
TEST_EXPR(Number, "1", 1)
|
TEST_EXPR(Number, "1", 1)
|
||||||
TEST_EXPR(Multiply, "2*2", 4)
|
TEST_EXPR(Multiply, "2*2", 4)
|
||||||
TEST_EXPR(Whitespace, "3 * 3", 9)
|
TEST_EXPR(Whitespace, "3 * 3", 9)
|
||||||
TEST_EXPR(Powers, "2^8", 256)
|
TEST_EXPR(Powers, "2^8", 256)
|
||||||
TEST_EXPR(OrderOfOperations, "2+2*2", 6)
|
TEST_EXPR(OrderOfOperations, "2+2*2", 6)
|
||||||
TEST_EXPR(Fn, "2*cos(1)", 2*cos(1))
|
TEST_EXPR(Fn, "2*cos(1)", 2 * cos(1))
|
||||||
TEST_EXPR(Variable, "x / 2", 4)
|
TEST_EXPR(Variable, "x / 2", 4)
|
||||||
TEST_EXPR(Negative, "-2 * 2", -4)
|
TEST_EXPR(Negative, "-2 * 2", -4)
|
||||||
TEST_EXPR(UnknownFnReturnsZero, "blah(22)", 0)
|
TEST_EXPR(UnknownFnReturnsZero, "blah(22)", 0)
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "clipboard_testing.h"
|
#include "clipboard_testing.h"
|
||||||
|
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
|
|
||||||
void Result::operator()(const InnerDecklistNode *innerDecklistNode, const DecklistCardNode *card)
|
void Result::operator()(const InnerDecklistNode *innerDecklistNode, const DecklistCardNode *card)
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define CLIPBOARD_TESTING_H
|
#define CLIPBOARD_TESTING_H
|
||||||
|
|
||||||
#include "../../common/decklist.h"
|
#include "../../common/decklist.h"
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
struct Result
|
struct Result
|
||||||
|
|
39
tests/password_hash_test.cpp
Normal file
39
tests/password_hash_test.cpp
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
#include "../common/passwordhasher.h"
|
||||||
|
#include "../common/rng_abstract.h"
|
||||||
|
#include "../common/rng_sfmt.h"
|
||||||
|
|
||||||
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
|
RNG_Abstract *rng;
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
class PasswordHashTest : public ::testing::Test
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
void SetUp() override
|
||||||
|
{
|
||||||
|
rng = new RNG_SFMT;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TearDown() override
|
||||||
|
{
|
||||||
|
delete rng;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST(PasswordHashTest, RegressionTest)
|
||||||
|
{
|
||||||
|
QString salt = "saltsaltsaltsalt";
|
||||||
|
QString password = "password";
|
||||||
|
QString expected = "vmKoWv975yf+WT2QCXhW48JNzZ2ghGxdgNvuKLBU0h7s6AQHSG72J6QO4ZswuSeqvBbAXbmgJSRBaSJrgc55WA==";
|
||||||
|
QString hash = PasswordHasher::computeHash(password, salt);
|
||||||
|
ASSERT_EQ(hash, salt + expected) << "The computed hash value remains the same";
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
::testing::InitGoogleTest(&argc, argv);
|
||||||
|
return RUN_ALL_TESTS();
|
||||||
|
}
|
Loading…
Reference in a new issue