PageRenderTime 34ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/test/llassetuploadqueue_tut.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 195 lines | 144 code | 25 blank | 26 comment | 0 complexity | 1ce9461aada894a045defbc25787054c MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file asset_upload_queue_tut.cpp
  3. * @brief Tests for newview/llassetuploadqueue.cpp
  4. *
  5. * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "linden_common.h"
  27. #include "lltut.h"
  28. #include "mock_http_client.h"
  29. #include "../newview/llassetuploadqueue.cpp"
  30. // Mock implementation.
  31. LLAssetUploadResponder::LLAssetUploadResponder(const LLSD& post_data,
  32. const LLUUID& vfile_id,
  33. LLAssetType::EType asset_type)
  34. {
  35. }
  36. LLAssetUploadResponder::LLAssetUploadResponder(const LLSD& post_data, const std::string& file_name)
  37. {
  38. }
  39. LLAssetUploadResponder::~LLAssetUploadResponder()
  40. {
  41. }
  42. void LLAssetUploadResponder::error(U32 statusNum, const std::string& reason)
  43. {
  44. }
  45. void LLAssetUploadResponder::result(const LLSD& content)
  46. {
  47. }
  48. void LLAssetUploadResponder::uploadUpload(const LLSD& content)
  49. {
  50. }
  51. void LLAssetUploadResponder::uploadComplete(const LLSD& content)
  52. {
  53. }
  54. void LLAssetUploadResponder::uploadFailure(const LLSD& content)
  55. {
  56. }
  57. LLUpdateTaskInventoryResponder::LLUpdateTaskInventoryResponder(const LLSD& post_data,
  58. const LLUUID& vfile_id,
  59. LLAssetType::EType asset_type) :
  60. LLAssetUploadResponder(post_data, vfile_id, asset_type)
  61. {
  62. }
  63. LLUpdateTaskInventoryResponder::LLUpdateTaskInventoryResponder(const LLSD& post_data,
  64. const std::string& file_name) :
  65. LLAssetUploadResponder(post_data, file_name)
  66. {
  67. }
  68. LLUpdateTaskInventoryResponder::LLUpdateTaskInventoryResponder(const LLSD& post_data,
  69. const std::string& file_name,
  70. const LLUUID& queue_id) :
  71. LLAssetUploadResponder(post_data, file_name)
  72. {
  73. }
  74. void LLUpdateTaskInventoryResponder::uploadComplete(const LLSD& content)
  75. {
  76. }
  77. namespace tut
  78. {
  79. class asset_upload_queue_test_data : public MockHttpClient {};
  80. typedef test_group<asset_upload_queue_test_data> asset_upload_queue_test;
  81. typedef asset_upload_queue_test::object asset_upload_queue_object;
  82. tut::asset_upload_queue_test asset_upload_queue("asset_upload_queue");
  83. void queue(LLAssetUploadQueue& q, const std::string& filename)
  84. {
  85. LLUUID task_id;
  86. LLUUID item_id;
  87. BOOL is_running = FALSE;
  88. BOOL is_target_mono = TRUE;
  89. LLUUID queue_id;
  90. q.queue(filename, task_id, item_id, is_running, is_target_mono, queue_id);
  91. }
  92. class LLTestSupplier : public LLAssetUploadQueueSupplier
  93. {
  94. public:
  95. void set(LLAssetUploadQueue* queue) {mQueue = queue;}
  96. virtual LLAssetUploadQueue* get() const
  97. {
  98. return mQueue;
  99. }
  100. private:
  101. LLAssetUploadQueue* mQueue;
  102. };
  103. template<> template<>
  104. void asset_upload_queue_object::test<1>()
  105. {
  106. setupTheServer();
  107. reset();
  108. LLTestSupplier* supplier = new LLTestSupplier();
  109. LLAssetUploadQueue q("http://localhost:8888/test/success", supplier);
  110. supplier->set(&q);
  111. queue(q, "foo.bar");
  112. ensure("upload queue not empty before request", q.isEmpty());
  113. runThePump(10);
  114. ensure("upload queue not empty after request", q.isEmpty());
  115. }
  116. template<> template<>
  117. void asset_upload_queue_object::test<2>()
  118. {
  119. reset();
  120. LLTestSupplier* supplier = new LLTestSupplier();
  121. LLAssetUploadQueue q("http://localhost:8888/test/error", supplier);
  122. supplier->set(&q);
  123. queue(q, "foo.bar");
  124. ensure("upload queue not empty before request", q.isEmpty());
  125. runThePump(10);
  126. ensure("upload queue not empty after request", q.isEmpty());
  127. }
  128. template<> template<>
  129. void asset_upload_queue_object::test<3>()
  130. {
  131. reset();
  132. LLTestSupplier* supplier = new LLTestSupplier();
  133. LLAssetUploadQueue q("http://localhost:8888/test/timeout", supplier);
  134. supplier->set(&q);
  135. queue(q, "foo.bar");
  136. ensure("upload queue not empty before request", q.isEmpty());
  137. runThePump(10);
  138. ensure("upload queue not empty after request", q.isEmpty());
  139. }
  140. template<> template<>
  141. void asset_upload_queue_object::test<4>()
  142. {
  143. reset();
  144. LLTestSupplier* supplier = new LLTestSupplier();
  145. LLAssetUploadQueue q("http://localhost:8888/test/success", supplier);
  146. supplier->set(&q);
  147. queue(q, "foo.bar");
  148. queue(q, "baz.bar");
  149. ensure("upload queue empty before request", !q.isEmpty());
  150. runThePump(10);
  151. ensure("upload queue not empty before request", q.isEmpty());
  152. runThePump(10);
  153. ensure("upload queue not empty after request", q.isEmpty());
  154. }
  155. template<> template<>
  156. void asset_upload_queue_object::test<5>()
  157. {
  158. reset();
  159. LLTestSupplier* supplier = new LLTestSupplier();
  160. LLAssetUploadQueue q("http://localhost:8888/test/success", supplier);
  161. supplier->set(&q);
  162. queue(q, "foo.bar");
  163. runThePump(10);
  164. ensure("upload queue not empty before request", q.isEmpty());
  165. queue(q, "baz.bar");
  166. ensure("upload queue not empty after request", q.isEmpty());
  167. runThePump(10);
  168. killServer();
  169. }
  170. }