launch_daemon: Completed condition parser.

This commit is contained in:
Axel Dörfler 2015-06-22 08:22:29 +02:00
parent e73c936699
commit f7cf381a14
2 changed files with 43 additions and 11 deletions

View File

@ -28,20 +28,19 @@ public:
add = &message;
index++;
}
const char* condition = parameter.values[index];
BMessage args;
for (index++; index < parameter.value_count; index++) {
status_t status = args.AddString("args",
parameter.values[index]);
if (status != B_OK)
return status;
}
status_t status = add->AddMessage(condition, &args);
status_t status = _AddSubMessage(parameter, index, *add);
if (status == B_OK && not)
status = target.AddMessage("not", &message);
return status;
}
if (strcmp(parameter.name, "not") == 0) {
if (index != 0)
return B_OK;
return _AddSubMessage(parameter, index, target);
}
message.AddString("args", parameter.values[index]);
return target.AddMessage(parameter.name, &message);
@ -57,6 +56,21 @@ public:
BMessage message;
return target.AddMessage(name, &message);
}
private:
status_t _AddSubMessage(const driver_parameter& parameter, int32 index,
BMessage& target)
{
const char* condition = parameter.values[index];
BMessage args;
for (index++; index < parameter.value_count; index++) {
status_t status = args.AddString("args",
parameter.values[index]);
if (status != B_OK)
return status;
}
return target.AddMessage(condition, &args);
}
};

View File

@ -122,7 +122,16 @@ SettingsParserTest::TestConditionsMultiLineFlatNot()
CPPUNIT_ASSERT_EQUAL(B_OK, _ParseCondition("if {\n"
"\tnot safemode\n"
"}\n", message));
message.PrintToStream();
BMessage subMessage;
CPPUNIT_ASSERT_EQUAL(B_OK, message.FindMessage("not",
&subMessage));
CPPUNIT_ASSERT_EQUAL(1, message.CountNames(B_ANY_TYPE));
BMessage args;
CPPUNIT_ASSERT_EQUAL(B_OK, subMessage.FindMessage("safemode", &args));
CPPUNIT_ASSERT_EQUAL(1, subMessage.CountNames(B_ANY_TYPE));
CPPUNIT_ASSERT(args.IsEmpty());
}
@ -133,7 +142,16 @@ SettingsParserTest::TestConditionsMultiLineFlatNotWithArgs()
CPPUNIT_ASSERT_EQUAL(B_OK, _ParseCondition("if {\n"
"\tnot file_exists one\n"
"}\n", message));
message.PrintToStream();
BMessage subMessage;
CPPUNIT_ASSERT_EQUAL(B_OK, message.FindMessage("not",
&subMessage));
BMessage args;
CPPUNIT_ASSERT_EQUAL(B_OK, subMessage.FindMessage("file_exists", &args));
CPPUNIT_ASSERT_EQUAL(BString("one"),
BString(args.GetString("args", 0, "-")));
CPPUNIT_ASSERT_EQUAL(1, args.CountNames(B_ANY_TYPE));
}