Ejemplo n.º 1
0
void MyMoneyInstitutionTest::testAccountIDList () {
	MyMoneyInstitution institution;
	QStringList list;
	QString id;

	// list must be empty
	list = institution.accountList();
	CPPUNIT_ASSERT(list.count() == 0);

	// add one account
	institution.addAccountId("A000002");
	list = institution.accountList();
	CPPUNIT_ASSERT(list.count() == 1);
	CPPUNIT_ASSERT(list.contains("A000002") == 1);

	// adding same account shouldn't make a difference
	institution.addAccountId("A000002");
	list = institution.accountList();
	CPPUNIT_ASSERT(list.count() == 1);
	CPPUNIT_ASSERT(list.contains("A000002") == 1);

	// now add another account
	institution.addAccountId("A000001");
	list = institution.accountList();
	CPPUNIT_ASSERT(list.count() == 2);
	CPPUNIT_ASSERT(list.contains("A000002") == 1);
	CPPUNIT_ASSERT(list.contains("A000001") == 1);

	id = institution.removeAccountId("A000001");
	CPPUNIT_ASSERT(id == "A000001");
	list = institution.accountList();
	CPPUNIT_ASSERT(list.count() == 1);
	CPPUNIT_ASSERT(list.contains("A000002") == 1);

}
Ejemplo n.º 2
0
void MyMoneyInstitutionTest::testReadXML() {
	MyMoneyInstitution i;
	QString ref_ok = QString(
		"<!DOCTYPE TEST>\n"
		"<INSTITUTION-CONTAINER>\n"
		" <INSTITUTION sortcode=\"sortcode\" id=\"I00001\" manager=\"manager\" name=\"name\" >\n"
		"  <ADDRESS street=\"street\" zip=\"postcode\" city=\"town\" telephone=\"telephone\" />\n"
		"  <ACCOUNTIDS>\n"
		"   <ACCOUNTID id=\"A000001\" />\n"
		"   <ACCOUNTID id=\"A000003\" />\n"
		"  </ACCOUNTIDS>\n"
                "  <KEYVALUEPAIRS>\n"
                "   <PAIR key=\"key\" value=\"value\" />\n"
                "  </KEYVALUEPAIRS>\n"
		" </INSTITUTION>\n"
		"</INSTITUTION-CONTAINER>\n");

	QString ref_false = QString(
		"<!DOCTYPE TEST>\n"
		"<INSTITUTION-CONTAINER>\n"
		" <KINSTITUTION sortcode=\"sortcode\" id=\"I00001\" manager=\"manager\" name=\"name\" >\n"
		"  <ADDRESS street=\"street\" zip=\"postcode\" city=\"town\" telephone=\"telephone\" />\n"
		"  <ACCOUNTIDS>\n"
		"   <ACCOUNTID id=\"A000001\" />\n"
		"   <ACCOUNTID id=\"A000003\" />\n"
		"  </ACCOUNTIDS>\n"
		" </KINSTITUTION>\n"
		"</INSTITUTION-CONTAINER>\n");

	QDomDocument doc;
	QDomElement node;

	doc.setContent(ref_false);
	node = doc.documentElement().firstChild().toElement();
	try {
		i = MyMoneyInstitution(node);
		CPPUNIT_FAIL("Missing expected exception");
	} catch(MyMoneyException *e) {
		delete e;
	}

	i.addAccountId("TEST");

	doc.setContent(ref_ok);
	node = doc.documentElement().firstChild().toElement();
	try {
		QStringList alist;
		alist << "A000001" << "A000003";
		i = MyMoneyInstitution(node);

		CPPUNIT_ASSERT(i.sortcode() == "sortcode");
		CPPUNIT_ASSERT(i.id() == "I00001");
		CPPUNIT_ASSERT(i.manager() == "manager");
		CPPUNIT_ASSERT(i.name() == "name");
		CPPUNIT_ASSERT(i.street() == "street");
		CPPUNIT_ASSERT(i.postcode() == "postcode");
		CPPUNIT_ASSERT(i.city() == "town");
		CPPUNIT_ASSERT(i.telephone() == "telephone");
		CPPUNIT_ASSERT(i.accountList() == alist);
		CPPUNIT_ASSERT(i.value(QString("key")) == "value");

	} catch(MyMoneyException *e) {
		delete e;
		CPPUNIT_FAIL("Unexpected exception");
	}
}