Allow deno_buf with null alloc_ptr to be memcpy'd

This is a temporary hack to allow for easier restructuring of
the serialization code as we move Flatbuffer stuff from C++ to Rust.
This commit is contained in:
Ryan Dahl 2018-07-23 14:11:41 -04:00
parent b87e6d5604
commit b79ce93010
3 changed files with 49 additions and 6 deletions

View file

@ -34,6 +34,17 @@ deno_buf strbuf(const char* str) {
return buf;
}
// Same as strbuf but with null alloc_ptr.
deno_buf StrBufNullAllocPtr(const char* str) {
auto len = strlen(str);
deno_buf buf;
buf.alloc_ptr = nullptr;
buf.alloc_len = 0;
buf.data_ptr = reinterpret_cast<uint8_t*>(strdup(str));
buf.data_len = len;
return buf;
}
TEST(MockRuntimeTest, SendSuccess) {
Deno* d = deno_new(nullptr, nullptr);
EXPECT_TRUE(deno_execute(d, "a.js", "SendSuccess()"));
@ -176,3 +187,15 @@ TEST(MockRuntimeTest, ErrorHandling) {
EXPECT_EQ(count, 1);
deno_delete(d);
}
TEST(MockRuntimeTest, SendNullAllocPtr) {
static int count = 0;
Deno* d = deno_new(nullptr, [](auto _, auto buf) { count++; });
EXPECT_TRUE(deno_execute(d, "a.js", "SendNullAllocPtr()"));
deno_buf buf = StrBufNullAllocPtr("abcd");
EXPECT_EQ(buf.alloc_ptr, nullptr);
EXPECT_EQ(buf.data_len, 4u);
EXPECT_TRUE(deno_send(d, buf));
EXPECT_EQ(count, 0);
deno_delete(d);
}