Ignore:
Timestamp:
Oct 14, 2011, 3:15:30 PM (13 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
d3d6c6
Parents:
9a6b76e
git-author:
Frederik Heber <heber@…> (09/27/11 19:04:36)
git-committer:
Frederik Heber <heber@…> (10/14/11 15:15:30)
Message:

Huge Refactoring of FormatParserStorage and all FormatParser's.

FormatParser:

FormatParserStorage:

  • We construct all lookup tables and alikes via boost preprocessor magic from a list of all available parser (enums).
  • we use the templated getParser() and addParser() functions to serve parsers to the outside. Instances are as usual created only once.

Tests:

  • tests only had to be changed because of the "renaming" of the Parsers.
Location:
src/Parser/unittests
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/unittests/ParserMpqcUnitTest.cpp

    r9a6b76e r765f16  
    3232#include "Descriptors/AtomTypeDescriptor.hpp"
    3333#include "CodePatterns/Assert.hpp"
     34#include "Parser/ChangeTracker.hpp"
     35#include "Parser/MpqcParser.hpp"
    3436
    3537#ifdef HAVE_TESTRUNNER
     
    157159
    158160void ParserMpqcUnitTest::setUp() {
    159   mpqc = new MpqcParser();
     161  parser = new FormatParser<mpqc>();
    160162
    161163  World::getInstance();
     
    169171
    170172void ParserMpqcUnitTest::tearDown() {
    171   delete mpqc;
     173  delete parser;
    172174  ChangeTracker::purgeInstance();
    173175  World::purgeInstance();
     
    178180void ParserMpqcUnitTest::ParameterTypeTest() {
    179181  // check types in boost::any map
    180   CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::hessianParam].type() == typeid(bool));
    181   CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::hessianParam].type() != typeid(int));
    182   CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::savestateParam].type() == typeid(bool));
    183   CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::do_gradientParam].type() == typeid(bool));
    184   CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::maxiterParam].type() == typeid(int));
    185   CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::memoryParam].type() == typeid(int));
    186   CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::stdapproxParam].type() == typeid(std::string));
    187   CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::nfzcParam].type() == typeid(int));
    188   CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::basisParam].type() == typeid(std::string));
    189   CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::aux_basisParam].type() == typeid(std::string));
    190   CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::integrationParam].type() == typeid(MpqcParser_Parameters::IntegralCints));
    191   CPPUNIT_ASSERT(mpqc->getParams().params[MpqcParser_Parameters::theoryParam].type() == typeid(MpqcParser_Parameters::MBPT2));
     182  CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::hessianParam].type() == typeid(bool));
     183  CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::hessianParam].type() != typeid(int));
     184  CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::savestateParam].type() == typeid(bool));
     185  CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::do_gradientParam].type() == typeid(bool));
     186  CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::maxiterParam].type() == typeid(int));
     187  CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::memoryParam].type() == typeid(int));
     188  CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::stdapproxParam].type() == typeid(std::string));
     189  CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::nfzcParam].type() == typeid(int));
     190  CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::basisParam].type() == typeid(std::string));
     191  CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::aux_basisParam].type() == typeid(std::string));
     192  CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::integrationParam].type() == typeid(MpqcParser_Parameters::IntegralCints));
     193  CPPUNIT_ASSERT(parser->getParams().params[MpqcParser_Parameters::theoryParam].type() == typeid(MpqcParser_Parameters::MBPT2));
    192194}
    193195
    194196void ParserMpqcUnitTest::ParameterDefaultTest() {
    195197  // check default values
    196   CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::hessianParam) == "no");
    197   CPPUNIT_ASSERT(!mpqc->getParams().getBool(MpqcParser_Parameters::hessianParam));
    198   CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::savestateParam) == "no");
    199   CPPUNIT_ASSERT(!mpqc->getParams().getBool(MpqcParser_Parameters::savestateParam));
    200   CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::do_gradientParam) == "yes");
    201   CPPUNIT_ASSERT(mpqc->getParams().getBool(MpqcParser_Parameters::do_gradientParam));
    202   CPPUNIT_ASSERT(mpqc->getParams().getInt(MpqcParser_Parameters::maxiterParam) == 1000);
    203   CPPUNIT_ASSERT(mpqc->getParams().getInt(MpqcParser_Parameters::memoryParam) == 16000000);
    204   CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::stdapproxParam) == "A'");
    205   CPPUNIT_ASSERT(mpqc->getParams().getInt(MpqcParser_Parameters::nfzcParam) == 1);
    206   CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::basisParam) == "3-21G");
    207   CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::aux_basisParam) == "aug-cc-pVDZ");
    208   CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::integrationParam) == "IntegralCints");
    209   CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::theoryParam) == "MBPT2");
    210   CPPUNIT_ASSERT(mpqc->getParams().getTheory() == MpqcParser_Parameters::MBPT2);
    211   CPPUNIT_ASSERT(mpqc->getParams().getIntegration() == MpqcParser_Parameters::IntegralCints);
     198  CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::hessianParam) == "no");
     199  CPPUNIT_ASSERT(!parser->getParams().getBool(MpqcParser_Parameters::hessianParam));
     200  CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::savestateParam) == "no");
     201  CPPUNIT_ASSERT(!parser->getParams().getBool(MpqcParser_Parameters::savestateParam));
     202  CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::do_gradientParam) == "yes");
     203  CPPUNIT_ASSERT(parser->getParams().getBool(MpqcParser_Parameters::do_gradientParam));
     204  CPPUNIT_ASSERT(parser->getParams().getInt(MpqcParser_Parameters::maxiterParam) == 1000);
     205  CPPUNIT_ASSERT(parser->getParams().getInt(MpqcParser_Parameters::memoryParam) == 16000000);
     206  CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::stdapproxParam) == "A'");
     207  CPPUNIT_ASSERT(parser->getParams().getInt(MpqcParser_Parameters::nfzcParam) == 1);
     208  CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::basisParam) == "3-21G");
     209  CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::aux_basisParam) == "aug-cc-pVDZ");
     210  CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::integrationParam) == "IntegralCints");
     211  CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::theoryParam) == "MBPT2");
     212  CPPUNIT_ASSERT(parser->getParams().getTheory() == MpqcParser_Parameters::MBPT2);
     213  CPPUNIT_ASSERT(parser->getParams().getIntegration() == MpqcParser_Parameters::IntegralCints);
    212214
    213215  // check that values are not removed
    214   CPPUNIT_ASSERT(!mpqc->getParams().params[MpqcParser_Parameters::theoryParam].empty());
     216  CPPUNIT_ASSERT(!parser->getParams().params[MpqcParser_Parameters::theoryParam].empty());
    215217
    216218  // check throw, for the moment aren't, are caught in getInt()
    217   CPPUNIT_ASSERT_THROW(mpqc->getParams().getInt(MpqcParser_Parameters::integrationParam), boost::bad_any_cast);
    218   CPPUNIT_ASSERT_THROW(mpqc->getParams().getInt(MpqcParser_Parameters::theoryParam), boost::bad_any_cast);
     219  CPPUNIT_ASSERT_THROW(parser->getParams().getInt(MpqcParser_Parameters::integrationParam), boost::bad_any_cast);
     220  CPPUNIT_ASSERT_THROW(parser->getParams().getInt(MpqcParser_Parameters::theoryParam), boost::bad_any_cast);
    219221
    220222}
    221223
    222224void ParserMpqcUnitTest::ParameterCloneTest() {
    223   FormatParser_Parameters *clone = mpqc->getParams().clone();
    224   CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::theoryParam) == "MBPT2");
     225  FormatParser_Parameters *clone = parser->getParams().clone();
     226  CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::theoryParam) == "MBPT2");
    225227  std::stringstream setvalue("theory = CLHF");
    226   setvalue >> mpqc->getParams();
    227   CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::theoryParam) == "CLHF");
    228   mpqc->getParams().makeClone(*clone);
    229   CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::theoryParam) == "MBPT2");
     228  setvalue >> parser->getParams();
     229  CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::theoryParam) == "CLHF");
     230  parser->getParams().makeClone(*clone);
     231  CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::theoryParam) == "MBPT2");
    230232}
    231233
     
    234236  {
    235237    std::stringstream setvalue("theory = CLHF");
    236     setvalue >> mpqc->getParams();
     238    setvalue >> parser->getParams();
    237239//    std::cout << "integration method is "
    238 //        << mpqc->getParams().getString(MpqcParser_Parameters::theoryParam) << std::endl;
    239     CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::theoryParam) == "CLHF");
     240//        << parser->getParams().getString(MpqcParser_Parameters::theoryParam) << std::endl;
     241    CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::theoryParam) == "CLHF");
    240242  }
    241243  // test a bool
    242244  {
    243245    std::stringstream setvalue("Hessian = yes");
    244     setvalue >> mpqc->getParams();
     246    setvalue >> parser->getParams();
    245247//    std::cout << "Hessian is "
    246 //        << mpqc->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl;
    247     CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::hessianParam) == "yes");
     248//        << parser->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl;
     249    CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::hessianParam) == "yes");
    248250  }
    249251  // test int
    250252  {
    251253    std::stringstream setvalue("maxiter = 500");
    252     setvalue >> mpqc->getParams();
     254    setvalue >> parser->getParams();
    253255//    std::cout << "maxiter is "
    254 //        << mpqc->getParams().getString(MpqcParser_Parameters::maxiterParam) << std::endl;
    255     CPPUNIT_ASSERT(mpqc->getParams().getInt(MpqcParser_Parameters::maxiterParam) == 500);
     256//        << parser->getParams().getString(MpqcParser_Parameters::maxiterParam) << std::endl;
     257    CPPUNIT_ASSERT(parser->getParams().getInt(MpqcParser_Parameters::maxiterParam) == 500);
    256258  }
    257259  // test whether unknown key fails
     
    261263#ifndef NDEBUG
    262264    ASSERT_DO(Assert::Throw);
    263     CPPUNIT_ASSERT_THROW(setvalue >> mpqc->getParams(), Assert::AssertionFailure);
     265    CPPUNIT_ASSERT_THROW(setvalue >> parser->getParams(), Assert::AssertionFailure);
    264266#else
    265     setvalue >> mpqc->getParams();
     267    setvalue >> parser->getParams();
    266268#endif
    267269//    std::cout << "Hessian is still "
    268 //        << mpqc->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl;
    269     CPPUNIT_ASSERT(mpqc->getParams().getString(MpqcParser_Parameters::hessianParam) == "yes");
     270//        << parser->getParams().getString(MpqcParser_Parameters::hessianParam) << std::endl;
     271    CPPUNIT_ASSERT(parser->getParams().getString(MpqcParser_Parameters::hessianParam) == "yes");
    270272  }
    271273}
     
    273275void ParserMpqcUnitTest::readMpqcTest() {
    274276  stringstream input(waterMpqc_CLHF);
    275   mpqc->getParams().setTheory(MpqcParser_Parameters::CLHF);
    276   mpqc->load(&input);
     277  parser->getParams().setTheory(MpqcParser_Parameters::CLHF);
     278  parser->load(&input);
    277279
    278280  CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
     
    301303    // compare both configs for CLHF
    302304    stringstream output;
    303     mpqc->getParams().setTheory(MpqcParser_Parameters::CLHF);
    304     mpqc->save(&output, atoms);
     305    parser->getParams().setTheory(MpqcParser_Parameters::CLHF);
     306    parser->save(&output, atoms);
    305307    stringstream input(waterMpqc_CLHF);
    306308    for (; std::getline(input, first) && std::getline(output, second); ) {
     
    312314    // compare both configs for CLKS
    313315    stringstream output;
    314     mpqc->getParams().setTheory(MpqcParser_Parameters::CLKS);
    315     mpqc->save(&output, atoms);
     316    parser->getParams().setTheory(MpqcParser_Parameters::CLKS);
     317    parser->save(&output, atoms);
    316318    stringstream input(waterMpqc_CLKS);
    317319    for (; std::getline(input, first) && std::getline(output, second); ) {
     
    323325    // compare both configs for MBPT2
    324326    stringstream output;
    325     mpqc->getParams().setTheory(MpqcParser_Parameters::MBPT2);
    326     mpqc->save(&output, atoms);
     327    parser->getParams().setTheory(MpqcParser_Parameters::MBPT2);
     328    parser->save(&output, atoms);
    327329    stringstream input(waterMpqc_MBPT2);
    328330    for (; std::getline(input, first) && std::getline(output, second); ) {
     
    334336    // compare both configs for MBPT2_R12
    335337    stringstream output;
    336     mpqc->getParams().setTheory(MpqcParser_Parameters::MBPT2_R12);
    337     mpqc->save(&output, atoms);
     338    parser->getParams().setTheory(MpqcParser_Parameters::MBPT2_R12);
     339    parser->save(&output, atoms);
    338340    stringstream input(waterMpqc_MBPT2_R12);
    339341    for (; std::getline(input, first) && std::getline(output, second); ) {
  • src/Parser/unittests/ParserMpqcUnitTest.hpp

    r9a6b76e r765f16  
    4141
    4242private:
    43   MpqcParser *mpqc;
     43  FormatParser<mpqc> *parser;
    4444};
    4545
  • src/Parser/unittests/ParserPcpUnitTest.cpp

    r9a6b76e r765f16  
    2424#include <cppunit/ui/text/TestRunner.h>
    2525
    26 #include "Parser/PcpParser.hpp"
    2726#include "World.hpp"
    2827#include "atom.hpp"
     
    3130#include "CodePatterns/Log.hpp"
    3231#include "Descriptors/AtomTypeDescriptor.hpp"
     32#include "Parser/ChangeTracker.hpp"
     33#include "Parser/PcpParser.hpp"
    3334
    3435#ifdef HAVE_TESTRUNNER
     
    119120  World::getInstance();
    120121
     122  parser = new FormatParser<pcp>();
     123
    121124  setVerbosity(2);
    122125
     
    126129}
    127130
    128 void ParserPcpUnitTest::tearDown() {
     131void ParserPcpUnitTest::tearDown()
     132{
     133  delete parser;
    129134  ChangeTracker::purgeInstance();
    130135  World::purgeInstance();
     
    135140void ParserPcpUnitTest::readwritePcpTest() {
    136141  stringstream input(waterPcp);
    137   PcpParser* testParser = new PcpParser();
    138   testParser->load(&input);
     142  parser->load(&input);
    139143  input.clear();
    140144
     
    142146
    143147  // check that equality function is ok
    144   CPPUNIT_ASSERT(*testParser == *testParser);
     148  CPPUNIT_ASSERT(*parser == *parser);
    145149
    146150  stringstream output;
    147151  std::vector<atom *> atoms = World::getInstance().getAllAtoms();
    148   testParser->save(&output, atoms);
     152  parser->save(&output, atoms);
    149153
    150154  input << output.str();
    151   PcpParser* testParser2 = new PcpParser();
    152   testParser2->load(&input);
     155  FormatParser<pcp>* parser2 = new FormatParser<pcp>();
     156  parser2->load(&input);
    153157
    154158  CPPUNIT_ASSERT_EQUAL(6, World::getInstance().numAtoms());
    155159
    156   CPPUNIT_ASSERT(*testParser == *testParser2);
     160  CPPUNIT_ASSERT(*parser == *parser2);
     161
     162  delete parser2;
    157163}
  • src/Parser/unittests/ParserPcpUnitTest.hpp

    r9a6b76e r765f16  
    1313#endif
    1414
     15#include "Parser/PcpParser.hpp"
    1516
    1617#include <cppunit/extensions/HelperMacros.h>
     
    2829
    2930  void readwritePcpTest();
     31
     32private:
     33  FormatParser<pcp> *parser;
    3034};
    3135
  • src/Parser/unittests/ParserPdbUnitTest.cpp

    r9a6b76e r765f16  
    2424#include <cppunit/ui/text/TestRunner.h>
    2525
    26 #include "Parser/PdbParser.hpp"
    2726#include "World.hpp"
    2827#include "atom.hpp"
     
    3130#include "CodePatterns/Log.hpp"
    3231#include "Descriptors/AtomTypeDescriptor.hpp"
     32#include "Parser/ChangeTracker.hpp"
     33#include "Parser/PdbParser.hpp"
    3334
    3435#ifdef HAVE_TESTRUNNER
     
    6364  World::getInstance();
    6465
     66  parser = new FormatParser<pdb>();
     67
    6568  setVerbosity(2);
    6669
     
    7073}
    7174
    72 void ParserPdbUnitTest::tearDown() {
     75void ParserPdbUnitTest::tearDown()
     76{
     77  delete parser;
    7378  ChangeTracker::purgeInstance();
    7479  World::purgeInstance();
     
    8085  stringstream input;
    8186  input << waterPdb;
    82   PdbParser* testParser = new PdbParser();
    83   testParser->load(&input);
     87  parser->load(&input);
    8488  input.clear();
    8589
     
    8892  stringstream output;
    8993  std::vector<atom *> atoms = World::getInstance().getAllAtoms();
    90   testParser->save(&output, atoms);
     94  parser->save(&output, atoms);
    9195
    9296//  std::cout << "Save PDB is:" << std::endl;
     
    9498
    9599  input << output.str();
    96   PdbParser* testParser2 = new PdbParser();
    97   testParser2->load(&input);
     100  FormatParser<pdb>* parser2 = new FormatParser<pdb>();
     101  parser2->load(&input);
    98102
    99103  CPPUNIT_ASSERT_EQUAL(12, World::getInstance().numAtoms());
     104
     105  delete parser2;
    100106}
  • src/Parser/unittests/ParserPdbUnitTest.hpp

    r9a6b76e r765f16  
    1313#endif
    1414
     15#include "Parser/PdbParser.hpp"
    1516
    1617#include <cppunit/extensions/HelperMacros.h>
     
    2829
    2930  void readwritePdbTest();
     31
     32private:
     33  FormatParser<pdb> *parser;
    3034};
    3135
  • src/Parser/unittests/ParserTremoloUnitTest.cpp

    r9a6b76e r765f16  
    2727#include "Descriptors/AtomTypeDescriptor.hpp"
    2828#include "element.hpp"
    29 #include "Parser/MpqcParser.hpp"
    30 #include "Parser/PdbParser.hpp"
    31 #include "Parser/PcpParser.hpp"
    3229#include "Parser/TremoloParser.hpp"
    33 #include "Parser/XyzParser.hpp"
     30#include "Parser/ChangeTracker.hpp"
    3431#include "periodentafel.hpp"
    3532#include "World.hpp"
     
    8582  World::getInstance();
    8683
     84  parser = new FormatParser<tremolo>();
     85
    8786  // we need hydrogens and oxygens in the following tests
    8887  CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(1) != NULL);
     
    9089}
    9190
    92 void ParserTremoloUnitTest::tearDown() {
     91void ParserTremoloUnitTest::tearDown()
     92{
     93  delete parser;
    9394  ChangeTracker::purgeInstance();
    9495  World::purgeInstance();
     
    99100void ParserTremoloUnitTest::readTremoloPreliminaryCommentsTest() {
    100101  cout << "Testing the tremolo parser." << endl;
    101   TremoloParser* testParser = new TremoloParser();
    102102  stringstream input, output;
    103103
     
    105105  {
    106106    input << Tremolo_Atomdata1;
    107     testParser->load(&input);
    108     std::vector<atom *> atoms = World::getInstance().getAllAtoms();
    109     testParser->save(&output, atoms);
     107    parser->load(&input);
     108    std::vector<atom *> atoms = World::getInstance().getAllAtoms();
     109    parser->save(&output, atoms);
    110110//    std::cout << output.str() << std::endl;
    111111//    std::cout << Tremolo_Atomdata1 << std::endl;
     
    118118  {
    119119    input << Tremolo_Atomdata2;
    120     testParser->load(&input);
    121     std::vector<atom *> atoms = World::getInstance().getAllAtoms();
    122     testParser->save(&output, atoms);
     120    parser->load(&input);
     121    std::vector<atom *> atoms = World::getInstance().getAllAtoms();
     122    parser->save(&output, atoms);
    123123    std::cout << output.str() << std::endl;
    124124    CPPUNIT_ASSERT(output.str().find("hydrogen") != string::npos);
     
    129129  // Invalid key in Atomdata line
    130130  input << Tremolo_invalidkey;
    131   testParser->load(&input);
     131  parser->load(&input);
    132132  //TODO: prove invalidity
    133133  input.clear();
     
    135135
    136136void ParserTremoloUnitTest::readTremoloCoordinatesTest() {
    137   TremoloParser* testParser = new TremoloParser();
    138137  stringstream input;
    139138
    140139  // One simple data line
    141140  input << Tremolo_Atomdata2;
    142   testParser->load(&input);
     141  parser->load(&input);
    143142  CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->at(0) == 3.0);
    144143  input.clear();
     
    146145
    147146void ParserTremoloUnitTest::readTremoloVelocityTest() {
    148   TremoloParser* testParser = new TremoloParser();
    149147  stringstream input;
    150148
    151149  // One simple data line
    152150  input << Tremolo_velocity;
    153   testParser->load(&input);
     151  parser->load(&input);
    154152  CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->getAtomicVelocity()[0] == 3.0);
    155153  input.clear();
     
    157155
    158156void ParserTremoloUnitTest::readTremoloNeighborInformationTest() {
    159   TremoloParser* testParser = new TremoloParser();
    160157  stringstream input;
    161158
    162159  // Neighbor data
    163160  input << Tremolo_neighbours;
    164   testParser->load(&input);
     161  parser->load(&input);
    165162
    166163  CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
     
    171168
    172169void ParserTremoloUnitTest::readAndWriteTremoloImprDataInformationTest() {
    173   TremoloParser* testParser = new TremoloParser();
    174170  stringstream input, output;
    175171
     
    177173  {
    178174    input << Tremolo_improper;
    179     testParser->load(&input);
    180     std::vector<atom *> atoms = World::getInstance().getAllAtoms();
    181     testParser->save(&output, atoms);
     175    parser->load(&input);
     176    std::vector<atom *> atoms = World::getInstance().getAllAtoms();
     177    parser->save(&output, atoms);
    182178    CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
    183179    std::cout << output.str() << std::endl;
     
    189185
    190186void ParserTremoloUnitTest::readAndWriteTremoloTorsionInformationTest() {
    191   TremoloParser* testParser = new TremoloParser();
    192187  stringstream input, output;
    193188
     
    195190  {
    196191    input << Tremolo_torsion;
    197     testParser->load(&input);
    198     std::vector<atom *> atoms = World::getInstance().getAllAtoms();
    199     testParser->save(&output, atoms);
     192    parser->load(&input);
     193    std::vector<atom *> atoms = World::getInstance().getAllAtoms();
     194    parser->save(&output, atoms);
    200195    CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
    201196    std::cout << output.str() << std::endl;
     
    207202
    208203void ParserTremoloUnitTest::writeTremoloTest() {
    209   TremoloParser* testParser = new TremoloParser();
    210204  stringstream output;
    211205
     
    214208    atom* newAtom = World::getInstance().createAtom();
    215209    newAtom->setType(1);
    216     testParser->setFieldsForSave("x=3 u=3 F stress Id neighbors=5 imprData GroupMeasureTypeNo type extType name resName chainID resSeq occupancy tempFactor segID Charge charge GrpTypeNo torsion");
    217     std::vector<atom *> atoms = World::getInstance().getAllAtoms();
    218     testParser->save(&output, atoms);
     210    parser->setFieldsForSave("x=3 u=3 F stress Id neighbors=5 imprData GroupMeasureTypeNo type extType name resName chainID resSeq occupancy tempFactor segID Charge charge GrpTypeNo torsion");
     211    std::vector<atom *> atoms = World::getInstance().getAllAtoms();
     212    parser->save(&output, atoms);
    219213    CPPUNIT_ASSERT(output.str() == Tremolo_full);
    220214  }
     
    222216  cout << "testing the tremolo parser is done" << endl;
    223217}
     218
  • src/Parser/unittests/ParserTremoloUnitTest.hpp

    r9a6b76e r765f16  
    1313#endif
    1414
     15#include "Parser/TremoloParser.hpp"
    1516
    1617#include <cppunit/extensions/HelperMacros.h>
     
    4041  void readAndWriteTremoloTorsionInformationTest();
    4142  void writeTremoloTest();
     43
     44private:
     45  FormatParser<tremolo> *parser;
    4246};
    4347
  • src/Parser/unittests/ParserXyzUnitTest.cpp

    r9a6b76e r765f16  
    2424#include <cppunit/ui/text/TestRunner.h>
    2525
    26 #include "Parser/XyzParser.hpp"
    2726#include "World.hpp"
    2827#include "atom.hpp"
     
    3130#include "CodePatterns/Log.hpp"
    3231#include "Descriptors/AtomTypeDescriptor.hpp"
     32#include "Parser/ChangeTracker.hpp"
     33#include "Parser/XyzParser.hpp"
    3334
    3435#ifdef HAVE_TESTRUNNER
     
    6263  World::getInstance();
    6364
     65  parser = new FormatParser<xyz>();
     66
    6467  setVerbosity(2);
    6568
     
    6972}
    7073
    71 void ParserXyzUnitTest::tearDown() {
     74void ParserXyzUnitTest::tearDown()
     75{
     76  delete parser;
    7277  ChangeTracker::purgeInstance();
    7378  World::purgeInstance();
     
    7883void ParserXyzUnitTest::rewriteAnXyzTest() {
    7984  cout << "Testing the XYZ parser." << endl;
    80   XyzParser* testParser = new XyzParser();
    8185  stringstream input;
    8286  input << waterXyz;
    83   testParser->load(&input);
     87  parser->load(&input);
    8488  input.clear();
    8589
     
    9094    stringstream output;
    9195    std::vector<atom *> atoms = World::getInstance().getAllAtoms();
    92     testParser->save(&output, atoms);
     96    parser->save(&output, atoms);
    9397    input << output.str();
    94     testParser->load(&input);
     98    parser->load(&input);
    9599  }
    96100
     
    115119void ParserXyzUnitTest::readMultiXyzTest() {
    116120  cout << "Testing the multi time step XYZ parser." << endl;
    117   XyzParser* testParser = new XyzParser();
    118121  stringstream input;
    119122  input << waterMultiXyz;
    120   testParser->load(&input);
     123  parser->load(&input);
    121124  input.clear();
    122125
     
    130133
    131134void ParserXyzUnitTest::writeMultiXyzTest() {
    132   XyzParser* testParser = new XyzParser();
    133135  stringstream input;
    134136  input << waterMultiXyz;
    135   testParser->load(&input);
     137  parser->load(&input);
    136138  input.clear();
    137139
     
    143145    stringstream output;
    144146    std::vector<atom *> atoms = World::getInstance().getAllAtoms();
    145     testParser->save(&output, atoms);
     147    parser->save(&output, atoms);
    146148    input << output.str();
    147     testParser->load(&input);
     149    parser->load(&input);
    148150  }
    149151
  • src/Parser/unittests/ParserXyzUnitTest.hpp

    r9a6b76e r765f16  
    1313#endif
    1414
     15#include "Parser/XyzParser.hpp"
    1516
    1617#include <cppunit/extensions/HelperMacros.h>
     
    3233  void readMultiXyzTest();
    3334  void writeMultiXyzTest();
     35
     36private:
     37  FormatParser<xyz> *parser;
    3438};
    3539
Note: See TracChangeset for help on using the changeset viewer.