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()
|
||||
add_test(NAME dummy_test COMMAND dummy_test)
|
||||
add_test(NAME expression_test COMMAND expression_test)
|
||||
add_test(NAME password_hash_test COMMAND password_hash_test)
|
||||
|
||||
# Find GTest
|
||||
|
||||
add_executable(dummy_test dummy_test.cpp)
|
||||
add_executable(expression_test expression_test.cpp)
|
||||
add_executable(password_hash_test password_hash_test.cpp)
|
||||
|
||||
find_package(GTest)
|
||||
|
||||
|
@ -35,6 +37,7 @@ if(NOT GTEST_FOUND)
|
|||
SET(GTEST_BOTH_LIBRARIES gtest)
|
||||
add_dependencies(dummy_test gtest)
|
||||
add_dependencies(expression_test gtest)
|
||||
add_dependencies(password_hash_test gtest)
|
||||
endif()
|
||||
|
||||
find_package(Qt5 COMPONENTS Widgets REQUIRED)
|
||||
|
@ -44,6 +47,7 @@ set(TEST_QT_MODULES Qt5::Widgets)
|
|||
include_directories(${GTEST_INCLUDE_DIRS})
|
||||
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(password_hash_test cockatrice_common Threads::Threads ${GTEST_BOTH_LIBRARIES} ${TEST_QT_MODULES})
|
||||
|
||||
add_subdirectory(carddatabase)
|
||||
add_subdirectory(loading_from_clipboard)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "gtest/gtest.h"
|
||||
|
||||
#include "mocks.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
|
|
|
@ -1,23 +1,25 @@
|
|||
#include "gtest/gtest.h"
|
||||
#include "../../cockatrice/src/filter_string.h"
|
||||
#include "mocks.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include <cmath>
|
||||
|
||||
CardDatabase *db;
|
||||
|
||||
#define Query(name, card, query, match) \
|
||||
TEST_F(CardQuery, name) {\
|
||||
#define QUERY(name, card, query, match) \
|
||||
TEST_F(CardQuery, name) \
|
||||
{ \
|
||||
ASSERT_EQ(FilterString(query).check(card), match); \
|
||||
}
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
class CardQuery : public ::testing::Test {
|
||||
class CardQuery : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
void SetUp() override {
|
||||
void SetUp() override
|
||||
{
|
||||
cat = db->getCardBySimpleName("Cat");
|
||||
}
|
||||
|
||||
|
@ -26,32 +28,32 @@ class CardQuery : public ::testing::Test {
|
|||
CardData cat;
|
||||
};
|
||||
|
||||
Query(Empty, cat, "", true)
|
||||
Query(Typing, cat, "t", true)
|
||||
QUERY(Empty, cat, "", true)
|
||||
QUERY(Typing, cat, "t", true)
|
||||
|
||||
Query(NonMatchingType, cat, "t:kithkin", false)
|
||||
Query(MatchingType, cat, "t:creature", true)
|
||||
Query(Not1, cat, "not t:kithkin", true)
|
||||
Query(Not2, cat, "not t:creature", false)
|
||||
Query(Case, cat, "t:cReAtUrE", true)
|
||||
QUERY(NonMatchingType, cat, "t:kithkin", false)
|
||||
QUERY(MatchingType, cat, "t:creature", true)
|
||||
QUERY(Not1, cat, "not t:kithkin", true)
|
||||
QUERY(Not2, cat, "not t:creature", false)
|
||||
QUERY(Case, cat, "t:cReAtUrE", true)
|
||||
|
||||
Query(And, cat, "t:creature t:creature", true)
|
||||
Query(And2, cat, "t:creature t:sorcery", false)
|
||||
QUERY(And, cat, "t:creature t:creature", true)
|
||||
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(Cmc2, cat, "cmc>3", false)
|
||||
Query(Cmc3, cat, "cmc>1", true)
|
||||
QUERY(Cmc1, cat, "cmc=2", true)
|
||||
QUERY(Cmc2, cat, "cmc>3", false)
|
||||
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(Color2, cat, "c:gw", true);
|
||||
Query(Color3, cat, "c!g", true);
|
||||
Query(Color4, cat, "c!gw", false);
|
||||
QUERY(Color1, cat, "c:g", true)
|
||||
QUERY(Color2, cat, "c:gw", true)
|
||||
QUERY(Color3, cat, "c!g", true)
|
||||
QUERY(Color4, cat, "c!gw", false)
|
||||
|
||||
} // namespace
|
||||
|
||||
|
|
|
@ -41,14 +41,9 @@ QString SettingsCache::getSafeConfigFilePath(QString /* configEntry */, QString
|
|||
return defaultPath;
|
||||
}
|
||||
SettingsCache::SettingsCache()
|
||||
: settings{new QSettings("global.ini", QSettings::IniFormat, this)},
|
||||
shortcutsSettings{nullptr},
|
||||
cardDatabaseSettings{new CardDatabaseSettings("", this)},
|
||||
serversSettings{nullptr},
|
||||
messageSettings{nullptr},
|
||||
gameFiltersSettings{nullptr},
|
||||
layoutsSettings{nullptr},
|
||||
downloadSettings{nullptr},
|
||||
: settings{new QSettings("global.ini", QSettings::IniFormat, this)}, shortcutsSettings{nullptr},
|
||||
cardDatabaseSettings{new CardDatabaseSettings("", this)}, serversSettings{nullptr}, messageSettings{nullptr},
|
||||
gameFiltersSettings{nullptr}, layoutsSettings{nullptr}, downloadSettings{nullptr},
|
||||
cardDatabasePath{QString("%1/cards.xml").arg(CARDDB_DATADIR)},
|
||||
customCardDatabasePath{QString("%1/customsets/").arg(CARDDB_DATADIR)},
|
||||
spoilerDatabasePath{QString("%1/spoiler.xml").arg(CARDDB_DATADIR)},
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
#include "gtest/gtest.h"
|
||||
#include "../common/expression.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include <cmath>
|
||||
|
||||
#define TEST_EXPR(name,a,b) TEST(name, Works) { \
|
||||
#define TEST_EXPR(name, a, b) \
|
||||
TEST(ExpressionTest, name) \
|
||||
{ \
|
||||
Expression exp(8); \
|
||||
ASSERT_EQ(exp.parse(a), b) << a; \
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "clipboard_testing.h"
|
||||
|
||||
#include <QTextStream>
|
||||
|
||||
void Result::operator()(const InnerDecklistNode *innerDecklistNode, const DecklistCardNode *card)
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define CLIPBOARD_TESTING_H
|
||||
|
||||
#include "../../common/decklist.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
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