Trim utf8 checker test

This commit is contained in:
Miguel Portilla
2017-08-01 14:00:51 -04:00
committed by Vinnie Falco
parent 66b07798e6
commit ee04fa096b
2 changed files with 30 additions and 46 deletions

View File

@@ -3,6 +3,7 @@ Version 98:
* basic_fields::key_compare is noexcept * basic_fields::key_compare is noexcept
* Fix bench-zlib cmake * Fix bench-zlib cmake
* Use unique names Jam projects * Use unique names Jam projects
* Trim utf8 checker test
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------

View File

@@ -129,7 +129,7 @@ public:
if (i == 224) if (i == 224)
{ {
for (auto l = 0; l < b; ++l) for(auto l = 0; l < b; ++l)
{ {
// Second byte invalid range 0-127 or 0-159 // Second byte invalid range 0-127 or 0-159
buf[1] = static_cast<std::uint8_t>(l); buf[1] = static_cast<std::uint8_t>(l);
@@ -145,7 +145,7 @@ public:
} }
else if (i == 237) else if (i == 237)
{ {
for (auto l = e + 1; l <= 255; ++l) for(auto l = e + 1; l <= 255; ++l)
{ {
// Second byte invalid range 160-255 or 192-255 // Second byte invalid range 160-255 or 192-255
buf[1] = static_cast<std::uint8_t>(l); buf[1] = static_cast<std::uint8_t>(l);
@@ -225,11 +225,11 @@ public:
// Third byte valid range 128-191 // Third byte valid range 128-191
buf[2] = static_cast<std::uint8_t>(k); buf[2] = static_cast<std::uint8_t>(k);
for(auto n = 128; n <= 191; ++n) for(auto n : {128, 191})
{ {
// Fourth byte valid range 128-191 // Fourth byte valid range 128-191
buf[3] = static_cast<std::uint8_t>(n); buf[3] = static_cast<std::uint8_t>(n);
BEAST_EXPECT(utf8.write(const_buffers_1{buf, 4})); BEAST_EXPECT(utf8.write(buf, 4));
BEAST_EXPECT(utf8.finish()); BEAST_EXPECT(utf8.finish());
// Segmented sequence // Segmented sequence
BEAST_EXPECT(utf8.write(buf, 1)); BEAST_EXPECT(utf8.write(buf, 1));
@@ -245,13 +245,13 @@ public:
utf8.reset(); utf8.reset();
if (i == 240) if (i == 240)
{
for (auto l = 0; l < b; ++l)
{ {
// Second byte invalid range 0-127 or 0-143 // Second byte invalid range 0-127 or 0-143
buf[1] = static_cast<std::uint8_t>(l); for(auto r : {0, b - 1})
{
buf[1] = static_cast<std::uint8_t>(r);
BEAST_EXPECT(! utf8.write(buf, 4)); BEAST_EXPECT(! utf8.write(buf, 4));
if (l > 127) if (r > 127)
{ {
// Segmented sequence second byte invalid // Segmented sequence second byte invalid
BEAST_EXPECT(! utf8.write(buf, 2)); BEAST_EXPECT(! utf8.write(buf, 2));
@@ -261,34 +261,24 @@ public:
buf[1] = static_cast<std::uint8_t>(j); buf[1] = static_cast<std::uint8_t>(j);
} }
else if (i == 244) else if (i == 244)
{
for (auto l = e + 1; l <= 255; ++l)
{ {
// Second byte invalid range 144-255 or 192-255 // Second byte invalid range 144-255 or 192-255
buf[1] = static_cast<std::uint8_t>(l); for(auto r : {e + 1, 255})
BEAST_EXPECT(! utf8.write(buf, 4));
if (l > 143)
{ {
buf[1] = static_cast<std::uint8_t>(r);
BEAST_EXPECT(! utf8.write(buf, 4));
// Segmented sequence second byte invalid // Segmented sequence second byte invalid
BEAST_EXPECT(! utf8.write(buf, 2)); BEAST_EXPECT(! utf8.write(buf, 2));
utf8.reset(); utf8.reset();
} }
}
buf[1] = static_cast<std::uint8_t>(j); buf[1] = static_cast<std::uint8_t>(j);
} }
} }
for(auto n = 0; n <= 127; ++n) // Fourth byte invalid ranges 0-127, 192-255
for(auto r : {0, 127, 192, 255})
{ {
// Fourth byte invalid range 0-127 buf[3] = static_cast<std::uint8_t>(r);
buf[3] = static_cast<std::uint8_t>(n);
BEAST_EXPECT(! utf8.write(const_buffers_1{buf, 4}));
}
for(auto n = 192; n <= 255; ++n)
{
// Fourth byte invalid range 192-255
buf[3] = static_cast<std::uint8_t>(n);
BEAST_EXPECT(! utf8.write(buf, 4)); BEAST_EXPECT(! utf8.write(buf, 4));
} }
@@ -298,17 +288,10 @@ public:
utf8.reset(); utf8.reset();
} }
for(auto k = 0; k <= 127; ++k) // Third byte invalid ranges 0-127, 192-255
for(auto r : {0, 127, 192, 255})
{ {
// Third byte invalid range 0-127 buf[2] = static_cast<std::uint8_t>(r);
buf[2] = static_cast<std::uint8_t>(k);
BEAST_EXPECT(! utf8.write(buf, 4));
}
for(auto k = 192; k <= 255; ++k)
{
// Third byte invalid range 192-255
buf[2] = static_cast<std::uint8_t>(k);
BEAST_EXPECT(! utf8.write(buf, 4)); BEAST_EXPECT(! utf8.write(buf, 4));
} }
@@ -318,17 +301,17 @@ public:
utf8.reset(); utf8.reset();
} }
for(auto j = 0; j < b; ++j)
{
// Second byte invalid range 0-127 or 0-143 // Second byte invalid range 0-127 or 0-143
buf[1] = static_cast<std::uint8_t>(j); for(auto r : {0, b - 1})
{
buf[1] = static_cast<std::uint8_t>(r);
BEAST_EXPECT(! utf8.write(buf, 4)); BEAST_EXPECT(! utf8.write(buf, 4));
} }
for(auto j = e + 1; j <= 255; ++j)
{
// Second byte invalid range 144-255 or 192-255 // Second byte invalid range 144-255 or 192-255
buf[1] = static_cast<std::uint8_t>(j); for(auto r : {e + 1, 255})
{
buf[1] = static_cast<std::uint8_t>(r);
BEAST_EXPECT(! utf8.write(buf, 4)); BEAST_EXPECT(! utf8.write(buf, 4));
} }
@@ -338,10 +321,10 @@ public:
utf8.reset(); utf8.reset();
} }
for (auto i = 245; i <= 255; ++i)
{
// First byte invalid range 245-255 // First byte invalid range 245-255
buf[0] = static_cast<std::uint8_t>(i); for(auto r : {245, 255})
{
buf[0] = static_cast<std::uint8_t>(r);
BEAST_EXPECT(! utf8.write(buf, 4)); BEAST_EXPECT(! utf8.write(buf, 4));
} }
} }