Added inlineNew() method to create ParserRecord

This commit is contained in:
Joakim Hove
2013-09-13 12:34:38 +02:00
parent 414752b78a
commit b36fa7d42c
4 changed files with 110 additions and 0 deletions

View File

@@ -87,4 +87,22 @@ namespace Opm {
return equal;
}
void ParserRecord::inlineNew(std::ostream& os , const std::string& lhs) const {
os << "ParserRecord * " << lhs << " = new ParserRecord();" << std::endl;
os << "{" << std::endl;
for (size_t i = 0; i < size(); i++) {
os << " {" << std::endl;
{
ParserItemConstPtr item = get(i);
os << " ParserItemConstPtr item(";
item->inlineNew(os);
os << ");" << std::endl;
os << " " << lhs << "->addItem(item);" << std::endl;
}
os << " }" << std::endl;
}
os << "}" << std::endl;
}
}

View File

@@ -39,6 +39,7 @@ namespace Opm {
ParserItemConstPtr get(const std::string& itemName) const;
DeckRecordConstPtr parse(RawRecordPtr rawRecord) const;
bool equal(const ParserRecord& other) const;
void inlineNew(std::ostream& os , const std::string& lhs) const;
private:
std::vector<ParserItemConstPtr> m_items;
std::map<std::string , ParserItemConstPtr> m_itemMap;

View File

@@ -33,3 +33,19 @@ add_custom_command( OUTPUT inlineItemTest.cpp
add_executable( inlineItemTest ${CMAKE_CURRENT_BINARY_DIR}/inlineItemTest.cpp )
target_link_libraries( inlineItemTest Parser ${Boost_LIBRARIES} )
add_test(inlineItemTest ${EXECUTABLE_OUTPUT_PATH}/inlineItemTest)
#-----------------------------------------------------------------
add_executable( createInlineRecordTest createInlineRecordTest.cpp )
target_link_libraries( createInlineRecordTest Parser ${Boost_LIBRARIES} )
add_custom_command( OUTPUT inlineRecordTest.cpp
COMMAND createInlineRecordTest ${CMAKE_CURRENT_BINARY_DIR}/inlineRecordTest.cpp inlineRecordTest
DEPENDS createInlineRecordTest )
add_executable( inlineRecordTest ${CMAKE_CURRENT_BINARY_DIR}/inlineRecordTest.cpp )
target_link_libraries( inlineRecordTest Parser ${Boost_LIBRARIES} )
add_test(inlineRecordTest ${EXECUTABLE_OUTPUT_PATH}/inlineRecordTest)

View File

@@ -0,0 +1,75 @@
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <string.h>
#include <opm/parser/eclipse/Parser/ParserItem.hpp>
#include <opm/parser/eclipse/Parser/ParserIntItem.hpp>
#include <opm/parser/eclipse/Parser/ParserStringItem.hpp>
#include <opm/parser/eclipse/Parser/ParserDoubleItem.hpp>
#include <opm/parser/eclipse/Parser/ParserRecord.hpp>
using namespace Opm;
void createHeader(std::ofstream& of , const std::string& test_module) {
of << "#define BOOST_TEST_MODULE " << test_module << std::endl;
of << "#include <boost/test/unit_test.hpp>" << std::endl;
of << "#include <opm/parser/eclipse/Parser/ParserItem.hpp>" << std::endl;
of << "#include <opm/parser/eclipse/Parser/ParserIntItem.hpp>" << std::endl;
of << "#include <opm/parser/eclipse/Parser/ParserStringItem.hpp>" << std::endl;
of << "#include <opm/parser/eclipse/Parser/ParserDoubleItem.hpp>" << std::endl;
of << "#include <opm/parser/eclipse/Parser/ParserRecord.hpp>" << std::endl;
of << "using namespace Opm;" << std::endl << std::endl;
}
void startTest(std::ofstream& of, const std::string& test_name) {
of << "BOOST_AUTO_TEST_CASE(" << test_name << ") {" << std::endl;
}
void endTest(std::ofstream& of) {
of << "}" << std::endl << std::endl;
}
void recordsEqual(std::ofstream& of) {
startTest(of , "recordsEqual");
of << "ParserIntItemPtr itemInt(new ParserIntItem(\"INTITEM1\", SINGLE , 0));" << std::endl;
of << "ParserDoubleItemPtr itemDouble(new ParserDoubleItem(\"DOUBLEITEM1\", SINGLE , 0));" << std::endl;
of << "ParserStringItemPtr itemString(new ParserStringItem(\"STRINGITEM1\", SINGLE));" << std::endl;
of << "ParserRecordPtr record(new ParserRecord());" << std::endl;
of << "record->addItem(itemInt);" << std::endl;
of << "record->addItem(itemDouble);" << std::endl;
of << "record->addItem(itemString);" << std::endl;
ParserIntItemPtr itemInt(new ParserIntItem("INTITEM1", SINGLE , 0));
ParserDoubleItemPtr itemDouble(new ParserDoubleItem("DOUBLEITEM1", SINGLE , 0));
ParserStringItemPtr itemString(new ParserStringItem("STRINGITEM1", SINGLE));
ParserRecordPtr record(new ParserRecord());
record->addItem(itemInt);
record->addItem(itemDouble);
record->addItem(itemString);
record->inlineNew(of , "inlineRecord");
of << "BOOST_CHECK( record->equal( *inlineRecord));" << std::endl;
endTest(of);
}
int main(int argc , char ** argv) {
const char * test_src = argv[1];
const char * test_module = argv[2];
std::ofstream of( test_src );
createHeader(of , test_module);
recordsEqual(of);
of.close();
}