TEST(BalanceExecuteCommand, ByCategoryAndWallet) { // category specified by '-c' is not found // set-up 1 createFile("testWalletFile" , "1447245226;-;500.00;categ;RON\n" "1447245226;-;500.00;bam;RON\n" "1447245226;-;500.00;categ;RON\n" "1447245226;+;100.00;bam;RON\n" "1448011815;+;20.00;salaros;RON\n"); BalanceCmd balance ; vector <string> params ; params.push_back("-c") ; params.push_back("bam") ; params.push_back("-w") ; params.push_back("testWalletFile") ; MessageHandler message ; balance.setMessageHandler(message) ; // test EXPECT_EQ(true, balance.validateParams(params)) ; EXPECT_EQ(true, balance.executeCommand(params)) ; EXPECT_EQ(BALANCE_IS_MSG, message.getMessageCode()) ; EXPECT_EQ("-400.00", params.at(0)) ; // tear-down remove("testWalletFile") ; }
TEST(BalanceValidateParams, CannotOpenSpecifiedWallet) { // wallet specified by '-w' can not be opened // set-up 1 BalanceCmd balance ; vector <string> params ; params.push_back("-w") ; params.push_back("inexistent_wallet") ; MessageHandler message ; balance.setMessageHandler(message) ; // test EXPECT_EQ(false, balance.validateParams(params)) ; EXPECT_EQ(COULD_NOT_OPEN_FILE_BAL_ERR, message.getMessageCode()); // set-up 2 params.clear() ; params.push_back("--wallet") ; params.push_back("nonexistent_wallet") ; // test EXPECT_EQ(false, balance.validateParams(params)) ; EXPECT_EQ(COULD_NOT_OPEN_FILE_BAL_ERR, message.getMessageCode()); }
TEST(BalanceValidateParams, CategoryNotDefined) { // category specified by '-c' is not found createFile("testWalletFile" , "1447245226;-;564.00;other;RON\n" "1448011815;+;20.00;salary;RON\n"); createFile("batchTestFile", "default_wallet = testWalletFile"); // set-up 1 BalanceCmd balance("batchTestFile") ; vector <string> params ; params.push_back("-c") ; params.push_back("inexistent_category") ; MessageHandler message ; balance.setMessageHandler(message) ; // test EXPECT_EQ(false, balance.validateParams(params)) ; EXPECT_EQ(NO_TRANSACTION_REG_ERR, message.getMessageCode()); // set-up 2 BalanceCmd balance2("batchTestFile") ; MessageHandler message2 ; params.clear() ; params.push_back("--category") ; params.push_back("nonexistent_category") ; balance2.setMessageHandler(message2); // test EXPECT_EQ(false, balance2.validateParams(params)) ; EXPECT_EQ(NO_TRANSACTION_REG_ERR, message2.getMessageCode()); // set-up 3 BalanceCmd balance3("batchTestFile") ; MessageHandler message3 ; params.clear() ; params.push_back("--category") ; params.push_back("nonexistent_category") ; params.push_back("-w") ; params.push_back("testWalletFile") ; balance3.setMessageHandler(message3); // test EXPECT_EQ(false, balance3.validateParams(params)) ; EXPECT_EQ(NO_TRANSACTION_REG_ERR, message3.getMessageCode()); //tear-down remove("testWalletFile") ; remove("batchTestFile"); }
TEST(BalanceValidateParams, NoDefaultWallet) { // default_wallet is not configured // set-up BalanceCmd balance("testConfigFile") ; createFile("testConfigFile" , "default_wallet = "); vector <string> params0 ; MessageHandler message ; balance.setMessageHandler(message) ; balance.validateParams(params0) ; EXPECT_EQ(false, balance.validateParams(params0)) ; EXPECT_EQ(NO_DEFAULT_WALLET_ERR, message.getMessageCode()); }
TEST(BalanceValidateParams, CannotOpenDefaultWallet) { // default_wallet can not be opened // set-up BalanceCmd balance("testConfigFile") ; createFile("testConfigFile" , "default_wallet = bambamparam"); vector <string> params0 ; MessageHandler message ; balance.setMessageHandler(message) ; balance.validateParams(params0) ; // test EXPECT_EQ(false, balance.validateParams(params0)) ; EXPECT_EQ(COULD_NOT_OPEN_FILE_BAL_ERR, message.getMessageCode()); remove("testConfigFile") ; }
TEST(BalanceValidateParams, NoConfigFile) { // moneytracker config can not be opened // set-up BalanceCmd balance("noConfigFile") ; vector <string> params0 ; MessageHandler message ; balance.setMessageHandler(message) ; balance.validateParams(params0) ; EXPECT_EQ(false, balance.validateParams(params0)) ; EXPECT_EQ(COULD_NOT_OPEN_CONFIG_ERR, message.getMessageCode()); }