From: Steve Brokenshire Date: Wed, 25 Oct 2017 07:43:57 +0000 (+0100) Subject: CommonFunctions Unit Tests: WIP changes (ConvertToHTML & MapDataExists left) X-Git-Tag: release-0.21~19 X-Git-Url: http://Server1/repobrowser/?a=commitdiff_plain;h=1c98aaa412ec1110cc69c5189a7339c10e8c1bbe;p=xestiaab%2F.git CommonFunctions Unit Tests: WIP changes (ConvertToHTML & MapDataExists left) --- diff --git a/source/tests/xestiaab_common.h b/source/tests/xestiaab_common.h index c506d11..4939178 100644 --- a/source/tests/xestiaab_common.h +++ b/source/tests/xestiaab_common.h @@ -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()); }