Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
CommonFunctions Unit Tests: cleanup
[xestiaab/.git] / source / tests / xestiaab_common.h
index c506d11..5a37f83 100644 (file)
@@ -27,7 +27,8 @@ static wxString AccountInput1 = "Example1";
 static wxString AccountInput2 = "Example2";
 static wxString AccountInput3 = "Example3";
 
-TEST(CommonFunctions, GivenAPredefinedPathWhenGetUserDirIsCalledThenReceivedPathMatches){
+TEST(CommonFunctions, GivenAPredefinedPathWhenGetUserDirIsCalledThenReceivedPathMatches)
+{
        
        // Run the unit tests depending on the operating system being used.
        
@@ -57,7 +58,8 @@ TEST(CommonFunctions, GivenAPredefinedPathWhenGetUserDirIsCalledThenReceivedPath
        
 }
 
-TEST(CommonFunctions, GivenAPredefinedPathWhenGetUserPrefDirIsCalledThenReceivedPathMatches){
+TEST(CommonFunctions, GivenAPredefinedPathWhenGetUserPrefDirIsCalledThenReceivedPathMatches)
+{
        
        // Run the unit tests depending on the operating system being used.
        
@@ -87,7 +89,8 @@ TEST(CommonFunctions, GivenAPredefinedPathWhenGetUserPrefDirIsCalledThenReceived
 
 }
 
-TEST(CommonFunctions, GivenThreePredefinedPathsWhenGetAccountDirIsCalledForEachThenReceivedPathsMatches){
+TEST(CommonFunctions, GivenThreePredefinedPathsWhenGetAccountDirIsCalledForEachThenReceivedPathsMatches)
+{
        
        // Run the unit tests depending on the operating system being used.
        
@@ -136,7 +139,8 @@ TEST(CommonFunctions, GivenThreePredefinedPathsWhenGetAccountDirIsCalledForEachT
        
 }
 
-TEST(CommonFunctions, GivenThreePredefinedFilePathsWhenGetAccountDirIsCalledWithAppendServerCertificateSetToTrueForEachThenReceivedPathsMatches){
+TEST(CommonFunctions, GivenThreePredefinedFilePathsWhenGetAccountDirIsCalledWithAppendServerCertificateSetToTrueForEachThenReceivedPathsMatches)
+{
        
        // Run the unit tests depending on the operating system being used.
        
@@ -185,7 +189,8 @@ TEST(CommonFunctions, GivenThreePredefinedFilePathsWhenGetAccountDirIsCalledWith
        
 }
 
-TEST(CommonFunctions, GivenPredefinedFilePathWhenGetAccountsFileIsCalledThenReceivedFilePathMatches){
+TEST(CommonFunctions, GivenPredefinedFilePathWhenGetAccountsFileIsCalledThenReceivedFilePathMatches)
+{
        
        // Run the unit tests depending on the operating system being used.
        
@@ -217,7 +222,8 @@ TEST(CommonFunctions, GivenPredefinedFilePathWhenGetAccountsFileIsCalledThenRece
        
 }
 
-TEST(CommonFunctions, GivenPredefinedFilePathWhenGetSettingsFileIsCalledThenReceivedFilePathMatches){
+TEST(CommonFunctions, GivenPredefinedFilePathWhenGetSettingsFileIsCalledThenReceivedFilePathMatches)
+{
        
        // Run the unit tests depending on the operating system being used.
        
@@ -249,7 +255,8 @@ TEST(CommonFunctions, GivenPredefinedFilePathWhenGetSettingsFileIsCalledThenRece
        
 }
 
-TEST(CommonFunctions, GivenFivePredefinedFilenamePathsWhenCreateFilenamePathIsCalledThenReceivedPathMatches){
+TEST(CommonFunctions, GivenFivePredefinedFilenamePathsWhenCreateFilenamePathIsCalledThenReceivedPathMatches)
+{
        
        // Run the unit tests depending on the operating system being used.
        
@@ -287,7 +294,8 @@ TEST(CommonFunctions, GivenFivePredefinedFilenamePathsWhenCreateFilenamePathIsCa
        
 }
 
-TEST(CommonFunctions, GivenTwoFilesWhenGetMIMEIsCalledThenBothFilesMIMETypesAreGiven){
+TEST(CommonFunctions, GivenTwoFilesWhenGetMIMEIsCalledThenBothFilesMIMETypesAreGiven)
+{
        
        // Get the MIME type based on the files given.
        
@@ -308,7 +316,8 @@ TEST(CommonFunctions, GivenTwoFilesWhenGetMIMEIsCalledThenBothFilesMIMETypesAreG
        
 }
 
-TEST(CommonFunctions, GivenTwoDomainNamesWhenCheckBlacklistIsCalledThenReturnsCorrectStatus){
+TEST(CommonFunctions, GivenTwoDomainNamesWhenCheckBlacklistIsCalledThenReturnsCorrectStatus)
+{
        
        // Test that the blacklist is actually working.
 
@@ -335,142 +344,541 @@ TEST(CommonFunctions, GivenTwoDomainNamesWhenCheckBlacklistIsCalledThenReturnsCo
        
 }
 
-TEST(CommonFunctions, EscapeString){
+TEST(CommonFunctions, GivenExampleStringWhenEscapeStringIsCalledThenReturnedStringIsExample)
+{
 
        // Test the escape string function.
 
+       // Given
+
        wxString EscapeStringData = "Example";
+       
+       // When
+       
        EscapeString(&EscapeStringData, false);
+       
+       // Then
+       
        ASSERT_EQ("Example", EscapeStringData.ToStdString());
+       
+}
+
+TEST(CommonFunctions, GivenStringWithCommaWhenEscapeStringIsCalledThenCommaIsEscaped)
+{
+
+       // Test the escape string function.
+
+       // Given
 
        EscapeStringData = "Here we go, an \"example\" of escaping string.";
+       
+       // When
+       
        EscapeString(&EscapeStringData, false);
+       
+       // Then
+       
        ASSERT_EQ("Here we go\\, an \"example\" of escaping string.", EscapeStringData.ToStdString());
 
+}
+
+TEST(CommonFunctions, GivenStringWithNewlineCharactersWhenEscapeStringIsCalledThenNewlinesAreEscaped)
+{
+
+       // Test the escape string function.
+
+       // Given
+
        EscapeStringData = "Lets put some \nnew \nlines \nin \nhere.";
+       
+       // When
+       
        EscapeString(&EscapeStringData, false);
+       
+       // Then
+       
        ASSERT_EQ("Lets put some \\nnew \\nlines \\nin \\nhere.", EscapeStringData.ToStdString());
 
+}
+
+TEST(CommonFunctions, GivenAStringWithReturnCharactersWhenEscapeStringIsCalledThenReturnsAreRemoved)
+{
+
+       // Test the escape string function.
+
+       // Given
+
        EscapeStringData = "Lets put some \r\nnew \r\nlines \r\nin \r\nhere.";
+       
+       // When
+       
        EscapeString(&EscapeStringData, false);
+       
+       // Then
+       
        ASSERT_EQ("Lets put some \\nnew \\nlines \\nin \\nhere.", EscapeStringData.ToStdString());
 
+}
+
+TEST(CommonFunctions, GivenStringWithBackslashesWhenEscapeStringIsCalledThenBackslashesAreEscaped)
+{
+
+       // Test the escape string function.
+
+       // Given
+
        EscapeStringData = "A:\\path\\example\\lets\\have\\some\\fun";
+       
+       // When
+       
        EscapeString(&EscapeStringData, false);
+       
+       // Then
+       
        ASSERT_EQ("A:\\\\path\\\\example\\\\lets\\\\have\\\\some\\\\fun", EscapeStringData.ToStdString());
 
 }
 
-TEST(CommonFunctions, CaptureString){
+TEST(CommonFunctions, GivenExampleStringWhenCaptureStringIsCalledThenReturnedStringIsExample)
+{
 
        // Test the capture string function.
        
+       // Given
+       
        wxString CaptureStringData = "Example";
+       
+       // When
+       
        CaptureString(&CaptureStringData, false);
+       
+       // Then
+       
        ASSERT_EQ("Example", CaptureStringData.ToStdString());
 
+}
+
+TEST(CommonFunctions, GivenStringWithEscapedCommasWhenCaptureStringIsCalledThenCommasAreCaptured)
+{
+
+       // Test the capture string function.
+       
+       // Given
+       
        CaptureStringData = "Here we go\\, an \"example\" of escaping string.";
+       
+       // When
+       
        CaptureString(&CaptureStringData, false);
+       
+       // Then
+       
        ASSERT_EQ("Here we go, an \"example\" of escaping string.", CaptureStringData.ToStdString());
 
+}
+
+TEST(CommonFunctions, GivenStringWithEscapedNewlinesWhenCaptureStringIsCalledThenNewlinesAreCaptured)
+{
+
+       // Test the capture string function.
+       
+       // Given
+       
        CaptureStringData = "Lets put some \\nnew \\nlines \\nin \\nhere.";
+       
+       // When
+       
        CaptureString(&CaptureStringData, false);
+       
+       // Then
+       
        ASSERT_EQ("Lets put some \nnew \nlines \nin \nhere.", CaptureStringData.ToStdString());
 
+}
+
+TEST(CommonFunctions, GivenStringWithEscapedBackslashesWhenCaptureStringIsCalledThenBackslashesAreCaptured)
+{
+
+       // Test the capture string function.
+       
+       // Given
+       
        CaptureStringData = "A:\\\\path\\\\example\\\\lets\\\\have\\\\some\\\\fun";
+       
+       // When
+       
        CaptureString(&CaptureStringData, false);
+       
+       // Then
+       
        ASSERT_EQ("A:\\path\\example\\lets\\have\\some\\fun", CaptureStringData.ToStdString());
 
 }
 
-TEST(CommonFunctions, ResetUnusedString){
+TEST(CommonFunctions, GivenStringWithSeveralBackslashesWhenResetUnusedStringIsCalledThenStringIsReset)
+{
 
        // Tests for resetting an unused string.
 
+       // Given
+
        wxString ResetUnusedStringData = "Random string with a \\\\\\\\serverpath\\\\location";
+       
+       // When
+       
        ResetUnusedString(&ResetUnusedStringData);
+       
+       // Then
+       
        ASSERT_EQ("Random string with a \\\\serverpath\\location", ResetUnusedStringData.ToStdString());        
 
-       ResetUnusedStringData = "Some text \\nwith new \\nlines!";
-       ResetUnusedString(&ResetUnusedStringData);
-       ASSERT_EQ("Some text \nwith new \nlines!", ResetUnusedStringData.ToStdString());
+}
+
+TEST(CommonFunctions, GivenStringWithNewlinesWhenResetUnusedStringIsCalledThenStringIsFormatted)
+{
+
+       // Tests for resetting an unused string.
+
+       // Given
 
        ResetUnusedStringData = "Some text \\nwith new \\nlines!";
+       
+       // When
+       
        ResetUnusedString(&ResetUnusedStringData);
+       
+       // Then
+       
        ASSERT_EQ("Some text \nwith new \nlines!", ResetUnusedStringData.ToStdString());
+
+}
+
+TEST(CommonFunctions, GivenStringWithSeveralCharactersWhenResetUnusedStringThenStringIsFormatted)
+{
+
+       // Tests for resetting an unused string.
+
+       // Given
        
        ResetUnusedStringData = "And now the list of characters: \\\\ \\n \\; \\,";
+
+       // When
+
        ResetUnusedString(&ResetUnusedStringData);
+
+       // Then
+
        ASSERT_EQ("And now the list of characters: \\ \n ; ,", ResetUnusedStringData.ToStdString());
 
 }
 
-TEST(CommonFunctions, ConvertToHTML){
+TEST(CommonFunctions, GivenStringWhenConvertToHTMLIsCalledThenStringisHTMLEscaped)
+{
 
        // Tests for converting data for inserting into a HTML
        // formatted document.
 
+       // Given
+
        wxString ConvertToHTMLData = "The test line where < is probably better than >!";
+       
+       // When
+       
        ConvertToHTML(&ConvertToHTMLData);
+       
+       // Then
+       
        ASSERT_EQ("The test line where &lt; is probably better than &gt;!", ConvertToHTMLData.ToStdString());
 
+}
+
+TEST(CommonFunctions, GivenStringWithNewlineWhenConvertToHTMLIsCalledThenStringIsHTMLEscapedWithFormattedNewline)
+{
+
+       // Tests for converting data for inserting into a HTML
+       // formatted document.
+
+       // Given
+
        ConvertToHTMLData = "More testing &<>\n";
+       
+       // When
+       
        ConvertToHTML(&ConvertToHTMLData);
+       
+       // Then
+       
        ASSERT_EQ("More testing &amp;&lt;&gt;<br>", ConvertToHTMLData.ToStdString());
 
+}
+
+TEST(CommonFunctions, GivenStringWithSeveralLinesWhenConvertToHTMLIsCalledThenStringIsHTMLEscapedWithFormattedNewlines)
+{
+
+       // Tests for converting data for inserting into a HTML
+       // formatted document.
+
+       // Given
+               
        ConvertToHTMLData = "This is the first line.\nThis is the second line.\nThis is the third line.";
+       
+       // When
+       
        ConvertToHTML(&ConvertToHTMLData);
+       
+       // Then
+       
        ASSERT_EQ("This is the first line.<br>This is the second line.<br>This is the third line.", ConvertToHTMLData.ToStdString());
 
 }
 
-TEST(CommonFunctions, MapDataExists){
+static std::map<int,int> mapExample;
+static int itemIndex = 0;
+
+static mapExample.insert(std::make_pair(0,1));
+static mapExample.insert(std::make_pair(1,1));
+static mapExample.insert(std::make_pair(2,1));
+static mapExample.insert(std::make_pair(5,1));
+static mapExample.insert(std::make_pair(500,1));
+static mapExample.insert(std::make_pair(2415,1));
+static mapExistsStatus = false;
+
+TEST(CommonFunctions, GivenMapExistsStatusIsFalseAndItemIndexIs0WhenMapDataExistsIsCalledThenConfirmItemIndex0DoesExist)
+{
+
+       // Tests for checking that map data exists.
+
+       // Given
+
+       mapExistsStatus = false;
+       itemIndex = 0;
+       
+       // When
+
+       mapExistsStatus = MapDataExists(&itemIndex, &mapExample);
+
+       // Then
+
+       ASSERT_EQ(true, mapExistsStatus);
+
+}
+
+TEST(CommonFunctions, GivenMapExistsStatusIsFalseAndItemIndexIs1WhenMapDataExistsIsCalledThenConfirmItemIndex1DoesExist)
+{
+
+       // Tests for checking that map data exists.
+
+       // Given
+
+       mapExistsStatus = false;
+       itemIndex = 1;
+       
+       // When
+       
+       mapExistsStatus = MapDataExists(&itemIndex, &mapExample);
+       
+       // Then
+       
+       ASSERT_EQ(true, mapExistsStatus);
+
+}
+
+TEST(CommonFunctions, GivenMapExistsStatusIsFalseAndItemIndexIs2WhenMapDataExistsIsCalledThenConfirmItemIndex2DoesExist)
+{
+
+       // Tests for checking that map data exists.
+
+       // Given
+
+       mapStatusExists = false;
+       itemIndex = 2;
+       
+       // When
+       
+       mapStatusExists = MapDataExists(&itemIndex, &mapExample);
+       
+       // Then
+       
+       ASSERT_EQ(true, mapStatusExists);
+       
+}
+
+TEST(CommonFunctions, GivenMapExistsStatusIsTrueAndItemIndexIs3WhenMapDataExistsIsCalledThenConfirmItemIndex3DoesntExist)
+{
+
+       // Tests for checking that map data exists.
+
+       // Given
+
+       mapStatusExists = true;
+       itemIndex = 3;
+       
+       // When
+       
+       mapStatusExists = MapDataExists(&itemIndex, &mapExample);
+       
+       // Then
+       
+       ASSERT_EQ(false, mapStatusExists);
+       
+}
+
+TEST(CommonFunctions, GivenMapExistsStatusIsFalseAndItemIndexIs5WhenMapDataExistsIsCalledThenConfirmItemIndex5DoesExist)
+{
+
+       // Tests for checking that map data exists.
+
+       // Given
+
+       mapStatusExists = false;
+       itemIndex = 5;
+       
+       // When
+       
+       mapStatusExists = MapDataExists(&itemIndex, &mapExample);
+       
+       // Then
+       
+       ASSERT_EQ(true, mapStatusExists);
+
+}
+
+TEST(CommonFunctions, GivenMapExistsStatusIsTrueAndItemIndexIs6WhenMapDataExistsIsCalledThenConfirmItemIndex6DoesntExist)
+{
+
+       // Tests for checking that map data exists.
+
+       // Given
+
+       mapStatusExists = true;
+       itemIndex = 6;
+       
+       // When
+
+       mapStatusExists = MapDataExists(&itemIndex, &mapExample);
+       
+       // Then
+       
+       ASSERT_EQ(false, mapStatusExists);
+
+}
+
+TEST(CommonFunctions, GivenMapExistsStatusIsFalseAndItemIndexIs499WhenMapDataExistsIsCalledThenConfirmItemIndex499DoesntExist)
+{
+
+       // Tests for checking that map data exists.
+
+       // Given
+
+       mapStatusExists = false;
+       itemIndex = 499;
+       
+       // When
+       
+       mapStatusExists = MapDataExists(&itemIndex, &mapExample);
+       
+       // Then
+       
+       ASSERT_EQ(false, mapStatusExists);
+
+}
+
+TEST(CommonFunctions, GivenMapExistsStatusIsFalseAndItemIndexIs500WhenMapDataExistsIsCalledThenConfirmItemIndex500DoesExist)
+{
+
+       // Tests for checking that map data exists.
+
+       // Given
+
+       mapStatusExists = false;
+       itemIndex = 500;
+       
+       // When
+       
+       mapStatusExists = MapDataExists(&itemIndex, &mapExample);
+       
+       // Then
+       
+       ASSERT_EQ(true, mapStatusExists);
+       
+}
+
+TEST(CommonFunctions, GivenMapExistsStatusIsTrueAndItemIndexIs501WhenMapDataExistsIsCalledThenConfirmItemIndex501DoesntExist)
+{
 
        // Tests for checking that map data exists.
 
-       std::map<int,int> MapExample;
-       int ItemIndex = 0;
+       // Given
 
-       MapExample.insert(std::make_pair(0,1));
-       MapExample.insert(std::make_pair(1,1));
-       MapExample.insert(std::make_pair(2,1));
-       MapExample.insert(std::make_pair(5,1));
-       MapExample.insert(std::make_pair(500,1));
-       MapExample.insert(std::make_pair(2415,1));
+       mapStatusExists = true;
+       itemIndex = 501;
+       
+       // When
+       
+       mapStatusExists = MapDataExists(&itemIndex, &mapExample);
+       
+       // Then
+       
+       ASSERT_EQ(false, mapStatusExists);
 
-       ASSERT_EQ(true, MapDataExists(&ItemIndex, &MapExample));
+}
 
-       ItemIndex = 1;
-       ASSERT_EQ(true, MapDataExists(&ItemIndex, &MapExample));
+TEST(CommonFunctions, GivenMapExistsStatusIsTrueAndItemIndexIs2414WhenMapDataExistsIsCalledThenConfirmItemIndex2414DoesntExist)
+{
 
-       ItemIndex = 2;
-       ASSERT_EQ(true, MapDataExists(&ItemIndex, &MapExample));
+       // Tests for checking that map data exists.
 
-       ItemIndex = 3;
-       ASSERT_EQ(false, MapDataExists(&ItemIndex, &MapExample));
+       // Given
 
-       ItemIndex = 5;
-       ASSERT_EQ(true, MapDataExists(&ItemIndex, &MapExample));
+       mapStatusExists = true;
+       itemIndex = 2414;
+       
+       // When
+       
+       mapStatusExists = MapDataExists(&itemIndex, &mapExample);
+       
+       // Then
+       
+       ASSERT_EQ(false, mapStatusExists);
 
-       ItemIndex = 6;
-       ASSERT_EQ(false, MapDataExists(&ItemIndex, &MapExample));
+}
 
-       ItemIndex = 499;
-       ASSERT_EQ(false, MapDataExists(&ItemIndex, &MapExample));
+TEST(CommonFunctions, GivenMapExistsStatusIsFalseAndItemIndexIs2415WhenMapDataExistsIsCalledThenConfirmItemIndex2415DoesExist)
+{
 
-       ItemIndex = 500;
-       ASSERT_EQ(true, MapDataExists(&ItemIndex, &MapExample));
+       // Tests for checking that map data exists.
+
+       // Given
+
+       mapStatusExists = false;
+       itemIndex = 2415;
+       
+       // When
+       
+       mapStatusExists = MapDataExists(&itemIndex, &mapExample);
+       
+       // Then
+       
+       ASSERT_EQ(true, mapStatusExists);
 
-       ItemIndex = 501;
-       ASSERT_EQ(false, MapDataExists(&ItemIndex, &MapExample));
+}
 
-       ItemIndex = 2414;
-       ASSERT_EQ(false, MapDataExists(&ItemIndex, &MapExample));
+TEST(CommonFunctions, GivenMapExistsStatusIsTrueAndItemIndexIs2416WhenMapDataExistsIsCalledThenConfirmItemIndex2416DoesntExist)
+{
 
-       ItemIndex = 2415;
-       ASSERT_EQ(true, MapDataExists(&ItemIndex, &MapExample));
+       // Tests for checking that map data exists.
 
-       ItemIndex = 2416;
-       ASSERT_EQ(false, MapDataExists(&ItemIndex, &MapExample));
+       // Given
+
+       mapStatusExists = true;
+       itemIndex = 2416;
+       
+       // When
+       
+       mapStatusExists = MapDataExists(&itemIndex, &mapExample);
+       
+       // Then
+       
+       ASSERT_EQ(false, mapStatusExists);
 
 }
\ No newline at end of file
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy