PageRenderTime 33ms CodeModel.GetById 22ms app.highlight 7ms RepoModel.GetById 1ms 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
 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
28#include "linden_common.h"
29
30#include "llsingleton.h"
31#include "../test/lltut.h"
32
33namespace tut
34{
35	struct singleton
36	{
37		// We need a class created with the LLSingleton template to test with.
38		class LLSingletonTest: public LLSingleton<LLSingletonTest>
39		{
40
41		};
42	};
43
44	typedef test_group<singleton> singleton_t;
45	typedef singleton_t::object singleton_object_t;
46	tut::singleton_t tut_singleton("LLSingleton");
47
48	template<> template<>
49	void singleton_object_t::test<1>()
50	{
51
52	}
53	template<> template<>
54	void singleton_object_t::test<2>()
55	{
56		LLSingletonTest* singleton_test = LLSingletonTest::getInstance();
57		ensure(singleton_test);
58	}
59	template<> template<>
60	void singleton_object_t::test<3>()
61	{
62		//Construct the instance
63		LLSingletonTest::getInstance();
64		ensure(LLSingletonTest::instanceExists());
65
66		//Delete the instance
67		LLSingletonTest::deleteSingleton();
68		ensure(LLSingletonTest::destroyed());
69		ensure(!LLSingletonTest::instanceExists());
70
71		//Construct it again.
72		LLSingletonTest* singleton_test = LLSingletonTest::getInstance();
73		ensure(singleton_test);
74		ensure(LLSingletonTest::instanceExists());
75	}
76}