source: tests/regression/DiffFragmentResultContainer.cpp@ 3f6aac

Action_Thermostats Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests AutomationFragmentation_failures Candidate_v1.6.1 ChemicalSpaceEvaluator EmpiricalPotential_contain_HomologyGraph_documentation Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph Fix_Verbose_Codepatterns ForceAnnealing_oldresults ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion Gui_displays_atomic_force_velocity IndependentFragmentGrids_IntegrationTest JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool PythonUI_with_named_parameters Recreated_GuiChecks StoppableMakroAction TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps
Last change on this file since 3f6aac was 557b39, checked in by Frederik Heber <frederik.heber@…>, 8 years ago

boost::serialization changed text output format.

  • needed to write comparator program that first deserializes and then serializes both archives in order to compare onto common grounds.
  • TESTFIX: ParseFragmentResultContainer needed an extra purgeInstance() in its performUndo().
  • Property mode set to 100644
File size: 3.4 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2017 Frederik Heber. All rights reserved.
5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * DiffFragmentResultContainer.cpp
25 *
26 * Created on: Apr 5, 2017
27 * Author: heber
28 */
29
30
31// include config.h
32#ifdef HAVE_CONFIG_H
33#include <config.h>
34#endif
35
36//#include "CodePatterns/MemDebug.hpp"
37
38// include headers that implement a archive in simple text format
39#include <boost/archive/text_oarchive.hpp>
40#include <boost/archive/text_iarchive.hpp>
41
42#include <boost/filesystem/operations.hpp>
43#include <boost/filesystem/path.hpp>
44#include <boost/bind.hpp>
45
46#include <algorithm>
47#include <fstream>
48
49#include "Fragmentation/Summation/Containers/FragmentationResultContainer.hpp"
50
51static bool file_not_exists(const boost::filesystem::path &path) {
52 return !boost::filesystem::exists(path);
53}
54
55int main(int argc, char **argv)
56{
57 if (argc < 2) {
58 std::cout << "Usage:" << argv[0] << "<file 1> <file2>\n";
59 return 255;
60 }
61
62 // parse two file names
63 std::vector<boost::filesystem::path> filenames;
64 filenames.reserve(2);
65 filenames.push_back(std::string(argv[1]));
66 filenames.push_back(std::string(argv[2]));
67
68 // check whether both files exists
69 std::vector<boost::filesystem::path>::iterator iter =
70 std::find_if(
71 filenames.begin(), filenames.end(),
72 file_not_exists);
73 if (iter != filenames.end()) {
74 std::cerr << "The file " << iter->string() << " does not exist.\n";
75 return 255;
76 }
77
78 // deserialize and compare
79 // Note that because FragmentationResultContainer is a singleton, we cannot
80 // compare two distinct instances. Therefore, we deserialize and serialize
81 // again both files in order to compare the strings on grounds of the same
82 // serialization function (and library).
83 std::stringstream outfile1;
84 std::stringstream outfile2;
85 FragmentationResultContainer::purgeInstance();
86 {
87 std::ifstream infile(filenames[0].string().c_str());
88 FragmentationResultContainer &results = FragmentationResultContainer::getInstance();
89 boost::archive::text_iarchive ia(infile);
90 boost::archive::text_oarchive oa(outfile1);
91 ia >> results;
92 oa << results;
93 }
94 FragmentationResultContainer::purgeInstance();
95 {
96 std::ifstream infile(filenames[1].string().c_str());
97 FragmentationResultContainer &results = FragmentationResultContainer::getInstance();
98 boost::archive::text_iarchive ia(infile);
99 boost::archive::text_oarchive oa(outfile2);
100 ia >> results;
101 oa << results;
102 }
103
104 // because container is a singleton, we can only copy the memory
105
106 if (outfile1.str() != outfile2.str()) {
107 std::cout << "The two containers differ:\n";
108 std::cout << outfile1.str() << std::endl;
109 std::cout << outfile2.str() << std::endl;
110 return 5;
111 }
112
113 return 0;
114}
Note: See TracBrowser for help on using the repository browser.