diff --git a/Makefile b/Makefile index 24aa53b64d4fe7..975efc96866009 100644 --- a/Makefile +++ b/Makefile @@ -715,6 +715,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 697fa2bacca85a..c7a282b75b4b8d 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; @@ -128,7 +137,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]; @@ -175,7 +184,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() { @@ -238,7 +247,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) { @@ -343,7 +352,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; @@ -367,7 +376,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)); } @@ -419,7 +428,6 @@ TEST_F(InspectorSocketTest, ReadsAndWritesInspectorMessage) { } TEST_F(InspectorSocketTest, BufferEdgeCases) { - do_write(const_cast(HANDSHAKE_REQ), sizeof(HANDSHAKE_REQ) - 1); expect_handshake(); @@ -497,7 +505,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(); } @@ -530,7 +539,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); @@ -548,7 +556,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) { @@ -862,7 +871,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()); @@ -895,3 +904,5 @@ TEST_F(InspectorSocketTest, ErrorCleansUpTheSocket) { SPIN_WHILE(err > 0); EXPECT_EQ(UV_EPROTO, err); } + +} // anonymous namespace