Improve encodings coverage

This commit is contained in:
Milo Yip
2016-04-15 13:50:24 +08:00
parent 105c92ee08
commit 1bfa188d18
2 changed files with 63 additions and 14 deletions

View File

@@ -423,3 +423,28 @@ TEST(EncodingsTest, UTF32) {
}
}
}
TEST(EncodingsTest, ASCII) {
StringBuffer os, os2;
for (unsigned codepoint = 0; codepoint < 128; codepoint++) {
os.Clear();
ASCII<>::Encode(os, codepoint);
const ASCII<>::Ch* encodedStr = os.GetString();
{
StringStream is(encodedStr);
unsigned decodedCodepoint;
bool result = ASCII<>::Decode(is, &decodedCodepoint);
if (!result || codepoint != decodedCodepoint)
std::cout << std::hex << codepoint << " " << decodedCodepoint << std::endl;
}
// Validate
{
StringStream is(encodedStr);
os2.Clear();
bool result = ASCII<>::Validate(is, os2);
EXPECT_TRUE(result);
EXPECT_EQ(0, StrCmp(encodedStr, os2.GetString()));
}
}
}