diff options
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/Makefile.am | 1 | ||||
-rw-r--r-- | src/tests/testaccount.cpp | 25 | ||||
-rw-r--r-- | src/tests/testaccount.h | 2 | ||||
-rw-r--r-- | src/tests/teststorage.cpp | 55 |
4 files changed, 60 insertions, 23 deletions
diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index c8f53d06..aaf3af82 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -28,6 +28,7 @@ tmwserv_test_LDADD = ../tmwserv-account.o \ ../tmwserv-dataproviderfactory.o \ ../tmwserv-logger.o \ ../tmwserv-object.o \ + ../tmwserv-being.o \ ../tmwserv-recordset.o \ ../tmwserv-storage.o diff --git a/src/tests/testaccount.cpp b/src/tests/testaccount.cpp index a086ef62..814aaa29 100644 --- a/src/tests/testaccount.cpp +++ b/src/tests/testaccount.cpp @@ -37,9 +37,18 @@ using namespace tmwserv; void AccountTest::setUp(void) { - Being* sam = new Being("sam", 1, 1, 1, 1, 1, 1, 1, 1); - Being* merry = new Being("merry", 1, 1, 1, 1, 1, 1, 1, 1); - Being* pippin = new Being("pippin", 1, 1, 1, 1, 1, 1, 1, 1); + //RawStatistics stats; + //stats.strength = 1; + //stats.agility = 1; + //stats.vitality = 1; + //stats.intelligence = 1; + //stats.dexterity = 1; + //stats.luck = 1; + const RawStatistics stats = {1, 1, 1, 1, 1, 1}; + + Being* sam = new Being("sam", GENDER_MALE, 0, 0, stats); + Being* merry = new Being("merry", GENDER_MALE, 0, 0, stats); + Being* pippin = new Being("pippin", GENDER_MALE, 0, 0, stats); mCharacters.push_back(sam); mCharacters.push_back(merry); mCharacters.push_back(pippin); @@ -124,7 +133,15 @@ AccountTest::testCreate2(void) void AccountTest::testAddCharacter1(void) { - Being* bilbo = new Being("bilbo", 1, 1, 1, 1, 1, 1, 1, 1); + RawStatistics stats; + stats.strength = 1; + stats.agility = 1; + stats.vitality = 1; + stats.intelligence = 1; + stats.dexterity = 1; + stats.luck = 1; + + Being* bilbo = new Being("bilbo", GENDER_MALE, 0, 0, stats); mAccount->addCharacter(bilbo); diff --git a/src/tests/testaccount.h b/src/tests/testaccount.h index fc2363c6..06a60bfc 100644 --- a/src/tests/testaccount.h +++ b/src/tests/testaccount.h @@ -109,7 +109,7 @@ class AccountTest: public CppUnit::TestFixture private: tmwserv::Account* mAccount; /**< the default account */ - Beings mCharacters; /**< a list of beings */ + tmwserv::Beings mCharacters; /**< a list of beings */ }; diff --git a/src/tests/teststorage.cpp b/src/tests/teststorage.cpp index 6836bc56..7a7cb7fd 100644 --- a/src/tests/teststorage.cpp +++ b/src/tests/teststorage.cpp @@ -37,6 +37,7 @@ #include <physfs.h> #include "../utils/cipher.h" +#include "../utils/functors.h" #include "../dalstoragesql.h" #include "../storage.h" #include "teststorage.h" @@ -218,10 +219,18 @@ StorageTest::testAddAccount2(void) } // prepare new account. + RawStatistics stats; + stats.strength = 1; + stats.agility = 1; + stats.vitality = 1; + stats.intelligence = 1; + stats.dexterity = 1; + stats.luck = 1; + const std::string sam1("sam1"); const std::string sam2("sam2"); - Being* b1 = new Being(sam1, 1, 1, 1, 1, 1, 1, 1, 1); - Being* b2 = new Being(sam2, 1, 1, 1, 1, 1, 1, 1, 1); + Being* b1 = new Being(sam1, GENDER_MALE, 0, 0, stats); + Being* b2 = new Being(sam2, GENDER_MALE, 0, 0, stats); Beings characters; characters.push_back(b1); characters.push_back(b2); @@ -268,9 +277,7 @@ StorageTest::testAddAccount2(void) sql = "select * from "; sql += CHARACTERS_TBL_NAME; - sql += " where user_id = '"; - sql += sam; - sql += "';"; + sql += " where user_id = 4;"; db->execSql(sql); @@ -315,10 +322,18 @@ StorageTest::testUpdAccount1(void) Account* account = myStorage.getAccount(name); // create new characters. + RawStatistics stats; + stats.strength = 1; + stats.agility = 1; + stats.vitality = 1; + stats.intelligence = 1; + stats.dexterity = 1; + stats.luck = 1; + const std::string sam1("sam1"); const std::string sam2("sam2"); - Being* b1 = new Being(sam1, 1, 1, 1, 1, 1, 1, 1, 1); - Being* b2 = new Being(sam2, 1, 1, 1, 1, 1, 1, 1, 1); + Being* b1 = new Being(sam1, GENDER_MALE, 0, 0, stats); + Being* b2 = new Being(sam2, GENDER_MALE, 0, 0, stats); // add the characters to the account. account->addCharacter(b1); @@ -360,9 +375,7 @@ StorageTest::testUpdAccount1(void) sql = "select * from "; sql += CHARACTERS_TBL_NAME; - sql += " where user_id = '"; - sql += frodo; - sql += "';"; + sql += " where user_id = 1;"; db->execSql(sql); @@ -408,10 +421,18 @@ StorageTest::testUpdAccount2(void) Account* account = myStorage.getAccount(name); // create new characters. + RawStatistics stats; + stats.strength = 1; + stats.agility = 1; + stats.vitality = 1; + stats.intelligence = 1; + stats.dexterity = 1; + stats.luck = 1; + const std::string sam1("sam1"); const std::string sam2("sam2"); - Being* b1 = new Being(sam1, 1, 1, 1, 1, 1, 1, 1, 1); - Being* b2 = new Being(sam2, 1, 1, 1, 1, 1, 1, 1, 1); + Being* b1 = new Being(sam1, GENDER_MALE, 0, 0, stats); + Being* b2 = new Being(sam2, GENDER_MALE, 0, 0, stats); // add the characters to the account. account->addCharacter(b1); @@ -426,7 +447,7 @@ StorageTest::testUpdAccount2(void) account->setPassword(newPassword); // change the strength of the first character. - // TODO: at the moment, there are no mutators defined for the Being class. + b1->setStrength(10); // update the database. myStorage.flush(); @@ -467,9 +488,7 @@ StorageTest::testUpdAccount2(void) sql = "select * from "; sql += CHARACTERS_TBL_NAME; - sql += " where user_id = '"; - sql += frodo; - sql += "';"; + sql += " where user_id = 1;"; db->execSql(sql); @@ -478,8 +497,8 @@ StorageTest::testUpdAccount2(void) CPPUNIT_ASSERT_EQUAL(sam1, rs(0, "name")); CPPUNIT_ASSERT_EQUAL(sam2, rs(1, "name")); - // TODO: when the mutators are implemented for the Being class, - // check the strength of the first character. + string_to<unsigned short> toUshort; + CPPUNIT_ASSERT_EQUAL((unsigned short) 10, toUshort(rs(0, "str"))); db->disconnect(); } |