X-Git-Url: http://Server1/repobrowser/?a=blobdiff_plain;ds=inline;f=source%2Ftests%2Fxestiacalendar_commonfunctions.h;h=e667aa6ee7e0610e05eb1095086fac82e90fa1d3;hb=e5ba41e02b0bfffed3f8d087f7a49e5fa617005f;hp=e6499fc02596cce5767288d2316954c24556eaf7;hpb=d0a9a1b8502a6ee2b2a24ad8338696dea87a68e3;p=xestiacalendar%2F.git
diff --git a/source/tests/xestiacalendar_commonfunctions.h b/source/tests/xestiacalendar_commonfunctions.h
index e6499fc..e667aa6 100644
--- a/source/tests/xestiacalendar_commonfunctions.h
+++ b/source/tests/xestiacalendar_commonfunctions.h
@@ -1,5 +1,24 @@
+// xestiacalendar_commonfunctions.h - Xestia Calendar Common Functions Unit Tests
+//
+// (c) 2016 Xestia Software Development.
+//
+// This file is part of Xestia Calendar.
+//
+// Xestia Address Book is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by the
+// Free Software Foundation, version 3 of the license.
+//
+// Xestia Address Book is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with Xestia Calendar. If not, see
+
#include "../common/file.h"
#include "../common/text.h"
+#include "../common/colour.h"
TEST(CommonFunctions, FileTests){
@@ -61,12 +80,30 @@ TEST(CommonFunctions, ProcessTextVectorsTests){
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"));
@@ -74,6 +111,13 @@ TEST(CommonFunctions, ProcessTextVectorsTests){
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."));
@@ -81,6 +125,13 @@ TEST(CommonFunctions, ProcessTextVectorsTests){
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"));
@@ -88,6 +139,13 @@ TEST(CommonFunctions, ProcessTextVectorsTests){
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"));
@@ -95,4 +153,144 @@ TEST(CommonFunctions, ProcessTextVectorsTests){
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 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, 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);
+
}
\ No newline at end of file