New tests for Add/Find/Replace/HasRef, and tweak in MessageTest.cpp to use

it.  Also, minor fix in entry_ref handling in BMessage::AddData().


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2967 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
ejakowatz
2003-03-20 06:02:27 +00:00
parent e60c601e2d
commit 74d9216544
3 changed files with 106 additions and 8 deletions
+1 -6
View File
@@ -825,12 +825,7 @@ status_t BMessage::AddData(const char* name, type_code type, const void* data,
break; break;
case B_REF_TYPE: case B_REF_TYPE:
{ {
entry_ref ref; err = AddRef(name, (entry_ref*)data);
uchar* dp = (uchar*)data;
ref.device = *(dev_t*)dp; dp += sizeof (dev_t);
ref.directory = *(ino_t*)dp; dp += sizeof (ino_t);
ref.set_name((const char*)dp);
err = AddRef(name, &ref);
break; break;
} }
case B_MESSAGE_TYPE: case B_MESSAGE_TYPE:
@@ -0,0 +1,103 @@
//------------------------------------------------------------------------------
// MessageRefItemTest.h
//
//------------------------------------------------------------------------------
#ifndef MESSAGEREFITEMTEST_H
#define MESSAGEREFITEMTEST_H
// Standard Includes -----------------------------------------------------------
// System Includes -------------------------------------------------------------
#include <Entry.h>
// Project Includes ------------------------------------------------------------
// Local Includes --------------------------------------------------------------
// Local Defines ---------------------------------------------------------------
// Globals ---------------------------------------------------------------------
struct TRefFuncPolicy
{
static status_t Add(BMessage& msg, const char* name, entry_ref& val)
{
return msg.AddRef(name, &val);
}
static status_t Find(BMessage& msg, const char* name, int32 index,
entry_ref* val)
{
return msg.FindRef(name, index, val);
}
static entry_ref QuickFind(BMessage& msg, const char* name, int32 index)
{
// TODO: make cooler
// There must be some 1337 template voodoo way of making the inclusion
// of this function conditional. In the meantime, we offer this
// cheesy hack
entry_ref ref;
msg.FindRef(name, index, &ref);
return ref;
}
static bool Has(BMessage& msg, const char* name, int32 index)
{
return msg.HasRef(name, index);
}
static status_t Replace(BMessage& msg, const char* name, int32 index,
entry_ref val)
{
return msg.ReplaceRef(name, index, &val);
}
};
//------------------------------------------------------------------------------
struct TRefInitPolicy : public ArrayTypeBase<entry_ref>
{
inline static entry_ref Zero() { return entry_ref(); }
static entry_ref Test1()
{
entry_ref ref;
get_ref_for_path("/boot/beos/apps/camera", &ref);
return ref;
}
static entry_ref Test2()
{
entry_ref ref;
get_ref_for_path("/boot/develop/headers/be/Be.h", &ref);
return ref;
}
inline static ArrayType Array()
{
ArrayType array;
array.push_back(Zero());
array.push_back(Test1());
array.push_back(Test2());
return array;
}
};
//------------------------------------------------------------------------------
struct TRefAssertPolicy
{
inline static entry_ref Zero() { return TRefInitPolicy::Zero(); }
inline static entry_ref Invalid() { return TRefInitPolicy::Zero();}
};
//------------------------------------------------------------------------------
typedef TMessageItemTest
<
entry_ref,
B_REF_TYPE,
TRefFuncPolicy,
TRefInitPolicy,
TRefAssertPolicy
>
TMessageRefItemTest;
#endif // MESSAGEREFITEMTEST_H
/*
* $Log $
*
* $Id $
*
*/
+2 -2
View File
@@ -13,7 +13,7 @@
#include "MessageEasyFindTest.h" #include "MessageEasyFindTest.h"
#include "MessageFloatItemTest.h" #include "MessageFloatItemTest.h"
#include "MessageDoubleItemTest.h" #include "MessageDoubleItemTest.h"
//#include "MessageRefItemTest.h" #include "MessageRefItemTest.h"
Test* MessageTestSuite() Test* MessageTestSuite()
{ {
@@ -31,7 +31,7 @@ Test* MessageTestSuite()
tests->addTest(TMessageEasyFindTest::Suite()); tests->addTest(TMessageEasyFindTest::Suite());
tests->addTest(TMessageFloatItemTest::Suite()); tests->addTest(TMessageFloatItemTest::Suite());
tests->addTest(TMessageDoubleItemTest::Suite()); tests->addTest(TMessageDoubleItemTest::Suite());
// tests->addTest(TMessageRefItemTest::Suite()); tests->addTest(TMessageRefItemTest::Suite());
return tests; return tests;
} }