test_Singleton.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- Python -*-
00003 
00004 # @file test_Singleton.py
00005 # @brief test for Singleton class
00006 # @date $Date$
00007 # @author Shinji Kurihara
00008 #
00009 # Copyright (C) 2003-2005
00010 #     Task-intelligence Research Group,
00011 #     Intelligent Systems Research Institute,
00012 #     National Institute of
00013 #         Advanced Industrial Science and Technology (AIST), Japan
00014 #     All rights reserved.
00015 #
00016 # $Id$
00017 #
00018 
00019 #
00020 # $Log$
00021 #
00022 #
00023 
00024 import sys
00025 sys.path.insert(1,"../")
00026 
00027 import unittest
00028 
00029 from Singleton import *
00030 
00031 class SingletonMock(Singleton):
00032         _cnt = 0
00033         def __init__(self):
00034                 print "SingletonMock"
00035                 #self._cnt = 0
00036                 pass
00037 
00038         def up(self):
00039                 self._cnt += 1
00040 
00041         def get(self):
00042                 return self._cnt
00043 
00044 
00045 class TestSingleton(unittest.TestCase):
00046         def setUp(self):
00047                 return
00048 
00049         def tearDown(self):
00050                 return
00051 
00052 
00053         def test_SingletonCase(self):
00054                 mock = SingletonMock()
00055                 print "Singleton 0"
00056                 mock0 = SingletonMock()
00057                 print "mock0 ", mock0
00058                 print "Singleton 1"
00059                 mock1 = SingletonMock()
00060                 print "mock1 ", mock1
00061                 self.assertEqual(mock0.get(), 0)
00062                 self.assertEqual(mock1.get(), 0)
00063                 mock0.up()
00064                 self.assertEqual(mock0.get(), 1)
00065                 self.assertEqual(mock1.get(), 1)
00066                 mock1.up()
00067                 self.assertEqual(mock0.get(), 2)
00068                 self.assertEqual(mock1.get(), 2)
00069                 mock2 = SingletonMock.instance()
00070                 print "mock2 ", mock2
00071                 self.assertEqual(mock0.get(), 2)
00072                 self.assertEqual(mock1.get(), 2)
00073                 self.assertEqual(mock2.get(), 2)
00074                 return
00075 
00076 if __name__ == "__main__":
00077         unittest.main()


openrtm_aist_python
Author(s): Shinji Kurihara
autogenerated on Thu Aug 27 2015 14:17:28