OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
ManagedIDsTest.cpp
Go to the documentation of this file.
1 //
2 // Test ManagedIDsTest
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/ManagedIDs.h"
22 #include "gtest/gtest.h"
23 #include "boost/smart_ptr.hpp"
24 
25 namespace {
26 
27  // The fixture for testing class Foo.
28  class ManagedIDsTest : public ::testing::Test {
29  protected:
30 
31  ManagedIDsTest() {
32  // You can do set-up work for each test here.
33  ids_.reset(new ManagedIDs());
34  }
35 
36  virtual ~ManagedIDsTest() {
37  // You can do clean-up work that doesn't throw exceptions here.
38  }
39 
40  // If the constructor and destructor are not enough for setting up
41  // and cleaning up each test, you can define the following methods:
42 
43  virtual void SetUp() {
44  // Code here will be called immediately after the constructor (right
45  // before each test).
46  }
47 
48  virtual void TearDown() {
49  // Code here will be called immediately after each test (right
50  // before the destructor).
51  }
52 
53  // Objects declared here can be used by all tests in the test case
54  boost::scoped_ptr<ManagedIDs> ids_;
55  };
56 
57  TEST_F(ManagedIDsTest, OneID) {
58 
59  size_t id = ids_->nextID();
60  EXPECT_EQ(static_cast<size_t>(0), id) << "first id should be 0";
61  }
62 
63  TEST_F(ManagedIDsTest, IDsContinuous) {
64 
65  size_t id0 = ids_->nextID();
66  size_t id1 = ids_->nextID();
67  EXPECT_EQ(id0 + 1, id1);
68  }
69 
70  TEST_F(ManagedIDsTest, ReusingFreedIDs) {
71 
72  size_t id0 = ids_->nextID();
73  ids_->freeID(id0);
74  size_t id1 = ids_->nextID();
75  EXPECT_EQ(id0, id1);
76  }
77 
78 }
79 
80 int main(int argc, char **argv) {
81  ::testing::InitGoogleTest(&argc, argv);
82  return RUN_ALL_TESTS();
83 }
int main(int argc, char **argv)