Commit a3757c7d authored by Gigg, Martyn Anthony's avatar Gigg, Martyn Anthony
Browse files

Add null pointer check to FunctionProperty::value.

Also updates the unit test to test for this behaviour. Refs #7004
parent 797e174f
......@@ -62,7 +62,8 @@ namespace API
*/
std::string FunctionProperty::value() const
{
return m_value->asString();
if(m_value) return m_value->asString();
else return getDefault();
}
/** Get the value the property was initialised with -its default value
......@@ -99,7 +100,7 @@ namespace API
*/
std::string FunctionProperty::isValid() const
{
return isDefault() ? "Funcion is empty." : "";
return isDefault() ? "Function is empty." : "";
}
/** Indicates if the function has not been created yet.
......
......@@ -41,6 +41,8 @@ public:
void testValue()
{
FunctionProperty prop("fun");
TS_ASSERT_EQUALS("", prop.value());
std::string error;
TS_ASSERT_THROWS_NOTHING(error = prop.setValue("name=FunctionPropertyTest_Function,A=3"));
TS_ASSERT(error.empty());
......
......@@ -30,6 +30,11 @@ class FunctionPropertyTest(unittest.TestCase):
func = FunctionProperty("fun")
self.assertEqual("Function", func.type)
def test_value_is_empty_string_for_default_property(self):
func = FunctionProperty("name")
self.assertEquals(None, func.value)
self.assertEquals("", func.valueAsStr)
def test_valid_string_value_gives_function_object_as_value(self):
alg=self.TestFunctionPropAlg()
alg.initialize()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment