/indra/newview/tests/lltexturestatsuploader_test.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 150 lines · 65 code · 22 blank · 63 comment · 0 complexity · d0e4f7833113f13aefe080e7f71d8202 MD5 · raw file

  1. /**
  2. * @file lltexturestatsuploader_test.cpp
  3. * @author Si
  4. * @date 2009-05-27
  5. *
  6. * $LicenseInfo:firstyear=2006&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. // Precompiled header: almost always required for newview cpp files
  28. #include "../llviewerprecompiledheaders.h"
  29. // Class to test
  30. #include "../lltexturestatsuploader.h"
  31. // Dependencies
  32. // Tut header
  33. #include "../test/lltut.h"
  34. // -------------------------------------------------------------------------------------------
  35. // Stubbing: Declarations required to link and run the class being tested
  36. // Notes:
  37. // * Add here stubbed implementation of the few classes and methods used in the class to be tested
  38. // * Add as little as possible (let the link errors guide you)
  39. // * Do not make any assumption as to how those classes or methods work (i.e. don't copy/paste code)
  40. // * A simulator for a class can be implemented here. Please comment and document thoroughly.
  41. #include "boost/intrusive_ptr.hpp"
  42. void boost::intrusive_ptr_add_ref(LLCurl::Responder*){}
  43. void boost::intrusive_ptr_release(LLCurl::Responder* p){}
  44. const F32 HTTP_REQUEST_EXPIRY_SECS = 0.0f;
  45. static std::string most_recent_url;
  46. static LLSD most_recent_body;
  47. void LLHTTPClient::post(
  48. const std::string& url,
  49. const LLSD& body,
  50. ResponderPtr,
  51. const LLSD& headers,
  52. const F32 timeout)
  53. {
  54. // set some sensor code
  55. most_recent_url = url;
  56. most_recent_body = body;
  57. return;
  58. }
  59. // End Stubbing
  60. // -------------------------------------------------------------------------------------------
  61. // -------------------------------------------------------------------------------------------
  62. // TUT
  63. // -------------------------------------------------------------------------------------------
  64. namespace tut
  65. {
  66. // Test wrapper declarations
  67. struct texturestatsuploader_test
  68. {
  69. // Constructor and destructor of the test wrapper
  70. texturestatsuploader_test()
  71. {
  72. most_recent_url = "some sort of default text that should never match anything the tests are expecting!";
  73. LLSD blank_llsd;
  74. most_recent_body = blank_llsd;
  75. }
  76. ~texturestatsuploader_test()
  77. {
  78. }
  79. };
  80. // Tut templating thingamagic: test group, object and test instance
  81. typedef test_group<texturestatsuploader_test> texturestatsuploader_t;
  82. typedef texturestatsuploader_t::object texturestatsuploader_object_t;
  83. tut::texturestatsuploader_t tut_texturestatsuploader("LLTextureStatsUploader");
  84. // ---------------------------------------------------------------------------------------
  85. // Test functions
  86. // Notes:
  87. // * Test as many as you possibly can without requiring a full blown simulation of everything
  88. // * The tests are executed in sequence so the test instance state may change between calls
  89. // * Remember that you cannot test private methods with tut
  90. // ---------------------------------------------------------------------------------------
  91. // ---------------------------------------------------------------------------------------
  92. // Test the LLTextureInfo
  93. // ---------------------------------------------------------------------------------------
  94. // Test instantiation
  95. template<> template<>
  96. void texturestatsuploader_object_t::test<1>()
  97. {
  98. LLTextureStatsUploader tsu;
  99. llinfos << &tsu << llendl;
  100. ensure("have we crashed?", true);
  101. }
  102. // does it call out to the provided url if we ask it to?
  103. template<> template<>
  104. void texturestatsuploader_object_t::test<2>()
  105. {
  106. LLTextureStatsUploader tsu;
  107. std::string url = "http://blahblahblah";
  108. LLSD texture_stats;
  109. tsu.uploadStatsToSimulator(url, texture_stats);
  110. ensure_equals("did the right url get called?", most_recent_url, url);
  111. ensure_equals("did the right body get sent?", most_recent_body, texture_stats);
  112. }
  113. // does it not call out to the provided url if we send it an ungranted cap?
  114. template<> template<>
  115. void texturestatsuploader_object_t::test<3>()
  116. {
  117. LLTextureStatsUploader tsu;
  118. // this url left intentionally blank to mirror
  119. // not getting a cap in the caller.
  120. std::string url_for_ungranted_cap = "";
  121. LLSD texture_stats;
  122. std::string most_recent_url_before_test = most_recent_url;
  123. tsu.uploadStatsToSimulator(url_for_ungranted_cap, texture_stats);
  124. ensure_equals("hopefully no url got called!", most_recent_url, most_recent_url_before_test);
  125. }
  126. // does it call out if the data is empty?
  127. // should it even do that?
  128. }