void TestEnc() { // Test empty string TestEncodeHelper("", ""); // Test that all characters we shouldn't encode ([33-36],[38,126]) are not. nsCString noenc; for (PRInt32 i = 33; i < 127; i++) { if (i != 37) { // skip % noenc.Append(static_cast<char>(i)); } } nsUrlClassifierUtils utils; nsCString out; utils.SpecialEncode(noenc, false, out); CheckEquals(noenc, out); // Test that all the chars that we should encode [0,32],37,[127,255] are nsCString yesAsString, yesExpectedString; for (PRInt32 i = 1; i < 256; i++) { if (i < 33 || i == 37 || i > 126) { yesAsString.Append(static_cast<char>(i)); yesExpectedString.Append('%'); yesExpectedString.Append(int_to_hex_digit(i / 16)); yesExpectedString.Append(int_to_hex_digit(i % 16)); } } out.Truncate(); utils.SpecialEncode(yesAsString, false, out); CheckEquals(yesExpectedString, out); TestEncodeHelper("blah//blah", "blah/blah"); }
void __fastcall TTestCalclator::Testplus() { //int plus(int, int); Calclator aCalc; CheckEquals(2, aCalc.plus(1,1)); CheckEquals(3, aCalc.plus(1,2)); CheckEquals(0, aCalc.plus(1,1)); }
void TestUnescapeHelper(const char* in, const char* expected) { nsCString out, strIn(in), strExp(expected); nsUrlClassifierUtils utils; NS_UnescapeURL(strIn.get(), strIn.Length(), esc_AlwaysCopy, out); CheckEquals(strExp, out); }
void TestCanonicalizeHelper(const char* in, const char* expected) { nsCString out, strIn(in), strExp(expected); nsUrlClassifierUtils utils; utils.CanonicalizePath(strIn, out); CheckEquals(strExp, out); }
void TestEncodeHelper(const char* in, const char* expected) { nsCString out, strIn(in), strExp(expected); nsUrlClassifierUtils utils; utils.SpecialEncode(strIn, true, out); CheckEquals(strExp, out); }
void TestParseIPAddressHelper(const char *in, const char *expected) { nsCString out, strIn(in), strExp(expected); nsUrlClassifierUtils utils; utils.Init(); utils.ParseIPAddress(strIn, out); CheckEquals(strExp, out); }
// Make sure Unescape from nsEncode.h's unescape does what the server does. void TestUnescape() { // test empty string TestUnescapeHelper("\0", "\0"); // Test docoding of all characters. nsCString allCharsEncoded, allCharsEncodedLowercase, allCharsAsString; for (PRInt32 i = 1; i < 256; ++i) { allCharsEncoded.Append('%'); allCharsEncoded.Append(int_to_hex_digit(i / 16)); allCharsEncoded.Append((int_to_hex_digit(i % 16))); allCharsEncodedLowercase.Append('%'); allCharsEncodedLowercase.Append(tolower(int_to_hex_digit(i / 16))); allCharsEncodedLowercase.Append(tolower(int_to_hex_digit(i % 16))); allCharsAsString.Append(static_cast<char>(i)); } nsUrlClassifierUtils utils; nsCString out; NS_UnescapeURL(allCharsEncoded.get(), allCharsEncoded.Length(), esc_AlwaysCopy, out); CheckEquals(allCharsAsString, out); out.Truncate(); NS_UnescapeURL(allCharsEncodedLowercase.get(), allCharsEncodedLowercase.Length(), esc_AlwaysCopy, out); CheckEquals(allCharsAsString, out); // Test %-related edge cases TestUnescapeHelper("%", "%"); TestUnescapeHelper("%xx", "%xx"); TestUnescapeHelper("%%", "%%"); TestUnescapeHelper("%%%", "%%%"); TestUnescapeHelper("%%%%", "%%%%"); TestUnescapeHelper("%1", "%1"); TestUnescapeHelper("%1z", "%1z"); TestUnescapeHelper("a%1z", "a%1z"); TestUnescapeHelper("abc%d%e%fg%hij%klmno%", "abc%d%e%fg%hij%klmno%"); // A few more tests TestUnescapeHelper("%25", "%"); TestUnescapeHelper("%25%32%35", "%25"); }
void TestCanonicalNumHelper(const char *in, PRUint32 bytes, bool allowOctal, const char *expected) { nsCString out, strIn(in), strExp(expected); nsUrlClassifierUtils utils; utils.Init(); utils.CanonicalNum(strIn, bytes, allowOctal, out); CheckEquals(strExp, out); }
void TestLongHostname() { static const int kTestSize = 1024 * 150; char *str = static_cast<char*>(malloc(kTestSize + 1)); memset(str, 'x', kTestSize); str[kTestSize] = '\0'; nsUrlClassifierUtils utils; utils.Init(); nsCAutoString out; nsDependentCString in(str); PRIntervalTime clockStart = PR_IntervalNow(); utils.CanonicalizeHostname(in, out); PRIntervalTime clockEnd = PR_IntervalNow(); CheckEquals(in, out); printf("CanonicalizeHostname on long string (%dms)\n", PR_IntervalToMilliseconds(clockEnd - clockStart)); }