#include "PropertyFindMatchTest.h"
#include <assert.h>
#include <Message.h>
PropertyFindMatchTest::PropertyFindMatchTest(std::string name) :
PropertyTestcase(name)
{
}
PropertyFindMatchTest::~PropertyFindMatchTest()
{
}
void PropertyFindMatchTest::TestProperty(
BPropertyInfo *propTest,
const property_info *prop_list,
const value_info *value_list,
int32 prop_count,
int32 value_count,
ssize_t flat_size,
const char *lflat_data,
const char *bflat_data)
{
const uint32 *commands;
const uint32 *specifiers;
const property_info *theProps = propTest->Properties();
int i, j, k;
bool wildcardCommand, wildcardSpec;
ExecFindMatch(propTest, uniquePropName, uniqueCommand, uniqueSpecifier, false, -1);
ExecFindMatch(propTest, commonPropName, uniqueCommand, uniqueSpecifier, false, -1);
ExecFindMatch(propTest, uniquePropName, commonCommand, uniqueSpecifier, false, -1);
ExecFindMatch(propTest, uniquePropName, uniqueCommand, commonSpecifier, false, -1);
for (i=0; i < prop_count; i++) {
wildcardCommand = (theProps[i].commands[0] == 0);
wildcardSpec = (theProps[i].specifiers[0] == 0);
if (wildcardCommand) {
commands = wildcardCommandTests;
} else {
commands = theProps[i].commands;
}
if (wildcardSpec) {
specifiers = wildcardSpecifierTests;
} else {
specifiers = theProps[i].specifiers;
}
for(j=0; j<10; j++) {
if (commands[j] == 0) {
break;
}
if (!wildcardSpec) {
ExecFindMatch(propTest, theProps[i].name, commands[j], uniqueSpecifier,
wildcardCommand, -1);
}
for(k=0; k<10; k++) {
if (specifiers[k] == 0) {
break;
}
if (!wildcardCommand) {
ExecFindMatch(propTest, theProps[i].name, uniqueCommand, specifiers[k],
wildcardCommand, -1);
}
ExecFindMatch(propTest, theProps[i].name, commands[j], specifiers[k],
wildcardCommand, i);
}
}
}
}
void PropertyFindMatchTest::ExecFindMatch(
BPropertyInfo *propTest,
const char *prop,
uint32 comm,
uint32 spec,
bool wildcardCommand,
int32 result
)
{
BMessage msg(comm);
BMessage specMsg(spec);
specMsg.AddString("property", prop);
msg.AddSpecifier(&specMsg);
uint32 extra_data;
assert(propTest->FindMatch(&msg, 0, &specMsg, spec, prop, &extra_data) == result);
if (result >= 0) {
assert((propTest->Properties())[result].extra_data == extra_data);
}
assert(propTest->FindMatch(&msg, 0, NULL, spec, prop, &extra_data) == result);
if (wildcardCommand) {
assert(propTest->FindMatch(&msg, 1, &specMsg, spec, prop, &extra_data) == result);
assert(propTest->FindMatch(&msg, 1, NULL, spec, prop, &extra_data) == result);
} else {
assert(propTest->FindMatch(&msg, 1, &specMsg, spec, prop, &extra_data) == -1);
assert(propTest->FindMatch(&msg, 1, NULL, spec, prop, &extra_data) == -1);
}
}
Test *PropertyFindMatchTest::suite(void)
{
typedef CppUnit::TestCaller<PropertyFindMatchTest>
PropertyFindMatchTestCaller;
return(new PropertyFindMatchTestCaller("BPropertyInfo::FindMatch Test", &PropertyFindMatchTest::PerformTest));
}