summaryrefslogtreecommitdiff
path: root/test/SingletonHolderTest.cc
blob: a3ac2eedd82c6a1d810d7a3fdd27b86895856e9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "SingletonHolder.h"

#include <iostream>

#include <cppunit/extensions/HelperMacros.h>

#include "SharedHandle.h"

namespace aria2 {

class SingletonHolderTest : public CppUnit::TestFixture {

  CPPUNIT_TEST_SUITE(SingletonHolderTest);
  CPPUNIT_TEST(testInstance);
  CPPUNIT_TEST_SUITE_END();
private:

public:
  void setUp() {
  }

  void testInstance();
};


CPPUNIT_TEST_SUITE_REGISTRATION( SingletonHolderTest );

class M {
private:
  std::string greeting_;
public:
  M(const std::string& greeting):greeting_(greeting) {}

  const std::string& greeting() const { return greeting_; }

  void greeting(const std::string& greeting) {
    greeting_ = greeting;
  }
};

void SingletonHolderTest::testInstance()
{
  SharedHandle<M> m(new M("Hello world."));
  SingletonHolder<M>::instance(m);
  CPPUNIT_ASSERT_EQUAL(std::string("Hello world."),
                       SingletonHolder<M>::instance()->greeting());

  SingletonHolder<M>::instance()->greeting("Yes, it worked!");
  CPPUNIT_ASSERT_EQUAL(std::string("Yes, it worked!"),
                       SingletonHolder<M>::instance()->greeting());
}

} // namespace aria2