Skip to content

Commit

Permalink
test: run cpplint on files in test/cctest
Browse files Browse the repository at this point in the history
Enable cpplint for files in test/cctest.  Fix up the style issues it
reports.

PR-URL: #9787
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
  • Loading branch information
bnoordhuis committed Dec 1, 2016
1 parent 330e63c commit 8264a22
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
))
Expand Down
41 changes: 26 additions & 15 deletions test/cctest/test_inspector_socket.cc
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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*>(
expectations* expects = static_cast<expectations*>(
inspector_from_stream(stream)->data);
expects->err_code = nread < 0 ? nread : 0;
if (nread > 0) {
Expand Down Expand Up @@ -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;
Expand All @@ -367,7 +376,7 @@ class InspectorSocketTest : public ::testing::Test {
connect.data = nullptr;
uv_tcp_connect(&connect, &client_socket,
reinterpret_cast<const sockaddr*>(&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<uv_handle_t*>(&server));
}
Expand Down Expand Up @@ -419,7 +428,6 @@ TEST_F(InspectorSocketTest, ReadsAndWritesInspectorMessage) {
}

TEST_F(InspectorSocketTest, BufferEdgeCases) {

do_write(const_cast<char*>(HANDSHAKE_REQ), sizeof(HANDSHAKE_REQ) - 1);
expect_handshake();

Expand Down Expand Up @@ -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<uv_handle_t*>(&client_socket)), 0);
GTEST_ASSERT_EQ(uv_is_active(reinterpret_cast<uv_handle_t*>(&client_socket)),
0);
manual_inspector_socket_cleanup();
}

Expand Down Expand Up @@ -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<char*>(BROKEN_REQUEST), sizeof(BROKEN_REQUEST) - 1);
SPIN_WHILE(last_event != kInspectorHandshakeFailed);
Expand All @@ -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<uv_handle_t*>(&client_socket)), 0);
GTEST_ASSERT_EQ(uv_is_active(reinterpret_cast<uv_handle_t*>(&client_socket)),
0);
}

TEST_F(InspectorSocketTest, CanStopReadingFromInspector) {
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -895,3 +904,5 @@ TEST_F(InspectorSocketTest, ErrorCleansUpTheSocket) {
SPIN_WHILE(err > 0);
EXPECT_EQ(UV_EPROTO, err);
}

} // anonymous namespace

0 comments on commit 8264a22

Please sign in to comment.