Skip to content

Commit 99ef3c0

Browse files
bnoordhuisMylesBorins
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 18b8e7b commit 99ef3c0

File tree

3 files changed

+29
-16
lines changed

3 files changed

+29
-16
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,8 @@ CPPLINT_FILES = $(filter-out $(CPPLINT_EXCLUDE), $(wildcard \
727727
src/*.h \
728728
test/addons/*/*.cc \
729729
test/addons/*/*.h \
730+
test/cctest/*.cc \
731+
test/cctest/*.h \
730732
tools/icu/*.cc \
731733
tools/icu/*.h \
732734
))

test/cctest/test_inspector_socket.cc

Lines changed: 26 additions & 15 deletions
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;
@@ -129,7 +138,7 @@ static void check_data_cb(read_expects* expectation, ssize_t nread,
129138
EXPECT_TRUE(nread >= 0 && nread != UV_EOF);
130139
ssize_t i;
131140
char c, actual;
132-
ASSERT_TRUE(expectation->expected_len > 0);
141+
ASSERT_GT(expectation->expected_len, 0);
133142
for (i = 0; i < nread && expectation->pos <= expectation->expected_len; i++) {
134143
c = expectation->expected[expectation->pos++];
135144
actual = buf->base[i];
@@ -176,7 +185,7 @@ static void fail_callback(uv_stream_t* stream, ssize_t nread,
176185
} else {
177186
fprintf(stderr, "Read %zd bytes\n", nread);
178187
}
179-
ASSERT_TRUE(false); // Shouldn't have been called
188+
ASSERT_TRUE(false); // Shouldn't have been called
180189
}
181190

182191
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) {
239248

240249
static void save_read_data(uv_stream_t* stream, ssize_t nread,
241250
const uv_buf_t* buf) {
242-
expectations* expects =static_cast<expectations*>(
251+
expectations* expects = static_cast<expectations*>(
243252
inspector_from_stream(stream)->data);
244253
expects->err_code = nread < 0 ? nread : 0;
245254
if (nread > 0) {
@@ -344,7 +353,7 @@ static void on_connection(uv_connect_t* connect, int status) {
344353
}
345354

346355
class InspectorSocketTest : public ::testing::Test {
347-
protected:
356+
protected:
348357
virtual void SetUp() {
349358
inspector.reinit();
350359
handshake_delegate = stop_if_stop_path;
@@ -368,7 +377,7 @@ class InspectorSocketTest : public ::testing::Test {
368377
connect.data = nullptr;
369378
uv_tcp_connect(&connect, &client_socket,
370379
reinterpret_cast<const sockaddr*>(&addr), on_connection);
371-
uv_tcp_nodelay(&client_socket, 1); // The buffering messes up the test
380+
uv_tcp_nodelay(&client_socket, 1); // The buffering messes up the test
372381
SPIN_WHILE(!connect.data || !connected);
373382
really_close(reinterpret_cast<uv_handle_t*>(&server));
374383
}
@@ -420,7 +429,6 @@ TEST_F(InspectorSocketTest, ReadsAndWritesInspectorMessage) {
420429
}
421430

422431
TEST_F(InspectorSocketTest, BufferEdgeCases) {
423-
424432
do_write(const_cast<char*>(HANDSHAKE_REQ), sizeof(HANDSHAKE_REQ) - 1);
425433
expect_handshake();
426434

@@ -498,7 +506,8 @@ TEST_F(InspectorSocketTest, AcceptsRequestInSeveralWrites) {
498506
SPIN_WHILE(!inspector_ready);
499507
expect_handshake();
500508
inspector_read_stop(&inspector);
501-
GTEST_ASSERT_EQ(uv_is_active(reinterpret_cast<uv_handle_t*>(&client_socket)), 0);
509+
GTEST_ASSERT_EQ(uv_is_active(reinterpret_cast<uv_handle_t*>(&client_socket)),
510+
0);
502511
manual_inspector_socket_cleanup();
503512
}
504513

@@ -531,7 +540,6 @@ TEST_F(InspectorSocketTest, RequestWithoutKey) {
531540
"Upgrade: websocket\r\n"
532541
"Connection: Upgrade\r\n"
533542
"Sec-WebSocket-Version: 13\r\n\r\n";
534-
;
535543

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

555564
TEST_F(InspectorSocketTest, CanStopReadingFromInspector) {
@@ -863,7 +872,7 @@ TEST_F(InspectorSocketTest, Send1Mb) {
863872
outgoing.resize(outgoing.size() + message.size());
864873
mask_message(message, &outgoing[sizeof(FRAME_TO_SERVER_HEADER)], MASK);
865874

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

@@ -896,3 +905,5 @@ TEST_F(InspectorSocketTest, ErrorCleansUpTheSocket) {
896905
SPIN_WHILE(err > 0);
897906
EXPECT_EQ(UV_EPROTO, err);
898907
}
908+
909+
} // anonymous namespace

test/cctest/util.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,4 @@ TEST(UtilTest, Calloc) {
102102
EXPECT_NE(nullptr, Calloc(1, 0));
103103
EXPECT_NE(nullptr, Calloc(0, 1));
104104
EXPECT_NE(nullptr, Calloc(1, 1));
105-
}
105+
}

0 commit comments

Comments
 (0)