OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
MPIHelperTest.cpp
Go to the documentation of this file.
1 //
2 // Test MPIHelperTest
3 //
4 // Copyright (c) 2010 - 2013, Yves Ineichen, ETH Zürich
5 // All rights reserved
6 //
7 // Implemented as part of the PhD thesis
8 // "Toward massively parallel multi-objective optimization with application to
9 // particle accelerators" (https://doi.org/10.3929/ethz-a-009792359)
10 //
11 // This file is part of OPAL.
12 //
13 // OPAL is free software: you can redistribute it and/or modify
14 // it under the terms of the GNU General Public License as published by
15 // the Free Software Foundation, either version 3 of the License, or
16 // (at your option) any later version.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with OPAL. If not, see <https://www.gnu.org/licenses/>.
20 //
21 #include "Util/MPIHelper.h"
22 #include "gtest/gtest.h"
23 
24 namespace {
25 
26  // The fixture for testing class Foo.
27  class MPIHelperTest : public ::testing::Test {
28  protected:
29 
30  MPIHelperTest() {
31  // You can do set-up work for each test here.
32  }
33 
34  virtual ~MPIHelperTest() {
35  // You can do clean-up work that doesn't throw exceptions here.
36  }
37 
38  // If the constructor and destructor are not enough for setting up
39  // and cleaning up each test, you can define the following methods:
40 
41  virtual void SetUp() {
42  // Code here will be called immediately after the constructor (right
43  // before each test).
44  }
45 
46  virtual void TearDown() {
47  // Code here will be called immediately after each test (right
48  // before the destructor).
49  }
50 
51  // Objects declared here can be used by all tests in the test case
52  };
53 
54  TEST_F(MPIHelperTest, ParamSerialization) {
55 
56  Param_t params;
57  params.insert(std::pair<std::string, double>("a", 5.5));
58  params.insert(std::pair<std::string, double>("b", -15.2));
59 
60  std::ostringstream serialized;
61  serialize(params, serialized);
62 
63  Param_t deserialized_params;
64  deserialize(const_cast<char*>(serialized.str().c_str()),
65  deserialized_params);
66 
67  EXPECT_EQ(5.5, deserialized_params["a"])
68  << "first param not serialized properly";
69  EXPECT_EQ(-15.2, deserialized_params["b"])
70  << "second param not serialized properly";
71  }
72 
73 }
74 
75 int main(int argc, char **argv) {
76  ::testing::InitGoogleTest(&argc, argv);
77  return RUN_ALL_TESTS();
78 }
int main(int argc, char **argv)
void serialize(Param_t params, std::ostringstream &os)
serializes params using Boost archive
Definition: MPIHelper.cpp:32
void deserialize(char *buffer, Param_t &params)
deserializes params using Boost archive
Definition: MPIHelper.cpp:44
namedVariableCollection_t Param_t
Definition: Types.h:48