diff --git a/Makefile b/Makefile index 8d3b1d4981c717..e244f73a344350 100644 --- a/Makefile +++ b/Makefile @@ -727,6 +727,8 @@ CPPLINT_FILES = $(filter-out $(CPPLINT_EXCLUDE), $(wildcard \ src/*.h \ test/addons/*/*.cc \ test/addons/*/*.h \ + test/cctest/*.cc \ + test/cctest/*.h \ tools/icu/*.cc \ tools/icu/*.h \ )) diff --git a/test/cctest/test_inspector_socket.cc b/test/cctest/test_inspector_socket.cc index 741b5cfc95403e..ada3df3d438ce8 100644 --- a/test/cctest/test_inspector_socket.cc +++ b/test/cctest/test_inspector_socket.cc @@ -1,10 +1,17 @@ #include "inspector_socket.h" - #include "gtest/gtest.h" #define PORT 9444 -using namespace node::inspector; +namespace { + +using node::inspector::InspectorSocket; +using node::inspector::inspector_from_stream; +using node::inspector::inspector_handshake_event; +using node::inspector::kInspectorHandshakeFailed; +using node::inspector::kInspectorHandshakeHttpGet; +using node::inspector::kInspectorHandshakeUpgraded; +using node::inspector::kInspectorHandshakeUpgrading; static const int MAX_LOOP_ITERATIONS = 10000; @@ -24,7 +31,7 @@ static enum inspector_handshake_event last_event = kInspectorHandshakeHttpGet; static uv_loop_t loop; static uv_tcp_t server, client_socket; static InspectorSocket inspector; -static std::string last_path; +static std::string last_path; // NOLINT(runtime/string) static void (*handshake_delegate)(enum inspector_handshake_event state, const std::string& path, bool* should_continue); @@ -45,7 +52,7 @@ static const char HANDSHAKE_REQ[] = "GET /ws/path HTTP/1.1\r\n" "Sec-WebSocket-Version: 13\r\n\r\n"; class Timeout { -public: + public: explicit Timeout(uv_loop_t* loop) : timed_out(false), done_(false) { uv_timer_init(loop, &timer_); uv_timer_start(&timer_, Timeout::set_flag, 5000, 0); @@ -58,8 +65,10 @@ class Timeout { uv_run(&loop, UV_RUN_NOWAIT); } } + bool timed_out; -private: + + private: static void set_flag(uv_timer_t* timer) { Timeout* t = node::ContainerOf(&Timeout::timer_, timer); t->timed_out = true; @@ -129,7 +138,7 @@ static void check_data_cb(read_expects* expectation, ssize_t nread, EXPECT_TRUE(nread >= 0 && nread != UV_EOF); ssize_t i; char c, actual; - ASSERT_TRUE(expectation->expected_len > 0); + ASSERT_GT(expectation->expected_len, 0); for (i = 0; i < nread && expectation->pos <= expectation->expected_len; i++) { c = expectation->expected[expectation->pos++]; actual = buf->base[i]; @@ -176,7 +185,7 @@ static void fail_callback(uv_stream_t* stream, ssize_t nread, } else { fprintf(stderr, "Read %zd bytes\n", nread); } - ASSERT_TRUE(false); // Shouldn't have been called + ASSERT_TRUE(false); // Shouldn't have been called } static void expect_nothing_on_client() { @@ -239,7 +248,7 @@ static void grow_expects_buffer(uv_handle_t* stream, size_t size, uv_buf_t* b) { static void save_read_data(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf) { - expectations* expects =static_cast( + expectations* expects = static_cast( inspector_from_stream(stream)->data); expects->err_code = nread < 0 ? nread : 0; if (nread > 0) { @@ -344,7 +353,7 @@ static void on_connection(uv_connect_t* connect, int status) { } class InspectorSocketTest : public ::testing::Test { -protected: + protected: virtual void SetUp() { inspector.reinit(); handshake_delegate = stop_if_stop_path; @@ -368,7 +377,7 @@ class InspectorSocketTest : public ::testing::Test { connect.data = nullptr; uv_tcp_connect(&connect, &client_socket, reinterpret_cast(&addr), on_connection); - uv_tcp_nodelay(&client_socket, 1); // The buffering messes up the test + uv_tcp_nodelay(&client_socket, 1); // The buffering messes up the test SPIN_WHILE(!connect.data || !connected); really_close(reinterpret_cast(&server)); } @@ -420,7 +429,6 @@ TEST_F(InspectorSocketTest, ReadsAndWritesInspectorMessage) { } TEST_F(InspectorSocketTest, BufferEdgeCases) { - do_write(const_cast(HANDSHAKE_REQ), sizeof(HANDSHAKE_REQ) - 1); expect_handshake(); @@ -498,7 +506,8 @@ TEST_F(InspectorSocketTest, AcceptsRequestInSeveralWrites) { SPIN_WHILE(!inspector_ready); expect_handshake(); inspector_read_stop(&inspector); - GTEST_ASSERT_EQ(uv_is_active(reinterpret_cast(&client_socket)), 0); + GTEST_ASSERT_EQ(uv_is_active(reinterpret_cast(&client_socket)), + 0); manual_inspector_socket_cleanup(); } @@ -531,7 +540,6 @@ TEST_F(InspectorSocketTest, RequestWithoutKey) { "Upgrade: websocket\r\n" "Connection: Upgrade\r\n" "Sec-WebSocket-Version: 13\r\n\r\n"; - ; do_write(const_cast(BROKEN_REQUEST), sizeof(BROKEN_REQUEST) - 1); SPIN_WHILE(last_event != kInspectorHandshakeFailed); @@ -549,7 +557,8 @@ TEST_F(InspectorSocketTest, KillsConnectionOnProtocolViolation) { const char SERVER_FRAME[] = "I'm not a good WS frame. Nope!"; do_write(SERVER_FRAME, sizeof(SERVER_FRAME)); expect_server_read_error(); - GTEST_ASSERT_EQ(uv_is_active(reinterpret_cast(&client_socket)), 0); + GTEST_ASSERT_EQ(uv_is_active(reinterpret_cast(&client_socket)), + 0); } TEST_F(InspectorSocketTest, CanStopReadingFromInspector) { @@ -863,7 +872,7 @@ TEST_F(InspectorSocketTest, Send1Mb) { outgoing.resize(outgoing.size() + message.size()); mask_message(message, &outgoing[sizeof(FRAME_TO_SERVER_HEADER)], MASK); - setup_inspector_expecting(); // Buffer on the client side. + setup_inspector_expecting(); // Buffer on the client side. do_write(&outgoing[0], outgoing.size()); expect_on_server(&message[0], message.size()); @@ -896,3 +905,5 @@ TEST_F(InspectorSocketTest, ErrorCleansUpTheSocket) { SPIN_WHILE(err > 0); EXPECT_EQ(UV_EPROTO, err); } + +} // anonymous namespace diff --git a/test/cctest/util.cc b/test/cctest/util.cc index 79f1524660b213..65a382bd3893fa 100644 --- a/test/cctest/util.cc +++ b/test/cctest/util.cc @@ -102,4 +102,4 @@ TEST(UtilTest, Calloc) { EXPECT_NE(nullptr, Calloc(1, 0)); EXPECT_NE(nullptr, Calloc(0, 1)); EXPECT_NE(nullptr, Calloc(1, 1)); -} \ No newline at end of file +}