From be45e9989d16b0f7dd19ee55544c921cc564cdc8 Mon Sep 17 00:00:00 2001 From: ejakowatz Date: Wed, 19 Mar 2003 04:24:18 +0000 Subject: [PATCH] The new, super-templatized tests for all those handy (and yet annoying to write tests for) BMessage convenience functions. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2950 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../kits/app/bmessage/MessageBPointItemTest.h | 80 ++++ .../kits/app/bmessage/MessageBRectItemTest.h | 87 ++++ .../kits/app/bmessage/MessageBoolItemTest.h | 114 +++++ .../kits/app/bmessage/MessageInt16ItemTest.h | 73 +++ .../app/bmessage/MessageInt32ItemTest.cpp | 2 + .../kits/app/bmessage/MessageInt32ItemTest.h | 47 ++ .../kits/app/bmessage/MessageInt64ItemTest.h | 72 +++ .../kits/app/bmessage/MessageInt8ItemTest.h | 72 +++ src/tests/kits/app/bmessage/MessageItemTest.h | 419 ++++++++++++++++++ src/tests/kits/app/bmessage/MessageTest.cpp | 13 + 10 files changed, 979 insertions(+) create mode 100644 src/tests/kits/app/bmessage/MessageBPointItemTest.h create mode 100644 src/tests/kits/app/bmessage/MessageBRectItemTest.h create mode 100644 src/tests/kits/app/bmessage/MessageBoolItemTest.h create mode 100644 src/tests/kits/app/bmessage/MessageInt16ItemTest.h create mode 100644 src/tests/kits/app/bmessage/MessageInt64ItemTest.h create mode 100644 src/tests/kits/app/bmessage/MessageInt8ItemTest.h create mode 100644 src/tests/kits/app/bmessage/MessageItemTest.h diff --git a/src/tests/kits/app/bmessage/MessageBPointItemTest.h b/src/tests/kits/app/bmessage/MessageBPointItemTest.h new file mode 100644 index 0000000000..c6cc555c9d --- /dev/null +++ b/src/tests/kits/app/bmessage/MessageBPointItemTest.h @@ -0,0 +1,80 @@ +//------------------------------------------------------------------------------ +// MessageBPointItemTest.h +// +//------------------------------------------------------------------------------ + +#ifndef MESSAGEBPOINTITEMTEST_H +#define MESSAGEBPOINTITEMTEST_H + +// Standard Includes ----------------------------------------------------------- + +// System Includes ------------------------------------------------------------- + +// Project Includes ------------------------------------------------------------ + +// Local Includes -------------------------------------------------------------- +#include "MessageItemTest.h" + +// Local Defines --------------------------------------------------------------- + +// Globals --------------------------------------------------------------------- + +typedef TMessageItemFuncPolicy +< + BPoint, + &BMessage::AddPoint, + &BMessage::FindPoint, + &BMessage::FindPoint, + &BMessage::HasPoint, + &BMessage::ReplacePoint +> +TPointFuncPolicy; + +struct TPointInitPolicy : public ArrayTypeBase +{ + inline static BPoint Zero() { return BPoint(0.0, 0.0); } + inline static BPoint Test1() { return BPoint(10.0, 10.0); } + inline static BPoint Test2() { return BPoint(20.0, 20.0); } + inline static ArrayType Array() + { + ArrayType array; + array.push_back(BPoint(30.0, 30.0)); + array.push_back(BPoint(40.0, 40.0)); + array.push_back(BPoint(50.0, 50.0)); + return array; + } +}; + +struct TPointAssertPolicy +{ + inline static BPoint Zero() { return BPoint(0.0, 0.0); } + inline static BPoint Invalid() { return BPoint(0.0, 0.0);} +}; + +typedef TMessageItemTest +< + BPoint, + B_POINT_TYPE, + TPointFuncPolicy, + TPointInitPolicy, + TPointAssertPolicy +> +TMessageBPointItemTest; + +ostream& operator<<(ostream& os, const BPoint& point) +{ + int precision = os.precision(); + os << "point(x:" << point.x << ", y:" << point.y; + os.precision(precision); + return os; +} + +#endif // MESSAGEBPOINTITEMTEST_H + +/* + * $Log $ + * + * $Id $ + * + */ + diff --git a/src/tests/kits/app/bmessage/MessageBRectItemTest.h b/src/tests/kits/app/bmessage/MessageBRectItemTest.h new file mode 100644 index 0000000000..9ae432e9bd --- /dev/null +++ b/src/tests/kits/app/bmessage/MessageBRectItemTest.h @@ -0,0 +1,87 @@ +//------------------------------------------------------------------------------ +// MessageBRectItemTest.h +// +//------------------------------------------------------------------------------ + +#ifndef MESSAGEBRECTITEMTEST_H +#define MESSAGEBRECTITEMTEST_H + +// Standard Includes ----------------------------------------------------------- + +// System Includes ------------------------------------------------------------- + +// Project Includes ------------------------------------------------------------ + +// Local Includes -------------------------------------------------------------- +#include "MessageItemTest.h" + +// Local Defines --------------------------------------------------------------- + +// Globals --------------------------------------------------------------------- + +typedef TMessageItemFuncPolicy +< + BRect, + &BMessage::AddRect, + &BMessage::FindRect, + &BMessage::FindRect, + &BMessage::HasRect, + &BMessage::ReplaceRect +> +TBRectFuncPolicy; + +struct TBRectInitPolicy : public ArrayTypeBase +{ + inline static BRect Zero() { return BRect(0, 0, 0, 0); } + inline static BRect Test1() { return BRect(1, 2, 3, 4); } + inline static BRect Test2() { return BRect(5, 6, 7, 8); } + inline static ArrayType Array() + { + ArrayType array; + array.push_back(BRect(1, 2, 3, 4)); + array.push_back(BRect(4, 5, 6, 7)); + array.push_back(BRect(7, 8, 9, 10)); + return array; + } +}; + +struct TBRectAssertPolicy +{ + inline static BRect Zero() { return BRect(0, 0, 0, 0); } + inline static BRect Invalid() { return BRect(0, 0, -1, -1); } +}; + +typedef TMessageItemTest +< + BRect, + B_RECT_TYPE, + TBRectFuncPolicy, + TBRectInitPolicy, + TBRectAssertPolicy +> +TMessageBRectItemTest; + +ostream& operator<<(ostream& os, const BRect& rect) +{ + int precision = os.precision(); + os.precision(1); + os << "rect" + << "(l:" << rect.left + << " t:" << rect.top + << " r:" << rect.right + << " b:" << rect.bottom + << ")"; + os.precision(precision); + + return os; +} + +#endif // MESSAGEBRECTITEMTEST_H + +/* + * $Log $ + * + * $Id $ + * + */ + diff --git a/src/tests/kits/app/bmessage/MessageBoolItemTest.h b/src/tests/kits/app/bmessage/MessageBoolItemTest.h new file mode 100644 index 0000000000..0e915ceee4 --- /dev/null +++ b/src/tests/kits/app/bmessage/MessageBoolItemTest.h @@ -0,0 +1,114 @@ +//------------------------------------------------------------------------------ +// MessageBoolItemTest.h +// +//------------------------------------------------------------------------------ + +#ifndef MESSAGEBOOLITEMTEST_H +#define MESSAGEBOOLITEMTEST_H + +// Standard Includes ----------------------------------------------------------- + +// System Includes ------------------------------------------------------------- + +// Project Includes ------------------------------------------------------------ + +// Local Includes -------------------------------------------------------------- +#include "MessageItemTest.h" + +// Local Defines --------------------------------------------------------------- + +// Globals --------------------------------------------------------------------- + +typedef TMessageItemFuncPolicy +< + bool, + &BMessage::AddBool, + &BMessage::FindBool, + &BMessage::FindBool, + &BMessage::HasBool, + &BMessage::ReplaceBool +> +TBoolFuncPolicy; + +template<> +struct ArrayTypeBase +{ + class ArrayType + { + public: + ArrayType() : array(NULL), size(0) {;} + ArrayType(const ArrayType& rhs) : array(NULL), size(0) + { *this = rhs; } + ArrayType(bool* data, uint32 len) : array(NULL), size(0) + { Assign(data, len); } + ~ArrayType() { if (array) delete[] array; } + + ArrayType& operator=(const ArrayType& rhs) + { + if (this != &rhs) + Assign(rhs.array, rhs.size); + return *this; + }; + + uint32 Size() { return size; } + bool& operator[](int index) + { + // We're just gonna let a segfault happen + return array[index]; + } + + private: + void Assign(bool* data, uint32 len) + { + size = len; + + if (array) + delete[] array; + array = new bool[Size()]; + memcpy(array, data, Size()); + } + bool* array; + uint32 size; + }; + + typedef uint32 SizeType; + static SizeType Size(ArrayType& array) { return array.Size(); } +}; + +struct TBoolInitPolicy : public ArrayTypeBase +{ + inline static bool Zero() { return false; } + inline static bool Test1() { return true; } + inline static bool Test2() { return false; } + inline static ArrayType Array() + { + static bool array[] = { true, true, true }; + return ArrayType(array, 3); + } +}; + +struct TBoolAssertPolicy +{ + inline static bool Zero() { return false; } + inline static bool Invalid() { return false;} +}; + +typedef TMessageItemTest +< + bool, + B_BOOL_TYPE, + TBoolFuncPolicy, + TBoolInitPolicy, + TBoolAssertPolicy +> +TMessageBoolItemTest; + +#endif // MESSAGEBOOLITEMTEST_H + +/* + * $Log $ + * + * $Id $ + * + */ + diff --git a/src/tests/kits/app/bmessage/MessageInt16ItemTest.h b/src/tests/kits/app/bmessage/MessageInt16ItemTest.h new file mode 100644 index 0000000000..39e66add63 --- /dev/null +++ b/src/tests/kits/app/bmessage/MessageInt16ItemTest.h @@ -0,0 +1,73 @@ +//------------------------------------------------------------------------------ +// MessageInt16ItemTest.h +// +//------------------------------------------------------------------------------ + +#ifndef MESSAGEINT16ITEMTEST_H +#define MESSAGEINT16ITEMTEST_H + +// Standard Includes ----------------------------------------------------------- + +// System Includes ------------------------------------------------------------- + +// Project Includes ------------------------------------------------------------ + +// Local Includes -------------------------------------------------------------- +#include "MessageItemTest.h" + +// Local Defines --------------------------------------------------------------- + +// Globals --------------------------------------------------------------------- + +typedef TMessageItemFuncPolicy +< + int16, + &BMessage::AddInt16, + &BMessage::FindInt16, + &BMessage::FindInt16, + &BMessage::HasInt16, + &BMessage::ReplaceInt16 +> +TInt16FuncPolicy; + +struct TInt16InitPolicy : public ArrayTypeBase +{ + inline static int16 Zero() { return 0; } + inline static int16 Test1() { return 1234; } + inline static int16 Test2() { return 5678; } + inline static ArrayType Array() + { + ArrayType array; + array.push_back(123); + array.push_back(456); + array.push_back(789); + return array; + } +}; + +struct TInt16AssertPolicy +{ + inline static int16 Zero() { return 0; } + inline static int16 Invalid() { return 0;} +}; + +typedef TMessageItemTest +< + int16, + B_INT16_TYPE, + TInt16FuncPolicy, + TInt16InitPolicy, + TInt16AssertPolicy +> +TMessageInt16ItemTest; + + +#endif // MESSAGEINT16ITEMTEST_H + +/* + * $Log $ + * + * $Id $ + * + */ + diff --git a/src/tests/kits/app/bmessage/MessageInt32ItemTest.cpp b/src/tests/kits/app/bmessage/MessageInt32ItemTest.cpp index d06628a492..98f116ec03 100644 --- a/src/tests/kits/app/bmessage/MessageInt32ItemTest.cpp +++ b/src/tests/kits/app/bmessage/MessageInt32ItemTest.cpp @@ -19,6 +19,7 @@ // Globals --------------------------------------------------------------------- +#ifndef USE_TEMPLATES //------------------------------------------------------------------------------ void TMessageInt32ItemTest::MessageInt32ItemTest1() { @@ -204,6 +205,7 @@ TestSuite* TMessageInt32ItemTest::Suite() return suite; } //------------------------------------------------------------------------------ +#endif /* * $Log $ diff --git a/src/tests/kits/app/bmessage/MessageInt32ItemTest.h b/src/tests/kits/app/bmessage/MessageInt32ItemTest.h index 60ebbaccfb..f74afe10cf 100644 --- a/src/tests/kits/app/bmessage/MessageInt32ItemTest.h +++ b/src/tests/kits/app/bmessage/MessageInt32ItemTest.h @@ -18,7 +18,53 @@ // Local Defines --------------------------------------------------------------- // Globals --------------------------------------------------------------------- +#define USE_TEMPLATES +#ifdef USE_TEMPLATES +#include "MessageItemTest.h" +typedef TMessageItemFuncPolicy +< + int32, + &BMessage::AddInt32, + &BMessage::FindInt32, + &BMessage::FindInt32, + &BMessage::HasInt32, + &BMessage::ReplaceInt32 +> +TInt32FuncPolicy; + +struct TInt32InitPolicy : public ArrayTypeBase +{ + inline static int32 Zero() { return 0; } + inline static int32 Test1() { return 1234; } + inline static int32 Test2() { return 5678; } + inline static ArrayType Array() + { + ArrayType array; + array.push_back(123); + array.push_back(456); + array.push_back(789); + return array; + } +}; + +struct TInt32AssertPolicy +{ + inline static int32 Zero() { return 0; } + inline static int32 Invalid() { return 0;} +}; + +typedef TMessageItemTest +< + int32, + B_INT32_TYPE, + TInt32FuncPolicy, + TInt32InitPolicy, + TInt32AssertPolicy +> +TMessageInt32ItemTest; + +#else class TMessageInt32ItemTest : public TestCase { public: @@ -36,6 +82,7 @@ class TMessageInt32ItemTest : public TestCase static TestSuite* Suite(); }; +#endif #endif // MESSAGEINT32ITEMTEST_H diff --git a/src/tests/kits/app/bmessage/MessageInt64ItemTest.h b/src/tests/kits/app/bmessage/MessageInt64ItemTest.h new file mode 100644 index 0000000000..d92bb22883 --- /dev/null +++ b/src/tests/kits/app/bmessage/MessageInt64ItemTest.h @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// MessageInt64ItemTest.h +// +//------------------------------------------------------------------------------ + +#ifndef MESSAGEINT64ITEMTEST_H +#define MESSAGEINT64ITEMTEST_H + +// Standard Includes ----------------------------------------------------------- + +// System Includes ------------------------------------------------------------- + +// Project Includes ------------------------------------------------------------ + +// Local Includes -------------------------------------------------------------- +#include "MessageItemTest.h" + +// Local Defines --------------------------------------------------------------- + +// Globals --------------------------------------------------------------------- + +typedef TMessageItemFuncPolicy +< + int64, + &BMessage::AddInt64, + &BMessage::FindInt64, + &BMessage::FindInt64, + &BMessage::HasInt64, + &BMessage::ReplaceInt64 +> +TInt64FuncPolicy; + +struct TInt64InitPolicy : public ArrayTypeBase +{ + inline static int64 Zero() { return 0; } + inline static int64 Test1() { return 1234; } + inline static int64 Test2() { return 5678; } + inline static ArrayType Array() + { + ArrayType array; + array.push_back(123); + array.push_back(456); + array.push_back(789); + return array; + } +}; + +struct TInt64AssertPolicy +{ + inline static int64 Zero() { return 0; } + inline static int64 Invalid() { return 0;} +}; + +typedef TMessageItemTest +< + int64, + B_INT64_TYPE, + TInt64FuncPolicy, + TInt64InitPolicy, + TInt64AssertPolicy +> +TMessageInt64ItemTest; + +#endif // MESSAGEINT64ITEMTEST_H + +/* + * $Log $ + * + * $Id $ + * + */ + diff --git a/src/tests/kits/app/bmessage/MessageInt8ItemTest.h b/src/tests/kits/app/bmessage/MessageInt8ItemTest.h new file mode 100644 index 0000000000..eae33c29c3 --- /dev/null +++ b/src/tests/kits/app/bmessage/MessageInt8ItemTest.h @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// MessageInt8ItemTest.h +// +//------------------------------------------------------------------------------ + +#ifndef MESSAGEINT8ITEMTEST_H +#define MESSAGEINT8ITEMTEST_H + +// Standard Includes ----------------------------------------------------------- + +// System Includes ------------------------------------------------------------- + +// Project Includes ------------------------------------------------------------ + +// Local Includes -------------------------------------------------------------- +#include "MessageItemTest.h" + +// Local Defines --------------------------------------------------------------- + +// Globals --------------------------------------------------------------------- + +typedef TMessageItemFuncPolicy +< + int8, + &BMessage::AddInt8, + &BMessage::FindInt8, + &BMessage::FindInt8, + &BMessage::HasInt8, + &BMessage::ReplaceInt8 +> +TInt8FuncPolicy; + +struct TInt8InitPolicy : public ArrayTypeBase +{ + inline static int8 Zero() { return 0; } + inline static int8 Test1() { return 16; } + inline static int8 Test2() { return 32; } + inline static ArrayType Array() + { + ArrayType array; + array.push_back(64); + array.push_back(128); + array.push_back(255); + return array; + } +}; + +struct TInt8AssertPolicy +{ + inline static int8 Zero() { return 0; } + inline static int8 Invalid() { return 0;} +}; + +typedef TMessageItemTest +< + int8, + B_INT8_TYPE, + TInt8FuncPolicy, + TInt8InitPolicy, + TInt8AssertPolicy +> +TMessageInt8ItemTest; + +#endif // MESSAGEINT8ITEMTEST_H + +/* + * $Log $ + * + * $Id $ + * + */ + diff --git a/src/tests/kits/app/bmessage/MessageItemTest.h b/src/tests/kits/app/bmessage/MessageItemTest.h new file mode 100644 index 0000000000..64f8180987 --- /dev/null +++ b/src/tests/kits/app/bmessage/MessageItemTest.h @@ -0,0 +1,419 @@ +//------------------------------------------------------------------------------ +// MessageItemTest.h +// +//------------------------------------------------------------------------------ + +#ifndef MESSAGEITEMTEST_H +#define MESSAGEITEMTEST_H + +// A sad attempt to get rid of the horrible and pathetic vector specialization +#define __SGI_STL_INTERNAL_BVECTOR_H + +// Standard Includes ----------------------------------------------------------- +#include +#include +#ifdef TEST_OBOS +#include +#else +#include +#endif +#include + +// System Includes ------------------------------------------------------------- +#include + +// Project Includes ------------------------------------------------------------ + +// Local Includes -------------------------------------------------------------- +#include "../common.h" + +// Local Defines --------------------------------------------------------------- +#define TEMPLATE_TEST_PARAMS +#define ADD_TEMPLATE_TEST(classbeingtested, suitename, classname, funcname) \ + (suitename)->addTest(new TestCaller(((string(#classbeingtested) + "::" + #funcname + "::" + typeid(Type).name()).c_str() ), \ + &classname::funcname)); + +// Globals --------------------------------------------------------------------- +template +< + class Type, // int32 + type_code TypeCode, // B_INT32_TYPE + class FuncPolicy, // status_t Add(BMessage&, const char*, Type&) + // status_t Find(BMessage&, const char*, int32, Type*) + // Type QuickFind(BMessage&, const char*, int32) + // bool Has(BMessage&, const char*, int32) + // status_t Replace(BMessage&, const char*, int32, Type) + class InitPolicy, // Type Zero() + // Type Test1() + // Type Test2() + // vector Array() + class AssertPolicy // Type Zero() +> +class TMessageItemTest; + + +//------------------------------------------------------------------------------ +template +struct ArrayTypeBase +{ + typedef vector ArrayType; + typedef typename ArrayType::size_type SizeType; + static SizeType Size(ArrayType& array) { return array.size(); } +}; +//------------------------------------------------------------------------------ +template +< + typename Type, + status_t (BMessage::*AddFunc)(const char*, Type), + status_t (BMessage::*FindFunc)(const char*, int32, Type*) const, + Type (BMessage::*QuickFindFunc)(const char*, int32) const, + bool (BMessage::*HasFunc)(const char*, int32) const, + status_t (BMessage::*ReplaceFunc)(const char*, int32, Type) +> +struct TMessageItemFuncPolicy +{ + static status_t Add(BMessage& msg, const char* name, Type& val) + { + return (msg.*AddFunc)(name, val); + } + static status_t Find(BMessage& msg, const char* name, int32 index, Type* val) + { + return (msg.*FindFunc)(name, index, val); + } + static Type QuickFind(BMessage& msg, const char* name, int32 index) + { + return (msg.*QuickFindFunc)(name, index); + } + static bool Has(BMessage& msg, const char* name, int32 index) + { + return (msg.*HasFunc)(name, index); + } + static status_t Replace(BMessage& msg, const char* name, int32 index, Type val) + { + return (msg.*ReplaceFunc)(name, index, val); + } +}; +//------------------------------------------------------------------------------ +template +< + class Type, // int32 + type_code TypeCode, // B_INT32_TYPE + class FuncPolicy, // status_t Add(BMessage&, const char*, Type&) + // status_t Find(BMessage&, const char*, int32, Type*) + // Type QuickFind(BMessage&, const char*, int32) + // bool Has(BMessage&, const char*, int32) + // status_t Replace(BMessage&, const char*, int32, Type) + class InitPolicy, // Type Zero() + // Type Test1() + // Type Test2() + // ArrayType Array() + // typedef XXX ArrayType + class AssertPolicy // Type Zero() + // Type Invalid() +> +class TMessageItemTest : public TestCase +{ + public: + TMessageItemTest() {;} + TMessageItemTest(std::string name) : TestCase(name) {;} + + void MessageItemTest1(); + void MessageItemTest2(); + void MessageItemTest3(); + void MessageItemTest4(); + void MessageItemTest5(); + void MessageItemTest6(); + void MessageItemTest7(); + void MessageItemTest8(); + + static TestSuite* Suite(); + + typedef typename InitPolicy::ArrayType ArrayType; +}; + + +//------------------------------------------------------------------------------ +template +< + class Type, + type_code TypeCode, + class FuncPolicy, + class InitPolicy, + class AssertPolicy +> +void +TMessageItemTest:: +MessageItemTest1() +{ + BMessage msg; + Type out = InitPolicy::Zero(); + CPPUNIT_ASSERT(FuncPolicy::Find(msg, "item", 0, &out) == B_NAME_NOT_FOUND); + CPPUNIT_ASSERT(out == AssertPolicy::Invalid()); + CPPUNIT_ASSERT(FuncPolicy::QuickFind(msg, "item", 0) == AssertPolicy::Invalid()); + CPPUNIT_ASSERT(!FuncPolicy::Has(msg, "item", 0)); + const void* ptr = &out; + ssize_t size; + CPPUNIT_ASSERT(msg.FindData("item", TypeCode, &ptr, &size) == + B_NAME_NOT_FOUND); + CPPUNIT_ASSERT(ptr == NULL); +} +//------------------------------------------------------------------------------ +template +< + class Type, + type_code TypeCode, + class FuncPolicy, + class InitPolicy, + class AssertPolicy +> +void +TMessageItemTest:: +MessageItemTest2() +{ + BMessage msg; + Type in = InitPolicy::Test1(); + Type out = InitPolicy::Zero(); + CPPUNIT_ASSERT(FuncPolicy::Add(msg, "item", in) == B_OK); + CPPUNIT_ASSERT(FuncPolicy::Has(msg, "item", 0)); + CPPUNIT_ASSERT(FuncPolicy::QuickFind(msg, "item", 0) == in); + CPPUNIT_ASSERT(FuncPolicy::Find(msg, "item", 0, &out) == B_OK); + CPPUNIT_ASSERT(out == in); + Type* pout = NULL; + ssize_t size; + status_t err = msg.FindData("item", TypeCode, (const void**)&pout, &size); + CPPUNIT_ASSERT(err == B_OK); + CPPUNIT_ASSERT(*pout == in); + CPPUNIT_ASSERT(size == sizeof (Type)); +} +//------------------------------------------------------------------------------ +template +< + class Type, + type_code TypeCode, + class FuncPolicy, + class InitPolicy, + class AssertPolicy +> +void +TMessageItemTest:: +MessageItemTest3() +{ + BMessage msg; + Type in = InitPolicy::Test1(); + Type in2 = InitPolicy::Test2(); + Type out = InitPolicy::Zero(); + CPPUNIT_ASSERT(FuncPolicy::Add(msg, "item", in) == B_OK); + CPPUNIT_ASSERT(FuncPolicy::Replace(msg, "item", 0, in2) == B_OK); + CPPUNIT_ASSERT(FuncPolicy::Has(msg, "item", 0)); + CPPUNIT_ASSERT(FuncPolicy::QuickFind(msg, "item", 0) == in2); + CPPUNIT_ASSERT(FuncPolicy::Find(msg, "item", 0, &out) == B_OK); + CPPUNIT_ASSERT(out == in2); + out = InitPolicy::Zero(); + Type* pout; + ssize_t size; + CPPUNIT_ASSERT(msg.FindData("item", TypeCode, (const void**)&pout, + &size) == B_OK); + CPPUNIT_ASSERT(*pout == in2); + CPPUNIT_ASSERT(size == sizeof (Type)); +} +//------------------------------------------------------------------------------ +template +< + class Type, + type_code TypeCode, + class FuncPolicy, + class InitPolicy, + class AssertPolicy +> +void +TMessageItemTest:: +MessageItemTest4() +{ + BMessage msg; + Type out = InitPolicy::Zero(); + CPPUNIT_ASSERT(FuncPolicy::Find(msg, "item", 1, &out) == B_NAME_NOT_FOUND); + CPPUNIT_ASSERT(out == AssertPolicy::Invalid()); + CPPUNIT_ASSERT(FuncPolicy::QuickFind(msg, "item", 1) == AssertPolicy::Invalid()); + CPPUNIT_ASSERT(!FuncPolicy::Has(msg, "item", 1)); + const void* ptr = &out; + ssize_t size; + CPPUNIT_ASSERT(msg.FindData("item", TypeCode, 1, &ptr, &size) == + B_NAME_NOT_FOUND); + CPPUNIT_ASSERT(ptr == NULL); +} +//------------------------------------------------------------------------------ +template +< + class Type, + type_code TypeCode, + class FuncPolicy, + class InitPolicy, + class AssertPolicy +> +void +TMessageItemTest:: +MessageItemTest5() +{ + BMessage msg; + ArrayType in = InitPolicy::Array(); + Type out = InitPolicy::Zero(); + Type* pout; + ssize_t size; + + for (int32 i = 0; i < InitPolicy::Size(in); ++i) + { + CPPUNIT_ASSERT(FuncPolicy::Add(msg, "item", in[i]) == B_OK); + } + + for (int32 i = 0; i < InitPolicy::Size(in); ++i) + { + CPPUNIT_ASSERT(FuncPolicy::Has(msg, "item", i)); + CPPUNIT_ASSERT(FuncPolicy::QuickFind(msg, "item", i) == in[i]); + CPPUNIT_ASSERT(FuncPolicy::Find(msg, "item", i, &out) == B_OK); + CPPUNIT_ASSERT(out == in[i]); + CPPUNIT_ASSERT(msg.FindData("item", TypeCode, i, + (const void**)&pout, &size) == B_OK); + CPPUNIT_ASSERT(*pout == in[i]); + CPPUNIT_ASSERT(size == sizeof (Type)); + } +} +//------------------------------------------------------------------------------ +template +< + class Type, + type_code TypeCode, + class FuncPolicy, + class InitPolicy, + class AssertPolicy +> +void +TMessageItemTest:: +MessageItemTest6() +{ + BMessage msg; + ArrayType in = InitPolicy::Array(); + Type in2 = InitPolicy::Test2(); + Type out = InitPolicy::Zero(); + const int rIndex = 2; + + for (int32 i = 0; i < InitPolicy::Size(in); ++i) + { + CPPUNIT_ASSERT(FuncPolicy::Add(msg, "item", in[i]) == B_OK); + } + + CPPUNIT_ASSERT(FuncPolicy::Replace(msg, "item", rIndex, in2) == B_OK); + CPPUNIT_ASSERT(FuncPolicy::Has(msg, "item", rIndex)); + CPPUNIT_ASSERT(FuncPolicy::QuickFind(msg, "item", rIndex) == in2); + CPPUNIT_ASSERT(FuncPolicy::Find(msg, "item", rIndex, &out) == B_OK); + CPPUNIT_ASSERT(out == in2); + out = InitPolicy::Zero(); + Type* pout; + ssize_t size; + CPPUNIT_ASSERT(msg.FindData("item", TypeCode, rIndex, + (const void**)&pout, &size) == B_OK); + CPPUNIT_ASSERT(*pout == in2); + CPPUNIT_ASSERT(size == sizeof (Type)); +} +//------------------------------------------------------------------------------ +template +< + class Type, + type_code TypeCode, + class FuncPolicy, + class InitPolicy, + class AssertPolicy +> +void +TMessageItemTest:: +MessageItemTest7() +{ + BMessage msg; + Type in = InitPolicy::Test1(); + Type out = InitPolicy::Zero(); + CPPUNIT_ASSERT(msg.AddData("item", TypeCode, (const void*)&in, + sizeof (Type)) == B_OK); + CPPUNIT_ASSERT(FuncPolicy::Has(msg, "item", 0)); + CPPUNIT_ASSERT(FuncPolicy::QuickFind(msg, "item", 0) == in); + CPPUNIT_ASSERT(FuncPolicy::Find(msg, "item", 0, &out) == B_OK); + CPPUNIT_ASSERT(out == in); + Type* pout = NULL; + ssize_t size; + CPPUNIT_ASSERT(msg.FindData("item", TypeCode, (const void**)&pout, + &size) == B_OK); + CPPUNIT_ASSERT(*pout == in); + CPPUNIT_ASSERT(size == sizeof (Type)); +} +//------------------------------------------------------------------------------ +template +< + class Type, + type_code TypeCode, + class FuncPolicy, + class InitPolicy, + class AssertPolicy +> +void +TMessageItemTest:: +MessageItemTest8() +{ + BMessage msg; + ArrayType in = InitPolicy::Array(); + Type out = InitPolicy::Zero(); + Type* pout; + ssize_t size; + + for (int32 i = 0; i < InitPolicy::Size(in); ++i) + { + CPPUNIT_ASSERT(msg.AddData("item", TypeCode, + (const void*)&in[i], sizeof (Type)) == B_OK); + } + + for (int32 i = 0; i < InitPolicy::Size(in); ++i) + { + CPPUNIT_ASSERT(FuncPolicy::Has(msg, "item", i)); + CPPUNIT_ASSERT(FuncPolicy::QuickFind(msg, "item", i) == in[i]); + CPPUNIT_ASSERT(FuncPolicy::Find(msg, "item", i, &out) == B_OK); + CPPUNIT_ASSERT(out == in[i]); + CPPUNIT_ASSERT(msg.FindData("item", TypeCode, i, + (const void**)&pout, &size) == B_OK); + CPPUNIT_ASSERT(*pout == in[i]); + CPPUNIT_ASSERT(size == sizeof (Type)); + } +} +//------------------------------------------------------------------------------ +template +< + class Type, + type_code TypeCode, + class FuncPolicy, + class InitPolicy, + class AssertPolicy +> +TestSuite* +TMessageItemTest:: +Suite() +{ + TestSuite* suite = new TestSuite("BMessage::Add/Find/Replace/HasRect()"); + + ADD_TEMPLATE_TEST(BMessage, suite, TMessageItemTest TEMPLATE_TEST_PARAMS, MessageItemTest1); + ADD_TEMPLATE_TEST(BMessage, suite, TMessageItemTest TEMPLATE_TEST_PARAMS, MessageItemTest2); + ADD_TEMPLATE_TEST(BMessage, suite, TMessageItemTest TEMPLATE_TEST_PARAMS, MessageItemTest3); + ADD_TEMPLATE_TEST(BMessage, suite, TMessageItemTest TEMPLATE_TEST_PARAMS, MessageItemTest4); + ADD_TEMPLATE_TEST(BMessage, suite, TMessageItemTest TEMPLATE_TEST_PARAMS, MessageItemTest5); + ADD_TEMPLATE_TEST(BMessage, suite, TMessageItemTest TEMPLATE_TEST_PARAMS, MessageItemTest6); + ADD_TEMPLATE_TEST(BMessage, suite, TMessageItemTest TEMPLATE_TEST_PARAMS, MessageItemTest7); + ADD_TEMPLATE_TEST(BMessage, suite, TMessageItemTest TEMPLATE_TEST_PARAMS, MessageItemTest8); + + return suite; +} +//------------------------------------------------------------------------------ + +#endif // MESSAGEITEMTEST_H + +/* + * $Log $ + * + * $Id $ + * + + */ \ No newline at end of file diff --git a/src/tests/kits/app/bmessage/MessageTest.cpp b/src/tests/kits/app/bmessage/MessageTest.cpp index 50d3c729f9..55646fa349 100644 --- a/src/tests/kits/app/bmessage/MessageTest.cpp +++ b/src/tests/kits/app/bmessage/MessageTest.cpp @@ -1,8 +1,15 @@ +#define __SGI_STL_INTERNAL_BVECTOR_H //#include "MessageTest.h" #include "../common.h" #include "MessageConstructTest.h" #include "MessageOpAssignTest.h" +#include "MessageBoolItemTest.h" +#include "MessageInt8ItemTest.h" +#include "MessageInt16ItemTest.h" #include "MessageInt32ItemTest.h" +#include "MessageInt64ItemTest.h" +#include "MessageBRectItemTest.h" +#include "MessageBPointItemTest.h" #include "MessageEasyFindTest.h" Test* MessageTestSuite() @@ -11,7 +18,13 @@ Test* MessageTestSuite() tests->addTest(TMessageConstructTest::Suite()); tests->addTest(TMessageOpAssignTest::Suite()); + tests->addTest(TMessageBoolItemTest::Suite()); + tests->addTest(TMessageInt8ItemTest::Suite()); + tests->addTest(TMessageInt16ItemTest::Suite()); tests->addTest(TMessageInt32ItemTest::Suite()); + tests->addTest(TMessageInt64ItemTest::Suite()); + tests->addTest(TMessageBRectItemTest::Suite()); + tests->addTest(TMessageBPointItemTest::Suite()); tests->addTest(TMessageEasyFindTest::Suite()); return tests;