Skip to content

Commit 3aa03bb

Browse files
committed
[clang-format] Code format
1 parent 573e65d commit 3aa03bb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+1192
-975
lines changed

.clang-format

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Language: Cpp
33
# BasedOnStyle: Google
44
AccessModifierOffset: -2
55
AlignAfterOpenBracket: Align
6-
AlignConsecutiveAssignments: false
6+
AlignConsecutiveAssignments: true
77
AlignConsecutiveDeclarations: false
88
AlignEscapedNewlines: Right
99
AlignOperands: true

code_format.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ clang-format -i include/*.h
1515

1616
# ext source file
1717
clang-format -i *.cc
18-
18+
clang-format -i *.h
1919

2020
clang-format -i examples/cpp/*.cc
2121

2222
# core-tests source file
23+
clang-format -i core-tests/src/_lib/*.cpp
2324
clang-format -i core-tests/src/client/*.cpp
2425
clang-format -i core-tests/src/core/*.cpp
2526
clang-format -i core-tests/src/coroutine/*.cpp

core-tests/src/_lib/http.cpp

+54-58
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ Client::Client(const std::string &host) : Client(host, 80, std::string(), std::s
9595
Client::Client(const std::string &host, int port) : Client(host, port, std::string(), std::string()) {}
9696

9797
Client::Client(const std::string &host,
98-
int port,
99-
const std::string &client_cert_path,
100-
const std::string &client_key_path)
98+
int port,
99+
const std::string &client_cert_path,
100+
const std::string &client_key_path)
101101
: host_(host),
102102
port_(port),
103103
host_and_port_(host_ + ":" + std::to_string(port_)),
@@ -439,12 +439,12 @@ bool Client::write_request(Stream &strm, const Request &req, bool close_connecti
439439
}
440440

441441
std::shared_ptr<Response> Client::send_with_content_provider(const char *method,
442-
const char *path,
443-
const Headers &headers,
444-
const std::string &body,
445-
size_t content_length,
446-
ContentProvider content_provider,
447-
const char *content_type) {
442+
const char *path,
443+
const Headers &headers,
444+
const std::string &body,
445+
size_t content_length,
446+
ContentProvider content_provider,
447+
const char *content_type) {
448448
Request req;
449449
req.method = method;
450450
req.headers = headers;
@@ -584,31 +584,29 @@ std::shared_ptr<Response> Client::Get(const char *path, ContentReceiver content_
584584
return Get(path, Headers(), nullptr, std::move(content_receiver), std::move(progress));
585585
}
586586

587-
std::shared_ptr<Response> Client::Get(const char *path,
588-
const Headers &headers,
589-
ContentReceiver content_receiver) {
587+
std::shared_ptr<Response> Client::Get(const char *path, const Headers &headers, ContentReceiver content_receiver) {
590588
return Get(path, headers, nullptr, std::move(content_receiver), Progress());
591589
}
592590

593591
std::shared_ptr<Response> Client::Get(const char *path,
594-
const Headers &headers,
595-
ContentReceiver content_receiver,
596-
Progress progress) {
592+
const Headers &headers,
593+
ContentReceiver content_receiver,
594+
Progress progress) {
597595
return Get(path, headers, nullptr, std::move(content_receiver), std::move(progress));
598596
}
599597

600598
std::shared_ptr<Response> Client::Get(const char *path,
601-
const Headers &headers,
602-
ResponseHandler response_handler,
603-
ContentReceiver content_receiver) {
599+
const Headers &headers,
600+
ResponseHandler response_handler,
601+
ContentReceiver content_receiver) {
604602
return Get(path, headers, std::move(response_handler), content_receiver, Progress());
605603
}
606604

607605
std::shared_ptr<Response> Client::Get(const char *path,
608-
const Headers &headers,
609-
ResponseHandler response_handler,
610-
ContentReceiver content_receiver,
611-
Progress progress) {
606+
const Headers &headers,
607+
ResponseHandler response_handler,
608+
ContentReceiver content_receiver,
609+
Progress progress) {
612610
Request req;
613611
req.method = "GET";
614612
req.path = path;
@@ -645,9 +643,9 @@ std::shared_ptr<Response> Client::Post(const char *path, const std::string &body
645643
}
646644

647645
std::shared_ptr<Response> Client::Post(const char *path,
648-
const Headers &headers,
649-
const std::string &body,
650-
const char *content_type) {
646+
const Headers &headers,
647+
const std::string &body,
648+
const char *content_type) {
651649
return send_with_content_provider("POST", path, headers, body, 0, nullptr, content_type);
652650
}
653651

@@ -656,17 +654,17 @@ std::shared_ptr<Response> Client::Post(const char *path, const Params &params) {
656654
}
657655

658656
std::shared_ptr<Response> Client::Post(const char *path,
659-
size_t content_length,
660-
ContentProvider content_provider,
661-
const char *content_type) {
657+
size_t content_length,
658+
ContentProvider content_provider,
659+
const char *content_type) {
662660
return Post(path, Headers(), content_length, content_provider, content_type);
663661
}
664662

665663
std::shared_ptr<Response> Client::Post(const char *path,
666-
const Headers &headers,
667-
size_t content_length,
668-
ContentProvider content_provider,
669-
const char *content_type) {
664+
const Headers &headers,
665+
size_t content_length,
666+
ContentProvider content_provider,
667+
const char *content_type) {
670668
return send_with_content_provider(
671669
"POST", path, headers, std::string(), content_length, content_provider, content_type);
672670
}
@@ -680,9 +678,7 @@ std::shared_ptr<Response> Client::Post(const char *path, const MultipartFormData
680678
return Post(path, Headers(), items);
681679
}
682680

683-
std::shared_ptr<Response> Client::Post(const char *path,
684-
const Headers &headers,
685-
const MultipartFormDataItems &items) {
681+
std::shared_ptr<Response> Client::Post(const char *path, const Headers &headers, const MultipartFormDataItems &items) {
686682
auto boundary = detail::make_multipart_data_boundary();
687683

688684
std::string body;
@@ -716,24 +712,24 @@ std::shared_ptr<Response> Client::Put(const char *path, const std::string &body,
716712
}
717713

718714
std::shared_ptr<Response> Client::Put(const char *path,
719-
const Headers &headers,
720-
const std::string &body,
721-
const char *content_type) {
715+
const Headers &headers,
716+
const std::string &body,
717+
const char *content_type) {
722718
return send_with_content_provider("PUT", path, headers, body, 0, nullptr, content_type);
723719
}
724720

725721
std::shared_ptr<Response> Client::Put(const char *path,
726-
size_t content_length,
727-
ContentProvider content_provider,
728-
const char *content_type) {
722+
size_t content_length,
723+
ContentProvider content_provider,
724+
const char *content_type) {
729725
return Put(path, Headers(), content_length, content_provider, content_type);
730726
}
731727

732728
std::shared_ptr<Response> Client::Put(const char *path,
733-
const Headers &headers,
734-
size_t content_length,
735-
ContentProvider content_provider,
736-
const char *content_type) {
729+
const Headers &headers,
730+
size_t content_length,
731+
ContentProvider content_provider,
732+
const char *content_type) {
737733
return send_with_content_provider(
738734
"PUT", path, headers, std::string(), content_length, content_provider, content_type);
739735
}
@@ -752,24 +748,24 @@ std::shared_ptr<Response> Client::Patch(const char *path, const std::string &bod
752748
}
753749

754750
std::shared_ptr<Response> Client::Patch(const char *path,
755-
const Headers &headers,
756-
const std::string &body,
757-
const char *content_type) {
751+
const Headers &headers,
752+
const std::string &body,
753+
const char *content_type) {
758754
return send_with_content_provider("PATCH", path, headers, body, 0, nullptr, content_type);
759755
}
760756

761757
std::shared_ptr<Response> Client::Patch(const char *path,
762-
size_t content_length,
763-
ContentProvider content_provider,
764-
const char *content_type) {
758+
size_t content_length,
759+
ContentProvider content_provider,
760+
const char *content_type) {
765761
return Patch(path, Headers(), content_length, content_provider, content_type);
766762
}
767763

768764
std::shared_ptr<Response> Client::Patch(const char *path,
769-
const Headers &headers,
770-
size_t content_length,
771-
ContentProvider content_provider,
772-
const char *content_type) {
765+
const Headers &headers,
766+
size_t content_length,
767+
ContentProvider content_provider,
768+
const char *content_type) {
773769
return send_with_content_provider(
774770
"PATCH", path, headers, std::string(), content_length, content_provider, content_type);
775771
}
@@ -787,9 +783,9 @@ std::shared_ptr<Response> Client::Delete(const char *path, const Headers &header
787783
}
788784

789785
std::shared_ptr<Response> Client::Delete(const char *path,
790-
const Headers &headers,
791-
const std::string &body,
792-
const char *content_type) {
786+
const Headers &headers,
787+
const std::string &body,
788+
const char *content_type) {
793789
Request req;
794790
req.method = "DELETE";
795791
req.headers = headers;

core-tests/src/core/base.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ TEST(base, swoole_hex2dec) {
4949
}
5050

5151
TEST(base, random_string) {
52-
char buf[1024] = { };
52+
char buf[1024] = {};
5353
swoole_random_string(buf, sizeof(buf) - 1);
5454
ASSERT_EQ(strlen(buf), sizeof(buf) - 1);
5555
}
@@ -87,10 +87,10 @@ TEST(base, shell_exec) {
8787
int _pipe = swoole_shell_exec(str.c_str(), &pid, 0);
8888
ASSERT_GT(_pipe, 0);
8989
ASSERT_GT(pid, 0);
90-
char buf[1024] = { };
90+
char buf[1024] = {};
9191
ssize_t n = read(_pipe, buf, sizeof(buf) - 1);
9292
ASSERT_GT(n, 0);
93-
ASSERT_STREQ(string(buf).substr(0, sizeof(TEST_JPG_MD5SUM) -1).c_str(), TEST_JPG_MD5SUM);
93+
ASSERT_STREQ(string(buf).substr(0, sizeof(TEST_JPG_MD5SUM) - 1).c_str(), TEST_JPG_MD5SUM);
9494
close(_pipe);
9595
}
9696

core-tests/src/coroutine/gethostbyname.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#include "test_coroutine.h"
22

33
using swoole::Coroutine;
4+
using swoole::Timer;
45
using swoole::coroutine::System;
56
using swoole::test::coroutine;
6-
using swoole::Timer;
77

88
TEST(coroutine_gethostbyname, resolve_cache) {
99
coroutine::run([](void *arg) {

core-tests/src/coroutine/hook.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ TEST(coroutine_hook, socket) {
110110
int sock = swoole_coroutine_socket(AF_INET, SOCK_STREAM, 0);
111111
ASSERT_GT(sock, 0);
112112
swoole::network::Address sa;
113-
std::string ip = System::gethostbyname( "www.baidu.com", AF_INET, 10);
113+
std::string ip = System::gethostbyname("www.baidu.com", AF_INET, 10);
114114
sa.assign(SW_SOCK_TCP, ip.c_str(), 80);
115115
ASSERT_EQ(swoole_coroutine_connect(sock, &sa.addr.ss, sa.len), 0);
116116
ASSERT_EQ(swoole_coroutine_socket_wait_event(sock, SW_EVENT_WRITE, 5), SW_OK);
@@ -120,7 +120,7 @@ TEST(coroutine_hook, socket) {
120120

121121
swoole::String resp(1024);
122122

123-
while(1) {
123+
while (1) {
124124
ssize_t n = swoole_coroutine_recv(sock, resp.value() + resp.length, resp.size - resp.length, 0);
125125
if (n <= 0) {
126126
break;

core-tests/src/coroutine/http_server.cpp

+2-8
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ TEST(coroutine_http_server, get) {
5151

5252
svr.Post("/post", [](const Request &req, Response &res) { res.set_content("Hello World!", "text/plain"); });
5353

54-
svr.BeforeListen([&lock]() {
55-
lock.unlock();
56-
});
54+
svr.BeforeListen([&lock]() { lock.unlock(); });
5755

5856
svr.listen(TEST_HOST, 8080);
5957
});
@@ -62,7 +60,6 @@ TEST(coroutine_http_server, get) {
6260
}
6361

6462
TEST(coroutine_http_server, post) {
65-
6663
Server svr;
6764
mutex lock;
6865
lock.lock();
@@ -86,17 +83,14 @@ TEST(coroutine_http_server, post) {
8683
});
8784

8885
coroutine::run([&lock, &svr](void *arg) {
89-
9086
svr.Get("/stop", [&svr](const Request &req, Response &res) {
9187
res.set_content("Stop Server!", "text/plain");
9288
svr.stop();
9389
});
9490

9591
svr.Post("/post", [](const Request &req, Response &res) { res.set_content("Hello World!", "text/plain"); });
9692

97-
svr.BeforeListen([&lock]() {
98-
lock.unlock();
99-
});
93+
svr.BeforeListen([&lock]() { lock.unlock(); });
10094

10195
svr.listen(TEST_HOST, 8080);
10296
});

0 commit comments

Comments
 (0)