summaryrefslogtreecommitdiff
path: root/src/mock_runtime_test.cc
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2018-07-23 14:11:41 -0400
committerRyan Dahl <ry@tinyclouds.org>2018-07-24 12:29:54 -0400
commitb79ce93010d0cc80a9345f646e562326de4588e5 (patch)
tree3117c6b795b593bd369880ea36be18533c766a73 /src/mock_runtime_test.cc
parentb87e6d560477354e8c1b3c69e9836cd92eaf9984 (diff)
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.
Diffstat (limited to 'src/mock_runtime_test.cc')
-rw-r--r--src/mock_runtime_test.cc23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/mock_runtime_test.cc b/src/mock_runtime_test.cc
index a2c4b3699..fae0b32a5 100644
--- a/src/mock_runtime_test.cc
+++ b/src/mock_runtime_test.cc
@@ -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);
+}