8#ifndef INCLUDED_BSLS_PROTOCOLTEST
9#define INCLUDED_BSLS_PROTOCOLTEST
303#include <bsls_compilerfeatures.h>
307#ifdef BSLS_COMPILERFEATURES_SUPPORT_TRAITS_HEADER
308#include <type_traits>
333struct ProtocolTest_IsAbstract;
335#ifdef BSLS_COMPILERFEATURES_SUPPORT_TRAITS_HEADER
338struct ProtocolTest_IsAbstract {
339 enum {
value = std::is_abstract<T>::value };
342#elif defined(BSLS_PLATFORM_CMP_GNU) && BSLS_PLATFORM_CMP_VERSION >= 110000
354struct ProtocolTest_VoidType {
366template <
class VOID_TYPE,
class T>
367struct ProtocolTest_IsClassTypeImp {
375 enum { value =
false };
379struct ProtocolTest_IsClassTypeImp<
380 typename ProtocolTest_VoidType<int T::*>::Type,
389 enum { value =
true };
393struct ProtocolTest_IsClassType {
401 value = ProtocolTest_IsClassTypeImp<void, T>::value
405template <
bool CONDITION,
class T =
void>
406struct ProtocolTest_EnableIf {
416struct ProtocolTest_EnableIf<true, T> {
427struct ProtocolTest_NoType {
437struct ProtocolTest_YesType {
447struct ProtocolTest_IsReturnableImpUtil {
457 static T returnThe();
467 static ProtocolTest_NoType test(...);
469 static ProtocolTest_YesType
470 test(
typename ProtocolTest_EnableIf<
static_cast<bool>(
471 sizeof(
static_cast<void>(returnThe<T>()), 0))>::Type *);
481struct ProtocolTest_IsReturnable {
491 value =
sizeof(ProtocolTest_YesType) ==
492 sizeof(ProtocolTest_IsReturnableImpUtil::test<T>(0))
498struct ProtocolTest_IsAbstract {
510 value = ProtocolTest_IsClassType<T>::value &&
511 !ProtocolTest_IsReturnable<T>::value
592template <
class BSLS_TESTIMP>
656#if defined (BSLS_LIBRARYFEATURES_HAS_CPP11_MISCELLANEOUS_UTILITIES)
658 std::max_align_t d_dummy[
sizeof(T) /
sizeof(std::max_align_t) + 1];
663 unsigned long long d_ull;
668 MaxAlignType d_dummy[
sizeof(T) /
sizeof(MaxAlignType) + 1];
687template <
class BSLS_PROTOCOL>
698 mutable bool d_entered;
704 mutable bool d_exited;
780template <
class BSLS_TESTIMP>
785 typedef typename BSLS_TESTIMP::ProtocolType ProtocolType;
799 void trace(
char const *message)
const;
813 BSLS_TESTIMP
method(
const char *methodDesc =
"");
856#define BSLS_PROTOCOLTEST_ASSERT(test, methodCall) \
858 (void) test.method( \
859 "inside BSLS_PROTOCOLTEST_ASSERT("#methodCall")")->methodCall;\
860 if (!test.lastStatus()) { \
861 ASSERT(0 && "Not a virtual method: "#methodCall); \
865#define BSLS_PROTOCOLTEST_RV_ASSERT(test, methodCall, returnValue) \
867 returnValue = test.method( \
868 "inside BSLS_PROTOCOLTEST_ASSERT("#methodCall")")->methodCall;\
869 if (!test.lastStatus()) { \
870 ASSERT(0 && "Not a virtual method: "#methodCall); \
887ProtocolTest_MethodReturnType::operator T()
const
899ProtocolTest_MethodReturnRefType::operator T&()
const
902 T *pObj =
reinterpret_cast<T *
>(&obj);
911template <
class BSLS_TESTIMP>
962template <
class BSLS_PROTOCOL>
971template <
class BSLS_PROTOCOL>
975 if (d_entered && !d_exited) {
981template <
class BSLS_PROTOCOL>
987 return static_cast<BSLS_PROTOCOL *
>(
this);
991template <
class BSLS_PROTOCOL>
997 return static_cast<const BSLS_PROTOCOL *
>(
this);
1000template <
class BSLS_PROTOCOL>
1009template <
class BSLS_PROTOCOL>
1018template <
class BSLS_PROTOCOL>
1027template <
class BSLS_PROTOCOL>
1034template <
class BSLS_PROTOCOL>
1039 d_status = testStatus;
1047template <
class BSLS_TESTIMP>
1051 d_status.resetLast();
1054template <
class BSLS_TESTIMP>
1056void ProtocolTest<BSLS_TESTIMP>::trace(
char const *message)
const
1059 std::printf(
"\t%s\n", message);
1064template <
class BSLS_TESTIMP>
1072template <
class BSLS_TESTIMP>
1080 impl.setTestStatus(&d_status);
1084template <
class BSLS_TESTIMP>
1088 trace(
"inside ProtocolTest::testAbstract()");
1095 return lastStatus();
1098template <
class BSLS_TESTIMP>
1102 trace(
"inside ProtocolTest::testNoDataMembers()");
1103 struct EmptyProtocol
1105 virtual ~EmptyProtocol() {}
1110 if (
sizeof(EmptyProtocol) !=
sizeof(ProtocolType)) {
1114 return lastStatus();
1117template <
class BSLS_TESTIMP>
1120 trace(
"inside ProtocolTest::testVirtualDestructor");
1131 BSLS_TESTIMP * base = obj;
1132 obj->setTestStatus(&d_status);
1143 return lastStatus();
1147template <
class BSLS_TESTIMP>
1151 return d_status.failures();
1154template <
class BSLS_TESTIMP>
1158 return d_status.last();
1163#ifndef BDE_OPENSOURCE_PUBLICATION
1168#ifdef bsls_ProtocolTest
1169#undef bsls_ProtocolTest
1172#define bsls_ProtocolTest bsls::ProtocolTest
1174#ifdef bsls_ProtocolTestImp
1175#undef bsls_ProtocolTestImp
1178#define bsls_ProtocolTestImp bsls::ProtocolTestImp
Definition bsls_protocoltest.h:688
ProtocolTest_MethodReturnRefType markDoneRef() const
Definition bsls_protocoltest.h:1012
BSLS_PROTOCOL ProtocolType
Definition bsls_protocoltest.h:712
~ProtocolTestImp()
Definition bsls_protocoltest.h:973
void setTestStatus(ProtocolTest_Status *testStatus) const
Definition bsls_protocoltest.h:1036
T markDoneVal(const T &value) const
Definition bsls_protocoltest.h:1021
BSLS_PROTOCOL * operator->()
Definition bsls_protocoltest.h:984
void markEnter() const
Definition bsls_protocoltest.h:1029
ProtocolTest_MethodReturnType markDone() const
Definition bsls_protocoltest.h:1003
ProtocolTestImp()
Create an object of the ProtocolTestImp class.
Definition bsls_protocoltest.h:964
Definition bsls_protocoltest.h:654
Definition bsls_protocoltest.h:610
ProtocolTest_Status()
Definition bsls_protocoltest.h:924
void fail()
Definition bsls_protocoltest.h:938
bool last() const
Definition bsls_protocoltest.h:952
int failures() const
Definition bsls_protocoltest.h:946
void resetLast()
Reset the status of the last test to true.
Definition bsls_protocoltest.h:932
Definition bsls_protocoltest.h:781
BSLS_TESTIMP method(const char *methodDesc="")
Definition bsls_protocoltest.h:1074
bool lastStatus() const
Definition bsls_protocoltest.h:1156
bool testAbstract()
Definition bsls_protocoltest.h:1086
ProtocolTest(bool verbose=false)
Construct a ProtocolTest object.
Definition bsls_protocoltest.h:1066
bool testNoDataMembers()
Definition bsls_protocoltest.h:1100
bool testVirtualDestructor()
Definition bsls_protocoltest.h:1118
int failures() const
Definition bsls_protocoltest.h:1149
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdlt_iso8601util.h:691
Definition bsls_protocoltest.h:593
~ProtocolTest_Dtor()
Definition bsls_protocoltest.h:913
Definition bsls_protocoltest.h:527
Definition bsls_protocoltest.h:524
static NoType test(U(*)[1])
@ value
Definition bsls_protocoltest.h:535
char YesType
Definition bsls_protocoltest.h:526
Definition bsls_protocoltest.h:572
Definition bsls_protocoltest.h:551