}
TEST(EscapeXml, ControlChars) {
- uint8_t cc1[] = { 0x01, 0x02, 0x03, 0x0 };
- ASSERT_EQ(escape_xml_attrs((char*)cc1), "");
+ ASSERT_EQ(escape_xml_attrs("\x01\x02\x03"), "");
- uint8_t cc2[] = { 0x61, 0x62, 0x63, 0x7f, 0x0 };
- ASSERT_EQ(escape_xml_attrs((char*)cc2), "abc");
+ ASSERT_EQ(escape_xml_attrs("abc\x7f"), "abc");
}
TEST(EscapeXml, Utf8) {
- uint8_t cc1[] = { 0xe6, 0xb1, 0x89, 0xe5, 0xad, 0x97, 0x0a, 0x0 };
- ASSERT_EQ(escape_xml_attrs((const char*)cc1), (const char*)cc1);
+ const char *cc1 = "\xe6\xb1\x89\xe5\xad\x97\n";
+ ASSERT_EQ(escape_xml_attrs(cc1), cc1);
- uint8_t cc2[] = { 0x3c, 0xe6, 0xb1, 0x89, 0xe5, 0xad, 0x97, 0x3e, 0x0a, 0x0 };
- uint8_t cc2_out[] = { 0x26, 0x6c, 0x74, 0x3b, 0xe6, 0xb1, 0x89, 0xe5,
- 0xad, 0x97, 0x26, 0x67, 0x74, 0x3b, 0x0a, 0x0 };
- ASSERT_EQ(escape_xml_attrs((const char*)cc2), (const char*)cc2_out);
+ ASSERT_EQ(escape_xml_attrs("<\xe6\xb1\x89\xe5\xad\x97>\n"), "<\xe6\xb1\x89\xe5\xad\x97>\n");
}
static std::string escape_json_attrs(const char *str)
}
TEST(EscapeJson, ControlChars) {
- uint8_t cc1[] = { 0x01, 0x02, 0x03, 0x0 };
- ASSERT_EQ(escape_json_attrs((char*)cc1), "\\u0001\\u0002\\u0003");
+ ASSERT_EQ(escape_json_attrs("\x01\x02\x03"), "\\u0001\\u0002\\u0003");
- uint8_t cc2[] = { 0x61, 0x62, 0x63, 0x7f, 0x0 };
- ASSERT_EQ(escape_json_attrs((char*)cc2), "abc\\u007f");
+ ASSERT_EQ(escape_json_attrs("abc\x7f"), "abc\\u007f");
}
TEST(EscapeJson, Utf8) {
- uint8_t cc1[] = { 0xe6, 0xb1, 0x89, 0xe5, 0xad, 0x97, 0x0a, 0x0 };
- ASSERT_EQ(escape_xml_attrs((const char*)cc1), (const char*)cc1);
+ EXPECT_EQ(escape_xml_attrs("\xe6\xb1\x89\xe5\xad\x97\n"), "\xe6\xb1\x89\xe5\xad\x97\n");
}