Skip to content

Commit a31f345

Browse files
author
Ivan Baidakou
committed
Fix remained tests
1 parent 733f223 commit a31f345

18 files changed

+454
-250
lines changed

.clang-format

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
Language: Cpp
3+
# BasedOnStyle: LLVM
4+
AccessModifierOffset: -2
5+
AlignAfterOpenBracket: true
6+
AlignConsecutiveAssignments: false
7+
AlignEscapedNewlinesLeft: false
8+
AlignOperands: true
9+
AlignTrailingComments: true
10+
AllowAllParametersOfDeclarationOnNextLine: true
11+
AllowShortBlocksOnASingleLine: false
12+
AllowShortCaseLabelsOnASingleLine: false
13+
AllowShortFunctionsOnASingleLine: All
14+
AllowShortIfStatementsOnASingleLine: false
15+
AllowShortLoopsOnASingleLine: false
16+
AlwaysBreakAfterDefinitionReturnType: None
17+
AlwaysBreakBeforeMultilineStrings: false
18+
AlwaysBreakTemplateDeclarations: false
19+
BinPackArguments: true
20+
BinPackParameters: true
21+
BreakBeforeBinaryOperators: None
22+
BreakBeforeBraces: Attach
23+
BreakBeforeTernaryOperators: true
24+
BreakConstructorInitializersBeforeComma: false
25+
ColumnLimit: 80
26+
CommentPragmas: '^ IWYU pragma:'
27+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
28+
ConstructorInitializerIndentWidth: 4
29+
ContinuationIndentWidth: 4
30+
Cpp11BracedListStyle: true
31+
DerivePointerAlignment: false
32+
DisableFormat: false
33+
ExperimentalAutoDetectBinPacking: false
34+
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
35+
IndentCaseLabels: false
36+
IndentWidth: 4
37+
IndentWrappedFunctionNames: false
38+
KeepEmptyLinesAtTheStartOfBlocks: true
39+
MacroBlockBegin: ''
40+
MacroBlockEnd: ''
41+
MaxEmptyLinesToKeep: 1
42+
NamespaceIndentation: None
43+
ObjCBlockIndentWidth: 4
44+
ObjCSpaceAfterProperty: false
45+
ObjCSpaceBeforeProtocolList: true
46+
PenaltyBreakBeforeFirstCallParameter: 19
47+
PenaltyBreakComment: 300
48+
PenaltyBreakFirstLessLess: 120
49+
PenaltyBreakString: 1000
50+
PenaltyExcessCharacter: 1000000
51+
PenaltyReturnTypeOnItsOwnLine: 60
52+
PointerAlignment: Right
53+
SpaceAfterCStyleCast: false
54+
SpaceBeforeAssignmentOperators: true
55+
SpaceBeforeParens: ControlStatements
56+
SpaceInEmptyParentheses: false
57+
SpacesBeforeTrailingComments: 1
58+
SpacesInAngles: false
59+
SpacesInContainerLiterals: true
60+
SpacesInCStyleCastParentheses: false
61+
SpacesInParentheses: false
62+
SpacesInSquareBrackets: false
63+
Standard: Cpp11
64+
TabWidth: 8
65+
UseTab: Never
66+
...
67+

CMakeLists.txt

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ include (CTest)
88
enable_testing()
99

1010
add_definitions(-DBOOST_ERROR_CODE_HEADER_ONLY)
11-
add_definitions(-DBREDIS_DEBUG)
11+
#add_definitions(-DBREDIS_DEBUG)
1212

1313
find_package(
1414
Boost
@@ -33,38 +33,38 @@ add_executable(t-10-ping t/10-ping.cpp)
3333
target_link_libraries(t-10-ping ${LINK_DEPENDENCIES})
3434
add_test("t-10-ping" t-10-ping)
3535

36-
#add_executable(t-11-multi-ping t/11-multi-ping.cpp)
37-
#target_link_libraries(t-11-multi-ping ${LINK_DEPENDENCIES})
38-
#add_test("t-11-multi-ping" t-11-multi-ping)
39-
#
40-
#add_executable(t-12-basic-types t/12-basic-types.cpp)
41-
#target_link_libraries(t-12-basic-types ${LINK_DEPENDENCIES})
42-
#add_test("t-12-basic-types" t-12-basic-types)
43-
#
44-
#add_executable(t-13-protol-error t/13-protol-error.cpp)
45-
#target_link_libraries(t-13-protol-error ${LINK_DEPENDENCIES})
46-
#add_test("t-13-protol-error" t-13-protol-error)
47-
#
48-
#add_executable(t-14-uds t/14-uds.cpp)
49-
#target_link_libraries(t-14-uds ${LINK_DEPENDENCIES})
50-
#add_test("t-14-uds" t-14-uds)
51-
#
52-
#add_executable(t-15-cancellation t/15-cancellation.cpp)
53-
#target_link_libraries(t-15-cancellation ${LINK_DEPENDENCIES})
54-
#add_test("t-15-cancellation" t-15-cancellation)
55-
#
56-
#add_executable(t-16-close-connection t/16-close-connection.cpp)
57-
#target_link_libraries(t-16-close-connection ${LINK_DEPENDENCIES})
58-
#add_test("t-16-close-connection" t-16-close-connection)
59-
#
60-
#add_executable(t-17-sync t/17-sync.cpp)
61-
#target_link_libraries(t-17-sync ${LINK_DEPENDENCIES})
62-
#add_test("t-17-sync" t-17-sync)
63-
#
64-
#add_executable(t-18-subscription t/18-subscription.cpp)
65-
#target_link_libraries(t-18-subscription ${LINK_DEPENDENCIES})
66-
#add_test("t-18-subscription" t-18-subscription)
67-
#
68-
#add_executable(t-19-transaction t/19-transaction.cpp)
69-
#target_link_libraries(t-19-transaction ${LINK_DEPENDENCIES})
70-
#add_test("t-19-transaction" t-19-transaction)
36+
add_executable(t-11-multi-ping t/11-multi-ping.cpp)
37+
target_link_libraries(t-11-multi-ping ${LINK_DEPENDENCIES})
38+
add_test("t-11-multi-ping" t-11-multi-ping)
39+
40+
add_executable(t-12-basic-types t/12-basic-types.cpp)
41+
target_link_libraries(t-12-basic-types ${LINK_DEPENDENCIES})
42+
add_test("t-12-basic-types" t-12-basic-types)
43+
44+
add_executable(t-13-protol-error t/13-protol-error.cpp)
45+
target_link_libraries(t-13-protol-error ${LINK_DEPENDENCIES})
46+
add_test("t-13-protol-error" t-13-protol-error)
47+
48+
add_executable(t-14-uds t/14-uds.cpp)
49+
target_link_libraries(t-14-uds ${LINK_DEPENDENCIES})
50+
add_test("t-14-uds" t-14-uds)
51+
52+
add_executable(t-15-cancellation t/15-cancellation.cpp)
53+
target_link_libraries(t-15-cancellation ${LINK_DEPENDENCIES})
54+
add_test("t-15-cancellation" t-15-cancellation)
55+
56+
add_executable(t-16-close-connection t/16-close-connection.cpp)
57+
target_link_libraries(t-16-close-connection ${LINK_DEPENDENCIES})
58+
add_test("t-16-close-connection" t-16-close-connection)
59+
60+
add_executable(t-17-sync t/17-sync.cpp)
61+
target_link_libraries(t-17-sync ${LINK_DEPENDENCIES})
62+
add_test("t-17-sync" t-17-sync)
63+
64+
add_executable(t-18-subscription t/18-subscription.cpp)
65+
target_link_libraries(t-18-subscription ${LINK_DEPENDENCIES})
66+
add_test("t-18-subscription" t-18-subscription)
67+
68+
add_executable(t-19-transaction t/19-transaction.cpp)
69+
target_link_libraries(t-19-transaction ${LINK_DEPENDENCIES})
70+
add_test("t-19-transaction" t-19-transaction)

include/bredis/Connection.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,18 @@ template <typename NextLayer> class Connection {
5050
template <typename ReadCallback, typename DynamicBuffer>
5151
void async_read(DynamicBuffer &rx_buff, ReadCallback read_callback,
5252
std::size_t replies_count = 1);
53-
#if 0
5453

5554
/* synchronous interface */
5655
void write(const command_wrapper_t &command);
5756
void write(const command_wrapper_t &command, boost::system::error_code &ec);
5857

5958
template <typename DynamicBuffer>
60-
positive_parse_result_t read(DynamicBuffer &rx_buff);
59+
positive_parse_result_t<typename to_iterator<DynamicBuffer>::iterator_t>
60+
read(DynamicBuffer &rx_buff);
61+
6162
template <typename DynamicBuffer>
62-
positive_parse_result_t read(DynamicBuffer &rx_buff,
63-
boost::system::error_code &ec);
64-
#endif
63+
positive_parse_result_t<typename to_iterator<DynamicBuffer>::iterator_t>
64+
read(DynamicBuffer &rx_buff, boost::system::error_code &ec);
6565
};
6666

6767
} // namespace bredis

include/bredis/MarkerHelpers.hpp

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#pragma once
88

99
#include <algorithm>
10+
#include <iterator>
1011
#include <string>
1112

1213
#include "Markers.hpp"
@@ -16,21 +17,67 @@ namespace bredis {
1617
namespace marker_helpers {
1718

1819
template <typename Iterator>
20+
struct stringizer : public boost::static_visitor<std::string> {
1921

22+
std::string operator()(const markers::string_t<Iterator> &value) const {
23+
auto size = std::distance(value.from, value.to);
24+
std::string r;
25+
r.reserve(size);
26+
r.append(value.from, value.to);
27+
return "[str] " + r;
28+
}
29+
30+
std::string operator()(const markers::error_t<Iterator> &value) const {
31+
auto size = std::distance(value.string.from, value.string.to);
32+
std::string r;
33+
r.reserve(size);
34+
r.append(value.string.from, value.string.to);
35+
return "[err] " + r;
36+
}
37+
38+
std::string operator()(const markers::int_t<Iterator> &value) const {
39+
auto size = std::distance(value.string.from, value.string.to);
40+
std::string r;
41+
r.reserve(size);
42+
r.append(value.string.from, value.string.to);
43+
return "[int] " + r;
44+
}
45+
46+
std::string operator()(const markers::nil_t<Iterator> &value) const {
47+
return "[nil] ";
48+
}
49+
50+
std::string
51+
operator()(const markers::array_holder_t<Iterator> &value) const {
52+
std::string r = "[array] {";
53+
for (const auto &v : value.elements) {
54+
r += boost::apply_visitor(*this, v) + ", ";
55+
}
56+
r += "}";
57+
return r;
58+
}
59+
};
60+
61+
template <typename Iterator>
2062
class equality : public boost::static_visitor<bool> {
63+
using StringIterator = std::string::const_iterator;
64+
2165
private:
22-
const char *begin_;
23-
const char *end_;
66+
std::string copy_;
67+
StringIterator begin_;
68+
StringIterator end_;
2469

2570
public:
2671
equality(std::string str)
27-
: begin_(str.c_str()), end_(str.c_str() + str.size()) {}
72+
: copy_(str), begin_(std::begin(copy_)), end_(std::end(copy_)) {}
2873

2974
template <typename T> bool operator()(const T &value) const {
3075
return false;
3176
}
3277

3378
bool operator()(const markers::string_t<Iterator> &value) const {
79+
auto helper = stringizer<Iterator>();
80+
auto str = helper(value);
3481
return std::equal(begin_, end_, value.from, value.to);
3582
}
3683

include/bredis/Result.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020

2121
namespace bredis {
2222

23+
template <typename DynamicBuffer> struct to_iterator {
24+
using iterator_t = boost::asio::buffers_iterator<
25+
typename DynamicBuffer::const_buffers_type, char>;
26+
};
27+
2328
struct protocol_error_t {
2429
std::string what;
2530
bool operator==(const char *rhs) { return what == rhs; }

include/bredis/impl/connection.ipp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ void Connection<NextLayer>::async_read(DynamicBuffer &rx_buff,
4343
namespace asio = boost::asio;
4444
namespace sys = boost::system;
4545
using boost::asio::async_read_until;
46-
using Iterator = boost::asio::buffers_iterator<
47-
typename DynamicBuffer::const_buffers_type, char>;
46+
using Iterator = typename to_iterator<DynamicBuffer>::iterator_t;
4847

4948
async_read_until(
5049
stream_, rx_buff, MatchResult<Iterator>(replies_count),
@@ -74,7 +73,6 @@ void Connection<NextLayer>::async_read(DynamicBuffer &rx_buff,
7473
read_callback(parse_error_code, std::move(result), 0);
7574
return;
7675
}
77-
auto *nod = boost::get<no_enogh_data_t>(&parse_result);
7876
auto &positive_result =
7977
boost::get<positive_parse_result_t<Iterator>>(parse_result);
8078
results.elements.emplace_back(positive_result.result);
@@ -90,7 +88,6 @@ void Connection<NextLayer>::async_read(DynamicBuffer &rx_buff,
9088
});
9189
}
9290

93-
#if 0
9491
template <typename NextLayer>
9592
void Connection<NextLayer>::write(const command_wrapper_t &command,
9693
boost::system::error_code &ec) {
@@ -111,35 +108,38 @@ void Connection<NextLayer>::write(const command_wrapper_t &command) {
111108

112109
template <typename NextLayer>
113110
template <typename DynamicBuffer>
114-
positive_parse_result_t
111+
positive_parse_result_t<typename to_iterator<DynamicBuffer>::iterator_t>
115112
Connection<NextLayer>::read(DynamicBuffer &rx_buff,
116113
boost::system::error_code &ec) {
117114
namespace asio = boost::asio;
118115
using boost::asio::read_until;
116+
using Iterator = typename to_iterator<DynamicBuffer>::iterator_t;
117+
using result_t = positive_parse_result_t<
118+
typename to_iterator<DynamicBuffer>::iterator_t>;
119119

120-
auto rx_bytes = read_until(stream_, rx_buff, MatchResult(1), ec);
120+
auto rx_bytes = read_until(stream_, rx_buff, MatchResult<Iterator>(1), ec);
121121
if (ec) {
122-
return positive_parse_result_t{{}, 0};
122+
return result_t{{}, 0};
123123
}
124124

125-
const auto char_ptr =
126-
boost::asio::buffer_cast<const char *>(rx_buff.data());
127-
auto size = rx_buff.size();
128-
string_t data(char_ptr, size);
125+
auto const_buff = rx_buff.data();
126+
auto begin = Iterator::begin(const_buff);
127+
auto end = Iterator::end(const_buff);
128+
129+
auto parse_result = Protocol::parse(begin, end);
129130

130-
auto parse_result = Protocol::parse(data);
131131
auto *parse_error = boost::get<protocol_error_t>(&parse_result);
132132
if (parse_error) {
133-
// BREDIS_LOG_DEBUG("protocol error: " << parse_error->what);
134133
ec = Error::make_error_code(bredis_errors::protocol_error);
135-
return positive_parse_result_t{{}, 0};
134+
return result_t{};
136135
}
137-
return boost::get<positive_parse_result_t>(parse_result);
136+
return boost::get<positive_parse_result_t<Iterator>>(parse_result);
138137
}
139138

140139
template <typename NextLayer>
141140
template <typename DynamicBuffer>
142-
positive_parse_result_t Connection<NextLayer>::read(DynamicBuffer &rx_buff) {
141+
positive_parse_result_t<typename to_iterator<DynamicBuffer>::iterator_t>
142+
Connection<NextLayer>::read(DynamicBuffer &rx_buff) {
143143
namespace asio = boost::asio;
144144

145145
boost::system::error_code ec;
@@ -149,6 +149,5 @@ positive_parse_result_t Connection<NextLayer>::read(DynamicBuffer &rx_buff) {
149149
}
150150
return result;
151151
}
152-
#endif
153152

154153
} // namespace bredis

0 commit comments

Comments
 (0)