int resultCode;
sqlite3_stmt *statementHandle;
+ sqlite3_stmt *findHandle;
+
+ if (accountName == ""){
+ return CDSACCOUNT_NONAME;
+ }
+
+ // Check if the account name already exsits.
+
+ resultCode = sqlite3_prepare_v2(db, "SELECT name FROM accounts WHERE name=(?1);", -1, &findHandle, nullptr);
+
+ if (resultCode != 0){
+ return CDSACCOUNT_FAILED;
+ }
+
+ resultCode = sqlite3_bind_text(findHandle, 1, accountName.c_str(), -1, SQLITE_STATIC);
+
+ if (resultCode != 0){
+ return CDSACCOUNT_FAILED;
+ }
+
+ resultCode = sqlite3_step(findHandle);
+
+ if (resultCode != SQLITE_DONE){
+ return CDSACCOUNT_FAILED;
+ } else if (resultCode == SQLITE_ROW){
+ return CDSACCOUNT_FAILED;
+ }
resultCode = sqlite3_prepare_v2(db, "INSERT INTO accounts (name, preferencesid) VALUES(?1, ?2);", -1, &statementHandle, nullptr);
int resultCode;
sqlite3_stmt *findHandle;
+ sqlite3_stmt *existingHandle;
sqlite3_stmt *statementHandle;
+ if (accountName == ""){
+ return CDSACCOUNT_NONAME;
+ }
+
// Check if account exists first.
resultCode = sqlite3_prepare_v2(db, "SELECT id from accounts WHERE id=(?1);", -1, &findHandle, nullptr);
return CDSACCOUNT_FAILED;
}
+ // Check if account with the name given already exists before renaming.
+
+ resultCode = sqlite3_prepare_v2(db, "SELECT name from accounts WHERE name=(?1);", -1, &existingHandle, nullptr);
+
+ if (resultCode != 0){
+ return CDSACCOUNT_FAILED;
+ }
+
+ resultCode = sqlite3_bind_text(existingHandle, 1, accountName.c_str(), -1, SQLITE_STATIC);
+
+ if (resultCode != 0){
+ return CDSACCOUNT_FAILED;
+ }
+
+ resultCode = sqlite3_step(existingHandle);
+
+ if (resultCode == SQLITE_ROW){
+ return CDSACCOUNT_FAILED;
+ } else if (resultCode == SQLITE_DONE) {
+
+ } else {
+ return CDSACCOUNT_FAILED;
+ }
+
// Update the account.
resultCode = sqlite3_prepare_v2(db, "UPDATE accounts SET name=(?1) WHERE id=(?2);", -1, &statementHandle, nullptr);
} else if (resultCode == SQLITE_DONE) {
return CDSACCOUNT_NOACCOUNT;
} else {
- return CDSACCOUNT_FAILED;
+
}
// Delete the account.
CDSCalendarResult addResult = CDSCALENDAR_UNITTESTFAIL;
int resultCode;
-
+
+ sqlite3_stmt *findHandle;
sqlite3_stmt *statementHandle;
+ // Check if the account exists first.
+
+ resultCode = sqlite3_prepare_v2(db, "SELECT id FROM accounts WHERE id=(?1);", -1, &findHandle, nullptr);
+
+ if (resultCode != 0){
+ return CDSCALENDAR_FAILED;
+ }
+
+ resultCode = sqlite3_bind_int(findHandle, 1, accountID);
+
+ if (resultCode != 0){
+ return CDSCALENDAR_FAILED;
+ }
+
+ resultCode = sqlite3_step(findHandle);
+
+ if (resultCode != SQLITE_DONE){
+ return CDSCALENDAR_NOACCOUNT;
+ }
+
resultCode = sqlite3_prepare_v2(db, "INSERT INTO calendars (name, calendarid, accountid, colour, description) VALUES(?1, ?2, ?3, ?4, ?5);", -1, &statementHandle, nullptr);
if (resultCode != 0){
}
+TEST(CalendarDataStorage, Add_Account_With_No_Name_And_Return_No_Name_Message){
+
+ CalendarDataStorage failNameTest;
+
+ ASSERT_EQ(CDSACCOUNT_NONAME, failNameTest.AddAccount("", 1));
+
+}
+
+TEST(CalendarDataStorage, Add_Account_With_Same_Name_Twice_And_Return_Failed_Message){
+
+ CalendarDataStorage duplicateNameTest;
+
+ ASSERT_EQ(CDSACCOUNT_OK, duplicateNameTest.AddAccount("Account 1", 1));
+ ASSERT_EQ(CDSACCOUNT_FAILED, duplicateNameTest.AddAccount("Account 1", 1));
+
+}
+
TEST(CalendarDataStorage, Get_Account_Information){
CalendarDataStorage accountInformationTest;
}
+TEST(CalendarDataStorage, Get_Account_Information_That_Does_Not_Exist_Return_No_Account_Message){
+
+ CalendarDataStorage noAccountTest;
+
+ ASSERT_EQ(CDSACCOUNT_NOACCOUNT, noAccountTest.GetAccount("Test Account 1").accountInfoResult);
+
+}
+
TEST(CalendarDataStorage, Get_Two_Accounts_Information){
CalendarDataStorage accountInformationTest;
}
+TEST(CalendarDataStorage, Update_One_Account_Set_Account_Name_To_No_Name_Return_No_Name_Message){
+
+ CalendarDataStorage updateAccountTest;
+
+ updateAccountTest.AddAccount("Test Account 1", 1);
+
+ int testAccount1ID = updateAccountTest.GetAccount("Test Account 1").accountID;
+
+ EXPECT_EQ(1, testAccount1ID);
+ ASSERT_EQ(CDSACCOUNT_NONAME, updateAccountTest.UpdateAccount(testAccount1ID, ""));
+
+}
+
+TEST(CalendarDataStorage, Update_One_Account_Set_Account_Name_To_Existing_Account_Return_Failed_Message){
+
+ CalendarDataStorage updateAccountTest;
+
+ updateAccountTest.AddAccount("Test Account 1", 1);
+ updateAccountTest.AddAccount("Test Account 2", 2);
+
+ int testAccount2ID = updateAccountTest.GetAccount("Test Account 2").accountID;
+
+ EXPECT_EQ(2, testAccount2ID);
+ ASSERT_EQ(CDSACCOUNT_FAILED, updateAccountTest.UpdateAccount(testAccount2ID, "Test Account 1"));
+
+}
+
+TEST(CalendarDataStorage, Update_One_Account_That_Does_Not_Exist_Return_No_Account_Message){
+
+ CalendarDataStorage updateAccountTest;
+
+ ASSERT_EQ(CDSACCOUNT_NOACCOUNT, updateAccountTest.UpdateAccount(1, "Missing Account"));
+
+}
+
TEST(CalendarDataStorage, Update_Two_Accounts){
CalendarDataStorage updateAccountTest;
}
+TEST(CalendarDataStorage, Delete_Account_That_Does_Not_Exist_Return_No_Account_Message){
+
+ CalendarDataStorage deleteAccountTest;
+
+ ASSERT_EQ(CDSACCOUNT_NOACCOUNT, deleteAccountTest.DeleteAccount(1));
+
+}
+
TEST(CalendarDataStorage, Add_One_Calendar_To_One_Account){
CalendarDataStorage addCalendarTest;
}
+TEST(CalendarDataStorage, Add_Calendar_To_Account_That_Does_Not_Exist_Return_No_Account_Message){
+
+ CalendarDataStorage addCalendarTest;
+
+ ASSERT_EQ(CDSCALENDAR_NOACCOUNT, addCalendarTest.AddCalendar(addCalendarTest.GetAccount("Test Account 1").accountID, "Calendar 1", "calendar1-test", defaultColour, "Calendar Description"));
+
+}
+
TEST(CalendarDataStorage, Add_One_Calendar_To_Two_Accounts){
CalendarDataStorage addCalendarTest;
EXPECT_EQ(CDSCALENDAR_OK, deleteAccountTest.DeleteAccount(1));
- EXPECT_EQ(CDSENTRY_NOACCOUNT, deleteAccountTest.GetCalendar("Test Account 1", "calendar1-test").calendarInfoResult);
+ EXPECT_EQ(CDSENTRY_NOACCOUNT, deleteAccountTest.GetCalendar("Test Account 1", "calendar1-test").accountInfoResult);
+ EXPECT_EQ(CDSENTRY_NOCALENDAR, deleteAccountTest.GetCalendar("Test Account 1", "calendar1-test").calendarInfoResult);
EXPECT_EQ(CDSENTRY_NOENTRY, deleteAccountTest.GetEvent(addEvent1Result.calendarEntryID).getEventResult);
EXPECT_EQ(CDSENTRY_NOENTRY, deleteAccountTest.GetEvent(addEvent2Result.calendarEntryID).getEventResult);
EXPECT_EQ(CDSCALENDAR_OK, deleteAccountTest.DeleteAccount(1));
- EXPECT_EQ(CDSENTRY_NOACCOUNT, deleteAccountTest.GetCalendar("Test Account 1", "calendar1-test").calendarInfoResult);
+ EXPECT_EQ(CDSENTRY_NOACCOUNT, deleteAccountTest.GetCalendar("Test Account 1", "calendar1-test").accountInfoResult);
+ EXPECT_EQ(CDSENTRY_NOCALENDAR, deleteAccountTest.GetCalendar("Test Account 1", "calendar1-test").calendarInfoResult);
EXPECT_EQ(CDSENTRY_NOENTRY, deleteAccountTest.GetEvent(addEvent1Result.calendarEntryID).getEventResult);
EXPECT_EQ(CDSENTRY_NOENTRY, deleteAccountTest.GetEvent(addEvent2Result.calendarEntryID).getEventResult);
EXPECT_EQ(CDSCALENDAR_OK, deleteAccountTest.DeleteAccount(2));
- EXPECT_EQ(CDSENTRY_NOACCOUNT, deleteAccountTest.GetCalendar("Test Account 2", "calendar1-test").calendarInfoResult);
+ EXPECT_EQ(CDSENTRY_NOACCOUNT, deleteAccountTest.GetCalendar("Test Account 2", "calendar1-test").accountInfoResult);
+ EXPECT_EQ(CDSENTRY_NOCALENDAR, deleteAccountTest.GetCalendar("Test Account 2", "calendar1-test").calendarInfoResult);
EXPECT_EQ(CDSENTRY_NOENTRY, deleteAccountTest.GetEvent(addEvent1Result.calendarEntryID).getEventResult);
EXPECT_EQ(CDSENTRY_NOENTRY, deleteAccountTest.GetEvent(addEvent2Result.calendarEntryID).getEventResult);
EXPECT_EQ(CDSCALENDAR_OK, deleteAccountTest.DeleteAccount(1));
- EXPECT_EQ(CDSENTRY_NOACCOUNT, deleteAccountTest.GetCalendar("Test Account 1", "calendar1-test").calendarInfoResult);
+ EXPECT_EQ(CDSENTRY_NOACCOUNT, deleteAccountTest.GetCalendar("Test Account 1", "calendar1-test").accountInfoResult);
+ EXPECT_EQ(CDSENTRY_NOCALENDAR, deleteAccountTest.GetCalendar("Test Account 1", "calendar1-test").calendarInfoResult);
EXPECT_EQ(CDSENTRY_NOENTRY, deleteAccountTest.GetEvent(addEvent1Result.calendarEntryID).getEventResult);
EXPECT_EQ(CDSENTRY_NOENTRY, deleteAccountTest.GetEvent(addEvent2Result.calendarEntryID).getEventResult);
EXPECT_EQ(CDSCALENDAR_OK, deleteAccountTest.DeleteAccount(2));
- EXPECT_EQ(CDSENTRY_NOACCOUNT, deleteAccountTest.GetCalendar("Test Account 2", "calendar1-test").calendarInfoResult);
+ EXPECT_EQ(CDSENTRY_NOACCOUNT, deleteAccountTest.GetCalendar("Test Account 2", "calendar1-test").accountInfoResult);
+ EXPECT_EQ(CDSENTRY_NOCALENDAR, deleteAccountTest.GetCalendar("Test Account 2", "calendar1-test").calendarInfoResult);
EXPECT_EQ(CDSENTRY_NOENTRY, deleteAccountTest.GetEvent(addEvent1Result.calendarEntryID).getEventResult);
EXPECT_EQ(CDSENTRY_NOENTRY, deleteAccountTest.GetEvent(addEvent2Result.calendarEntryID).getEventResult);
EXPECT_EQ(CDSCALENDAR_OK, deleteAccountTest.DeleteAccount(3));
- EXPECT_EQ(CDSENTRY_NOACCOUNT, deleteAccountTest.GetCalendar("Test Account 3", "calendar1-test").calendarInfoResult);
+ EXPECT_EQ(CDSENTRY_NOACCOUNT, deleteAccountTest.GetCalendar("Test Account 3", "calendar1-test").accountInfoResult);
+ EXPECT_EQ(CDSENTRY_NOCALENDAR, deleteAccountTest.GetCalendar("Test Account 3", "calendar1-test").calendarInfoResult);
EXPECT_EQ(CDSENTRY_NOENTRY, deleteAccountTest.GetEvent(addEvent1Result.calendarEntryID).getEventResult);
EXPECT_EQ(CDSENTRY_NOENTRY, deleteAccountTest.GetEvent(addEvent2Result.calendarEntryID).getEventResult);