diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2018-06-11 18:17:28 +0200 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-06-11 18:17:28 +0200 |
commit | cbbe8ad9992765bc0883759e4075cf7a4a1918ff (patch) | |
tree | 844555d6da87fc08e4ffb3f98a9c9d2742a41dd3 /deno2/mock_runtime_test.cc | |
parent | 0e07e16dd63992f5f989dc99c891d53d930a2d5b (diff) |
Add deno_send tests.
Diffstat (limited to 'deno2/mock_runtime_test.cc')
-rw-r--r-- | deno2/mock_runtime_test.cc | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/deno2/mock_runtime_test.cc b/deno2/mock_runtime_test.cc index 951710fb9..00651f68e 100644 --- a/deno2/mock_runtime_test.cc +++ b/deno2/mock_runtime_test.cc @@ -19,6 +19,30 @@ TEST(MockRuntimeTest, ErrorsCorrectly) { EXPECT_FALSE(deno_load(d, "a.js", "throw Error()")); } +deno_buf strbuf(const char* str) { + void* d = reinterpret_cast<void*>(const_cast<char*>(str)); + return deno_buf{d, strlen(str)}; +} + +TEST(MockRuntimeTest, SendSuccess) { + Deno* d = deno_new(NULL, NULL); + EXPECT_TRUE(deno_load(d, "a.js", "recvabc();")); + EXPECT_TRUE(deno_send(d, strbuf("abc"))); +} + +TEST(MockRuntimeTest, SendByteLength) { + Deno* d = deno_new(NULL, NULL); + EXPECT_TRUE(deno_load(d, "a.js", "recvabc();")); + // We send the wrong sized message, it should throw. + EXPECT_FALSE(deno_send(d, strbuf("abcd"))); +} + +TEST(MockRuntimeTest, SendNoCallback) { + Deno* d = deno_new(NULL, NULL); + // We didn't call deno_recv(), sending should fail. + EXPECT_FALSE(deno_send(d, strbuf("abc"))); +} + int main(int argc, char** argv) { testing::InitGoogleTest(&argc, argv); deno_init(); |