diff --git a/src/kits/app/Message.cpp b/src/kits/app/Message.cpp index 0224bbaaa3..7a4fc952c2 100644 --- a/src/kits/app/Message.cpp +++ b/src/kits/app/Message.cpp @@ -825,12 +825,7 @@ status_t BMessage::AddData(const char* name, type_code type, const void* data, break; case B_REF_TYPE: { - entry_ref ref; - 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); + err = AddRef(name, (entry_ref*)data); break; } case B_MESSAGE_TYPE: diff --git a/src/tests/kits/app/bmessage/MessageRefItemTest.h b/src/tests/kits/app/bmessage/MessageRefItemTest.h new file mode 100644 index 0000000000..1eb10c951c --- /dev/null +++ b/src/tests/kits/app/bmessage/MessageRefItemTest.h @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// MessageRefItemTest.h +// +//------------------------------------------------------------------------------ + +#ifndef MESSAGEREFITEMTEST_H +#define MESSAGEREFITEMTEST_H + +// Standard Includes ----------------------------------------------------------- + +// System Includes ------------------------------------------------------------- +#include + +// 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 +{ + 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 $ + * + */ + diff --git a/src/tests/kits/app/bmessage/MessageTest.cpp b/src/tests/kits/app/bmessage/MessageTest.cpp index dc71292852..b800f6f12e 100644 --- a/src/tests/kits/app/bmessage/MessageTest.cpp +++ b/src/tests/kits/app/bmessage/MessageTest.cpp @@ -13,7 +13,7 @@ #include "MessageEasyFindTest.h" #include "MessageFloatItemTest.h" #include "MessageDoubleItemTest.h" -//#include "MessageRefItemTest.h" +#include "MessageRefItemTest.h" Test* MessageTestSuite() { @@ -31,7 +31,7 @@ Test* MessageTestSuite() tests->addTest(TMessageEasyFindTest::Suite()); tests->addTest(TMessageFloatItemTest::Suite()); tests->addTest(TMessageDoubleItemTest::Suite()); -// tests->addTest(TMessageRefItemTest::Suite()); + tests->addTest(TMessageRefItemTest::Suite()); return tests; }