Added Json parsing of action attribute

This commit is contained in:
Joakim Hove 2013-10-08 14:13:45 +02:00
parent e6b38c6445
commit cc21644c9e
2 changed files with 25 additions and 3 deletions

View File

@ -114,8 +114,13 @@ namespace Opm {
ParserKeyword::ParserKeyword(const Json::JsonObject& jsonConfig) {
ParserKeywordActionEnum action = INTERNALIZE;
if (jsonConfig.has_item("action"))
action = ParserKeywordActionEnumFromString( jsonConfig.get_string("action") );
if (jsonConfig.has_item("name")) {
commonInit(jsonConfig.get_string("name") , INTERNALIZE);
commonInit(jsonConfig.get_string("name") , action);
} else
throw std::invalid_argument("Json object is missing name: property");
@ -130,7 +135,7 @@ namespace Opm {
if (isTableCollection())
addTableItems();
if (m_fixedSize == 0 && m_keywordSizeType == FIXED)
if ((m_fixedSize == 0 && m_keywordSizeType == FIXED) || (m_action != INTERNALIZE))
return;
else {
if (numItems() == 0)
@ -345,7 +350,8 @@ namespace Opm {
(m_record->equal( *(other.m_record) )) &&
(m_keywordSizeType == other.m_keywordSizeType) &&
(m_isDataKeyword == other.m_isDataKeyword) &&
(m_isTableCollection == other.m_isTableCollection))
(m_isTableCollection == other.m_isTableCollection) &&
(m_action == other.m_action))
{
bool equal = false;
switch(m_keywordSizeType) {

View File

@ -130,8 +130,18 @@ BOOST_AUTO_TEST_CASE(ConstructFromJsonObject) {
}
BOOST_AUTO_TEST_CASE(ConstructFromJsonObjectWithActionInvalidThrows) {
Json::JsonObject jsonObject("{\"name\": \"XXX\" , \"size\" : 0, \"action\" : \"WhatEver?\"}");
BOOST_CHECK_THROW(ParserKeyword parserKeyword(jsonObject) , std::invalid_argument);
}
BOOST_AUTO_TEST_CASE(ConstructFromJsonObjectWithAction) {
Json::JsonObject jsonObject("{\"name\": \"XXX\" , \"size\" : 0, \"action\" : \"IGNORE\"}");
ParserKeyword parserKeyword(jsonObject);
BOOST_CHECK_EQUAL( IGNORE , parserKeyword.getAction() );
}
BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_withSize) {
Json::JsonObject jsonObject("{\"name\": \"BPR\", \"size\" : 100 , \"items\" :[{\"name\":\"ItemX\" , \"size_type\":\"SINGLE\" , \"value_type\" : \"FLOAT\"}]}");
@ -150,6 +160,12 @@ BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_missingItemThrows) {
BOOST_CHECK_THROW( ParserKeyword parserKeyword(jsonObject) , std::invalid_argument);
}
BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_missingItemActionIgnoreOK) {
Json::JsonObject jsonObject("{\"name\": \"BPR\", \"size\" : 100, \"action\" : \"IGNORE\"}");
BOOST_CHECK_NO_THROW( ParserKeyword parserKeyword(jsonObject));
}
BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_nosize_notItems_OK) {
Json::JsonObject jsonObject("{\"name\": \"BPR\"}");
ParserKeyword parserKeyword(jsonObject);