Esempio n. 1
0
void TxnListTestCase::testLoad()
{
    copyFiles("txnbackup_ok");

    TxnManager txnManager;
    txnManager.loadFromFile();

    PRINT_DEBUG(txnManager.toJson());
    Assert(txnManager.size() == 2);
    TransactionPtr txnPtr = txnManager.getTransaction(1);
    Assert(txnPtr != NULL);
    Assert(txnPtr->getTimestamp() == 1441002600);
    PRINT_DEBUG(txnPtr->getPaymentType());
    Assert(txnPtr->getPaymentType() == "cash");
    Assert(txnPtr->getCartItem(1)->getType() == "LLSC");
    Assert(txnPtr->getCartItem(2)->getType() == "LLSC");

    txnPtr = txnManager.getTransaction(2);
    Assert(txnPtr->getTimestamp() == 1441002601);
    Assert(txnPtr->getCartItem(1)->getType() == "ThirdParty");
}
Esempio n. 2
0
void TxnListTestCase::testSave()
{
    TxnManager txnManager;

    TransactionPtr txnPtr(new CashTransaction(txnManager, CURRENT_TIME));
    txnManager.addTransaction(1, txnPtr);
    txnPtr->addCartItem(1, CartItemPtr(new TopupCartItem("tpurseload", 3, 300, "TPurse Load", false, 4, "123456789")));
    txnPtr->addCartItem(2, CartItemPtr(new TopupCartItem("tpurseload", 3, 300, "TPurse Load", false, 4, "12345678"))); 
    txnPtr->addCartItem(3, CartItemPtr(new TopupCartItem("tpurseload", 3, 300, "TPurse Load", false, 4, "1234567")));

    CURRENT_TIME += 1;

    txnPtr.reset(new CashTransaction(txnManager, CURRENT_TIME));
    txnManager.addTransaction(2, txnPtr);
    txnPtr->addCartItem(1, CartItemPtr(new CartItem("ThirdParty", 50, 46, "GTS Timetable short", true)));

    txnManager.saveToFile();

    // make sure our transactions are definitely there!
    Assert(txnManager.size() == 2);

    // constructor automatically loads from file
    TxnManager newTxnManager;
    newTxnManager.loadFromFile();

    Assert(newTxnManager.size() == 2);

    TransactionPtr newTxnPtr = newTxnManager.getTransaction(1);
    Assert(newTxnPtr->getTimestamp() == CURRENT_TIME - 1);
    Assert(newTxnPtr->getPaymentType() == "cash");
    Assert(newTxnPtr->getCartItem(1)->getType() == "tpurseload");
    Assert(newTxnPtr->getCartItem(2)->getType() == "tpurseload");
    Assert(newTxnPtr->getCartItem(3)->getType() == "tpurseload");

    newTxnPtr = newTxnManager.getTransaction(2);
    Assert(newTxnPtr->getTimestamp() == CURRENT_TIME);
    Assert(newTxnPtr->getPaymentType() == "cash");
    Assert(newTxnPtr->getCartItem(1)->getType() == "ThirdParty");
}
Esempio n. 3
0
void TxnListTestCase::testLoadInvalidCrc()
{
    copyFiles("txnbackup_invalidcrc");

    TxnManager txnManager;
    txnManager.loadFromFile();

    Assert(txnManager.size() == 1);
    txnManager.toJson();
    TransactionPtr txnPtr = txnManager.getTransaction(1);

    Assert(txnPtr != NULL);
    Assert(txnPtr->getTimestamp() == 1441002400);
    Assert(txnPtr->getPaymentType() == "cash");
    Assert(txnPtr->getCartItem(1)->getType() == "ThirdParty");
    Assert(txnPtr->getCartItem(2)->getType() == "LLSC");
}