Skip to content

Commit 74dfe5c

Browse files
committed
Fixes and additional tests.
- Added as many test cases as possible for supported advanced WAMP features. Some features cannot be tested because they are not supported on Crossbar, or they are not "symmetrically" supported on CppWAMP (closes #43). - Added test cases where asynchronous Session operations are executed within call/event slots (closes #44). - Made changes to allow building with Clang on OS X (thanks taion!) (fixes #55). - Added test case for constructing Variant from std::vector (closes #58). - Rpc, Procedure, Pub, Topic, and friends now have converting (implicit) constructors (closes #60). - NaN and infinite Real values are now encoded as null over JSON (fixes #61). - Fixed unpackedEvent and unpackedRpc so that they can take a lambda functions by value. - Reorganized wamptest.cpp so that related test cases are grouped in SCENARIO blocks. The Crossbar router process can no longer be forked from the test suite because of this.
1 parent 6defeb0 commit 74dfe5c

19 files changed

+941
-103
lines changed

.hgignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ doc/html
66
CMakeLists.txt.user
77
.git
88
*.vpp.working
9+
.gitignore
10+
.gitmodules
11+

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
v0.3.1
2+
======
3+
Fixes and additional tests.
4+
5+
### Details
6+
- Added as many test cases as possible for supported advanced WAMP features. Some features cannot be tested because they are not supported on Crossbar, or they are not "symmetrically" supported on CppWAMP (closes #43).
7+
- Added test cases where asynchronous Session operations are executed within call/event slots (closes #44).
8+
- Made changes to allow building with Clang on OS X (thanks taion!) (fixes #55).
9+
- Added test case for constructing `Variant` from `std::vector` (closes #58).
10+
- `Rpc`, `Procedure`, `Pub`, `Topic`, and friends now have converting (implicit) constructors (closes #60).
11+
- NaN and infinite `Real` values are now encoded as `null` over JSON (fixes #61).
12+
- Fixed `unpackedEvent` and `unpackedRpc` so that they can take a lambda functions by value.
13+
- Reorganized `wamptest.cpp` so that related test cases are grouped in `SCENARIO` blocks. The Crossbar router process can no longer be forked from the test suite because of this.
14+
115
v0.3.0
216
======
317
Made further refinements to the API. The minimal Boost library version required is now 1.58.0.

cppwamp/include/cppwamp/dialoguedata.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ namespace wamp
2828
class Reason : public Options<Reason>
2929
{
3030
public:
31-
/** Constructor taking an optional reason URI. */
32-
explicit Reason(String uri = "");
31+
/** Converting constructor taking an optional reason URI. */
32+
Reason(String uri = "");
3333

3434
/** Obtains the reason URI. */
3535
const String& uri() const;
@@ -48,8 +48,8 @@ class Reason : public Options<Reason>
4848
class Error : public Options<Error>, public Payload<Error>
4949
{
5050
public:
51-
/** Constructor taking a reason URI. */
52-
explicit Error(String reason);
51+
/** Converting constructor taking a reason URI. */
52+
Error(String reason);
5353

5454
/** Obtains the reason URI. */
5555
const String& reason() const;

cppwamp/include/cppwamp/internal/json.ipp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
------------------------------------------------------------------------------*/
77

88
#include <cassert>
9+
#include <cmath>
910
#include <cstdio>
1011
#include <sstream>
1112
#include <rapidjson/reader.h>
@@ -95,10 +96,23 @@ struct EncodeJson : public Visitor<>
9596

9697
void operator()(Real x, TBuffer& buf) const
9798
{
98-
char str[32];
99-
auto length = std::snprintf(str, sizeof(str), "%.17e", x);
100-
assert(length < sizeof(str));
101-
buf.write(str, length);
99+
static const std::string nullStr("null");
100+
101+
if (std::isfinite(x))
102+
{
103+
char str[32];
104+
auto length = std::snprintf(str, sizeof(str), "%.17e", x);
105+
assert(length < sizeof(str));
106+
buf.write(str, length);
107+
}
108+
else
109+
{
110+
// ECMA-262, NOTE 4, p.208:
111+
// "Finite numbers are stringified as if by calling
112+
// ToString(number). NaN and Infinity regardless of sign are
113+
// represented as the String null.
114+
write(buf, nullStr);
115+
}
102116
}
103117

104118
void operator()(const std::string& s, TBuffer& buf) const

cppwamp/include/cppwamp/internal/registration.ipp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ namespace wamp
1616
* Registration
1717
*******************************************************************************/
1818

19+
/** @post `!!(*this) == false` */
1920
CPPWAMP_INLINE Registration::Registration() {}
2021

22+
CPPWAMP_INLINE Registration::operator bool() const {return id_ != invalidId_;}
23+
2124
CPPWAMP_INLINE RegistrationId Registration::id() const {return id_;}
2225

2326
CPPWAMP_INLINE void Registration::unregister() const

cppwamp/include/cppwamp/internal/session.ipp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,15 @@ CPPWAMP_INLINE void Session::subscribe(
256256
will effectively do nothing.
257257
@see Subscription, ScopedSubscription
258258
@note Duplicate unsubscribes using the same Subscription object
259-
are safely ignored. */
259+
are safely ignored.
260+
@pre `!!sub == true`
261+
@throws error::Logic if the given subscription is empty */
260262
//------------------------------------------------------------------------------
261263
CPPWAMP_INLINE void Session::unsubscribe(
262264
const Subscription& sub /**< The subscription to unsubscribe from. */
263265
)
264266
{
267+
CPPWAMP_LOGIC_CHECK(!!sub, "The subscription is empty");
265268
if (impl_)
266269
impl_->unsubscribe(sub);
267270
}
@@ -275,6 +278,7 @@ CPPWAMP_INLINE void Session::unsubscribe(
275278
@returns `false` if the subscription was already removed, `true` otherwise.
276279
@note Duplicate unsubscribes using the same Subscription handle
277280
are safely ignored.
281+
@pre `!!sub == true`
278282
@pre `this->state() == SessionState::established`
279283
@par Error Codes
280284
- SessionErrc::sessionEnded if the operation was aborted.
@@ -284,6 +288,7 @@ CPPWAMP_INLINE void Session::unsubscribe(
284288
- SessionErrc::unsubscribeError if the router reports some other
285289
error.
286290
- Some other `std::error_code` for protocol and transport errors.
291+
@throws error::Logic if the given subscription is empty
287292
@throws error::Logic if `this->state() != SessionState::established` */
288293
//------------------------------------------------------------------------------
289294
CPPWAMP_INLINE void Session::unsubscribe(
@@ -292,6 +297,7 @@ CPPWAMP_INLINE void Session::unsubscribe(
292297
completes. */
293298
)
294299
{
300+
CPPWAMP_LOGIC_CHECK(!!sub, "The subscription is empty");
295301
CPPWAMP_LOGIC_CHECK(state() == State::established,
296302
"Session is not established");
297303
impl_->unsubscribe(sub, std::move(handler));
@@ -363,12 +369,15 @@ CPPWAMP_INLINE void Session::enroll(Procedure procedure, CallSlot slot,
363369
will effectively do nothing.
364370
@see Registration, ScopedRegistration
365371
@note Duplicate unregistrations using the same Registration handle
366-
are safely ignored. */
372+
are safely ignored.
373+
@pre `!!reg == true`
374+
@throws error::Logic if the given registration is empty */
367375
//------------------------------------------------------------------------------
368376
CPPWAMP_INLINE void Session::unregister(
369377
const Registration& reg /**< The RPC registration to unregister. */
370378
)
371379
{
380+
CPPWAMP_LOGIC_CHECK(!!reg, "The registration is empty");
372381
if (impl_)
373382
impl_->unregister(reg);
374383
}
@@ -378,6 +387,7 @@ CPPWAMP_INLINE void Session::unregister(
378387
@returns `false` if the registration was already removed, `true` otherwise.
379388
@note Duplicate unregistrations using the same Registration handle
380389
are safely ignored.
390+
@pre `!!reg == true`
381391
@pre `this->state() == SessionState::established`
382392
@par Error Codes
383393
- SessionErrc::sessionEnded if the operation was aborted.
@@ -387,6 +397,7 @@ CPPWAMP_INLINE void Session::unregister(
387397
- SessionErrc::unregisterError if the router reports some other
388398
error.
389399
- Some other `std::error_code` for protocol and transport errors.
400+
@throws error::Logic if the given registration is empty
390401
@throws error::Logic if `this->state() != SessionState::established` */
391402
//------------------------------------------------------------------------------
392403
CPPWAMP_INLINE void Session::unregister(
@@ -395,6 +406,7 @@ CPPWAMP_INLINE void Session::unregister(
395406
completes. */
396407
)
397408
{
409+
CPPWAMP_LOGIC_CHECK(!!reg, "The registration is empty");
398410
CPPWAMP_LOGIC_CHECK(state() == State::established,
399411
"Session is not established");
400412
if (impl_)

cppwamp/include/cppwamp/internal/sessiondata.ipp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,15 +665,15 @@ CPPWAMP_INLINE Variant Invocation::procedure() const
665665
}
666666

667667
/** @pre `this->calleeHasExpired == false` */
668-
CPPWAMP_INLINE void Invocation::yield(Result result)
668+
CPPWAMP_INLINE void Invocation::yield(Result result) const
669669
{
670670
auto callee = callee_.lock();
671671
CPPWAMP_LOGIC_CHECK(!!callee, "Client no longer exists");
672672
callee->yield(id_, std::move(result));
673673
}
674674

675675
/** @pre `this->calleeHasExpired == false` */
676-
CPPWAMP_INLINE void Invocation::yield(Error error)
676+
CPPWAMP_INLINE void Invocation::yield(Error error) const
677677
{
678678
auto callee = callee_.lock();
679679
CPPWAMP_LOGIC_CHECK(!!callee, "Client no longer exists");

cppwamp/include/cppwamp/internal/subscription.ipp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,14 @@ namespace wamp
1616
* Subscription
1717
*******************************************************************************/
1818

19+
/** @post `!!(*this) == false` */
1920
CPPWAMP_INLINE Subscription::Subscription() {}
2021

22+
CPPWAMP_INLINE Subscription::operator bool() const
23+
{
24+
return subId_ != invalidId_;
25+
}
26+
2127
CPPWAMP_INLINE SubscriptionId Subscription::id() const {return subId_;}
2228

2329
CPPWAMP_INLINE void Subscription::unsubscribe() const

cppwamp/include/cppwamp/internal/unpacker.ipp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,10 @@ EventUnpacker<S,A...>::get(const Array& args)
7979
}
8080

8181
template <typename... TArgs, typename TSlot>
82-
EventUnpacker<TSlot, TArgs...> unpackedEvent(TSlot&& slot)
82+
EventUnpacker<DecayedSlot<TSlot>, TArgs...> unpackedEvent(TSlot&& slot)
8383
{
84-
return EventUnpacker<TSlot, TArgs...>(std::forward<TSlot>(slot));
84+
return EventUnpacker<DecayedSlot<TSlot>, TArgs...>(
85+
std::forward<TSlot>(slot));
8586
}
8687

8788

@@ -138,9 +139,10 @@ InvocationUnpacker<S,A...>::get(const Array& args)
138139
}
139140

140141
template <typename... TArgs, typename TSlot>
141-
InvocationUnpacker<TSlot, TArgs...> unpackedRpc(TSlot&& slot)
142+
InvocationUnpacker<DecayedSlot<TSlot>, TArgs...> unpackedRpc(TSlot&& slot)
142143
{
143-
return InvocationUnpacker<TSlot, TArgs...>(std::forward<TSlot>(slot));
144+
return InvocationUnpacker<DecayedSlot<TSlot>, TArgs...>(
145+
std::forward<TSlot>(slot) );
144146
}
145147

146148
} // namespace wamp

cppwamp/include/cppwamp/registration.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,12 @@ namespace internal { class Callee; }
4242
class Registration
4343
{
4444
public:
45-
/** Default constructor */
45+
/** Constructs an empty registration. */
4646
Registration();
4747

48+
/** Returns false if the registration is empty. */
49+
explicit operator bool() const;
50+
4851
/** Obtains the ID number of this registration. */
4952
RegistrationId id() const;
5053

@@ -57,8 +60,10 @@ class Registration
5760
Registration(CalleePtr callee, RegistrationId id, internal::PassKey);
5861

5962
private:
63+
static constexpr RegistrationId invalidId_ = -1;
64+
6065
CalleePtr callee_;
61-
RegistrationId id_ = -1;
66+
RegistrationId id_ = invalidId_;
6267
};
6368

6469

0 commit comments

Comments
 (0)