OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
ManagedIDsTest.cpp
Go to the documentation of this file.
1 #include "Util/ManagedIDs.h"
2 #include "gtest/gtest.h"
3 #include "boost/smart_ptr.hpp"
4 
5 namespace {
6 
7  // The fixture for testing class Foo.
8  class ManagedIDsTest : public ::testing::Test {
9  protected:
10 
11  ManagedIDsTest() {
12  // You can do set-up work for each test here.
13  ids_.reset(new ManagedIDs());
14  }
15 
16  virtual ~ManagedIDsTest() {
17  // You can do clean-up work that doesn't throw exceptions here.
18  }
19 
20  // If the constructor and destructor are not enough for setting up
21  // and cleaning up each test, you can define the following methods:
22 
23  virtual void SetUp() {
24  // Code here will be called immediately after the constructor (right
25  // before each test).
26  }
27 
28  virtual void TearDown() {
29  // Code here will be called immediately after each test (right
30  // before the destructor).
31  }
32 
33  // Objects declared here can be used by all tests in the test case
34  boost::scoped_ptr<ManagedIDs> ids_;
35  };
36 
37  TEST_F(ManagedIDsTest, OneID) {
38 
39  size_t id = ids_->nextID();
40  EXPECT_EQ(static_cast<size_t>(0), id) << "first id should be 0";
41  }
42 
43  TEST_F(ManagedIDsTest, IDsContinuous) {
44 
45  size_t id0 = ids_->nextID();
46  size_t id1 = ids_->nextID();
47  EXPECT_EQ(id0 + 1, id1);
48  }
49 
50  TEST_F(ManagedIDsTest, ReusingFreedIDs) {
51 
52  size_t id0 = ids_->nextID();
53  ids_->freeID(id0);
54  size_t id1 = ids_->nextID();
55  EXPECT_EQ(id0, id1);
56  }
57 
58 }
59 
60 int main(int argc, char **argv) {
61  ::testing::InitGoogleTest(&argc, argv);
62  return RUN_ALL_TESTS();
63 }
Simple class to manage an ID pool.
Definition: ManagedIDs.h:9
int main(int argc, char *argv[])
Definition: Main.cpp:107