PageRenderTime 45ms CodeModel.GetById 29ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llmessage/tests/llavatarnamecache_test.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 102 lines | 54 code | 19 blank | 29 comment | 0 complexity | d81d0816341e67ab8bcbab0503d71352 MD5 | raw file
  1/**
  2 * @file llavatarnamecache_test.cpp
  3 * @author James Cook
  4 * @brief LLAvatarNameCache test cases.
  5 *
  6 * $LicenseInfo:firstyear=2010&license=viewerlgpl$
  7 * Second Life Viewer Source Code
  8 * Copyright (C) 2010, 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 "../llavatarnamecache.h"
 31
 32#include "../test/lltut.h"
 33
 34namespace tut
 35{
 36	struct avatarnamecache_data
 37	{
 38	};
 39	typedef test_group<avatarnamecache_data> avatarnamecache_test;
 40	typedef avatarnamecache_test::object avatarnamecache_object;
 41	tut::avatarnamecache_test avatarnamecache_testcase("LLAvatarNameCache");
 42
 43	template<> template<>
 44	void avatarnamecache_object::test<1>()
 45	{
 46		bool valid = false;
 47		S32 max_age = 0;
 48
 49		valid = max_age_from_cache_control("max-age=3600", &max_age);
 50		ensure("typical input valid", valid);
 51		ensure_equals("typical input parsed", max_age, 3600);
 52
 53		valid = max_age_from_cache_control(
 54			" max-age=600 , no-cache,private=\"stuff\" ", &max_age);
 55		ensure("complex input valid", valid);
 56		ensure_equals("complex input parsed", max_age, 600);
 57
 58		valid = max_age_from_cache_control(
 59			"no-cache, max-age = 123 ", &max_age);
 60		ensure("complex input 2 valid", valid);
 61		ensure_equals("complex input 2 parsed", max_age, 123);
 62	}
 63
 64	template<> template<>
 65	void avatarnamecache_object::test<2>()
 66	{
 67		bool valid = false;
 68		S32 max_age = -1;
 69
 70		valid = max_age_from_cache_control("", &max_age);
 71		ensure("empty input returns invalid", !valid);
 72		ensure_equals("empty input doesn't change val", max_age, -1);
 73
 74		valid = max_age_from_cache_control("no-cache", &max_age);
 75		ensure("no max-age field returns invalid", !valid);
 76
 77		valid = max_age_from_cache_control("max", &max_age);
 78		ensure("just 'max' returns invalid", !valid);
 79
 80		valid = max_age_from_cache_control("max-age", &max_age);
 81		ensure("partial max-age is invalid", !valid);
 82
 83		valid = max_age_from_cache_control("max-age=", &max_age);
 84		ensure("longer partial max-age is invalid", !valid);
 85
 86		valid = max_age_from_cache_control("max-age=FOO", &max_age);
 87		ensure("invalid integer max-age is invalid", !valid);
 88
 89		valid = max_age_from_cache_control("max-age 234", &max_age);
 90		ensure("space separated max-age is invalid", !valid);
 91
 92		valid = max_age_from_cache_control("max-age=0", &max_age);
 93		ensure("zero max-age is valid", valid);
 94
 95		// *TODO: Handle "0000" as zero
 96		//valid = max_age_from_cache_control("max-age=0000", &max_age);
 97		//ensure("multi-zero max-age is valid", valid);
 98
 99		valid = max_age_from_cache_control("max-age=-123", &max_age);
100		ensure("less than zero max-age is invalid", !valid);
101	}
102}