Tune the makefile according to new principles, which adds a few bells
and whistles and for clarity.
Synopsis:
* The dependency on opm-common is completely gone. This is reflected in
travis and appveyor as well. No non-kitware cmake modules are used.
* Directories are flattened, quite a bit - source code is located in the
lib/ directory if it belongs to opm-parser, and external/ if third
party.
* The sibling build feature is implemented through cmake's
export(PACKAGE) rather than implicitly looking through source files.
* Targets explicitly set required public and private include
directories, compile options and definitions, which cmake will handle
and propagate
* opm-parser-config.cmake for downstream users is now provided.
* Dependencies are set up using targets. In the future, when cmake 3.x+
can be used, these should be either targets from newer Find modules,
or interface libraries.
* Fewer system specific assumptions are coded in, instead we assume
cmake or users set up system specific details.
* All module wide configuration and looking up libraries is handled in
the root makefile - all sub directories only set up libraries and
compile options for the module in question.
* Targets are defined and links handled transitively because cmake now
is told about them. ${module_LIBRARIES} variables are gone.
This is largely guided by the principles outlined in
https://rix0r.nl/blog/2015/08/13/cmake-guide/
Most source files are just moved - if they have some content change then
it's nothing more than include fixes or similar in order to make them
compile.
612 lines
21 KiB
C++
612 lines
21 KiB
C++
/*
|
|
Copyright 2013 Statoil ASA.
|
|
|
|
This file is part of the Open Porous Media project (OPM).
|
|
|
|
OPM is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
OPM is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
|
|
#define BOOST_TEST_MODULE ParserItemTests
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
#include <opm/json/JsonObject.hpp>
|
|
|
|
#include <opm/parser/eclipse/Parser/ParserEnums.hpp>
|
|
#include <opm/parser/eclipse/Parser/ParserItem.hpp>
|
|
|
|
#include <opm/parser/eclipse/RawDeck/RawRecord.hpp>
|
|
|
|
#include <cmath>
|
|
|
|
using namespace Opm;
|
|
|
|
BOOST_AUTO_TEST_CASE(Initialize) {
|
|
auto sizeType = ParserItem::item_size::SINGLE;
|
|
BOOST_CHECK_NO_THROW(ParserItem item1("ITEM1", sizeType));
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(ScalarCheck) {
|
|
ParserItem item1("ITEM1", ParserItem::item_size::SINGLE );
|
|
ParserItem item2("ITEM1", ParserItem::item_size::ALL );
|
|
|
|
BOOST_CHECK( item1.scalar());
|
|
BOOST_CHECK( !item2.scalar());
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(Initialize_DefaultSizeType) {
|
|
ParserItem item1(std::string("ITEM1"));
|
|
BOOST_CHECK_EQUAL( ParserItem::item_size::SINGLE, item1.sizeType());
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(Initialize_Default) {
|
|
ParserItem item1(std::string("ITEM1"));
|
|
ParserItem item2(std::string("ITEM1"), 88);
|
|
BOOST_CHECK(!item1.hasDefault());
|
|
BOOST_CHECK_THROW(item1.getDefault< int >(), std::invalid_argument);
|
|
BOOST_CHECK(item2.hasDefault());
|
|
BOOST_CHECK_EQUAL(item2.getDefault< int >(), 88);
|
|
}
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(Initialize_Default_Double) {
|
|
ParserItem item1(std::string("ITEM1"));
|
|
ParserItem item2("ITEM1", 88.91);
|
|
BOOST_CHECK(!item1.hasDefault());
|
|
BOOST_CHECK_THROW( item1.getDefault< double >(), std::invalid_argument );
|
|
BOOST_CHECK_EQUAL( 88.91 , item2.getDefault< double >());
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(Initialize_Default_String) {
|
|
ParserItem item1(std::string("ITEM1"));
|
|
BOOST_CHECK(!item1.hasDefault());
|
|
BOOST_CHECK_THROW(item1.getDefault< std::string >(), std::invalid_argument);
|
|
|
|
ParserItem item2("ITEM1", "String");
|
|
BOOST_CHECK(item2.hasDefault());
|
|
BOOST_CHECK_EQUAL( "String" , item2.getDefault< std::string >());
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(scan_PreMatureTerminator_defaultUsed) {
|
|
ParserItem itemInt("ITEM2", 123);
|
|
|
|
RawRecord rawRecord1( "" );
|
|
const auto defaulted = itemInt.scan(rawRecord1);
|
|
|
|
BOOST_CHECK(defaulted.defaultApplied(0));
|
|
BOOST_CHECK_EQUAL(defaulted.get< int >(0), 123);
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(InitializeIntItem_setDescription_canReadBack) {
|
|
ParserItem itemInt("ITEM1");
|
|
std::string description("This is the description");
|
|
itemInt.setDescription(description);
|
|
|
|
BOOST_CHECK_EQUAL( description, itemInt.getDescription() );
|
|
}
|
|
|
|
|
|
/******************************************************************/
|
|
/* <Json> */
|
|
BOOST_AUTO_TEST_CASE(InitializeIntItem_FromJsonObject_missingName_throws) {
|
|
Json::JsonObject jsonConfig("{\"nameX\": \"ITEM1\" , \"size_type\" : \"ALL\"}");
|
|
BOOST_CHECK_THROW( ParserItem item1( jsonConfig ) , std::invalid_argument );
|
|
}
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(InitializeIntItem_FromJsonObject_defaultSizeType) {
|
|
Json::JsonObject jsonConfig("{\"name\": \"ITEM1\", \"value_type\": \"INT\" }");
|
|
ParserItem item1( jsonConfig );
|
|
BOOST_CHECK_EQUAL( ParserItem::item_size::SINGLE , item1.sizeType());
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(InitializeIntItem_FromJsonObject) {
|
|
Json::JsonObject jsonConfig("{\"name\": \"ITEM1\" , \"size_type\" : \"ALL\", \"value_type\": \"INT\" }");
|
|
ParserItem item1( jsonConfig );
|
|
BOOST_CHECK_EQUAL( "ITEM1" , item1.name() );
|
|
BOOST_CHECK_EQUAL( ParserItem::item_size::ALL, item1.sizeType() );
|
|
BOOST_CHECK(item1.getDefault< int >() < 0);
|
|
}
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(InitializeIntItem_FromJsonObject_withDefault) {
|
|
Json::JsonObject jsonConfig("{\"name\": \"ITEM1\" , \"size_type\" : \"SINGLE\", \"default\" : 100, \"value_type\": \"INT\" }");
|
|
ParserItem item1( jsonConfig );
|
|
BOOST_CHECK_EQUAL( 100 , item1.getDefault< int >() );
|
|
}
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(InitializeIntItem_FromJsonObject_withDefaultInvalid_throws) {
|
|
Json::JsonObject jsonConfig("{\"name\": \"ITEM1\" , \"size_type\" : \"SINGLE\", \"default\" : \"100X\"}");
|
|
BOOST_CHECK_THROW( ParserItem item1( jsonConfig ) , std::invalid_argument );
|
|
}
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(InitializeIntItem_FromJsonObject_withSizeTypeALL_throws) {
|
|
Json::JsonObject jsonConfig("{\"name\": \"ITEM1\" , \"value_type\": \"INT\", \"size_type\" : \"ALL\", \"default\" : 100}");
|
|
BOOST_CHECK_THROW( ParserItem item1( jsonConfig ) , std::invalid_argument );
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(InitializeIntItem_WithDescription_DescriptionPropertyShouldBePopulated) {
|
|
std::string description("Description goes here");
|
|
Json::JsonObject jsonConfig("{\"name\": \"ITEM1\" , \"value_type\": \"INT\", \"description\" : \"Description goes here\"}");
|
|
ParserItem item(jsonConfig);
|
|
|
|
BOOST_CHECK_EQUAL( "Description goes here", item.getDescription() );
|
|
}
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(InitializeIntItem_WithoutDescription_DescriptionPropertyShouldBeEmpty) {
|
|
Json::JsonObject jsonConfig("{\"name\": \"ITEM1\", \"value_type\": \"INT\" }");
|
|
ParserItem item(jsonConfig);
|
|
|
|
BOOST_CHECK_EQUAL( "", item.getDescription() );
|
|
}
|
|
|
|
|
|
|
|
/* </Json> */
|
|
/******************************************************************/
|
|
|
|
/* EQUAL */
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(IntItem_Equal_ReturnsTrue) {
|
|
auto sizeType = ParserItem::item_size::ALL;
|
|
ParserItem item1("ITEM1", sizeType);
|
|
ParserItem item2("ITEM1", sizeType);
|
|
ParserItem item3 = item1;
|
|
|
|
BOOST_CHECK_EQUAL( item1, item2 );
|
|
BOOST_CHECK_EQUAL( item1, item3 );
|
|
}
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(IntItem_Different_ReturnsFalse) {
|
|
ParserItem item1("ITEM1", ParserItem::item_size::ALL);
|
|
ParserItem item2("ITEM2", ParserItem::item_size::ALL);
|
|
ParserItem item3("ITEM1");
|
|
ParserItem item4("ITEM1" , 42);
|
|
|
|
BOOST_CHECK_NE( item1, item2 );
|
|
BOOST_CHECK_NE( item1, item3 );
|
|
BOOST_CHECK_NE( item2, item3 );
|
|
BOOST_CHECK_NE( item4, item3 );
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(DoubleItem_DimEqual_ReturnsTrue) {
|
|
auto sizeType = ParserItem::item_size::ALL;
|
|
ParserItem item1("ITEM1", sizeType, 0.0);
|
|
ParserItem item2("ITEM1", sizeType, 0.0);
|
|
|
|
item1.push_backDimension("Length*Length");
|
|
item2.push_backDimension("Length*Length");
|
|
|
|
BOOST_CHECK_EQUAL( item1, item2 );
|
|
}
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(DoubleItem_DimDifferent_ReturnsFalse) {
|
|
auto sizeType = ParserItem::item_size::ALL;
|
|
ParserItem item1("ITEM1", sizeType, 0.0); // Dim: []
|
|
ParserItem item2("ITEM1", sizeType, 0.0); // Dim: [Length]
|
|
ParserItem item3("ITEM1", sizeType, 0.0); // Dim: [Length ,Length]
|
|
ParserItem item4("ITEM1", sizeType, 0.0); // Dim: [t]
|
|
|
|
item2.push_backDimension("Length");
|
|
item3.push_backDimension("Length");
|
|
item3.push_backDimension("Length");
|
|
item4.push_backDimension("Time");
|
|
|
|
BOOST_CHECK_NE(item1, item2 );
|
|
BOOST_CHECK_NE(item2, item3 );
|
|
BOOST_CHECK_NE(item2, item1 );
|
|
BOOST_CHECK_NE(item2, item4 );
|
|
BOOST_CHECK_NE(item1, item3 );
|
|
BOOST_CHECK_NE(item3, item1 );
|
|
BOOST_CHECK_NE(item4, item2 );
|
|
}
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(DoubleItem_Different_ReturnsFalse) {
|
|
ParserItem item1("ITEM1", ParserItem::item_size::ALL, 0.0);
|
|
ParserItem item2("ITEM2", ParserItem::item_size::ALL, 0.0);
|
|
ParserItem item3("ITEM1", 0.0 );
|
|
ParserItem item4("ITEM1", 42.89);
|
|
|
|
BOOST_CHECK_NE( item1, item2 );
|
|
BOOST_CHECK_NE( item1, item3 );
|
|
BOOST_CHECK_NE( item2, item3 );
|
|
BOOST_CHECK_NE( item4, item3 );
|
|
}
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(StringItem_Equal_ReturnsTrue) {
|
|
auto sizeType = ParserItem::item_size::ALL;
|
|
ParserItem item1("ITEM1", sizeType, "");
|
|
ParserItem item2("ITEM1", sizeType, "");
|
|
ParserItem item3 = item1;
|
|
|
|
BOOST_CHECK_EQUAL( item1, item2 );
|
|
BOOST_CHECK_EQUAL( item1, item3 );
|
|
}
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(StringItem_Different_ReturnsFalse) {
|
|
ParserItem item1("ITEM1", ParserItem::item_size::ALL, "");
|
|
ParserItem item2("ITEM2", ParserItem::item_size::ALL, "");
|
|
ParserItem item3("ITEM1", "" );
|
|
ParserItem item4("ITEM1", "42.89");
|
|
|
|
BOOST_CHECK_NE( item1, item2 );
|
|
BOOST_CHECK_NE( item1, item3 );
|
|
BOOST_CHECK_NE( item2, item3 );
|
|
BOOST_CHECK_NE( item4, item3 );
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************************************************/
|
|
|
|
BOOST_AUTO_TEST_CASE(Name_ReturnsCorrectName) {
|
|
auto sizeType = ParserItem::item_size::ALL;
|
|
|
|
ParserItem item1("ITEM1", sizeType);
|
|
BOOST_CHECK_EQUAL("ITEM1", item1.name());
|
|
|
|
ParserItem item2("", sizeType);
|
|
BOOST_CHECK_EQUAL("", item2.name());
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(Size_ReturnsCorrectSizeTypeSingle) {
|
|
auto sizeType = ParserItem::item_size::SINGLE;
|
|
ParserItem item1("ITEM1", sizeType);
|
|
BOOST_CHECK_EQUAL(sizeType, item1.sizeType());
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(Size_ReturnsCorrectSizeTypeAll) {
|
|
auto sizeType = ParserItem::item_size::ALL;
|
|
ParserItem item1("ITEM1", sizeType);
|
|
BOOST_CHECK_EQUAL(sizeType, item1.sizeType());
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(Scan_All_CorrectIntSetInDeckItem) {
|
|
auto sizeType = ParserItem::item_size::ALL;
|
|
ParserItem itemInt("ITEM", sizeType, 0);
|
|
|
|
RawRecord rawRecord( "100 443 10*77 10*1 25" );
|
|
const auto deckIntItem = itemInt.scan(rawRecord);
|
|
BOOST_CHECK_EQUAL(23U, deckIntItem.size());
|
|
BOOST_CHECK_EQUAL(77, deckIntItem.get< int >(3));
|
|
BOOST_CHECK_EQUAL(1, deckIntItem.get< int >(21));
|
|
BOOST_CHECK_EQUAL(25, deckIntItem.get< int >(22));
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(Scan_All_WithDefaults) {
|
|
auto sizeType = ParserItem::item_size::ALL;
|
|
ParserItem itemInt("ITEM", sizeType);
|
|
itemInt.setType( int() );
|
|
|
|
RawRecord rawRecord( "100 10* 10*1 25" );
|
|
const auto deckIntItem = itemInt.scan(rawRecord);
|
|
BOOST_CHECK_EQUAL(22U, deckIntItem.size());
|
|
BOOST_CHECK(!deckIntItem.defaultApplied(0));
|
|
BOOST_CHECK( deckIntItem.defaultApplied(1));
|
|
BOOST_CHECK(!deckIntItem.defaultApplied(11));
|
|
BOOST_CHECK(!deckIntItem.defaultApplied(21));
|
|
BOOST_CHECK_EQUAL(1, deckIntItem.get< int >(20));
|
|
BOOST_CHECK_EQUAL(25, deckIntItem.get< int >(21));
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(Scan_SINGLE_CorrectIntSetInDeckItem) {
|
|
ParserItem itemInt(std::string("ITEM2"), 0);
|
|
|
|
RawRecord rawRecord("100 44.3 'Heisann'" );
|
|
const auto deckIntItem = itemInt.scan(rawRecord);
|
|
BOOST_CHECK_EQUAL(100, deckIntItem.get< int >(0));
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(Scan_SeveralInts_CorrectIntsSetInDeckItem) {
|
|
ParserItem itemInt1(std::string("ITEM1"), 0);
|
|
ParserItem itemInt2(std::string("ITEM2"), 0);
|
|
ParserItem itemInt3(std::string("ITEM3"), 0);
|
|
|
|
RawRecord rawRecord( "100 443 338932 222.33 'Heisann' " );
|
|
const auto deckIntItem1 = itemInt1.scan(rawRecord);
|
|
BOOST_CHECK_EQUAL(100, deckIntItem1.get< int >(0));
|
|
|
|
const auto deckIntItem2 = itemInt2.scan(rawRecord);
|
|
BOOST_CHECK_EQUAL(443, deckIntItem2.get< int >(0));
|
|
|
|
const auto deckIntItem3 = itemInt3.scan(rawRecord);
|
|
BOOST_CHECK_EQUAL(338932, deckIntItem3.get< int >(0));
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(Scan_Multiplier_CorrectIntsSetInDeckItem) {
|
|
auto sizeType = ParserItem::item_size::ALL;
|
|
ParserItem itemInt("ITEM2", sizeType, 0);
|
|
|
|
RawRecord rawRecord( "3*4 " );
|
|
const auto deckIntItem = itemInt.scan(rawRecord);
|
|
BOOST_CHECK_EQUAL(4, deckIntItem.get< int >(0));
|
|
BOOST_CHECK_EQUAL(4, deckIntItem.get< int >(1));
|
|
BOOST_CHECK_EQUAL(4, deckIntItem.get< int >(2));
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(Scan_StarNoMultiplier_ExceptionThrown) {
|
|
auto sizeType = ParserItem::item_size::SINGLE;
|
|
ParserItem itemInt("ITEM2", sizeType , 100);
|
|
|
|
RawRecord rawRecord( "*45 " );
|
|
BOOST_CHECK_THROW(itemInt.scan(rawRecord), std::invalid_argument);
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(Scan_MultipleItems_CorrectIntsSetInDeckItem) {
|
|
ParserItem itemInt1(std::string("ITEM1"), 0);
|
|
ParserItem itemInt2(std::string("ITEM2"), 0);
|
|
|
|
RawRecord rawRecord( "10 20" );
|
|
const auto deckIntItem1 = itemInt1.scan(rawRecord);
|
|
const auto deckIntItem2 = itemInt2.scan(rawRecord);
|
|
|
|
BOOST_CHECK_EQUAL(10, deckIntItem1.get< int >(0));
|
|
BOOST_CHECK_EQUAL(20, deckIntItem2.get< int >(0));
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(Scan_MultipleDefault_CorrectIntsSetInDeckItem) {
|
|
ParserItem itemInt1("ITEM1", 10);
|
|
ParserItem itemInt2("ITEM2", 20);
|
|
|
|
RawRecord rawRecord( "* * " );
|
|
const auto deckIntItem1 = itemInt1.scan(rawRecord);
|
|
const auto deckIntItem2 = itemInt2.scan(rawRecord);
|
|
|
|
BOOST_CHECK_EQUAL(10, deckIntItem1.get< int >(0));
|
|
BOOST_CHECK_EQUAL(20, deckIntItem2.get< int >(0));
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(Scan_MultipleWithMultiplier_CorrectIntsSetInDeckItem) {
|
|
ParserItem itemInt1("ITEM1", 10);
|
|
ParserItem itemInt2("ITEM2", 20);
|
|
|
|
RawRecord rawRecord( "2*30" );
|
|
const auto deckIntItem1 = itemInt1.scan(rawRecord);
|
|
const auto deckIntItem2 = itemInt2.scan(rawRecord);
|
|
|
|
BOOST_CHECK_EQUAL(30, deckIntItem1.get< int >(0));
|
|
BOOST_CHECK_EQUAL(30, deckIntItem2.get< int >(0));
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(Scan_MalformedMultiplier_Throw) {
|
|
ParserItem itemInt1("ITEM1" , 10);
|
|
|
|
RawRecord rawRecord( "2.10*30" );
|
|
BOOST_CHECK_THROW(itemInt1.scan(rawRecord), std::invalid_argument);
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(Scan_MalformedMultiplierChar_Throw) {
|
|
ParserItem itemInt1("ITEM1", 10);
|
|
|
|
RawRecord rawRecord( "210X30" );
|
|
BOOST_CHECK_THROW(itemInt1.scan(rawRecord), std::invalid_argument);
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(Scan_MultipleWithMultiplierDefault_CorrectIntsSetInDeckItem) {
|
|
ParserItem itemInt1("ITEM1", 10);
|
|
ParserItem itemInt2("ITEM2", 20);
|
|
|
|
RawRecord rawRecord( "2*" );
|
|
const auto deckIntItem1 = itemInt1.scan(rawRecord);
|
|
const auto deckIntItem2 = itemInt2.scan(rawRecord);
|
|
|
|
BOOST_CHECK_EQUAL(10, deckIntItem1.get< int >(0));
|
|
BOOST_CHECK_EQUAL(20, deckIntItem2.get< int >(0));
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(Scan_RawRecordErrorInRawData_ExceptionThrown) {
|
|
ParserItem itemInt(std::string("ITEM2"), 0);
|
|
|
|
// Wrong type
|
|
RawRecord rawRecord2( "333.2 /" );
|
|
BOOST_CHECK_THROW(itemInt.scan(rawRecord2), std::invalid_argument);
|
|
|
|
// Wrong type
|
|
RawRecord rawRecord3( "100X /" );
|
|
BOOST_CHECK_THROW(itemInt.scan(rawRecord3), std::invalid_argument);
|
|
|
|
// Wrong type
|
|
RawRecord rawRecord5( "astring /" );
|
|
BOOST_CHECK_THROW(itemInt.scan(rawRecord5), std::invalid_argument);
|
|
}
|
|
|
|
/*********************String************************'*/
|
|
/*****************************************************************/
|
|
/*</json>*/
|
|
|
|
BOOST_AUTO_TEST_CASE(InitializeStringItem_FromJsonObject_missingName_throws) {
|
|
Json::JsonObject jsonConfig("{\"nameX\": \"ITEM1\" , \"size_type\" : \"ALL\"}");
|
|
BOOST_CHECK_THROW( ParserItem item1( jsonConfig ) , std::invalid_argument );
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(InitializeStringItem_FromJsonObject_withDefault) {
|
|
Json::JsonObject jsonConfig("{\"name\": \"ITEM1\" , \"value_type\": \"STRING\", \"size_type\" : \"SINGLE\", \"default\" : \"100\"}");
|
|
ParserItem item1( jsonConfig );
|
|
BOOST_CHECK_EQUAL( "100" , item1.getDefault< std::string >() );
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(InitializeStringItem_FromJsonObject_withDefaultInvalid_throws) {
|
|
Json::JsonObject jsonConfig("{\"name\": \"ITEM1\" , \"size_type\" : \"ALL\", \"default\" : [1,2,3]}");
|
|
BOOST_CHECK_THROW( ParserItem item1( jsonConfig ) , std::invalid_argument );
|
|
}
|
|
/*</json>*/
|
|
/*****************************************************************/
|
|
|
|
BOOST_AUTO_TEST_CASE(init_defaultvalue_defaultset) {
|
|
ParserItem itemString(std::string("ITEM1") , "DEFAULT");
|
|
RawRecord rawRecord( "'1*'" );
|
|
BOOST_CHECK_EQUAL("1*", itemString.scan( rawRecord ).get< std::string >(0) );
|
|
|
|
RawRecord rawRecord1( "13*" );
|
|
BOOST_CHECK_EQUAL("DEFAULT" , itemString.scan( rawRecord1 ).get< std::string >(0) );
|
|
|
|
RawRecord rawRecord2( "*" );
|
|
BOOST_CHECK_EQUAL("DEFAULT", itemString.scan( rawRecord2 ).get< std::string >(0) );
|
|
|
|
ParserItem itemStringDefaultChanged("ITEM2", "SPECIAL");
|
|
RawRecord rawRecord3( "*" );
|
|
BOOST_CHECK_EQUAL("SPECIAL", itemStringDefaultChanged.scan( rawRecord3 ).get< std::string >(0) );
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(scan_all_valuesCorrect) {
|
|
auto sizeType = ParserItem::item_size::ALL;
|
|
ParserItem itemString("ITEMWITHMANY", sizeType, "");
|
|
RawRecord rawRecord( "'WELL1' FISK BANAN 3*X OPPLEGG_FOR_DATAANALYSE 'Foo$*!% BAR' " );
|
|
const auto deckItem = itemString.scan(rawRecord);
|
|
BOOST_CHECK_EQUAL(8U, deckItem.size());
|
|
|
|
BOOST_CHECK_EQUAL("WELL1", deckItem.get< std::string >(0));
|
|
BOOST_CHECK_EQUAL("FISK", deckItem.get< std::string >(1));
|
|
BOOST_CHECK_EQUAL("BANAN", deckItem.get< std::string >(2));
|
|
BOOST_CHECK_EQUAL("X", deckItem.get< std::string >(3));
|
|
BOOST_CHECK_EQUAL("X", deckItem.get< std::string >(4));
|
|
BOOST_CHECK_EQUAL("X", deckItem.get< std::string >(5));
|
|
BOOST_CHECK_EQUAL("OPPLEGG_FOR_DATAANALYSE", deckItem.get< std::string >(6));
|
|
BOOST_CHECK_EQUAL("Foo$*!% BAR", deckItem.get< std::string >(7));
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(scan_all_withdefaults) {
|
|
auto sizeType = ParserItem::item_size::ALL;
|
|
ParserItem itemString("ITEMWITHMANY", sizeType, 0);
|
|
RawRecord rawRecord( "10*1 10* 10*2 " );
|
|
const auto deckItem = itemString.scan(rawRecord);
|
|
|
|
BOOST_CHECK_EQUAL(30U, deckItem.size());
|
|
|
|
BOOST_CHECK( !deckItem.defaultApplied(0) );
|
|
BOOST_CHECK( !deckItem.defaultApplied(9) );
|
|
BOOST_CHECK( deckItem.defaultApplied(10) );
|
|
BOOST_CHECK( deckItem.defaultApplied(19) );
|
|
BOOST_CHECK( !deckItem.defaultApplied(20) );
|
|
BOOST_CHECK( !deckItem.defaultApplied(29) );
|
|
|
|
BOOST_CHECK_THROW(deckItem.get< int >(30), std::out_of_range);
|
|
BOOST_CHECK_THROW(deckItem.defaultApplied(30), std::out_of_range);
|
|
|
|
BOOST_CHECK_EQUAL(1, deckItem.get< int >(0));
|
|
BOOST_CHECK_EQUAL(1, deckItem.get< int >(9));
|
|
BOOST_CHECK_EQUAL(2, deckItem.get< int >(20));
|
|
BOOST_CHECK_EQUAL(2, deckItem.get< int >(29));
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(scan_single_dataCorrect) {
|
|
ParserItem itemString( "ITEM1", "");
|
|
RawRecord rawRecord( "'WELL1' 'WELL2'" );
|
|
const auto deckItem = itemString.scan(rawRecord);
|
|
BOOST_CHECK_EQUAL(1U, deckItem.size());
|
|
BOOST_CHECK_EQUAL("WELL1", deckItem.get< std::string >(0));
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(scan_singleWithMixedRecord_dataCorrect) {
|
|
ParserItem itemString("ITEM1", "");
|
|
ParserItem itemInt("ITEM1", "");
|
|
|
|
RawRecord rawRecord( "2 'WELL1' /" );
|
|
itemInt.scan(rawRecord);
|
|
const auto deckItem = itemString.scan(rawRecord);
|
|
BOOST_CHECK_EQUAL("WELL1", deckItem.get< std::string >(0));
|
|
}
|
|
|
|
/******************String and int**********************/
|
|
BOOST_AUTO_TEST_CASE(scan_intsAndStrings_dataCorrect) {
|
|
RawRecord rawRecord( "'WELL1' 2 2 2*3" );
|
|
|
|
auto sizeTypeItemBoxed = ParserItem::item_size::ALL;
|
|
|
|
ParserItem itemSingleString(std::string("ITEM1"), "");
|
|
const auto deckItemWell1 = itemSingleString.scan(rawRecord);
|
|
BOOST_CHECK_EQUAL("WELL1", deckItemWell1.get< std::string >(0));
|
|
|
|
ParserItem itemSomeInts("SOMEINTS", sizeTypeItemBoxed, 0 );
|
|
const auto deckItemInts = itemSomeInts.scan(rawRecord);
|
|
BOOST_CHECK_EQUAL(2, deckItemInts.get< int >(0));
|
|
BOOST_CHECK_EQUAL(2, deckItemInts.get< int >(1));
|
|
BOOST_CHECK_EQUAL(3, deckItemInts.get< int >(2));
|
|
BOOST_CHECK_EQUAL(3, deckItemInts.get< int >(3));
|
|
}
|
|
|
|
/*****************************************************************/
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(ParserDefaultHasDimensionReturnsFalse) {
|
|
ParserItem intItem(std::string("SOMEINTS"), 0);
|
|
ParserItem stringItem(std::string("SOMESTRING"), "");
|
|
ParserItem doubleItem(std::string("SOMEDOUBLE"), 0.0);
|
|
|
|
BOOST_CHECK( !intItem.hasDimension() );
|
|
BOOST_CHECK( !stringItem.hasDimension() );
|
|
BOOST_CHECK( !doubleItem.hasDimension() );
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(ParserIntItemGetDimensionThrows) {
|
|
ParserItem intItem(std::string("SOMEINT"));
|
|
|
|
BOOST_CHECK_THROW( intItem.getDimension(0) , std::invalid_argument );
|
|
BOOST_CHECK_THROW( intItem.push_backDimension("Length") , std::invalid_argument );
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(ParserDoubleItemAddMultipleDimensionToSIngleSizeThrows) {
|
|
ParserItem doubleItem(std::string("SOMEDOUBLE"), 0.0);
|
|
|
|
doubleItem.push_backDimension("Length*Length");
|
|
BOOST_CHECK_THROW( doubleItem.push_backDimension("Length*Length"), std::invalid_argument);
|
|
}
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(ParserDoubleItemWithDimensionHasReturnsCorrect) {
|
|
ParserItem doubleItem("SOMEDOUBLE", 0.0);
|
|
|
|
BOOST_CHECK( !doubleItem.hasDimension() );
|
|
doubleItem.push_backDimension("Length*Length");
|
|
BOOST_CHECK( doubleItem.hasDimension() );
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(ParserDoubleItemGetDimension) {
|
|
ParserItem doubleItem( "SOMEDOUBLE" , ParserItem::item_size::ALL, 0.0 );
|
|
|
|
BOOST_CHECK_THROW( doubleItem.getDimension( 10 ) , std::out_of_range );
|
|
BOOST_CHECK_THROW( doubleItem.getDimension( 0 ) , std::out_of_range );
|
|
|
|
doubleItem.push_backDimension("Length");
|
|
doubleItem.push_backDimension("Length*Length");
|
|
doubleItem.push_backDimension("Length*Length*Length");
|
|
|
|
BOOST_CHECK_EQUAL( "Length" , doubleItem.getDimension(0));
|
|
BOOST_CHECK_EQUAL( "Length*Length" , doubleItem.getDimension(1));
|
|
BOOST_CHECK_EQUAL( "Length*Length*Length" , doubleItem.getDimension(2));
|
|
BOOST_CHECK_THROW( doubleItem.getDimension( 3 ) , std::out_of_range );
|
|
}
|