+ vector<string> textPropertiesExample1;
+ vector<string> textValueExample1;
+ multimap<string, string> textExample1TestResult;
+
+ textPropertiesExample1.push_back("ATTENDEE");
+ textValueExample1.push_back("Example Attendee 1");
+
+ textPropertiesExample1.push_back("ATTENDEE");
+ textValueExample1.push_back("Example Attendee 2");
+
+ textPropertiesExample1.push_back("ATTENDEE");
+ textValueExample1.push_back("Example Attendee 3");
+
+ textPropertiesExample1.push_back("CATEGORIES");
+ textValueExample1.push_back("CATEGORY 1");
+
+ textPropertiesExample1.push_back("CATEGORIES");
+ textValueExample1.push_back("CATEGORY 2");
+
+ textPropertiesExample1.push_back("CATEGORIES");
+ textValueExample1.push_back("CATEGORY 3");
+
+ textPropertiesExample1.push_back("COMMENT");
+ textValueExample1.push_back("This is the first comment.");
+
+ textPropertiesExample1.push_back("COMMENT");
+ textValueExample1.push_back("This is the second comment.");
+
+ textPropertiesExample1.push_back("COMMENT");
+ textValueExample1.push_back("This is the third comment.");
+
+ textPropertiesExample1.push_back("CONTACT;TEST=VALUE");
+ textValueExample1.push_back("First Contact");
+
+ textPropertiesExample1.push_back("CONTACT;LAZY=NOPE");
+ textValueExample1.push_back("Second Contact");
+
+ textPropertiesExample1.push_back("CONTACT;SETUP=NO");
+ textValueExample1.push_back("Third Contact");
+
+ textPropertiesExample1.push_back("RESOURCES;ROOM=YES");
+ textValueExample1.push_back("First Resource Widget");
+
+ textPropertiesExample1.push_back("RESOURCES;ROOM=NO");
+ textValueExample1.push_back("Second Resource Widget");
+
+ textPropertiesExample1.push_back("RESOURCES;ROOM=UNKNOWN");
+ textValueExample1.push_back("Third Resource Widget");
+
+ textPropertiesExample1.push_back("RELATED;RELATION=NO");
+ textValueExample1.push_back("First Relation");
+
+ textPropertiesExample1.push_back("RELATED;RELATION=YES");
+ textValueExample1.push_back("Second Relation");
+
+ textPropertiesExample1.push_back("RELATED;RELATION=MAYBE");
+ textValueExample1.push_back("Third Relation");
+
+ // Examples 1 & 2: ATTENDEE
+
+ textExample1TestResult.insert(make_pair("ATTENDEE", "Example Attendee 1"));
+ textExample1TestResult.insert(make_pair("ATTENDEE", "Example Attendee 2"));
+ textExample1TestResult.insert(make_pair("ATTENDEE", "Example Attendee 3"));
+
+ ASSERT_EQ(textExample1TestResult, ProcessTextVectors(&textPropertiesExample1, &textValueExample1, true, "ATTENDEE"));
+
+ textExample1TestResult.clear();
+ textExample1TestResult.insert(make_pair("ATTENDEE", "Example Attendee 1"));
+
+ ASSERT_EQ(textExample1TestResult, ProcessTextVectors(&textPropertiesExample1, &textValueExample1, false, "ATTENDEE"));
+
+ // Examples 3 & 4: CATEGORIES
+
+ textExample1TestResult.clear();
+ textExample1TestResult.insert(make_pair("CATEGORIES", "CATEGORY 1"));
+ textExample1TestResult.insert(make_pair("CATEGORIES", "CATEGORY 2"));
+ textExample1TestResult.insert(make_pair("CATEGORIES", "CATEGORY 3"));
+
+ ASSERT_EQ(textExample1TestResult, ProcessTextVectors(&textPropertiesExample1, &textValueExample1, true, "CATEGORIES"));
+
+ textExample1TestResult.clear();
+ textExample1TestResult.insert(make_pair("CATEGORIES", "CATEGORY 1"));
+
+ // Examples 5 & 6: COMMENT
+
+ ASSERT_EQ(textExample1TestResult, ProcessTextVectors(&textPropertiesExample1, &textValueExample1, false, "CATEGORIES"));
+
+ textExample1TestResult.clear();
+ textExample1TestResult.insert(make_pair("COMMENT", "This is the first comment."));
+ textExample1TestResult.insert(make_pair("COMMENT", "This is the second comment."));
+ textExample1TestResult.insert(make_pair("COMMENT", "This is the third comment."));
+
+ ASSERT_EQ(textExample1TestResult, ProcessTextVectors(&textPropertiesExample1, &textValueExample1, true, "COMMENT"));
+
+ textExample1TestResult.clear();
+ textExample1TestResult.insert(make_pair("COMMENT", "This is the first comment."));
+
+ // Examples 7 & 8: CONTACT;(properties)
+
+ ASSERT_EQ(textExample1TestResult, ProcessTextVectors(&textPropertiesExample1, &textValueExample1, false, "COMMENT"));
+
+ textExample1TestResult.clear();
+ textExample1TestResult.insert(make_pair("CONTACT;TEST=VALUE", "First Contact"));
+ textExample1TestResult.insert(make_pair("CONTACT;LAZY=NOPE", "Second Contact"));
+ textExample1TestResult.insert(make_pair("CONTACT;SETUP=NO", "Third Contact"));
+
+ ASSERT_EQ(textExample1TestResult, ProcessTextVectors(&textPropertiesExample1, &textValueExample1, true, "CONTACT"));
+
+ textExample1TestResult.clear();
+ textExample1TestResult.insert(make_pair("CONTACT;TEST=VALUE", "First Contact"));
+
+ // Examples 9 & 10: RESOURCES;(properties)
+
+ ASSERT_EQ(textExample1TestResult, ProcessTextVectors(&textPropertiesExample1, &textValueExample1, false, "CONTACT"));
+
+ textExample1TestResult.clear();
+ textExample1TestResult.insert(make_pair("RESOURCES;ROOM=YES", "First Resource Widget"));
+ textExample1TestResult.insert(make_pair("RESOURCES;ROOM=NO", "Second Resource Widget"));
+ textExample1TestResult.insert(make_pair("RESOURCES;ROOM=UNKNOWN", "Third Resource Widget"));
+
+ ASSERT_EQ(textExample1TestResult, ProcessTextVectors(&textPropertiesExample1, &textValueExample1, true, "RESOURCES"));
+
+ textExample1TestResult.clear();
+ textExample1TestResult.insert(make_pair("RESOURCES;ROOM=YES", "First Resource Widget"));
+
+ ASSERT_EQ(textExample1TestResult, ProcessTextVectors(&textPropertiesExample1, &textValueExample1, false, "RESOURCES"));
+
+ // Examples 11 & 12: RELATED;(properties)
+
+ textExample1TestResult.clear();
+ textExample1TestResult.insert(make_pair("RELATED;RELATION=NO", "First Relation"));
+ textExample1TestResult.insert(make_pair("RELATED;RELATION=YES", "Second Relation"));
+ textExample1TestResult.insert(make_pair("RELATED;RELATION=MAYBE", "Third Relation"));
+
+ ASSERT_EQ(textExample1TestResult, ProcessTextVectors(&textPropertiesExample1, &textValueExample1, true, "RELATED"));
+
+ textExample1TestResult.clear();
+ textExample1TestResult.insert(make_pair("RELATED;RELATION=NO", "First Relation"));
+
+ ASSERT_EQ(textExample1TestResult, ProcessTextVectors(&textPropertiesExample1, &textValueExample1, false, "RELATED"));
+
+}
+
+TEST(CommonFunctions, SplitValuesTests){
+
+ map<string, string> textExample1TestResult;
+
+ textExample1TestResult.insert(make_pair("RELATION", "NO"));
+ textExample1TestResult.insert(make_pair("TEST", "YES"));
+ textExample1TestResult.insert(make_pair("DATA", "SOMEDATA"));
+
+ ASSERT_EQ(textExample1TestResult, SplitValues("TEST;RELATION=NO;TEST=YES;DATA=SOMEDATA"));
+
+}
+
+TEST(CommonFunctions, SplitNameValueTests){
+
+ PropertyNameValue nameValueResult;
+
+ nameValueResult = SplitNameValue("TEST=OK");
+
+ string propertyName = nameValueResult.name;
+ string propertyValue = nameValueResult.value;
+
+ ASSERT_EQ(propertyName, "TEST");
+ ASSERT_EQ(propertyValue, "OK");
+
+}
+
+TEST(CommonFunctions, HexToInt){
+
+ string value1 = "10"; // 16
+ string value2 = "50"; // 80
+ string value3 = "4F"; // 79
+ string value4 = "FF"; // 255
+ string value5 = "FFF"; // 4095
+ string value6 = "FFFF"; // 65535
+ string value7 = "75AB"; // 30123
+ string value8 = "2AC"; // 684
+ string value9 = "!"; // Fail
+ string value10 = "4BZ"; // Fail
+ string value11 = "Z?!$"; // Fail
+
+ int outputValue = 0;
+ bool result = false;
+
+ result = HexToInt(&value1, &outputValue);
+
+ ASSERT_EQ(result, true);
+ ASSERT_EQ(outputValue, 16);
+
+ result = HexToInt(&value2, &outputValue);
+ ASSERT_EQ(result, true);
+ ASSERT_EQ(outputValue, 80);
+
+ result = HexToInt(&value3, &outputValue);
+ ASSERT_EQ(result, true);
+ ASSERT_EQ(outputValue, 79);
+
+ result = HexToInt(&value4, &outputValue);
+ ASSERT_EQ(result, true);
+ ASSERT_EQ(outputValue, 255);
+
+ result = HexToInt(&value5, &outputValue);
+ ASSERT_EQ(result, true);
+ ASSERT_EQ(outputValue, 4095);
+
+ result = HexToInt(&value6, &outputValue);
+ ASSERT_EQ(result, true);
+ ASSERT_EQ(outputValue, 65535);
+
+ result = HexToInt(&value7, &outputValue);
+ ASSERT_EQ(result, true);
+ ASSERT_EQ(outputValue, 30123);
+
+ result = HexToInt(&value8, &outputValue);
+ ASSERT_EQ(result, true);
+ ASSERT_EQ(outputValue, 684);
+
+ result = HexToInt(&value9, &outputValue);
+ ASSERT_EQ(result, false);
+
+ result = HexToInt(&value10, &outputValue);
+ ASSERT_EQ(result, false);
+
+ result = HexToInt(&value11, &outputValue);
+ ASSERT_EQ(result, false);
+
+}
+
+TEST(CommonFunctions, SplitPathFilename){
+
+ // Setup the file split.
+
+ string pathFilenameOriginal = "/example/file/yay.txt";
+ string path = "";
+ string file = "";
+
+ SplitPathFilename(&pathFilenameOriginal, &path, &file);
+
+ ASSERT_EQ("/example/file/", path);
+ ASSERT_EQ("yay.txt", file);
+
+ pathFilenameOriginal = "/a/path/with/lots/of/bits/in/andthenthis.html";
+ path.clear();
+ file.clear();
+
+ SplitPathFilename(&pathFilenameOriginal, &path, &file);
+
+ ASSERT_EQ("/a/path/with/lots/of/bits/in/", path);
+ ASSERT_EQ("andthenthis.html", file);
+
+ pathFilenameOriginal = "/one/more/for/a/laugh/hahaha.zip";
+ path.clear();
+ file.clear();
+
+ SplitPathFilename(&pathFilenameOriginal, &path, &file);
+
+ ASSERT_EQ("/one/more/for/a/laugh/", path);
+ ASSERT_EQ("hahaha.zip", file);
+
+}
+
+TEST(CommonFunctions, ColourStruct){
+
+ Colour colour1;
+ Colour colour2;
+ Colour colour3;
+ Colour colour4;
+
+ colour1.red = 0;
+ colour1.green = 0;
+ colour1.blue = 0;
+ colour1.alpha = 0;
+
+ colour2.red = 512;
+ colour2.green = 512;
+ colour2.blue = 512;
+ colour2.alpha = 512;
+
+ colour3.red = 16;
+ colour3.green = 16;
+ colour3.blue = 16;
+ colour3.alpha = 16;
+
+ colour4.red = 80;
+ colour4.green = 80;
+ colour4.blue = 80;
+ colour4.alpha = 80;
+
+ ASSERT_EQ("#00000000", (string)colour1);
+ ASSERT_EQ("#FFFFFFFF", (string)colour2);
+ ASSERT_EQ("#10101010", (string)colour3);
+ ASSERT_EQ("#50505050", (string)colour4);
+
+ string colourInput1 = "#204040FF";
+ string colourInput2 = "#408080FF";
+ string colourInput3 = "#A0A0A000";
+ string colourInput4 = "#FFFFFF20";
+
+ Colour colour5;
+ Colour colour6;
+ Colour colour7;
+ Colour colour8;
+
+ colour5 = colourInput1;
+ colour6 = colourInput2;
+ colour7 = colourInput3;
+ colour8 = colourInput4;
+
+ ASSERT_EQ(32, colour5.red);
+ ASSERT_EQ(64, colour5.green);
+ ASSERT_EQ(64, colour5.blue);
+ ASSERT_EQ(255, colour5.alpha);
+
+ ASSERT_EQ(64, colour6.red);
+ ASSERT_EQ(128, colour6.green);
+ ASSERT_EQ(128, colour6.blue);
+ ASSERT_EQ(255, colour6.alpha);
+
+ ASSERT_EQ(160, colour7.red);
+ ASSERT_EQ(160, colour7.green);
+ ASSERT_EQ(160, colour7.blue);
+ ASSERT_EQ(0, colour7.alpha);
+
+ ASSERT_EQ(255, colour8.red);
+ ASSERT_EQ(255, colour8.green);
+ ASSERT_EQ(255, colour8.blue);
+ ASSERT_EQ(32, colour8.alpha);
+}
+
+TEST(CommonFunctions, OutputText){
+
+ string inputText1 = "This is an example text.";
+ string outputText1 = "This is an example text.";
+ string resultText1 = "";
+
+ string inputText2 = "This is the first sentence. This is the second sentence"
+ ". This is the third sentence. This is the fourth sentence. This "
+ "is the fifth sentence.";
+ string outputText2 = "This is the first sentence. This is the second sentence"
+ ". This is the third se\n ntence. This is the fourth sentence. This "
+ "is the fifth sentence.";
+ string resultText2 = "";
+
+ string inputText3 = "This is the first sentence. This is the second sentence"
+ ". This is the third sentence. This is the fourth sentence. This "
+ "is the fifth sentence. This is the sixth sentence. This is the s"
+ "eventh sentence. This is the eighth sentence. This is the ninth "
+ "sentence. This is the tenth sentence.";
+ string outputText3 = "This is the first sentence. This is the second sentence. This is the third se\n"
+ " ntence. This is the fourth sentence. This is the fifth sentence. This is the\n"
+ " sixth sentence. This is the seventh sentence. This is the eighth sentence. \n"
+ " This is the ninth sentence. This is the tenth sentence.";
+ string resultText3 = "";
+
+ string inputText4 = "This is the first sentence. This is the second sentence"
+ ". This is the third sentence. This is the fourth sentence. This "
+ "is the fifth sentence. This is the sixth sentence. This is the s"
+ "eventh sentence. This is the eighth sentence. This is the ninth "
+ "sentence. This is the tenth sentence. This is the eleventh sente"
+ "nce. This is the twelfth sentence. This is the thirteenth senten"
+ "ce. This is the fourteenth sentence. This is the fifteenth sente"
+ "nce.";
+ string outputText4 = "This is the first sentence. This is the second sentence. This is the third se\n"
+ " ntence. This is the fourth sentence. This is the fifth sentence. This is the\n"
+ " sixth sentence. This is the seventh sentence. This is the eighth sentence. \n"
+ " This is the ninth sentence. This is the tenth sentence. This is the eleventh\n"
+ " sentence. This is the twelfth sentence. This is the thirteenth sentence. Th\n"
+ " is is the fourteenth sentence. This is the fifteenth sentence.";
+ string resultText4 = "";
+
+ string inputText5 = "This is the first sentence. This is the second sentence"
+ ". This is the third sentence. This is the fourth sentence. This "
+ "is the fifth sentence. This is the sixth sentence. This is the s"
+ "eventh sentence. This is the eighth sentence. This is the ninth "
+ "sentence. This is the tenth sentence. This is the eleventh sente"
+ "nce. This is the twelfth sentence. This is the thirteenth senten"
+ "ce. This is the fourteenth sentence. This is the fifteenth sente"
+ "nce. This is the sixteenth sentence. This is the seventeenth sen"
+ "tence. This is the eighteenth sentence. This is the ninteenth se"
+ "ntence. This is the twentieth sentence.";
+ string outputText5 = "This is the first sentence. This is the second sentence. This is the third se\n"
+ " ntence. This is the fourth sentence. This is the fifth sentence. This is the\n"
+ " sixth sentence. This is the seventh sentence. This is the eighth sentence. \n"
+ " This is the ninth sentence. This is the tenth sentence. This is the eleventh\n"
+ " sentence. This is the twelfth sentence. This is the thirteenth sentence. Th\n"
+ " is is the fourteenth sentence. This is the fifteenth sentence. This is the s\n"
+ " ixteenth sentence. This is the seventeenth sentence. This is the eighteenth \n"
+ " sentence. This is the ninteenth sentence. This is the twentieth sentence.";
+ string resultText5;
+
+ resultText1 = OutputText(&inputText1);
+ resultText2 = OutputText(&inputText2);
+ resultText3 = OutputText(&inputText3);
+ resultText4 = OutputText(&inputText4);
+ resultText5 = OutputText(&inputText5);
+
+ ASSERT_EQ(resultText1, outputText1);
+ ASSERT_EQ(resultText2, outputText2);
+ ASSERT_EQ(resultText3, outputText3);
+ ASSERT_EQ(resultText4, outputText4);
+ ASSERT_EQ(resultText5, outputText5);
+
+}
+
+TEST(CommonFunctions, PreviousMonthNumberofDays){
+
+ // Test the year 2015 (does not have a leap year).
+
+ ASSERT_EQ(30, PreviousMonthNumberofDays(12, 2015));
+
+ // Test the year 2016 (has a leap year).
+
+ ASSERT_EQ(31, PreviousMonthNumberofDays(1, 2016));
+ ASSERT_EQ(31, PreviousMonthNumberofDays(2, 2016));
+ ASSERT_EQ(29, PreviousMonthNumberofDays(3, 2016));
+ ASSERT_EQ(31, PreviousMonthNumberofDays(4, 2016));
+ ASSERT_EQ(30, PreviousMonthNumberofDays(5, 2016));
+ ASSERT_EQ(31, PreviousMonthNumberofDays(6, 2016));
+ ASSERT_EQ(30, PreviousMonthNumberofDays(7, 2016));
+ ASSERT_EQ(31, PreviousMonthNumberofDays(8, 2016));
+ ASSERT_EQ(31, PreviousMonthNumberofDays(9, 2016));
+ ASSERT_EQ(30, PreviousMonthNumberofDays(10, 2016));
+ ASSERT_EQ(31, PreviousMonthNumberofDays(11, 2016));
+ ASSERT_EQ(30, PreviousMonthNumberofDays(12, 2016));
+ ASSERT_EQ(31, PreviousMonthNumberofDays(1, 2017));
+
+ // Test the leap year section.
+
+ ASSERT_EQ(29, PreviousMonthNumberofDays(3, 2016));
+ ASSERT_EQ(29, PreviousMonthNumberofDays(3, 2012));
+ ASSERT_EQ(29, PreviousMonthNumberofDays(3, 2008));
+ ASSERT_EQ(29, PreviousMonthNumberofDays(3, 2004));
+ ASSERT_EQ(29, PreviousMonthNumberofDays(3, 2000));