Unit tests for the Pointer convenience functions.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3383 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
58453f3bbb
commit
7dc2890fbb
90
src/tests/kits/app/bmessage/MessagePointerItemTest.h
Normal file
90
src/tests/kits/app/bmessage/MessagePointerItemTest.h
Normal file
@ -0,0 +1,90 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// MessagePointerItemTest.h
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef MESSAGEPOINTERITEMTEST_H
|
||||
#define MESSAGEPOINTERITEMTEST_H
|
||||
|
||||
// Standard Includes -----------------------------------------------------------
|
||||
|
||||
// System Includes -------------------------------------------------------------
|
||||
|
||||
// Project Includes ------------------------------------------------------------
|
||||
|
||||
// Local Includes --------------------------------------------------------------
|
||||
#include "MessageItemTest.h"
|
||||
|
||||
// Local Defines ---------------------------------------------------------------
|
||||
|
||||
// Globals ---------------------------------------------------------------------
|
||||
|
||||
struct TPointerFuncPolicy
|
||||
{
|
||||
static status_t Add(BMessage& msg, const char* name, const void* val)
|
||||
{ return msg.AddPointer(name, val); }
|
||||
static status_t AddData(BMessage& msg, const char* name, type_code type,
|
||||
const void* data, ssize_t size, bool)
|
||||
{ return msg.AddData(name, type, data, size); }
|
||||
static status_t Find(BMessage& msg, const char* name, int32 index,
|
||||
const void** val)
|
||||
{ return msg.FindPointer(name, index, (void**)val); }
|
||||
static const void* QuickFind(BMessage& msg, const char* name, int32 index)
|
||||
{
|
||||
const void* ptr;
|
||||
msg.FindPointer(name, index, (void**)&ptr);
|
||||
return ptr;
|
||||
}
|
||||
static bool Has(BMessage& msg, const char* name, int32 index)
|
||||
{ return msg.HasPointer(name, index); }
|
||||
static status_t Replace(BMessage& msg, const char* name, int32 index,
|
||||
const void* val)
|
||||
{ return msg.ReplacePointer(name, index, val); }
|
||||
static status_t FindData(BMessage& msg, const char* name, type_code type,
|
||||
int32 index, const void** data, ssize_t* size)
|
||||
{ return msg.FindData(name, type, index, data, size); }
|
||||
};
|
||||
|
||||
struct TPointerInitPolicy : public ArrayTypeBase<const void*>
|
||||
{
|
||||
inline static const void* Zero() { return NULL; }
|
||||
inline static const void* Test1() { return &Test1; }
|
||||
inline static const void* Test2() { return &Test2; }
|
||||
inline static size_t SizeOf(const void*) { return sizeof (const void*); }
|
||||
inline static ArrayType Array()
|
||||
{
|
||||
ArrayType array;
|
||||
array.push_back(Zero());
|
||||
array.push_back(Test1());
|
||||
array.push_back(Test2());
|
||||
return array;
|
||||
}
|
||||
};
|
||||
|
||||
struct TPointerAssertPolicy
|
||||
{
|
||||
inline static const void* Zero() { return NULL; }
|
||||
inline static const void* Invalid() { return NULL; }
|
||||
inline static bool Size(size_t size, const void* t)
|
||||
{ return size == sizeof (t); }
|
||||
};
|
||||
|
||||
typedef TMessageItemTest
|
||||
<
|
||||
const void*,
|
||||
B_POINTER_TYPE,
|
||||
TPointerFuncPolicy,
|
||||
TPointerInitPolicy,
|
||||
TPointerAssertPolicy
|
||||
>
|
||||
TMessagePointerItemTest;
|
||||
|
||||
#endif // MESSAGEPOINTERITEMTEST_H
|
||||
|
||||
/*
|
||||
* $Log $
|
||||
*
|
||||
* $Id $
|
||||
*
|
||||
*/
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "MessageBStringItemTest.h"
|
||||
#include "MessageCStringItemTest.h"
|
||||
#include "MessageMessengerItemTest.h"
|
||||
#include "MessagePointerItemTest.h"
|
||||
|
||||
Test* MessageTestSuite()
|
||||
{
|
||||
@ -40,6 +41,7 @@ Test* MessageTestSuite()
|
||||
tests->addTest(TMessageBStringItemTest::Suite());
|
||||
tests->addTest(TMessageCStringItemTest::Suite());
|
||||
tests->addTest(TMessageMessengerItemTest::Suite());
|
||||
tests->addTest(TMessagePointerItemTest::Suite());
|
||||
|
||||
return tests;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user