Line data Source code
1 : #include <iostream>
2 : #include <wjrpc/method.hpp>
3 : #include <wjrpc/noparams_json.hpp>
4 : #include <fas/testing.hpp>
5 : #include "req.hpp"
6 :
7 3 : UNIT(incoming1, "")
8 : {
9 : using namespace fas::testing;
10 : using namespace ::wjrpc;
11 : //std::string data = "{\"method\":\"test\"}";
12 1 : t << is_true<expect>(true) ;
13 8 : for (auto r : good_parse )
14 : {
15 14 : incoming_holder h( std::make_unique<data_type>(r.begin(), r.end()) );
16 7 : t << message("good parse: ") << r;
17 7 : t << flush;
18 7 : h.parse(nullptr);
19 : }
20 :
21 8 : for (auto r : bad_parse )
22 : {
23 7 : t << message("bad parse: [") << r << "]";
24 14 : incoming_holder h( std::make_unique<data_type>(r.begin(), r.end()) );
25 7 : ::wjson::json_error e;
26 7 : h.parse(&e);
27 7 : t << is_true<expect>( e ) << FAS_FL;
28 7 : t << message("JSON-RPC error: ") << ::wjson::strerror::message_trace(e, r.begin(), r.end() );
29 : }
30 :
31 1 : t << nothing;
32 1 : }
33 :
34 3 : UNIT(incoming2, "")
35 : {
36 : using namespace fas::testing;
37 : using namespace ::wjrpc;
38 : using namespace std::chrono;
39 : using namespace wjson::literals;
40 1 : std::string json = "{'method':'test','params':[1,2,3]}"_json;
41 2 : incoming_holder h( std::make_unique<data_type>(json.begin(), json.end()), high_resolution_clock::now() );
42 1 : ::wjson::json_error e;
43 1 : h.parse(&e);
44 2 : auto errstr = h.error_error_message(e);
45 1 : auto tp = h.get_time_point();
46 1 : t << message(errstr) << " " << duration_cast< nanoseconds >( high_resolution_clock::now() - tp ).count();
47 1 : t << message( h.id_error_message(e) );
48 1 : t << message( h.result_error_message(e) );
49 1 : t << message( h.params_error_message(e) );
50 :
51 1 : t << message( std::string( h.raw_method().first, h.raw_method().second ) );
52 1 : t << is_true<expect>( h.ready() ) << FAS_FL;
53 1 : t << is_true<expect>( h.is_valid() ) << FAS_FL;
54 1 : t << is_false<expect>( h.is_request_error() ) << FAS_FL;
55 1 : t << is_false<expect>( h.is_other_error() ) << FAS_FL;
56 1 : t << is_false<assert>( e ) << FAS_FL;
57 1 : t << stop;
58 2 : auto d = h.acquire_params();
59 2 : t << equal<expect, std::string>( "[1,2,3]", std::string(d->begin(), d->end() ) ) << FAS_FL;
60 :
61 :
62 1 : }
63 :
64 1 : BEGIN_SUITE(incoming_suite, "")
65 : ADD_UNIT(incoming1)
66 : ADD_UNIT(incoming2)
67 7 : END_SUITE(incoming_suite)
|