Skip to content

Commit 51f570f

Browse files
Working through more warnings
1 parent a229b1f commit 51f570f

File tree

4 files changed

+26
-10
lines changed

4 files changed

+26
-10
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ if (COMPILE_TESTS)
3131
target_link_libraries(coverage_config INTERFACE --coverage)
3232
endif ()
3333
add_executable(jsonrpccpp-test test/main.cpp test/client.cpp test/typemapper.cpp test/dispatcher.cpp test/server.cpp test/batchclient.cpp test/testclientconnector.hpp examples/warehouse/warehouseapp.cpp test/warehouseapp.cpp)
34+
target_compile_options(jsonrpccpp-test PUBLIC "${_warning_opts}")
3435
target_include_directories(jsonrpccpp-test PRIVATE vendor examples)
3536
target_link_libraries(jsonrpccpp-test coverage_config json-rpc-cxx)
3637
enable_testing()

test/client.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct F {
1313
TestClientConnector c;
1414
JsonRpcClient clientV1;
1515
JsonRpcClient clientV2;
16-
F() : clientV1(c, version::v1), clientV2(c, version::v2) {}
16+
F() : c(), clientV1(c, version::v1), clientV2(c, version::v2) {}
1717
};
1818

1919
TEST_CASE_METHOD(F, "v2_method_noparams", TEST_MODULE) {
@@ -256,4 +256,4 @@ TEST_CASE_METHOD(F, "v1_notification_call_params_byposition", TEST_MODULE) {
256256
CHECK(c.request["params"][2] == true);
257257
}
258258

259-
// TODO: test cases with return type mapping and param mapping for v1/v2 method and notification
259+
// TODO: test cases with return type mapping and param mapping for v1/v2 method and notification

test/testclientconnector.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ using namespace std;
1111

1212
class TestClientConnector : public IClientConnector {
1313
public:
14+
TestClientConnector() : request(), raw_response() {}
15+
1416
json request;
1517
string raw_response;
1618

@@ -64,4 +66,4 @@ class TestClientConnector : public IClientConnector {
6466
CHECK(has_key(request, "params"));
6567
}
6668
}
67-
};
69+
};

test/typemapper.cpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,21 +85,34 @@ TEST_CASE("test incorrect params", TEST_MODULE) {
8585
enum class category { order, cash_carry };
8686

8787
struct product {
88+
product() : id(), price(), name(), cat() {}
8889
int id;
8990
double price;
9091
string name;
9192
category cat;
9293
};
9394

94-
NLOHMANN_JSON_SERIALIZE_ENUM(category, {{category::order, "order"}, {category::cash_carry, "cc"}});
95+
NLOHMANN_JSON_SERIALIZE_ENUM(category, {{category::order, "order"}, {category::cash_carry, "cc"}})
9596

9697
void to_json(json &j, const product &p) { j = json{{"id", p.id}, {"price", p.price}, {"name", p.name}, {"category", p.cat}}; }
9798

9899
product get_product(int id) {
99-
if (id == 1)
100-
return product{1, 22.50, "some product", category::order};
101-
else if (id == 2)
102-
return product{2, 55.50, "some product 2", category::cash_carry};
100+
if (id == 1) {
101+
product p;
102+
p.id = 1;
103+
p.price = 22.50;
104+
p.name = "some product";
105+
p.cat = category::order;
106+
return p;
107+
}
108+
else if (id == 2) {
109+
product p;
110+
p.id = 2;
111+
p.price = 55.50;
112+
p.name = "some product 2";
113+
p.cat = category::cash_carry;
114+
return p;
115+
}
103116
throw JsonRpcException(-50000, "product not found");
104117
}
105118

@@ -131,7 +144,7 @@ static vector<product> catalog;
131144
bool add_products(const vector<product> &products) {
132145
std::copy(products.begin(), products.end(), std::back_inserter(catalog));
133146
return true;
134-
};
147+
}
135148

136149
TEST_CASE("test with custom params", TEST_MODULE) {
137150
MethodHandle mh = GetHandle(&add_products);
@@ -175,4 +188,4 @@ TEST_CASE("test number range checking", TEST_MODULE) {
175188
unsigned short max_ss = numeric_limits<short>::max();
176189
CHECK(mh2({max_su, max_ss}) == max_su + max_ss);
177190
REQUIRE_THROWS_WITH(mh2({max_su, max_su}), Contains("invalid parameter: exceeds value range of integer"));
178-
}
191+
}

0 commit comments

Comments
 (0)