1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-23 23:49:46 -05:00
denoland-deno/deno2/mock_runtime_test.cc

51 lines
1.4 KiB
C++
Raw Normal View History

2018-06-11 17:01:35 +02:00
// Copyright 2018 Ryan Dahl <ry@tinyclouds.org>
// All rights reserved. MIT License.
#include "testing/gtest/include/gtest/gtest.h"
#include "include/deno.h"
TEST(MockRuntimeTest, InitializesCorrectly) {
Deno* d = deno_new(NULL, NULL);
EXPECT_TRUE(deno_load(d, "a.js", "1 + 2"));
}
TEST(MockRuntimeTest, CanCallFoo) {
Deno* d = deno_new(NULL, NULL);
EXPECT_TRUE(deno_load(d, "a.js", "if (foo() != 'foo') throw Error();"));
}
TEST(MockRuntimeTest, ErrorsCorrectly) {
Deno* d = deno_new(NULL, NULL);
EXPECT_FALSE(deno_load(d, "a.js", "throw Error()"));
}
2018-06-11 18:17:28 +02:00
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")));
}
2018-06-11 17:01:35 +02:00
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
deno_init();
return RUN_ALL_TESTS();
}