diff options
Diffstat (limited to 'deps/v8/test/cctest/test-inspector.cc')
-rw-r--r-- | deps/v8/test/cctest/test-inspector.cc | 109 |
1 files changed, 107 insertions, 2 deletions
diff --git a/deps/v8/test/cctest/test-inspector.cc b/deps/v8/test/cctest/test-inspector.cc index 6dd2aefb9e1..e36ce19eca0 100644 --- a/deps/v8/test/cctest/test-inspector.cc +++ b/deps/v8/test/cctest/test-inspector.cc @@ -4,11 +4,11 @@ #include <memory> -#include "test/cctest/cctest.h" - #include "include/v8-inspector.h" #include "include/v8.h" #include "src/inspector/protocol/Runtime.h" +#include "src/inspector/string-util.h" +#include "test/cctest/cctest.h" using v8_inspector::StringBuffer; using v8_inspector::StringView; @@ -63,3 +63,108 @@ TEST(WrapInsideWrapOnInterrupt) { isolate->RequestInterrupt(&WrapOnInterrupt, session.get()); session->wrapObject(env.local(), v8::Null(isolate), object_group_view, false); } + +TEST(BinaryFromBase64) { + auto checkBinary = [](const v8_inspector::protocol::Binary& binary, + const std::vector<uint8_t>& values) { + std::vector<uint8_t> binary_vector(binary.data(), + binary.data() + binary.size()); + CHECK_EQ(binary_vector, values); + }; + + { + bool success; + auto binary = v8_inspector::protocol::Binary::fromBase64("", &success); + CHECK(success); + checkBinary(binary, {}); + } + { + bool success; + auto binary = v8_inspector::protocol::Binary::fromBase64("YQ==", &success); + CHECK(success); + checkBinary(binary, {'a'}); + } + { + bool success; + auto binary = v8_inspector::protocol::Binary::fromBase64("YWI=", &success); + CHECK(success); + checkBinary(binary, {'a', 'b'}); + } + { + bool success; + auto binary = v8_inspector::protocol::Binary::fromBase64("YWJj", &success); + CHECK(success); + checkBinary(binary, {'a', 'b', 'c'}); + } + { + bool success; + // Wrong input length: + auto binary = v8_inspector::protocol::Binary::fromBase64("Y", &success); + CHECK(!success); + } + { + bool success; + // Invalid space: + auto binary = v8_inspector::protocol::Binary::fromBase64("=AAA", &success); + CHECK(!success); + } + { + bool success; + // Invalid space in a non-final block of four: + auto binary = + v8_inspector::protocol::Binary::fromBase64("AAA=AAAA", &success); + CHECK(!success); + } + { + bool success; + // Invalid invalid space in second to last position: + auto binary = v8_inspector::protocol::Binary::fromBase64("AA=A", &success); + CHECK(!success); + } + { + bool success; + // Invalid character: + auto binary = v8_inspector::protocol::Binary::fromBase64(" ", &success); + CHECK(!success); + } +} + +TEST(BinaryToBase64) { + uint8_t input[] = {'a', 'b', 'c'}; + { + auto binary = v8_inspector::protocol::Binary::fromSpan(input, 0); + v8_inspector::protocol::String base64 = binary.toBase64(); + CHECK_EQ(base64.utf8(), ""); + } + { + auto binary = v8_inspector::protocol::Binary::fromSpan(input, 1); + v8_inspector::protocol::String base64 = binary.toBase64(); + CHECK_EQ(base64.utf8(), "YQ=="); + } + { + auto binary = v8_inspector::protocol::Binary::fromSpan(input, 2); + v8_inspector::protocol::String base64 = binary.toBase64(); + CHECK_EQ(base64.utf8(), "YWI="); + } + { + auto binary = v8_inspector::protocol::Binary::fromSpan(input, 3); + v8_inspector::protocol::String base64 = binary.toBase64(); + CHECK_EQ(base64.utf8(), "YWJj"); + } +} + +TEST(BinaryBase64RoundTrip) { + std::array<uint8_t, 256> values; + for (uint16_t b = 0x0; b <= 0xFF; ++b) values[b] = b; + auto binary = + v8_inspector::protocol::Binary::fromSpan(values.data(), values.size()); + v8_inspector::protocol::String base64 = binary.toBase64(); + bool success = false; + auto roundtrip_binary = + v8_inspector::protocol::Binary::fromBase64(base64, &success); + CHECK(success); + CHECK_EQ(values.size(), roundtrip_binary.size()); + for (size_t i = 0; i < values.size(); ++i) { + CHECK_EQ(values[i], roundtrip_binary.data()[i]); + } +} |