Skip to content

Commit 0bdd5ca

Browse files
bnoordhuisaddaleax
authored andcommitted
test: run cpplint on files in test/cctest
Enable cpplint for files in test/cctest. Fix up the style issues it reports. PR-URL: #9787 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
1 parent 9562391 commit 0bdd5ca

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,8 @@ CPPLINT_FILES = $(filter-out $(CPPLINT_EXCLUDE), $(wildcard \
715715
src/*.h \
716716
test/addons/*/*.cc \
717717
test/addons/*/*.h \
718+
test/cctest/*.cc \
719+
test/cctest/*.h \
718720
tools/icu/*.cc \
719721
tools/icu/*.h \
720722
))

test/cctest/test_inspector_socket.cc

+26-15
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
#include "inspector_socket.h"
2-
32
#include "gtest/gtest.h"
43

54
#define PORT 9444
65

7-
using namespace node::inspector;
6+
namespace {
7+
8+
using node::inspector::InspectorSocket;
9+
using node::inspector::inspector_from_stream;
10+
using node::inspector::inspector_handshake_event;
11+
using node::inspector::kInspectorHandshakeFailed;
12+
using node::inspector::kInspectorHandshakeHttpGet;
13+
using node::inspector::kInspectorHandshakeUpgraded;
14+
using node::inspector::kInspectorHandshakeUpgrading;
815

916
static const int MAX_LOOP_ITERATIONS = 10000;
1017

@@ -24,7 +31,7 @@ static enum inspector_handshake_event last_event = kInspectorHandshakeHttpGet;
2431
static uv_loop_t loop;
2532
static uv_tcp_t server, client_socket;
2633
static InspectorSocket inspector;
27-
static std::string last_path;
34+
static std::string last_path; // NOLINT(runtime/string)
2835
static void (*handshake_delegate)(enum inspector_handshake_event state,
2936
const std::string& path,
3037
bool* should_continue);
@@ -45,7 +52,7 @@ static const char HANDSHAKE_REQ[] = "GET /ws/path HTTP/1.1\r\n"
4552
"Sec-WebSocket-Version: 13\r\n\r\n";
4653

4754
class Timeout {
48-
public:
55+
public:
4956
explicit Timeout(uv_loop_t* loop) : timed_out(false), done_(false) {
5057
uv_timer_init(loop, &timer_);
5158
uv_timer_start(&timer_, Timeout::set_flag, 5000, 0);
@@ -58,8 +65,10 @@ class Timeout {
5865
uv_run(&loop, UV_RUN_NOWAIT);
5966
}
6067
}
68+
6169
bool timed_out;
62-
private:
70+
71+
private:
6372
static void set_flag(uv_timer_t* timer) {
6473
Timeout* t = node::ContainerOf(&Timeout::timer_, timer);
6574
t->timed_out = true;
@@ -128,7 +137,7 @@ static void check_data_cb(read_expects* expectation, ssize_t nread,
128137
EXPECT_TRUE(nread >= 0 && nread != UV_EOF);
129138
ssize_t i;
130139
char c, actual;
131-
ASSERT_TRUE(expectation->expected_len > 0);
140+
ASSERT_GT(expectation->expected_len, 0);
132141
for (i = 0; i < nread && expectation->pos <= expectation->expected_len; i++) {
133142
c = expectation->expected[expectation->pos++];
134143
actual = buf->base[i];
@@ -175,7 +184,7 @@ static void fail_callback(uv_stream_t* stream, ssize_t nread,
175184
} else {
176185
fprintf(stderr, "Read %zd bytes\n", nread);
177186
}
178-
ASSERT_TRUE(false); // Shouldn't have been called
187+
ASSERT_TRUE(false); // Shouldn't have been called
179188
}
180189

181190
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) {
238247

239248
static void save_read_data(uv_stream_t* stream, ssize_t nread,
240249
const uv_buf_t* buf) {
241-
expectations* expects =static_cast<expectations*>(
250+
expectations* expects = static_cast<expectations*>(
242251
inspector_from_stream(stream)->data);
243252
expects->err_code = nread < 0 ? nread : 0;
244253
if (nread > 0) {
@@ -343,7 +352,7 @@ static void on_connection(uv_connect_t* connect, int status) {
343352
}
344353

345354
class InspectorSocketTest : public ::testing::Test {
346-
protected:
355+
protected:
347356
virtual void SetUp() {
348357
inspector.reinit();
349358
handshake_delegate = stop_if_stop_path;
@@ -367,7 +376,7 @@ class InspectorSocketTest : public ::testing::Test {
367376
connect.data = nullptr;
368377
uv_tcp_connect(&connect, &client_socket,
369378
reinterpret_cast<const sockaddr*>(&addr), on_connection);
370-
uv_tcp_nodelay(&client_socket, 1); // The buffering messes up the test
379+
uv_tcp_nodelay(&client_socket, 1); // The buffering messes up the test
371380
SPIN_WHILE(!connect.data || !connected);
372381
really_close(reinterpret_cast<uv_handle_t*>(&server));
373382
}
@@ -419,7 +428,6 @@ TEST_F(InspectorSocketTest, ReadsAndWritesInspectorMessage) {
419428
}
420429

421430
TEST_F(InspectorSocketTest, BufferEdgeCases) {
422-
423431
do_write(const_cast<char*>(HANDSHAKE_REQ), sizeof(HANDSHAKE_REQ) - 1);
424432
expect_handshake();
425433

@@ -497,7 +505,8 @@ TEST_F(InspectorSocketTest, AcceptsRequestInSeveralWrites) {
497505
SPIN_WHILE(!inspector_ready);
498506
expect_handshake();
499507
inspector_read_stop(&inspector);
500-
GTEST_ASSERT_EQ(uv_is_active(reinterpret_cast<uv_handle_t*>(&client_socket)), 0);
508+
GTEST_ASSERT_EQ(uv_is_active(reinterpret_cast<uv_handle_t*>(&client_socket)),
509+
0);
501510
manual_inspector_socket_cleanup();
502511
}
503512

@@ -530,7 +539,6 @@ TEST_F(InspectorSocketTest, RequestWithoutKey) {
530539
"Upgrade: websocket\r\n"
531540
"Connection: Upgrade\r\n"
532541
"Sec-WebSocket-Version: 13\r\n\r\n";
533-
;
534542

535543
do_write(const_cast<char*>(BROKEN_REQUEST), sizeof(BROKEN_REQUEST) - 1);
536544
SPIN_WHILE(last_event != kInspectorHandshakeFailed);
@@ -548,7 +556,8 @@ TEST_F(InspectorSocketTest, KillsConnectionOnProtocolViolation) {
548556
const char SERVER_FRAME[] = "I'm not a good WS frame. Nope!";
549557
do_write(SERVER_FRAME, sizeof(SERVER_FRAME));
550558
expect_server_read_error();
551-
GTEST_ASSERT_EQ(uv_is_active(reinterpret_cast<uv_handle_t*>(&client_socket)), 0);
559+
GTEST_ASSERT_EQ(uv_is_active(reinterpret_cast<uv_handle_t*>(&client_socket)),
560+
0);
552561
}
553562

554563
TEST_F(InspectorSocketTest, CanStopReadingFromInspector) {
@@ -862,7 +871,7 @@ TEST_F(InspectorSocketTest, Send1Mb) {
862871
outgoing.resize(outgoing.size() + message.size());
863872
mask_message(message, &outgoing[sizeof(FRAME_TO_SERVER_HEADER)], MASK);
864873

865-
setup_inspector_expecting(); // Buffer on the client side.
874+
setup_inspector_expecting(); // Buffer on the client side.
866875
do_write(&outgoing[0], outgoing.size());
867876
expect_on_server(&message[0], message.size());
868877

@@ -895,3 +904,5 @@ TEST_F(InspectorSocketTest, ErrorCleansUpTheSocket) {
895904
SPIN_WHILE(err > 0);
896905
EXPECT_EQ(UV_EPROTO, err);
897906
}
907+
908+
} // anonymous namespace

0 commit comments

Comments
 (0)