diff --git a/cockatrice/src/carddatabase.cpp b/cockatrice/src/carddatabase.cpp index dcb13661..917ffe04 100644 --- a/cockatrice/src/carddatabase.cpp +++ b/cockatrice/src/carddatabase.cpp @@ -1,7 +1,6 @@ #include "carddatabase.h" #include "pictureloader.h" #include "settingscache.h" -#include "thememanager.h" #include #include @@ -386,6 +385,8 @@ void CardDatabase::clear() delete setIt.value(); } sets.clear(); + + loadStatus = NotLoaded; } void CardDatabase::addCard(CardInfo *card) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 93deb7df..5591a991 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -35,4 +35,6 @@ if(NOT GTEST_FOUND) endif() include_directories(${GTEST_INCLUDE_DIRS}) -target_link_libraries(dummy_test ${GTEST_BOTH_LIBRARIES}) \ No newline at end of file +target_link_libraries(dummy_test ${GTEST_BOTH_LIBRARIES}) + +add_subdirectory(carddatabase) \ No newline at end of file diff --git a/tests/carddatabase/CMakeLists.txt b/tests/carddatabase/CMakeLists.txt new file mode 100644 index 00000000..759f1b80 --- /dev/null +++ b/tests/carddatabase/CMakeLists.txt @@ -0,0 +1,44 @@ +ADD_DEFINITIONS("-DCARDDB_DATADIR=\"${CMAKE_CURRENT_SOURCE_DIR}/data/\"") +add_executable(carddatabase_test + carddatabase_test.cpp + ../../cockatrice/src/carddatabase.cpp + +) +if(NOT GTEST_FOUND) + add_dependencies(carddatabase_test gtest) +endif() +target_link_libraries(carddatabase_test ${GTEST_BOTH_LIBRARIES}) +add_test(NAME carddatabase_test COMMAND carddatabase_test) + +# Qt4 stuff +if(Qt4_FOUND) + SET(QT_USE_QTNETWORK TRUE) + SET(QT_USE_QTMULTIMEDIA TRUE) + + # Include directories + INCLUDE(${QT_USE_FILE}) + INCLUDE_DIRECTORIES(${QT_INCLUDES}) + TARGET_LINK_LIBRARIES(carddatabase_test {QT_LIBRARIES}) +endif() + +# qt5 stuff +if(Qt5Widgets_FOUND) + include_directories(${Qt5Widgets_INCLUDE_DIRS}) + list(APPEND COCKATRICE_LIBS Widgets) + + # QtConcurrent + find_package(Qt5Concurrent) + if(Qt5Concurrent_FOUND) + include_directories(${Qt5Concurrent_INCLUDE_DIRS}) + list(APPEND ORACLE_LIBS Concurrent) + endif() + + # QtNetwork + find_package(Qt5Network) + if(Qt5Network_FOUND) + include_directories(${Qt5Network_INCLUDE_DIRS}) + list(APPEND COCKATRICE_LIBS Network) + endif() + + qt5_use_modules(carddatabase_test ${COCKATRICE_LIBS}) +endif() \ No newline at end of file diff --git a/tests/carddatabase/carddatabase_test.cpp b/tests/carddatabase/carddatabase_test.cpp new file mode 100644 index 00000000..66fcad32 --- /dev/null +++ b/tests/carddatabase/carddatabase_test.cpp @@ -0,0 +1,60 @@ +#include "gtest/gtest.h" + +#include "carddatabase_test.h" + +void CardDatabaseSettings::setSortKey(QString /* shortName */, unsigned int /* sortKey */) { }; +void CardDatabaseSettings::setEnabled(QString /* shortName */, bool /* enabled */) { }; +void CardDatabaseSettings::setIsKnown(QString /* shortName */, bool /* isknown */) { }; +unsigned int CardDatabaseSettings::getSortKey(QString /* shortName */) { return 0; }; +bool CardDatabaseSettings::isEnabled(QString /* shortName */) { return true; }; +bool CardDatabaseSettings::isKnown(QString /* shortName */) { return true; }; + +SettingsCache::SettingsCache() { cardDatabaseSettings = new CardDatabaseSettings(); }; +SettingsCache::~SettingsCache() { delete cardDatabaseSettings; }; +QString SettingsCache::getCustomCardDatabasePath() const { return QString("%1/customsets/").arg(CARDDB_DATADIR); } +QString SettingsCache::getCardDatabasePath() const { return QString("%1/cards.xml").arg(CARDDB_DATADIR); } +QString SettingsCache::getTokenDatabasePath() const { return QString("%1/tokens.xml").arg(CARDDB_DATADIR); } +CardDatabaseSettings& SettingsCache::cardDatabase() const { return *cardDatabaseSettings; } + +SettingsCache *settingsCache; + +void PictureLoader::clearPixmapCache(CardInfo * /* card */) { } + +// include out main header file _after_ the hack is complete +#include "../../cockatrice/src/carddatabase.h" + +namespace { + + TEST(CardDatabaseTest, LoadXml) { + settingsCache = new SettingsCache; + CardDatabase *db = new CardDatabase; + + // 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->getAllColors().size()) << "Colors not empty at start"; + ASSERT_EQ(0, db->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(6, db->getCardList().size()) << "Wrong card count after load"; + ASSERT_EQ(3, db->getSetList().size()) << "Wrong sets count after load"; + ASSERT_EQ(4, db->getAllColors().size()) << "Wrong colors count after load"; + ASSERT_EQ(2, db->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->getAllColors().size()) << "Colors not empty after clear"; + ASSERT_EQ(0, db->getAllMainCardTypes().size()) << "Types not empty after clear"; + ASSERT_EQ(NotLoaded, db->getLoadStatus()) << "Incorrect status after clear"; + } +} + +int main(int argc, char **argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} \ No newline at end of file diff --git a/tests/carddatabase/carddatabase_test.h b/tests/carddatabase/carddatabase_test.h new file mode 100644 index 00000000..a29b2857 --- /dev/null +++ b/tests/carddatabase/carddatabase_test.h @@ -0,0 +1,44 @@ +/* + * Beware of this preprocessor hack used to redefine the settingCache class + * instead of including it and all of its dependencies. + */ + +#include +#include + +#define SETTINGSCACHE_H + +class CardDatabaseSettings +{ +public: + void setSortKey(QString shortName, unsigned int sortKey); + void setEnabled(QString shortName, bool enabled); + void setIsKnown(QString shortName, bool isknown); + + unsigned int getSortKey(QString shortName); + bool isEnabled(QString shortName); + bool isKnown(QString shortName); +}; + +class SettingsCache: public QObject { + Q_OBJECT +private: + CardDatabaseSettings *cardDatabaseSettings; +public: + SettingsCache(); + ~SettingsCache(); + QString getCustomCardDatabasePath() const; + QString getCardDatabasePath() const; + QString getTokenDatabasePath() const; + CardDatabaseSettings& cardDatabase() const; +signals: + void cardDatabasePathChanged(); +}; + + +#define PICTURELOADER_H +class CardInfo; + +class PictureLoader { + void clearPixmapCache(CardInfo *card); +}; diff --git a/tests/carddatabase/data/cards.xml b/tests/carddatabase/data/cards.xml new file mode 100644 index 00000000..c0dc7dd2 --- /dev/null +++ b/tests/carddatabase/data/cards.xml @@ -0,0 +1,27 @@ + + + + + Cat + CAT + G + 2G + 2 + Creature + 3/3 + 0 + Meow! + + + Dog + DOG + R + 2RR + 4 + Creature + 4/4 + 0 + Woof! + + + diff --git a/tests/carddatabase/data/customsets/customset1.xml b/tests/carddatabase/data/customsets/customset1.xml new file mode 100644 index 00000000..b2f187d5 --- /dev/null +++ b/tests/carddatabase/data/customsets/customset1.xml @@ -0,0 +1,27 @@ + + + + + Sparrow + BRD + W + W + 1 + Creature + 1/1 + 0 + + + + Crow + BRD + B + 1B + 2 + Creature + 2/2 + 0 + + + + diff --git a/tests/carddatabase/data/tokens.xml b/tests/carddatabase/data/tokens.xml new file mode 100644 index 00000000..03b539a5 --- /dev/null +++ b/tests/carddatabase/data/tokens.xml @@ -0,0 +1,29 @@ + + + + + Kitten + CAT + G + + + Token + 1/1 + 0 + + 1 + + + Puppy + DOG + R + + + Token + 1/1 + 0 + + 1 + + +