Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
CommonFunctions Unit Tests: WIP changes (ConvertToHTML & MapDataExists left)
authorSteve Brokenshire <sbrokenshire@xestia.co.uk>
Wed, 25 Oct 2017 07:43:57 +0000 (08:43 +0100)
committerSteve Brokenshire <sbrokenshire@xestia.co.uk>
Wed, 25 Oct 2017 07:43:57 +0000 (08:43 +0100)
source/tests/xestiaab_common.h

index c506d11..4939178 100644 (file)
@@ -335,72 +335,218 @@ 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());
 
 }
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