Initial commit of mtgonline project
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(CardDatabaseTests VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
|
||||
|
||||
# ------------------------
|
||||
# Definitions
|
||||
# ------------------------
|
||||
add_definitions("-DCARDDB_DATADIR=\"${CMAKE_CURRENT_SOURCE_DIR}/data/\"")
|
||||
|
||||
# ------------------------
|
||||
# Card Database Test
|
||||
# ------------------------
|
||||
add_executable(carddatabase_test ${MOCKS_SOURCES} ${VERSION_STRING_CPP} carddatabase_test.cpp mocks.cpp)
|
||||
|
||||
target_link_libraries(
|
||||
carddatabase_test
|
||||
PRIVATE libcockatrice_card
|
||||
PRIVATE Threads::Threads
|
||||
PRIVATE ${GTEST_BOTH_LIBRARIES}
|
||||
PRIVATE ${TEST_QT_MODULES}
|
||||
)
|
||||
|
||||
add_test(NAME carddatabase_test COMMAND carddatabase_test)
|
||||
|
||||
# ------------------------
|
||||
# Filter String Test
|
||||
# (guard must match the condition for libcockatrice_filters in the root CMakeLists.txt)
|
||||
# ------------------------
|
||||
if(WITH_ORACLE OR WITH_CLIENT)
|
||||
add_executable(filter_string_test ${MOCKS_SOURCES} ${VERSION_STRING_CPP} filter_string_test.cpp mocks.cpp)
|
||||
|
||||
target_link_libraries(
|
||||
filter_string_test
|
||||
PRIVATE libcockatrice_filters
|
||||
PRIVATE Threads::Threads
|
||||
PRIVATE ${GTEST_BOTH_LIBRARIES}
|
||||
PRIVATE ${TEST_QT_MODULES}
|
||||
)
|
||||
|
||||
add_test(NAME filter_string_test COMMAND filter_string_test)
|
||||
|
||||
if(NOT GTEST_FOUND)
|
||||
add_dependencies(filter_string_test gtest)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# ------------------------
|
||||
# Dependencies on gtest
|
||||
# ------------------------
|
||||
if(NOT GTEST_FOUND)
|
||||
add_dependencies(carddatabase_test gtest)
|
||||
endif()
|
||||
@@ -0,0 +1,42 @@
|
||||
#include "mocks.h"
|
||||
#include "test_card_database_path_provider.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include <libcockatrice/interfaces/noop_card_preference_provider.h>
|
||||
#include <libcockatrice/interfaces/noop_card_set_priority_controller.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
TEST(CardDatabaseTest, LoadXml)
|
||||
{
|
||||
CardDatabase *db = new CardDatabase(nullptr, new NoopCardPreferenceProvider(), new TestCardDatabasePathProvider(),
|
||||
new NoopCardSetPriorityController());
|
||||
|
||||
// ensure the card database is empty at start
|
||||
ASSERT_EQ(0, db->getCardList().size()) << "Cards not empty at start";
|
||||
ASSERT_EQ(0, db->getSetList().size()) << "Sets not empty at start";
|
||||
ASSERT_EQ(0, db->query()->getAllMainCardTypes().size()) << "Types not empty at start";
|
||||
ASSERT_EQ(NotLoaded, db->getLoadStatus()) << "Incorrect status at start";
|
||||
|
||||
// load dummy cards and test result
|
||||
db->loadCardDatabases();
|
||||
ASSERT_EQ(9, db->getCardList().size()) << "Wrong card count after load";
|
||||
ASSERT_EQ(5, db->getSetList().size()) << "Wrong sets count after load";
|
||||
ASSERT_EQ(3, db->query()->getAllMainCardTypes().size()) << "Wrong types count after load";
|
||||
ASSERT_EQ(Ok, db->getLoadStatus()) << "Wrong status after load";
|
||||
|
||||
// ensure the card database is empty after clear()
|
||||
db->clear();
|
||||
ASSERT_EQ(0, db->getCardList().size()) << "Cards not empty after clear";
|
||||
ASSERT_EQ(0, db->getSetList().size()) << "Sets not empty after clear";
|
||||
ASSERT_EQ(0, db->query()->getAllMainCardTypes().size()) << "Types not empty after clear";
|
||||
ASSERT_EQ(NotLoaded, db->getLoadStatus()) << "Incorrect status after clear";
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
#include "mocks.h"
|
||||
#include "test_card_database_path_provider.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include <libcockatrice/filters/filter_string.h>
|
||||
#include <libcockatrice/interfaces/noop_card_preference_provider.h>
|
||||
#include <libcockatrice/interfaces/noop_card_set_priority_controller.h>
|
||||
|
||||
#define QUERY(name, card, query, match) \
|
||||
TEST_F(CardQuery, name) \
|
||||
{ \
|
||||
ASSERT_EQ(FilterString(query).check(card), match); \
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
class CardQuery : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
void SetUp() override
|
||||
{
|
||||
CardDatabase *db = new CardDatabase(nullptr, new NoopCardPreferenceProvider(),
|
||||
new TestCardDatabasePathProvider(), new NoopCardSetPriorityController());
|
||||
db->loadCardDatabases();
|
||||
|
||||
cat = db->query()->getCardBySimpleName("Cat");
|
||||
notDeadAfterAll = db->query()->getCardBySimpleName("Not Dead");
|
||||
truth = db->query()->getCardBySimpleName("Truth");
|
||||
doctor = db->query()->getCardBySimpleName("Doctor");
|
||||
}
|
||||
// void TearDown() override {}
|
||||
|
||||
CardData cat;
|
||||
CardData notDeadAfterAll;
|
||||
CardData truth;
|
||||
CardData doctor;
|
||||
};
|
||||
|
||||
QUERY(Empty, cat, "", true)
|
||||
QUERY(Typing, cat, "t", true)
|
||||
|
||||
QUERY(NonMatchingType, cat, "t:kithkin", false)
|
||||
QUERY(MatchingType, cat, "t:creature", true)
|
||||
QUERY(MatchingCreatureType, cat, "t:cat", true)
|
||||
QUERY(PartialMatchingType, cat, "t:ca", false)
|
||||
QUERY(MatchingMultiWordType, doctor, "t:\"Time Lord\"", true)
|
||||
QUERY(Not1, cat, "NOT t:kithkin", true)
|
||||
QUERY(Not2, cat, "NOT t:creature", false)
|
||||
QUERY(NonKeyword1, cat, "not t:kithkin", false)
|
||||
QUERY(NonKeyword2, cat, "t:bat or t:creature", false)
|
||||
QUERY(NonKeyword3, notDeadAfterAll, "not dead", true)
|
||||
QUERY(NonKeyword4, truth, "truth or trail", false)
|
||||
QUERY(Case, cat, "t:cReAtUrE", true)
|
||||
|
||||
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(Cmc1, cat, "cmc=2", true)
|
||||
QUERY(Cmc2, cat, "cmc>3", false)
|
||||
QUERY(Cmc3, cat, "cmc>1", true)
|
||||
|
||||
QUERY(Quotes, cat, "t:\"creature\"", 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(BracketNextToUnquotedString, cat, "(o:woof OR o:meow)", true)
|
||||
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
|
||||
#include "mocks.h"
|
||||
|
||||
void CardPictureLoader::clearPixmapCache(CardInfoPtr /* card */)
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Beware of this preprocessor hack used to redefine the settingCache class
|
||||
* instead of including it and all of its dependencies.
|
||||
* Always set header guards of mocked objects before including any headers
|
||||
* with mocked objects.
|
||||
*/
|
||||
|
||||
#define PICTURELOADER_H
|
||||
|
||||
#include <libcockatrice/card/database/card_database.h>
|
||||
|
||||
class CardPictureLoader
|
||||
{
|
||||
public:
|
||||
static void clearPixmapCache(CardInfoPtr card);
|
||||
};
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef COCKATRICE_TEST_CARD_DATABASE_PATH_PROVIDER_H
|
||||
#define COCKATRICE_TEST_CARD_DATABASE_PATH_PROVIDER_H
|
||||
|
||||
#include <libcockatrice/interfaces/interface_card_database_path_provider.h>
|
||||
|
||||
class TestCardDatabasePathProvider : public ICardDatabasePathProvider
|
||||
{
|
||||
|
||||
public:
|
||||
QString getCardDatabasePath() const override
|
||||
{
|
||||
return QString("%1/cards.xml").arg(CARDDB_DATADIR);
|
||||
}
|
||||
QString getCustomCardDatabasePath() const override
|
||||
{
|
||||
return QString("%1/customsets/").arg(CARDDB_DATADIR);
|
||||
}
|
||||
QString getTokenDatabasePath() const override
|
||||
{
|
||||
return QString("%1/tokens.xml").arg(CARDDB_DATADIR);
|
||||
}
|
||||
QString getSpoilerCardDatabasePath() const override
|
||||
{
|
||||
return QString("%1/spoiler.xml").arg(CARDDB_DATADIR);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // COCKATRICE_TEST_CARD_DATABASE_PATH_PROVIDER_H
|
||||
Reference in New Issue
Block a user