void MyMoneyAccountTest::testAssignmentConstructor() { MyMoneyAccount a; a.setAccountType(MyMoneyAccount::Checkings); a.setName("Account"); a.setInstitutionId("Inst1"); a.setDescription("Bla"); a.setNumber("assigned Number"); a.setValue("Key", "Value"); a.addAccountId("ChildAccount"); MyMoneyAccount b; b.setLastModified(QDate::currentDate()); b = a; QVERIFY(b.name() == "Account"); QVERIFY(b.institutionId() == "Inst1"); QVERIFY(b.accountType() == MyMoneyAccount::Checkings); QVERIFY(b.lastModified() == QDate()); QVERIFY(b.openingDate() == a.openingDate()); QVERIFY(b.description() == "Bla"); QVERIFY(b.number() == "assigned Number"); QVERIFY(b.value("Key") == "Value"); QVERIFY(b.accountList().count() == 1); QVERIFY(b.accountList()[0] == "ChildAccount"); }
void MyMoneyAccountTest::testCopyConstructor() { QString id = "A000001"; QString institutionid = "B000001"; QString parent = "ParentAccount"; MyMoneyAccount r; r.setAccountType(MyMoneyAccount::Expense); r.setOpeningDate(QDate::currentDate()); r.setLastModified(QDate::currentDate()); r.setName("Account"); r.setInstitutionId("Inst1"); r.setDescription("Desc1"); r.setNumber("Number"); r.setParentAccountId(parent); r.setValue("Key", "Value"); MyMoneyAccount a(id, r); a.setInstitutionId(institutionid); MyMoneyAccount b(a); QVERIFY(b.name() == "Account"); QVERIFY(b.institutionId() == institutionid); QVERIFY(b.accountType() == MyMoneyAccount::Expense); QVERIFY(b.lastModified() == QDate::currentDate()); QVERIFY(b.openingDate() == QDate::currentDate()); QVERIFY(b.description() == "Desc1"); QVERIFY(b.number() == "Number"); QVERIFY(b.parentAccountId() == "ParentAccount"); QVERIFY(b.value("Key") == "Value"); }
void MyMoneyAccountTest::testHasReferenceTo() { MyMoneyAccount a; a.setInstitutionId("I0001"); a.addAccountId("A_001"); a.addAccountId("A_002"); a.setParentAccountId("A_Parent"); a.setCurrencyId("Currency"); QVERIFY(a.hasReferenceTo("I0001") == true); QVERIFY(a.hasReferenceTo("I0002") == false); QVERIFY(a.hasReferenceTo("A_001") == false); QVERIFY(a.hasReferenceTo("A_Parent") == true); QVERIFY(a.hasReferenceTo("Currency") == true); }
void MyMoneyAccountTest::testSetFunctions() { MyMoneyAccount a; QDate today(QDate::currentDate()); QVERIFY(a.name().isEmpty()); QVERIFY(a.lastModified() == QDate()); QVERIFY(a.description().isEmpty()); a.setName("Account"); a.setInstitutionId("Institution1"); a.setLastModified(today); a.setDescription("Desc"); a.setNumber("123456"); a.setAccountType(MyMoneyAccount::MoneyMarket); QVERIFY(a.name() == "Account"); QVERIFY(a.institutionId() == "Institution1"); QVERIFY(a.lastModified() == today); QVERIFY(a.description() == "Desc"); QVERIFY(a.number() == "123456"); QVERIFY(a.accountType() == MyMoneyAccount::MoneyMarket); }
void MyMoneyAccountTest::testWriteXML() { QString id = "A000001"; QString institutionid = "B000001"; QString parent = "Parent"; MyMoneyAccount r; r.setAccountType(MyMoneyAccount::Asset); r.setOpeningDate(QDate::currentDate()); r.setLastModified(QDate::currentDate()); r.setDescription("Desc"); r.setName("AccountName"); r.setNumber("465500"); r.setParentAccountId(parent); r.setInstitutionId(institutionid); r.setValue(QString("key"), "value"); r.addAccountId("A000002"); r.addReconciliation(QDate(2011, 1, 1), MyMoneyMoney(123, 100)); r.addReconciliation(QDate(2011, 2, 1), MyMoneyMoney(456, 100)); QCOMPARE(r.m_kvp.count(), 2); QCOMPARE(r.value("key"), QLatin1String("value")); QCOMPARE(r.value("reconciliationHistory"), QLatin1String("2011-01-01:123/100;2011-02-01:114/25")); MyMoneyAccount a(id, r); QDomDocument doc("TEST"); QDomElement el = doc.createElement("ACCOUNT-CONTAINER"); doc.appendChild(el); a.writeXML(doc, el); QCOMPARE(doc.doctype().name(), QLatin1String("TEST")); QDomElement accountContainer = doc.documentElement(); QVERIFY(accountContainer.isElement()); QCOMPARE(accountContainer.tagName(), QLatin1String("ACCOUNT-CONTAINER")); QVERIFY(accountContainer.childNodes().size() == 1); QVERIFY(accountContainer.childNodes().at(0).isElement()); QDomElement account = accountContainer.childNodes().at(0).toElement(); QCOMPARE(account.tagName(), QLatin1String("ACCOUNT")); QCOMPARE(account.attribute("id"), QLatin1String("A000001")); QCOMPARE(account.attribute("lastreconciled"), QString()); QCOMPARE(account.attribute("institution"), QLatin1String("B000001")); QCOMPARE(account.attribute("name"), QLatin1String("AccountName")); QCOMPARE(account.attribute("number"), QLatin1String("465500")); QCOMPARE(account.attribute("description"), QLatin1String("Desc")); QCOMPARE(account.attribute("parentaccount"), QLatin1String("Parent")); QCOMPARE(account.attribute("opened"), QDate::currentDate().toString(Qt::ISODate)); QCOMPARE(account.attribute("type"), QLatin1String("9")); QCOMPARE(account.attribute("lastmodified"), QDate::currentDate().toString(Qt::ISODate)); QCOMPARE(account.attribute("id"), QLatin1String("A000001")); QCOMPARE(account.childNodes().size(), 2); QVERIFY(account.childNodes().at(0).isElement()); QDomElement subAccounts = account.childNodes().at(0).toElement(); QCOMPARE(subAccounts.tagName(), QLatin1String("SUBACCOUNTS")); QCOMPARE(subAccounts.childNodes().size(), 1); QVERIFY(subAccounts.childNodes().at(0).isElement()); QDomElement subAccount = subAccounts.childNodes().at(0).toElement(); QCOMPARE(subAccount.tagName(), QLatin1String("SUBACCOUNT")); QCOMPARE(subAccount.attribute("id"), QLatin1String("A000002")); QCOMPARE(subAccount.childNodes().size(), 0); QDomElement keyValuePairs = account.childNodes().at(1).toElement(); QCOMPARE(keyValuePairs.tagName(), QLatin1String("KEYVALUEPAIRS")); QCOMPARE(keyValuePairs.childNodes().size(), 2); QVERIFY(keyValuePairs.childNodes().at(0).isElement()); QDomElement keyValuePair1 = keyValuePairs.childNodes().at(0).toElement(); QCOMPARE(keyValuePair1.tagName(), QLatin1String("PAIR")); QCOMPARE(keyValuePair1.attribute("key"), QLatin1String("key")); QCOMPARE(keyValuePair1.attribute("value"), QLatin1String("value")); QCOMPARE(keyValuePair1.childNodes().size(), 0); QVERIFY(keyValuePairs.childNodes().at(1).isElement()); QDomElement keyValuePair2 = keyValuePairs.childNodes().at(1).toElement(); QCOMPARE(keyValuePair2.tagName(), QLatin1String("PAIR")); QCOMPARE(keyValuePair2.attribute("key"), QLatin1String("reconciliationHistory")); QCOMPARE(keyValuePair2.attribute("value"), QLatin1String("2011-01-01:123/100;2011-02-01:114/25")); QCOMPARE(keyValuePair2.childNodes().size(), 0); }
void MyMoneyAccountTest::testEquality() { MyMoneyAccount a; a.setLastModified(QDate::currentDate()); a.setName("Name"); a.setNumber("Number"); a.setDescription("Desc"); a.setInstitutionId("I-ID"); a.setOpeningDate(QDate::currentDate()); a.setLastReconciliationDate(QDate::currentDate()); a.setAccountType(MyMoneyAccount::Asset); a.setParentAccountId("P-ID"); a.setId("A-ID"); a.setCurrencyId("C-ID"); a.setValue("Key", "Value"); MyMoneyAccount b; b = a; QVERIFY(b == a); a.setName("Noname"); QVERIFY(!(b == a)); b = a; a.setLastModified(QDate::currentDate().addDays(-1)); QVERIFY(!(b == a)); b = a; a.setNumber("Nonumber"); QVERIFY(!(b == a)); b = a; a.setDescription("NoDesc"); QVERIFY(!(b == a)); b = a; a.setInstitutionId("I-noID"); QVERIFY(!(b == a)); b = a; a.setOpeningDate(QDate::currentDate().addDays(-1)); QVERIFY(!(b == a)); b = a; a.setLastReconciliationDate(QDate::currentDate().addDays(-1)); QVERIFY(!(b == a)); b = a; a.setAccountType(MyMoneyAccount::Liability); QVERIFY(!(b == a)); b = a; a.setParentAccountId("P-noID"); QVERIFY(!(b == a)); b = a; a.setId("A-noID"); QVERIFY(!(b == a)); b = a; a.setCurrencyId("C-noID"); QVERIFY(!(b == a)); b = a; a.setValue("Key", "noValue"); QVERIFY(!(b == a)); b = a; a.setValue("noKey", "Value"); QVERIFY(!(b == a)); b = a; }