From d54bb194d767c8764ac91bbf63130063ce6b76f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Thu, 16 Jul 2015 22:13:05 +0200 Subject: [PATCH] launch_daemon: Empty conditions are now NULL. * Instead of an empty and-condition. --- src/servers/launch/Conditions.cpp | 6 +++--- src/tests/servers/launch/ConditionsTest.cpp | 13 ++++++++++++- src/tests/servers/launch/ConditionsTest.h | 1 + 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/servers/launch/Conditions.cpp b/src/servers/launch/Conditions.cpp index 9e51664046..6eb3b6ecc5 100644 --- a/src/servers/launch/Conditions.cpp +++ b/src/servers/launch/Conditions.cpp @@ -105,11 +105,11 @@ private: static Condition* create_condition(const char* name, const BMessage& args) { - if (strcmp(name, "and") == 0) + if (strcmp(name, "and") == 0 && !args.IsEmpty()) return new AndCondition(args); - if (strcmp(name, "or") == 0) + if (strcmp(name, "or") == 0 && !args.IsEmpty()) return new OrCondition(args); - if (strcmp(name, "not") == 0) + if (strcmp(name, "not") == 0 && !args.IsEmpty()) return new NotCondition(args); if (strcmp(name, "safemode") == 0) diff --git a/src/tests/servers/launch/ConditionsTest.cpp b/src/tests/servers/launch/ConditionsTest.cpp index ad9f6f90d6..48b3f56d9f 100644 --- a/src/tests/servers/launch/ConditionsTest.cpp +++ b/src/tests/servers/launch/ConditionsTest.cpp @@ -40,6 +40,14 @@ ConditionsTest::~ConditionsTest() } +void +ConditionsTest::TestEmpty() +{ + Condition* condition = _Condition(""); + CPPUNIT_ASSERT(condition == NULL); +} + + void ConditionsTest::TestSafemode() { @@ -176,6 +184,8 @@ ConditionsTest::AddTests(BTestSuite& parent) { CppUnit::TestSuite& suite = *new CppUnit::TestSuite("ConditionsTest"); + suite.addTest(new CppUnit::TestCaller( + "ConditionsTest::TestEmpty", &ConditionsTest::TestEmpty)); suite.addTest(new CppUnit::TestCaller( "ConditionsTest::TestSafemode", &ConditionsTest::TestSafemode)); suite.addTest(new CppUnit::TestCaller( @@ -210,6 +220,7 @@ ConditionsTest::_Condition(const char* string) CPPUNIT_ASSERT_EQUAL(B_OK, job.FindMessage("if", &message)); Condition* condition = Conditions::FromMessage(message); - CPPUNIT_ASSERT(condition != NULL); + if (string[0] != '\0') + CPPUNIT_ASSERT(condition != NULL); return condition; } diff --git a/src/tests/servers/launch/ConditionsTest.h b/src/tests/servers/launch/ConditionsTest.h index 4ea14e4fc9..fe6036773d 100644 --- a/src/tests/servers/launch/ConditionsTest.h +++ b/src/tests/servers/launch/ConditionsTest.h @@ -18,6 +18,7 @@ public: ConditionsTest(); virtual ~ConditionsTest(); + void TestEmpty(); void TestSafemode(); void TestFileExists(); void TestOr();