First batch of tests for BMessage.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1902 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
fb39a31ca7
commit
1dc215ba9b
233
src/tests/kits/app/bmessage/BMessageCases
Normal file
233
src/tests/kits/app/bmessage/BMessageCases
Normal file
@ -0,0 +1,233 @@
|
||||
BMessage();
|
||||
--------------
|
||||
case 1: default construction
|
||||
|
||||
BMessage(uint32 what);
|
||||
--------------
|
||||
case 1: what initialization
|
||||
|
||||
BMessage(const BMessage &a_message);
|
||||
--------------
|
||||
case 1: copy of default constructed
|
||||
|
||||
~BMessage();
|
||||
BMessage& operator=(const BMessage &msg);
|
||||
--------------
|
||||
case 1: assignment of default constructed
|
||||
|
||||
status_t GetInfo(type_code typeRequested, int32 which, char **name,
|
||||
type_code *typeReturned, int32 *count = NULL) const;
|
||||
|
||||
status_t GetInfo(const char *name, type_code *type, int32 *c = 0) const;
|
||||
status_t GetInfo(const char *name, type_code *type, bool *fixed_size) const;
|
||||
|
||||
int32 CountNames(type_code type) const;
|
||||
bool IsEmpty() const;
|
||||
bool IsSystem() const;
|
||||
bool IsReply() const;
|
||||
void PrintToStream() const;
|
||||
|
||||
status_t Rename(const char *old_entry, const char *new_entry);
|
||||
|
||||
bool WasDelivered() const;
|
||||
bool IsSourceWaiting() const;
|
||||
bool IsSourceRemote() const;
|
||||
BMessenger ReturnAddress() const;
|
||||
const BMessage *Previous() const;
|
||||
bool WasDropped() const;
|
||||
BPoint DropPoint(BPoint *offset = NULL) const;
|
||||
|
||||
status_t SendReply(uint32 command, BHandler *reply_to = NULL);
|
||||
status_t SendReply(BMessage *the_reply, BHandler *reply_to = NULL,
|
||||
bigtime_t timeout = B_INFINITE_TIMEOUT);
|
||||
status_t SendReply(BMessage *the_reply, BMessenger reply_to,
|
||||
bigtime_t timeout = B_INFINITE_TIMEOUT);
|
||||
|
||||
status_t SendReply(uint32 command, BMessage *reply_to_reply);
|
||||
status_t SendReply(BMessage *the_reply, BMessage *reply_to_reply,
|
||||
bigtime_t send_timeout = B_INFINITE_TIMEOUT,
|
||||
bigtime_t reply_timeout = B_INFINITE_TIMEOUT);
|
||||
|
||||
ssize_t FlattenedSize() const;
|
||||
status_t Flatten(char *buffer, ssize_t size) const;
|
||||
status_t Flatten(BDataIO *stream, ssize_t *size = NULL) const;
|
||||
status_t Unflatten(const char *flat_buffer);
|
||||
status_t Unflatten(BDataIO *stream);
|
||||
|
||||
status_t AddSpecifier(const char *property);
|
||||
status_t AddSpecifier(const char *property, int32 index);
|
||||
status_t AddSpecifier(const char *property, int32 index, int32 range);
|
||||
status_t AddSpecifier(const char *property, const char *name);
|
||||
status_t AddSpecifier(const BMessage *specifier);
|
||||
status_t SetCurrentSpecifier(int32 index);
|
||||
status_t GetCurrentSpecifier(int32 *index, BMessage *specifier = NULL,
|
||||
int32 *form = NULL, const char **property = NULL) const;
|
||||
bool HasSpecifiers() const;
|
||||
status_t PopSpecifier();
|
||||
|
||||
status_t AddInt32(const char *name, int32 val);
|
||||
status_t FindInt32(const char *name, int32 *value) const;
|
||||
status_t FindInt32(const char *name, int32 index, int32 *val) const;
|
||||
status_t ReplaceInt32(const char *name, int32 val);
|
||||
status_t ReplaceInt32(const char *name, int32 index, int32 val);
|
||||
bool HasInt32(const char *, int32 n = 0) const;
|
||||
int32 FindInt32(const char *, int32 n = 0) const;
|
||||
--------------
|
||||
case: No item added. HasInt32() should return false; simple FindInt32() should
|
||||
return 0; FindInt32() should return B_NAME_NOT_FOUND and set data param to
|
||||
0; FindData() should return B_NAME_NOT_FOUND and set data param to NULL.
|
||||
|
||||
case: Add single item. HasInt32() should return true; simple FindInt32() should
|
||||
return added item; FindInt32() should return B_OK and set data param to
|
||||
added item; FindData() should return B_OK and set data param to added item.
|
||||
|
||||
case: Add single item. Replace item. HasInt32() should return true; simple
|
||||
FindInt32() should return replacement; FindInt32() should return B_OK and
|
||||
set data param to replacement; FindData() should return B_OK and set data
|
||||
param to replacement.
|
||||
|
||||
case: No item added. For index 1: HasInt32() should return false; simple
|
||||
FindInt32() should return 0; FindInt32() should return B_NAME_NOT_FOUND
|
||||
and set data param to 0; FindData() should return B_NAME_NOT_FOUND and
|
||||
set data param to NULL.
|
||||
|
||||
case: Add multiple items. For each index: HasInt32() should return true; simple
|
||||
FindInt32() should return added item; FindInt32() should return B_OK and set
|
||||
data param to added item; FindData() should return B_OK and set data param
|
||||
to added item.
|
||||
|
||||
case: Add multiple items. Replace item. For replaced index: HasInt32() should
|
||||
return true; simple FindInt32() should return replacement; FindInt32()
|
||||
should return B_OK and set data param to replacement; FindData() should
|
||||
return B_OK and set data param to replacement.
|
||||
|
||||
case: Add single item via generic AddData(). HasInt32() should return true; simple
|
||||
FindInt32() should return added item; FindInt32() should return B_OK and set
|
||||
data param to added item; FindData() should return B_OK and set data param to
|
||||
added item.
|
||||
|
||||
case: Add multiple items via generic AddData(). For each index: HasInt32() should
|
||||
return true; simple FindInt32() should return added item; FindInt32() should
|
||||
return B_OK and set data param to added item; FindData() should return B_OK
|
||||
and set data param to added item.
|
||||
|
||||
status_t AddRect(const char *name, BRect a_rect);
|
||||
status_t AddPoint(const char *name, BPoint a_point);
|
||||
status_t AddString(const char *name, const char *a_string);
|
||||
status_t AddString(const char *name, const BString& a_string);
|
||||
status_t AddInt8(const char *name, int8 val);
|
||||
status_t AddInt16(const char *name, int16 val);
|
||||
status_t AddInt64(const char *name, int64 val);
|
||||
status_t AddBool(const char *name, bool a_boolean);
|
||||
status_t AddFloat(const char *name, float a_float);
|
||||
status_t AddDouble(const char *name, double a_double);
|
||||
status_t AddPointer(const char *name, const void *ptr);
|
||||
status_t AddMessenger(const char *name, BMessenger messenger);
|
||||
status_t AddRef(const char *name, const entry_ref *ref);
|
||||
status_t AddMessage(const char *name, const BMessage *msg);
|
||||
status_t AddFlat(const char *name, BFlattenable *obj, int32 count = 1);
|
||||
status_t AddData(const char *name, type_code type, const void *data,
|
||||
ssize_t numBytes, bool is_fixed_size = true, int32 count = 1);
|
||||
|
||||
status_t RemoveData(const char *name, int32 index = 0);
|
||||
status_t RemoveName(const char *name);
|
||||
status_t MakeEmpty();
|
||||
|
||||
status_t FindRect(const char *name, BRect *rect) const;
|
||||
status_t FindRect(const char *name, int32 index, BRect *rect) const;
|
||||
status_t FindPoint(const char *name, BPoint *pt) const;
|
||||
status_t FindPoint(const char *name, int32 index, BPoint *pt) const;
|
||||
status_t FindString(const char *name, const char **str) const;
|
||||
status_t FindString(const char *name, int32 index, const char **str) const;
|
||||
status_t FindString(const char *name, BString *str) const;
|
||||
status_t FindString(const char *name, int32 index, BString *str) const;
|
||||
status_t FindInt8(const char *name, int8 *value) const;
|
||||
status_t FindInt8(const char *name, int32 index, int8 *val) const;
|
||||
status_t FindInt16(const char *name, int16 *value) const;
|
||||
status_t FindInt16(const char *name, int32 index, int16 *val) const;
|
||||
status_t FindInt64(const char *name, int64 *value) const;
|
||||
status_t FindInt64(const char *name, int32 index, int64 *val) const;
|
||||
status_t FindBool(const char *name, bool *value) const;
|
||||
status_t FindBool(const char *name, int32 index, bool *value) const;
|
||||
status_t FindFloat(const char *name, float *f) const;
|
||||
status_t FindFloat(const char *name, int32 index, float *f) const;
|
||||
status_t FindDouble(const char *name, double *d) const;
|
||||
status_t FindDouble(const char *name, int32 index, double *d) const;
|
||||
status_t FindPointer(const char *name, void **ptr) const;
|
||||
status_t FindPointer(const char *name, int32 index, void **ptr) const;
|
||||
status_t FindMessenger(const char *name, BMessenger *m) const;
|
||||
status_t FindMessenger(const char *name, int32 index, BMessenger *m) const;
|
||||
status_t FindRef(const char *name, entry_ref *ref) const;
|
||||
status_t FindRef(const char *name, int32 index, entry_ref *ref) const;
|
||||
status_t FindMessage(const char *name, BMessage *msg) const;
|
||||
status_t FindMessage(const char *name, int32 index, BMessage *msg) const;
|
||||
status_t FindFlat(const char *name, BFlattenable *obj) const;
|
||||
status_t FindFlat(const char *name, int32 index, BFlattenable *obj) const;
|
||||
status_t FindData(const char *name, type_code type,
|
||||
const void **data, ssize_t *numBytes) const;
|
||||
status_t FindData(const char *name, type_code type, int32 index,
|
||||
const void **data, ssize_t *numBytes) const;
|
||||
|
||||
status_t ReplaceRect(const char *name, BRect a_rect);
|
||||
status_t ReplaceRect(const char *name, int32 index, BRect a_rect);
|
||||
status_t ReplacePoint(const char *name, BPoint a_point);
|
||||
status_t ReplacePoint(const char *name, int32 index, BPoint a_point);
|
||||
status_t ReplaceString(const char *name, const char *string);
|
||||
status_t ReplaceString(const char *name, int32 index, const char *string);
|
||||
status_t ReplaceString(const char *name, const BString& string);
|
||||
status_t ReplaceString(const char *name, int32 index, const BString& string);
|
||||
status_t ReplaceInt8(const char *name, int8 val);
|
||||
status_t ReplaceInt8(const char *name, int32 index, int8 val);
|
||||
status_t ReplaceInt16(const char *name, int16 val);
|
||||
status_t ReplaceInt16(const char *name, int32 index, int16 val);
|
||||
status_t ReplaceInt64(const char *name, int64 val);
|
||||
status_t ReplaceInt64(const char *name, int32 index, int64 val);
|
||||
status_t ReplaceBool(const char *name, bool a_bool);
|
||||
status_t ReplaceBool(const char *name, int32 index, bool a_bool);
|
||||
status_t ReplaceFloat(const char *name, float a_float);
|
||||
status_t ReplaceFloat(const char *name, int32 index, float a_float);
|
||||
status_t ReplaceDouble(const char *name, double a_double);
|
||||
status_t ReplaceDouble(const char *name, int32 index, double a_double);
|
||||
status_t ReplacePointer(const char *name, const void *ptr);
|
||||
status_t ReplacePointer(const char *name,int32 index,const void *ptr);
|
||||
status_t ReplaceMessenger(const char *name, BMessenger messenger);
|
||||
status_t ReplaceMessenger(const char *name, int32 index, BMessenger msngr);
|
||||
status_t ReplaceRef( const char *name,const entry_ref *ref);
|
||||
status_t ReplaceRef( const char *name, int32 index, const entry_ref *ref);
|
||||
status_t ReplaceMessage(const char *name, const BMessage *msg);
|
||||
status_t ReplaceMessage(const char *name, int32 index, const BMessage *msg);
|
||||
status_t ReplaceFlat(const char *name, BFlattenable *obj);
|
||||
status_t ReplaceFlat(const char *name, int32 index, BFlattenable *obj);
|
||||
status_t ReplaceData(const char *name, type_code type,
|
||||
const void *data, ssize_t data_size);
|
||||
status_t ReplaceData(const char *name, type_code type, int32 index,
|
||||
const void *data, ssize_t data_size);
|
||||
|
||||
void *operator new(size_t size);
|
||||
void operator delete(void *ptr, size_t size);
|
||||
|
||||
bool HasRect(const char *, int32 n = 0) const;
|
||||
bool HasPoint(const char *, int32 n = 0) const;
|
||||
bool HasString(const char *, int32 n = 0) const;
|
||||
bool HasInt8(const char *, int32 n = 0) const;
|
||||
bool HasInt16(const char *, int32 n = 0) const;
|
||||
bool HasInt64(const char *, int32 n = 0) const;
|
||||
bool HasBool(const char *, int32 n = 0) const;
|
||||
bool HasFloat(const char *, int32 n = 0) const;
|
||||
bool HasDouble(const char *, int32 n = 0) const;
|
||||
bool HasPointer(const char *, int32 n = 0) const;
|
||||
bool HasMessenger(const char *, int32 n = 0) const;
|
||||
bool HasRef(const char *, int32 n = 0) const;
|
||||
bool HasMessage(const char *, int32 n = 0) const;
|
||||
bool HasFlat(const char *, const BFlattenable *) const;
|
||||
bool HasFlat(const char *,int32 ,const BFlattenable *) const;
|
||||
bool HasData(const char *, type_code , int32 n = 0) const;
|
||||
BRect FindRect(const char *, int32 n = 0) const;
|
||||
BPoint FindPoint(const char *, int32 n = 0) const;
|
||||
const char *FindString(const char *, int32 n = 0) const;
|
||||
int8 FindInt8(const char *, int32 n = 0) const;
|
||||
int16 FindInt16(const char *, int32 n = 0) const;
|
||||
int64 FindInt64(const char *, int32 n = 0) const;
|
||||
bool FindBool(const char *, int32 n = 0) const;
|
||||
float FindFloat(const char *, int32 n = 0) const;
|
||||
double FindDouble(const char *, int32 n = 0) const;
|
After Width: | Height: | Size: 11 KiB |
93
src/tests/kits/app/bmessage/MessageConstructTest.cpp
Normal file
93
src/tests/kits/app/bmessage/MessageConstructTest.cpp
Normal file
@ -0,0 +1,93 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// MessageConstructTest.cpp
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Standard Includes -----------------------------------------------------------
|
||||
#include <stdio.h>
|
||||
|
||||
// System Includes -------------------------------------------------------------
|
||||
#include <Message.h>
|
||||
// Project Includes ------------------------------------------------------------
|
||||
|
||||
// Local Includes --------------------------------------------------------------
|
||||
#include "../common.h"
|
||||
#include "MessageConstructTest.h"
|
||||
|
||||
// Local Defines ---------------------------------------------------------------
|
||||
|
||||
// Globals ---------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/**
|
||||
BMessage()
|
||||
@case Default construction
|
||||
@params none
|
||||
@results BMessage::what == 0
|
||||
*/
|
||||
void TMessageConstructTest::MessageConstructTest1()
|
||||
{
|
||||
BMessage msg;
|
||||
CPPUNIT_ASSERT(msg.what == 0);
|
||||
ConfirmNullConstruction(msg);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
/**
|
||||
BMessage(uint32 what)
|
||||
@case what initialization constructor
|
||||
@params what a uint32 message ID code
|
||||
@results BMessage::what == what param
|
||||
*/
|
||||
void TMessageConstructTest::MessageConstructTest2()
|
||||
{
|
||||
BMessage msg(1234);
|
||||
CPPUNIT_ASSERT(msg.what == 1234);
|
||||
ConfirmNullConstruction(msg);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
/**
|
||||
BMessage(const BMessage& msg)
|
||||
@case copy of default constructed
|
||||
@params msg a default constructed BMessage instance
|
||||
@results what == msg.what and ConfirmNullConstruction is good
|
||||
*/
|
||||
void TMessageConstructTest::MessageConstructTest3()
|
||||
{
|
||||
BMessage msg1(1234);
|
||||
CPPUNIT_ASSERT(msg1.what == 1234);
|
||||
ConfirmNullConstruction(msg1);
|
||||
|
||||
BMessage msg2(msg1);
|
||||
CPPUNIT_ASSERT(msg2.what == msg1.what);
|
||||
ConfirmNullConstruction(msg2);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
TestSuite* TMessageConstructTest::Suite()
|
||||
{
|
||||
TestSuite* suite = new TestSuite("BMessage::BMessage()");
|
||||
|
||||
ADD_TEST4(BMessage, suite, TMessageConstructTest, MessageConstructTest1);
|
||||
ADD_TEST4(BMessage, suite, TMessageConstructTest, MessageConstructTest2);
|
||||
|
||||
return suite;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void TMessageConstructTest::ConfirmNullConstruction(BMessage& msg)
|
||||
{
|
||||
CPPUNIT_ASSERT(msg.CountNames(B_ANY_TYPE) == 0);
|
||||
CPPUNIT_ASSERT(msg.IsEmpty());
|
||||
CPPUNIT_ASSERT(!msg.IsSystem());
|
||||
CPPUNIT_ASSERT(!msg.IsReply());
|
||||
CPPUNIT_ASSERT(!msg.WasDelivered());
|
||||
CPPUNIT_ASSERT(!msg.IsSourceWaiting());
|
||||
CPPUNIT_ASSERT(!msg.IsSourceRemote());
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* $Log $
|
||||
*
|
||||
* $Id $
|
||||
*
|
||||
*/
|
||||
|
48
src/tests/kits/app/bmessage/MessageConstructTest.h
Normal file
48
src/tests/kits/app/bmessage/MessageConstructTest.h
Normal file
@ -0,0 +1,48 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// MessageConstructTest.h
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef MESSAGECONSTRUCTTEST_H
|
||||
#define MESSAGECONSTRUCTTEST_H
|
||||
|
||||
// Standard Includes -----------------------------------------------------------
|
||||
|
||||
// System Includes -------------------------------------------------------------
|
||||
|
||||
// Project Includes ------------------------------------------------------------
|
||||
|
||||
// Local Includes --------------------------------------------------------------
|
||||
#include "../common.h"
|
||||
|
||||
// Local Defines ---------------------------------------------------------------
|
||||
|
||||
// Globals ---------------------------------------------------------------------
|
||||
|
||||
class BMessage;
|
||||
|
||||
class TMessageConstructTest : public TestCase
|
||||
{
|
||||
public:
|
||||
TMessageConstructTest() {;}
|
||||
TMessageConstructTest(std::string name) : TestCase(name) {;}
|
||||
|
||||
void MessageConstructTest1();
|
||||
void MessageConstructTest2();
|
||||
void MessageConstructTest3();
|
||||
|
||||
static TestSuite* Suite();
|
||||
|
||||
private:
|
||||
void ConfirmNullConstruction(BMessage& msg);
|
||||
};
|
||||
|
||||
#endif //MESSAGECONSTRUCTTEST_H
|
||||
|
||||
/*
|
||||
* $Log $
|
||||
*
|
||||
* $Id $
|
||||
*
|
||||
*/
|
||||
|
56
src/tests/kits/app/bmessage/MessageEasyFindTest.cpp
Normal file
56
src/tests/kits/app/bmessage/MessageEasyFindTest.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// MessageEasyFindTest.cpp
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Standard Includes -----------------------------------------------------------
|
||||
|
||||
// System Includes -------------------------------------------------------------
|
||||
#include <Message.h>
|
||||
#include <Point.h>
|
||||
#include <Rect.h>
|
||||
|
||||
// Project Includes ------------------------------------------------------------
|
||||
|
||||
// Local Includes --------------------------------------------------------------
|
||||
#include "MessageEasyFindTest.h"
|
||||
|
||||
// Local Defines ---------------------------------------------------------------
|
||||
|
||||
// Globals ---------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void TMessageEasyFindTest::MessageEasyFindTest1()
|
||||
{
|
||||
BRect r(0, 0, -1, -1);
|
||||
BPoint p(0, 0);
|
||||
BMessage msg;
|
||||
CPPUNIT_ASSERT(msg.FindRect("data") == r);
|
||||
CPPUNIT_ASSERT(msg.FindPoint("data") == p);
|
||||
CPPUNIT_ASSERT(msg.FindString("data") == NULL);
|
||||
CPPUNIT_ASSERT(msg.FindInt8("data") == 0);
|
||||
CPPUNIT_ASSERT(msg.FindInt16("data") == 0);
|
||||
CPPUNIT_ASSERT(msg.FindInt32("data") == 0);
|
||||
CPPUNIT_ASSERT(msg.FindInt64("data") == 0);
|
||||
CPPUNIT_ASSERT(msg.FindBool("data") == false);
|
||||
CPPUNIT_ASSERT(msg.FindFloat("data") == 0);
|
||||
CPPUNIT_ASSERT(msg.FindDouble("data") == 0);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
TestSuite* TMessageEasyFindTest::Suite()
|
||||
{
|
||||
TestSuite* suite = new TestSuite("BMessage::EasyFinds");
|
||||
|
||||
ADD_TEST4(BMessage, suite, TMessageEasyFindTest, MessageEasyFindTest1);
|
||||
|
||||
return suite;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* $Log $
|
||||
*
|
||||
* $Id $
|
||||
*
|
||||
*/
|
||||
|
41
src/tests/kits/app/bmessage/MessageEasyFindTest.h
Normal file
41
src/tests/kits/app/bmessage/MessageEasyFindTest.h
Normal file
@ -0,0 +1,41 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// MessageEasyFindTest.h
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef MESSAGEEASYFINDTEST_H
|
||||
#define MESSAGEEASYFINDTEST_H
|
||||
|
||||
// Standard Includes -----------------------------------------------------------
|
||||
|
||||
// System Includes -------------------------------------------------------------
|
||||
|
||||
// Project Includes ------------------------------------------------------------
|
||||
|
||||
// Local Includes --------------------------------------------------------------
|
||||
#include "../common.h"
|
||||
|
||||
// Local Defines ---------------------------------------------------------------
|
||||
|
||||
// Globals ---------------------------------------------------------------------
|
||||
|
||||
class TMessageEasyFindTest : public TestCase
|
||||
{
|
||||
public:
|
||||
TMessageEasyFindTest() {;}
|
||||
TMessageEasyFindTest(std::string name) : TestCase(name) {;}
|
||||
|
||||
void MessageEasyFindTest1();
|
||||
|
||||
static TestSuite* Suite();
|
||||
};
|
||||
|
||||
#endif // MESSAGEEASYFINDTEST_H
|
||||
|
||||
/*
|
||||
* $Log $
|
||||
*
|
||||
* $Id $
|
||||
*
|
||||
*/
|
||||
|
214
src/tests/kits/app/bmessage/MessageInt32ItemTest.cpp
Normal file
214
src/tests/kits/app/bmessage/MessageInt32ItemTest.cpp
Normal file
@ -0,0 +1,214 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// MessageInt32ItemTest.cpp
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Standard Includes -----------------------------------------------------------
|
||||
#include <stdio.h>
|
||||
#include <posix/string.h>
|
||||
|
||||
// System Includes -------------------------------------------------------------
|
||||
#include <Message.h>
|
||||
|
||||
// Project Includes ------------------------------------------------------------
|
||||
|
||||
// Local Includes --------------------------------------------------------------
|
||||
#include "MessageInt32ItemTest.h"
|
||||
|
||||
// Local Defines ---------------------------------------------------------------
|
||||
|
||||
// Globals ---------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void TMessageInt32ItemTest::MessageInt32ItemTest1()
|
||||
{
|
||||
BMessage msg;
|
||||
int32 out = 0;
|
||||
CPPUNIT_ASSERT(msg.FindInt32("an int32", &out) == B_NAME_NOT_FOUND);
|
||||
CPPUNIT_ASSERT(out == 0);
|
||||
CPPUNIT_ASSERT(msg.FindInt32("an int32") == 0);
|
||||
CPPUNIT_ASSERT(!msg.HasInt32("an int32"));
|
||||
const void* ptr = &out;
|
||||
ssize_t size;
|
||||
CPPUNIT_ASSERT(msg.FindData("an int32", B_INT32_TYPE, &ptr, &size) ==
|
||||
B_NAME_NOT_FOUND);
|
||||
CPPUNIT_ASSERT(ptr == NULL);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void TMessageInt32ItemTest::MessageInt32ItemTest2()
|
||||
{
|
||||
BMessage msg;
|
||||
int32 in = 1234;
|
||||
int32 out = 0;
|
||||
CPPUNIT_ASSERT(msg.AddInt32("an int32", in) == B_OK);
|
||||
CPPUNIT_ASSERT(msg.HasInt32("an int32"));
|
||||
CPPUNIT_ASSERT(msg.FindInt32("an int32") == in);
|
||||
CPPUNIT_ASSERT(msg.FindInt32("an int32", &out) == B_OK);
|
||||
CPPUNIT_ASSERT(out == in);
|
||||
int32* pout;
|
||||
ssize_t size;
|
||||
CPPUNIT_ASSERT(msg.FindData("an int32", B_INT32_TYPE, (const void**)&pout,
|
||||
&size) == B_OK);
|
||||
CPPUNIT_ASSERT(*pout == in);
|
||||
CPPUNIT_ASSERT(size == sizeof (int32));
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void TMessageInt32ItemTest::MessageInt32ItemTest3()
|
||||
{
|
||||
BMessage msg;
|
||||
int32 in = 1234;
|
||||
int32 in2 = 7890;
|
||||
int32 out = 0;
|
||||
CPPUNIT_ASSERT(msg.AddInt32("an int32", in) == B_OK);
|
||||
CPPUNIT_ASSERT(msg.ReplaceInt32("an int32", in2) == B_OK);
|
||||
CPPUNIT_ASSERT(msg.HasInt32("an int32"));
|
||||
CPPUNIT_ASSERT(msg.FindInt32("an int32") == in2);
|
||||
CPPUNIT_ASSERT(msg.FindInt32("an int32", &out) == B_OK);
|
||||
CPPUNIT_ASSERT(out == in2);
|
||||
out = 0;
|
||||
int32* pout;
|
||||
ssize_t size;
|
||||
CPPUNIT_ASSERT(msg.FindData("an int32", B_INT32_TYPE, (const void**)&pout,
|
||||
&size) == B_OK);
|
||||
CPPUNIT_ASSERT(*pout == in2);
|
||||
CPPUNIT_ASSERT(size == sizeof (int32));
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void TMessageInt32ItemTest::MessageInt32ItemTest4()
|
||||
{
|
||||
BMessage msg;
|
||||
int32 out = 0;
|
||||
CPPUNIT_ASSERT(msg.FindInt32("an int32", 1, &out) == B_NAME_NOT_FOUND);
|
||||
CPPUNIT_ASSERT(out == 0);
|
||||
CPPUNIT_ASSERT(msg.FindInt32("an int32", 1) == 0);
|
||||
CPPUNIT_ASSERT(!msg.HasInt32("an int32", 1));
|
||||
const void* ptr = &out;
|
||||
ssize_t size;
|
||||
CPPUNIT_ASSERT(msg.FindData("an int32", B_INT32_TYPE, 1, &ptr, &size) ==
|
||||
B_NAME_NOT_FOUND);
|
||||
CPPUNIT_ASSERT(ptr == NULL);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void TMessageInt32ItemTest::MessageInt32ItemTest5()
|
||||
{
|
||||
BMessage msg;
|
||||
int32 in[] = { 123, 456, 789 };
|
||||
int32 out = 0;
|
||||
int32* pout;
|
||||
ssize_t size;
|
||||
|
||||
for (int32 i = 0; i < sizeof (in) / sizeof (int32); ++i)
|
||||
{
|
||||
CPPUNIT_ASSERT(msg.AddInt32("an int32", in[i]) == B_OK);
|
||||
}
|
||||
|
||||
for (int32 i = 0; i < sizeof (in) / sizeof (int32); ++i)
|
||||
{
|
||||
CPPUNIT_ASSERT(msg.HasInt32("an int32", i));
|
||||
CPPUNIT_ASSERT(msg.FindInt32("an int32", i) == in[i]);
|
||||
CPPUNIT_ASSERT(msg.FindInt32("an int32", i, &out) == B_OK);
|
||||
CPPUNIT_ASSERT(out == in[i]);
|
||||
CPPUNIT_ASSERT(msg.FindData("an int32", B_INT32_TYPE, i,
|
||||
(const void**)&pout, &size) == B_OK);
|
||||
CPPUNIT_ASSERT(*pout == in[i]);
|
||||
CPPUNIT_ASSERT(size == sizeof (int32));
|
||||
}
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void TMessageInt32ItemTest::MessageInt32ItemTest6()
|
||||
{
|
||||
BMessage msg;
|
||||
int32 in[] = { 123, 456, 789 };
|
||||
int32 in2 = 654;
|
||||
int32 out = 0;
|
||||
const int rIndex = 2;
|
||||
|
||||
for (int32 i = 0; i < sizeof (in) / sizeof (int32); ++i)
|
||||
{
|
||||
CPPUNIT_ASSERT(msg.AddInt32("an int32", in[i]) == B_OK);
|
||||
}
|
||||
|
||||
CPPUNIT_ASSERT(msg.ReplaceInt32("an int32", rIndex, in2) == B_OK);
|
||||
CPPUNIT_ASSERT(msg.HasInt32("an int32", rIndex));
|
||||
CPPUNIT_ASSERT(msg.FindInt32("an int32", rIndex) == in2);
|
||||
CPPUNIT_ASSERT(msg.FindInt32("an int32", rIndex, &out) == B_OK);
|
||||
CPPUNIT_ASSERT(out == in2);
|
||||
out = 0;
|
||||
int32* pout;
|
||||
ssize_t size;
|
||||
CPPUNIT_ASSERT(msg.FindData("an int32", B_INT32_TYPE, rIndex,
|
||||
(const void**)&pout, &size) == B_OK);
|
||||
CPPUNIT_ASSERT(*pout == in2);
|
||||
CPPUNIT_ASSERT(size == sizeof (int32));
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void TMessageInt32ItemTest::MessageInt32ItemTest7()
|
||||
{
|
||||
BMessage msg;
|
||||
int32 in = 1234;
|
||||
int32 out = 0;
|
||||
CPPUNIT_ASSERT(msg.AddData("an int32", B_INT32_TYPE, (const void*)&in,
|
||||
sizeof (int32)) == B_OK);
|
||||
CPPUNIT_ASSERT(msg.HasInt32("an int32"));
|
||||
CPPUNIT_ASSERT(msg.FindInt32("an int32") == in);
|
||||
CPPUNIT_ASSERT(msg.FindInt32("an int32", &out) == B_OK);
|
||||
CPPUNIT_ASSERT(out == in);
|
||||
int32* pout;
|
||||
ssize_t size;
|
||||
CPPUNIT_ASSERT(msg.FindData("an int32", B_INT32_TYPE, (const void**)&pout,
|
||||
&size) == B_OK);
|
||||
CPPUNIT_ASSERT(*pout == in);
|
||||
CPPUNIT_ASSERT(size == sizeof (int32));
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void TMessageInt32ItemTest::MessageInt32ItemTest8()
|
||||
{
|
||||
BMessage msg;
|
||||
int32 in[] = { 123, 456, 789 };
|
||||
int32 out = 0;
|
||||
int32* pout;
|
||||
ssize_t size;
|
||||
|
||||
for (int32 i = 0; i < sizeof (in) / sizeof (int32); ++i)
|
||||
{
|
||||
CPPUNIT_ASSERT(msg.AddData("an int32", B_INT32_TYPE,
|
||||
(const void*)&in[i], sizeof (int32)) == B_OK);
|
||||
}
|
||||
|
||||
for (int32 i = 0; i < sizeof (in) / sizeof (int32); ++i)
|
||||
{
|
||||
CPPUNIT_ASSERT(msg.HasInt32("an int32", i));
|
||||
CPPUNIT_ASSERT(msg.FindInt32("an int32", i) == in[i]);
|
||||
CPPUNIT_ASSERT(msg.FindInt32("an int32", i, &out) == B_OK);
|
||||
CPPUNIT_ASSERT(out == in[i]);
|
||||
CPPUNIT_ASSERT(msg.FindData("an int32", B_INT32_TYPE, i,
|
||||
(const void**)&pout, &size) == B_OK);
|
||||
CPPUNIT_ASSERT(*pout == in[i]);
|
||||
CPPUNIT_ASSERT(size == sizeof (int32));
|
||||
}
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
TestSuite* TMessageInt32ItemTest::Suite()
|
||||
{
|
||||
TestSuite* suite = new TestSuite("BMessage::Add/Find/Replace/HasRect()");
|
||||
|
||||
ADD_TEST4(BMessage, suite, TMessageInt32ItemTest, MessageInt32ItemTest1);
|
||||
ADD_TEST4(BMessage, suite, TMessageInt32ItemTest, MessageInt32ItemTest2);
|
||||
ADD_TEST4(BMessage, suite, TMessageInt32ItemTest, MessageInt32ItemTest3);
|
||||
ADD_TEST4(BMessage, suite, TMessageInt32ItemTest, MessageInt32ItemTest4);
|
||||
ADD_TEST4(BMessage, suite, TMessageInt32ItemTest, MessageInt32ItemTest5);
|
||||
ADD_TEST4(BMessage, suite, TMessageInt32ItemTest, MessageInt32ItemTest6);
|
||||
ADD_TEST4(BMessage, suite, TMessageInt32ItemTest, MessageInt32ItemTest7);
|
||||
ADD_TEST4(BMessage, suite, TMessageInt32ItemTest, MessageInt32ItemTest8);
|
||||
|
||||
return suite;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* $Log $
|
||||
*
|
||||
* $Id $
|
||||
*
|
||||
*/
|
||||
|
48
src/tests/kits/app/bmessage/MessageInt32ItemTest.h
Normal file
48
src/tests/kits/app/bmessage/MessageInt32ItemTest.h
Normal file
@ -0,0 +1,48 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// MessageInt32ItemTest.h
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef MESSAGEINT32ITEMTEST_H
|
||||
#define MESSAGEINT32ITEMTEST_H
|
||||
|
||||
// Standard Includes -----------------------------------------------------------
|
||||
|
||||
// System Includes -------------------------------------------------------------
|
||||
|
||||
// Project Includes ------------------------------------------------------------
|
||||
|
||||
// Local Includes --------------------------------------------------------------
|
||||
#include "../common.h"
|
||||
|
||||
// Local Defines ---------------------------------------------------------------
|
||||
|
||||
// Globals ---------------------------------------------------------------------
|
||||
|
||||
class TMessageInt32ItemTest : public TestCase
|
||||
{
|
||||
public:
|
||||
TMessageInt32ItemTest() {;}
|
||||
TMessageInt32ItemTest(std::string name) : TestCase(name) {;}
|
||||
|
||||
void MessageInt32ItemTest1();
|
||||
void MessageInt32ItemTest2();
|
||||
void MessageInt32ItemTest3();
|
||||
void MessageInt32ItemTest4();
|
||||
void MessageInt32ItemTest5();
|
||||
void MessageInt32ItemTest6();
|
||||
void MessageInt32ItemTest7();
|
||||
void MessageInt32ItemTest8();
|
||||
|
||||
static TestSuite* Suite();
|
||||
};
|
||||
|
||||
#endif // MESSAGEINT32ITEMTEST_H
|
||||
|
||||
/*
|
||||
* $Log $
|
||||
*
|
||||
* $Id $
|
||||
*
|
||||
*/
|
||||
|
45
src/tests/kits/app/bmessage/MessageOpAssignTest.cpp
Normal file
45
src/tests/kits/app/bmessage/MessageOpAssignTest.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// MessageOpAssignTest.cpp
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Standard Includes -----------------------------------------------------------
|
||||
|
||||
// System Includes -------------------------------------------------------------
|
||||
#include <Message.h>
|
||||
|
||||
// Project Includes ------------------------------------------------------------
|
||||
|
||||
// Local Includes --------------------------------------------------------------
|
||||
#include "MessageOpAssignTest.h"
|
||||
|
||||
// Local Defines ---------------------------------------------------------------
|
||||
|
||||
// Globals ---------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void TMessageOpAssignTest::MessageOpAssignTest1()
|
||||
{
|
||||
BMessage msg1(1234);
|
||||
BMessage msg2;
|
||||
msg2 = msg1;
|
||||
CPPUNIT_ASSERT(msg2.what == msg1.what);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
TestSuite* TMessageOpAssignTest::Suite()
|
||||
{
|
||||
TestSuite* suite = new TestSuite("BMessage::operator=(const BMessage&)");
|
||||
|
||||
ADD_TEST4(BMessage, suite, TMessageOpAssignTest, MessageOpAssignTest1);
|
||||
|
||||
return suite;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* $Log $
|
||||
*
|
||||
* $Id $
|
||||
*
|
||||
*/
|
||||
|
41
src/tests/kits/app/bmessage/MessageOpAssignTest.h
Normal file
41
src/tests/kits/app/bmessage/MessageOpAssignTest.h
Normal file
@ -0,0 +1,41 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// MessageOpAssignTest.h
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef MESSAGEOPASSIGNTEST_H
|
||||
#define MESSAGEOPASSIGNTEST_H
|
||||
|
||||
// Standard Includes -----------------------------------------------------------
|
||||
|
||||
// System Includes -------------------------------------------------------------
|
||||
|
||||
// Project Includes ------------------------------------------------------------
|
||||
|
||||
// Local Includes --------------------------------------------------------------
|
||||
#include "../common.h"
|
||||
|
||||
// Local Defines ---------------------------------------------------------------
|
||||
|
||||
// Globals ---------------------------------------------------------------------
|
||||
|
||||
class TMessageOpAssignTest : public TestCase
|
||||
{
|
||||
public:
|
||||
TMessageOpAssignTest() {;}
|
||||
TMessageOpAssignTest(std::string name) : TestCase(name) {;}
|
||||
|
||||
void MessageOpAssignTest1();
|
||||
|
||||
static TestSuite* Suite();
|
||||
};
|
||||
|
||||
#endif // MESSAGEOPASSIGNTEST_H
|
||||
|
||||
/*
|
||||
* $Log $
|
||||
*
|
||||
* $Id $
|
||||
*
|
||||
*/
|
||||
|
19
src/tests/kits/app/bmessage/MessageTest.cpp
Normal file
19
src/tests/kits/app/bmessage/MessageTest.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
//#include "MessageTest.h"
|
||||
#include "../common.h"
|
||||
#include "MessageConstructTest.h"
|
||||
#include "MessageOpAssignTest.h"
|
||||
#include "MessageInt32ItemTest.h"
|
||||
#include "MessageEasyFindTest.h"
|
||||
|
||||
Test* MessageTestSuite()
|
||||
{
|
||||
TestSuite* tests = new TestSuite();
|
||||
|
||||
tests->addTest(TMessageConstructTest::Suite());
|
||||
tests->addTest(TMessageOpAssignTest::Suite());
|
||||
tests->addTest(TMessageInt32ItemTest::Suite());
|
||||
tests->addTest(TMessageEasyFindTest::Suite());
|
||||
|
||||
return tests;
|
||||
}
|
||||
|
33
src/tests/kits/app/bmessage/MessageTest.h
Normal file
33
src/tests/kits/app/bmessage/MessageTest.h
Normal file
@ -0,0 +1,33 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// MessageTest.h
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifndef MESSAGETEST_H
|
||||
#define MESSAGETEST_H
|
||||
|
||||
// Standard Includes -----------------------------------------------------------
|
||||
|
||||
// System Includes -------------------------------------------------------------
|
||||
|
||||
// Project Includes ------------------------------------------------------------
|
||||
|
||||
// Local Includes --------------------------------------------------------------
|
||||
|
||||
// Local Defines ---------------------------------------------------------------
|
||||
|
||||
// Globals ---------------------------------------------------------------------
|
||||
|
||||
class CppUnit::Test;
|
||||
|
||||
CppUnit::Test* MessageTestSuite();
|
||||
|
||||
#endif // MESSAGETEST_H
|
||||
|
||||
/*
|
||||
* $Log $
|
||||
*
|
||||
* $Id $
|
||||
*
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user