#include "CalendarEvent.h"
+using namespace std;
+
CalendarObjectValidResult CalendarEventObject::ValidObject(){
- return CALENDAROBJECTVALID_UNITTESTFAIL;
-
+ bool ValidBegin = false;
+ bool ValidEnd = false;
+ bool ValidDateTimeStamp = false;
+ bool ValidUniqueID = false;
+ int SeekCount = 0;
+
+ // Look for BEGIN:VEVENT.
+
+ for (vector<string>::iterator iter = ObjectName.begin();
+ iter != ObjectName.end(); iter++){
+
+ if (ObjectName[SeekCount] == "BEGIN" &&
+ ObjectData[SeekCount] == "VEVENT"){
+
+ if (ValidBegin == false){
+ ValidBegin = true;
+ } else {
+ return CALENDAROBJECTVALID_INVALIDFORMAT;
+ }
+
+ }
+
+ if (ObjectName[SeekCount] == "END" &&
+ ObjectData[SeekCount] == "VEVENT" &&
+ ValidBegin == false){
+
+ return CALENDAROBJECTVALID_INVALIDFORMAT;
+
+ }
+
+ SeekCount++;
+
+ }
+
+ SeekCount = 0;
+
+ // Look for DTSTAMP.
+
+ for (vector<string>::iterator iter = ObjectName.begin();
+ iter != ObjectName.end(); iter++){
+
+ if (ObjectName[SeekCount] == "DTSTAMP"){
+
+ if (ValidDateTimeStamp == false){
+ ValidDateTimeStamp = true;
+ } else {
+ return CALENDAROBJECTVALID_INVALIDFORMAT;
+ }
+
+ }
+
+ SeekCount++;
+
+ }
+
+ SeekCount = 0;
+
+ // Look for UID.
+
+ for (vector<string>::iterator iter = ObjectName.begin();
+ iter != ObjectName.end(); iter++){
+
+ if (ObjectName[SeekCount] == "UID"){
+
+ if (ValidUniqueID == false){
+ ValidUniqueID = true;
+ } else {
+ return CALENDAROBJECTVALID_INVALIDFORMAT;
+ }
+
+ }
+
+ SeekCount++;
+
+ }
+
+ SeekCount = 0;
+
+ // Look for END:VEVENT.
+
+ for (vector<string>::iterator iter = ObjectName.begin();
+ iter != ObjectName.end(); iter++){
+
+ if (ObjectName[SeekCount] == "END" &&
+ ObjectData[SeekCount] == "VEVENT"){
+
+ if (ValidEnd == false){
+ ValidEnd = true;
+ } else {
+ return CALENDAROBJECTVALID_INVALIDFORMAT;
+ }
+
+ }
+
+ SeekCount++;
+
+ }
+
+ // Check if the VEVENT is valid.
+
+ if (ValidBegin == true &&
+ ValidEnd == true &&
+ ValidDateTimeStamp == true &&
+ ValidUniqueID == true){
+
+ return CALENDAROBJECTVALID_OK;
+
+ } else {
+
+ return CALENDAROBJECTVALID_INVALIDFORMAT;
+
+ }
+
}