First test for card database: loading and clear
This commit is contained in:
parent
df393638ed
commit
18993b397b
8 changed files with 236 additions and 2 deletions
|
@ -1,7 +1,6 @@
|
|||
#include "carddatabase.h"
|
||||
#include "pictureloader.h"
|
||||
#include "settingscache.h"
|
||||
#include "thememanager.h"
|
||||
|
||||
#include <QCryptographicHash>
|
||||
#include <QDebug>
|
||||
|
@ -386,6 +385,8 @@ void CardDatabase::clear()
|
|||
delete setIt.value();
|
||||
}
|
||||
sets.clear();
|
||||
|
||||
loadStatus = NotLoaded;
|
||||
}
|
||||
|
||||
void CardDatabase::addCard(CardInfo *card)
|
||||
|
|
|
@ -35,4 +35,6 @@ if(NOT GTEST_FOUND)
|
|||
endif()
|
||||
|
||||
include_directories(${GTEST_INCLUDE_DIRS})
|
||||
target_link_libraries(dummy_test ${GTEST_BOTH_LIBRARIES})
|
||||
target_link_libraries(dummy_test ${GTEST_BOTH_LIBRARIES})
|
||||
|
||||
add_subdirectory(carddatabase)
|
44
tests/carddatabase/CMakeLists.txt
Normal file
44
tests/carddatabase/CMakeLists.txt
Normal file
|
@ -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()
|
60
tests/carddatabase/carddatabase_test.cpp
Normal file
60
tests/carddatabase/carddatabase_test.cpp
Normal file
|
@ -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();
|
||||
}
|
44
tests/carddatabase/carddatabase_test.h
Normal file
44
tests/carddatabase/carddatabase_test.h
Normal file
|
@ -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 <QObject>
|
||||
#include <QString>
|
||||
|
||||
#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);
|
||||
};
|
27
tests/carddatabase/data/cards.xml
Normal file
27
tests/carddatabase/data/cards.xml
Normal file
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<cockatrice_carddatabase version="3">
|
||||
<cards>
|
||||
<card>
|
||||
<name>Cat</name>
|
||||
<set muId="111">CAT</set>
|
||||
<color>G</color>
|
||||
<manacost>2G</manacost>
|
||||
<cmc>2</cmc>
|
||||
<type>Creature</type>
|
||||
<pt>3/3</pt>
|
||||
<tablerow>0</tablerow>
|
||||
<text>Meow!</text>
|
||||
</card>
|
||||
<card>
|
||||
<name>Dog</name>
|
||||
<set muId="222">DOG</set>
|
||||
<color>R</color>
|
||||
<manacost>2RR</manacost>
|
||||
<cmc>4</cmc>
|
||||
<type>Creature</type>
|
||||
<pt>4/4</pt>
|
||||
<tablerow>0</tablerow>
|
||||
<text>Woof!</text>
|
||||
</card>
|
||||
</cards>
|
||||
</cockatrice_carddatabase>
|
27
tests/carddatabase/data/customsets/customset1.xml
Normal file
27
tests/carddatabase/data/customsets/customset1.xml
Normal file
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<cockatrice_carddatabase version="3">
|
||||
<cards>
|
||||
<card>
|
||||
<name>Sparrow</name>
|
||||
<set muId="333">BRD</set>
|
||||
<color>W</color>
|
||||
<manacost>W</manacost>
|
||||
<cmc>1</cmc>
|
||||
<type>Creature</type>
|
||||
<pt>1/1</pt>
|
||||
<tablerow>0</tablerow>
|
||||
<text></text>
|
||||
</card>
|
||||
<card>
|
||||
<name>Crow</name>
|
||||
<set muId="334">BRD</set>
|
||||
<color>B</color>
|
||||
<manacost>1B</manacost>
|
||||
<cmc>2</cmc>
|
||||
<type>Creature</type>
|
||||
<pt>2/2</pt>
|
||||
<tablerow>0</tablerow>
|
||||
<text></text>
|
||||
</card>
|
||||
</cards>
|
||||
</cockatrice_carddatabase>
|
29
tests/carddatabase/data/tokens.xml
Normal file
29
tests/carddatabase/data/tokens.xml
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<cockatrice_carddatabase version="3">
|
||||
<cards>
|
||||
<card>
|
||||
<name>Kitten</name>
|
||||
<set muId="112">CAT</set>
|
||||
<color>G</color>
|
||||
<manacost></manacost>
|
||||
<cmc></cmc>
|
||||
<type>Token</type>
|
||||
<pt>1/1</pt>
|
||||
<tablerow>0</tablerow>
|
||||
<text></text>
|
||||
<token>1</token>
|
||||
</card>
|
||||
<card>
|
||||
<name>Puppy</name>
|
||||
<set muId="223">DOG</set>
|
||||
<color>R</color>
|
||||
<manacost></manacost>
|
||||
<cmc></cmc>
|
||||
<type>Token</type>
|
||||
<pt>1/1</pt>
|
||||
<tablerow>0</tablerow>
|
||||
<text></text>
|
||||
<token>1</token>
|
||||
</card>
|
||||
</cards>
|
||||
</cockatrice_carddatabase>
|
Loading…
Reference in a new issue