PageRenderTime 32ms CodeModel.GetById 8ms 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
Possible License(s): LGPL-2.1
  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. #include "linden_common.h"
  28. #include "../llavatarnamecache.h"
  29. #include "../test/lltut.h"
  30. namespace tut
  31. {
  32. struct avatarnamecache_data
  33. {
  34. };
  35. typedef test_group<avatarnamecache_data> avatarnamecache_test;
  36. typedef avatarnamecache_test::object avatarnamecache_object;
  37. tut::avatarnamecache_test avatarnamecache_testcase("LLAvatarNameCache");
  38. template<> template<>
  39. void avatarnamecache_object::test<1>()
  40. {
  41. bool valid = false;
  42. S32 max_age = 0;
  43. valid = max_age_from_cache_control("max-age=3600", &max_age);
  44. ensure("typical input valid", valid);
  45. ensure_equals("typical input parsed", max_age, 3600);
  46. valid = max_age_from_cache_control(
  47. " max-age=600 , no-cache,private=\"stuff\" ", &max_age);
  48. ensure("complex input valid", valid);
  49. ensure_equals("complex input parsed", max_age, 600);
  50. valid = max_age_from_cache_control(
  51. "no-cache, max-age = 123 ", &max_age);
  52. ensure("complex input 2 valid", valid);
  53. ensure_equals("complex input 2 parsed", max_age, 123);
  54. }
  55. template<> template<>
  56. void avatarnamecache_object::test<2>()
  57. {
  58. bool valid = false;
  59. S32 max_age = -1;
  60. valid = max_age_from_cache_control("", &max_age);
  61. ensure("empty input returns invalid", !valid);
  62. ensure_equals("empty input doesn't change val", max_age, -1);
  63. valid = max_age_from_cache_control("no-cache", &max_age);
  64. ensure("no max-age field returns invalid", !valid);
  65. valid = max_age_from_cache_control("max", &max_age);
  66. ensure("just 'max' returns invalid", !valid);
  67. valid = max_age_from_cache_control("max-age", &max_age);
  68. ensure("partial max-age is invalid", !valid);
  69. valid = max_age_from_cache_control("max-age=", &max_age);
  70. ensure("longer partial max-age is invalid", !valid);
  71. valid = max_age_from_cache_control("max-age=FOO", &max_age);
  72. ensure("invalid integer max-age is invalid", !valid);
  73. valid = max_age_from_cache_control("max-age 234", &max_age);
  74. ensure("space separated max-age is invalid", !valid);
  75. valid = max_age_from_cache_control("max-age=0", &max_age);
  76. ensure("zero max-age is valid", valid);
  77. // *TODO: Handle "0000" as zero
  78. //valid = max_age_from_cache_control("max-age=0000", &max_age);
  79. //ensure("multi-zero max-age is valid", valid);
  80. valid = max_age_from_cache_control("max-age=-123", &max_age);
  81. ensure("less than zero max-age is invalid", !valid);
  82. }
  83. }