X-Git-Url: http://Server1/repobrowser/?p=xestiaab%2F.git;a=blobdiff_plain;f=source%2Ftests%2Fxestiaab_common.h;h=49391785d7c64fb449a07684f057619cc5649d8d;hp=c506d1113faf5f0fbec3679b577dc0262320d34f;hb=1c98aaa412ec1110cc69c5189a7339c10e8c1bbe;hpb=89a5f60f67b881c9a38a276a249d165d6fb4bd9a 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()); }