PageRenderTime 29ms CodeModel.GetById 21ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llcommon/tests/llmemtype_test.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 117 lines | 70 code | 16 blank | 31 comment | 0 complexity | 68466e57cd564cc45e98ef16909bcc0e MD5 | raw file
  1/**
  2 * @file   llmemtype_test.cpp
  3 * @author Palmer Truelson
  4 * @date   2008-03-
  5 * @brief  Test for llmemtype.cpp.
  6 * 
  7 * $LicenseInfo:firstyear=2009&license=viewerlgpl$
  8 * Second Life Viewer Source Code
  9 * Copyright (C) 2010, Linden Research, Inc.
 10 * 
 11 * This library is free software; you can redistribute it and/or
 12 * modify it under the terms of the GNU Lesser General Public
 13 * License as published by the Free Software Foundation;
 14 * version 2.1 of the License only.
 15 * 
 16 * This library is distributed in the hope that it will be useful,
 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 19 * Lesser General Public License for more details.
 20 * 
 21 * You should have received a copy of the GNU Lesser General Public
 22 * License along with this library; if not, write to the Free Software
 23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 24 * 
 25 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 26 * $/LicenseInfo$
 27 */
 28
 29#include "../llmemtype.h"
 30#include "../test/lltut.h"
 31#include "../llallocator.h"
 32
 33
 34#include <stack>
 35
 36std::stack<S32> memTypeStack;
 37
 38void LLAllocator::pushMemType(S32 i)
 39{
 40	memTypeStack.push(i);
 41}
 42
 43S32 LLAllocator::popMemType(void)
 44{
 45	S32 ret = memTypeStack.top();
 46	memTypeStack.pop();
 47	return ret;
 48}
 49
 50namespace tut
 51{
 52    struct llmemtype_data
 53    {
 54    };
 55
 56    typedef test_group<llmemtype_data> factory;
 57    typedef factory::object object;
 58}
 59namespace
 60{
 61        tut::factory llmemtype_test_factory("LLMemType");
 62}
 63
 64namespace tut
 65{
 66    template<> template<>
 67    void object::test<1>()
 68    {
 69        ensure("Simplest test ever", true);
 70    }
 71
 72	// test with no scripts
 73	template<> template<>
 74	void object::test<2>()
 75	{
 76		{
 77			LLMemType m1(LLMemType::MTYPE_INIT);
 78		}
 79		ensure("Test that you can construct and destruct the mem type");
 80	}
 81
 82	// test creation and stack testing
 83	template<> template<>
 84	void object::test<3>()
 85	{
 86		{
 87			ensure("Test that creation and destruction properly inc/dec the stack");			
 88			ensure_equals(memTypeStack.size(), 0);
 89			{
 90				LLMemType m1(LLMemType::MTYPE_INIT);
 91				ensure_equals(memTypeStack.size(), 1);
 92				LLMemType m2(LLMemType::MTYPE_STARTUP);
 93				ensure_equals(memTypeStack.size(), 2);
 94			}
 95			ensure_equals(memTypeStack.size(), 0);
 96		}
 97	}
 98
 99	// test with no scripts
100	template<> template<>
101	void object::test<4>()
102	{
103		// catch the begining and end
104		std::string test_name = LLMemType::getNameFromID(LLMemType::MTYPE_INIT.mID);
105		ensure_equals("Init name", test_name, "Init");
106
107		std::string test_name2 = LLMemType::getNameFromID(LLMemType::MTYPE_VOLUME.mID);
108		ensure_equals("Volume name", test_name2, "Volume");
109
110		std::string test_name3 = LLMemType::getNameFromID(LLMemType::MTYPE_OTHER.mID);
111		ensure_equals("Other name", test_name3, "Other");
112
113        std::string test_name4 = LLMemType::getNameFromID(-1);
114        ensure_equals("Invalid name", test_name4, "INVALID");
115	}
116
117};