PageRenderTime 48ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llcommon/tests/llsingleton_test.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 76 lines | 37 code | 9 blank | 30 comment | 0 complexity | da1452983ff99f7fcc373ddea50b353c MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llsingleton_test.cpp
  3. * @date 2011-08-11
  4. * @brief Unit test for the LLSingleton class
  5. *
  6. * $LicenseInfo:firstyear=2011&license=viewerlgpl$
  7. * Second Life Viewer Source Code
  8. * Copyright (C) 2011, Linden Research, Inc.
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation;
  13. * version 2.1 of the License only.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with this library; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. *
  24. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  25. * $/LicenseInfo$
  26. */
  27. #include "linden_common.h"
  28. #include "llsingleton.h"
  29. #include "../test/lltut.h"
  30. namespace tut
  31. {
  32. struct singleton
  33. {
  34. // We need a class created with the LLSingleton template to test with.
  35. class LLSingletonTest: public LLSingleton<LLSingletonTest>
  36. {
  37. };
  38. };
  39. typedef test_group<singleton> singleton_t;
  40. typedef singleton_t::object singleton_object_t;
  41. tut::singleton_t tut_singleton("LLSingleton");
  42. template<> template<>
  43. void singleton_object_t::test<1>()
  44. {
  45. }
  46. template<> template<>
  47. void singleton_object_t::test<2>()
  48. {
  49. LLSingletonTest* singleton_test = LLSingletonTest::getInstance();
  50. ensure(singleton_test);
  51. }
  52. template<> template<>
  53. void singleton_object_t::test<3>()
  54. {
  55. //Construct the instance
  56. LLSingletonTest::getInstance();
  57. ensure(LLSingletonTest::instanceExists());
  58. //Delete the instance
  59. LLSingletonTest::deleteSingleton();
  60. ensure(LLSingletonTest::destroyed());
  61. ensure(!LLSingletonTest::instanceExists());
  62. //Construct it again.
  63. LLSingletonTest* singleton_test = LLSingletonTest::getInstance();
  64. ensure(singleton_test);
  65. ensure(LLSingletonTest::instanceExists());
  66. }
  67. }