PageRenderTime 40ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/viewer_components/updater/tests/llupdaterservice_test.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 194 lines | 129 code | 19 blank | 46 comment | 0 complexity | 92999fdcf82ef45b7f0b561b59fe80f5 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llupdaterservice_test.cpp
  3. * @brief Tests of llupdaterservice.cpp.
  4. *
  5. * $LicenseInfo:firstyear=2010&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. // Precompiled header
  27. #include "linden_common.h"
  28. // associated header
  29. #include "../llupdaterservice.h"
  30. #include "../llupdatechecker.h"
  31. #include "../llupdatedownloader.h"
  32. #include "../llupdateinstaller.h"
  33. #include "../../../test/lltut.h"
  34. //#define DEBUG_ON
  35. #include "../../../test/debug.h"
  36. #include "llevents.h"
  37. #include "lldir.h"
  38. /*****************************************************************************
  39. * MOCK'd
  40. *****************************************************************************/
  41. LLUpdateChecker::LLUpdateChecker(LLUpdateChecker::Client & client)
  42. {}
  43. void LLUpdateChecker::check(std::string const & protocolVersion, std::string const & hostUrl,
  44. std::string const & servicePath, std::string channel, std::string version)
  45. {}
  46. LLUpdateDownloader::LLUpdateDownloader(Client & ) {}
  47. void LLUpdateDownloader::download(LLURI const & , std::string const &, std::string const &, bool){}
  48. class LLDir_Mock : public LLDir
  49. {
  50. void initAppDirs(const std::string &app_name,
  51. const std::string& app_read_only_data_dir = "") {}
  52. U32 countFilesInDir(const std::string &dirname, const std::string &mask)
  53. {
  54. return 0;
  55. }
  56. void getRandomFileInDir(const std::string &dirname,
  57. const std::string &mask,
  58. std::string &fname) {}
  59. std::string getCurPath() { return ""; }
  60. BOOL fileExists(const std::string &filename) const { return false; }
  61. std::string getLLPluginLauncher() { return ""; }
  62. std::string getLLPluginFilename(std::string base_name) { return ""; }
  63. } gDirUtil;
  64. LLDir* gDirUtilp = &gDirUtil;
  65. LLDir::LLDir() {}
  66. LLDir::~LLDir() {}
  67. S32 LLDir::deleteFilesInDir(const std::string &dirname,
  68. const std::string &mask)
  69. { return 0; }
  70. void LLDir::setChatLogsDir(const std::string &path){}
  71. void LLDir::setPerAccountChatLogsDir(const std::string &username){}
  72. void LLDir::setLindenUserDir(const std::string &username){}
  73. void LLDir::setSkinFolder(const std::string &skin_folder){}
  74. bool LLDir::setCacheDir(const std::string &path){ return true; }
  75. void LLDir::dumpCurrentDirectories() {}
  76. std::string LLDir::getExpandedFilename(ELLPath location,
  77. const std::string &filename) const
  78. {
  79. return "";
  80. }
  81. std::string LLUpdateDownloader::downloadMarkerPath(void)
  82. {
  83. return "";
  84. }
  85. void LLUpdateDownloader::resume(void) {}
  86. void LLUpdateDownloader::cancel(void) {}
  87. void LLUpdateDownloader::setBandwidthLimit(U64 bytesPerSecond) {}
  88. int ll_install_update(std::string const &, std::string const &, bool, LLInstallScriptMode)
  89. {
  90. return 0;
  91. }
  92. std::string const & ll_install_failed_marker_path()
  93. {
  94. static std::string wubba;
  95. return wubba;
  96. }
  97. /*
  98. #pragma warning(disable: 4273)
  99. llus_mock_llifstream::llus_mock_llifstream(const std::string& _Filename,
  100. ios_base::openmode _Mode,
  101. int _Prot) :
  102. std::basic_istream<char,std::char_traits< char > >(NULL,true)
  103. {}
  104. llus_mock_llifstream::~llus_mock_llifstream() {}
  105. bool llus_mock_llifstream::is_open() const {return true;}
  106. void llus_mock_llifstream::close() {}
  107. */
  108. /*****************************************************************************
  109. * TUT
  110. *****************************************************************************/
  111. namespace tut
  112. {
  113. struct llupdaterservice_data
  114. {
  115. llupdaterservice_data() :
  116. pumps(LLEventPumps::instance()),
  117. test_url("dummy_url"),
  118. test_channel("dummy_channel"),
  119. test_version("dummy_version")
  120. {}
  121. LLEventPumps& pumps;
  122. std::string test_url;
  123. std::string test_channel;
  124. std::string test_version;
  125. };
  126. typedef test_group<llupdaterservice_data> llupdaterservice_group;
  127. typedef llupdaterservice_group::object llupdaterservice_object;
  128. llupdaterservice_group llupdaterservicegrp("LLUpdaterService");
  129. template<> template<>
  130. void llupdaterservice_object::test<1>()
  131. {
  132. DEBUG;
  133. LLUpdaterService updater;
  134. bool got_usage_error = false;
  135. try
  136. {
  137. updater.startChecking();
  138. }
  139. catch(LLUpdaterService::UsageError)
  140. {
  141. got_usage_error = true;
  142. }
  143. ensure("Caught start before params", got_usage_error);
  144. }
  145. template<> template<>
  146. void llupdaterservice_object::test<2>()
  147. {
  148. DEBUG;
  149. LLUpdaterService updater;
  150. bool got_usage_error = false;
  151. try
  152. {
  153. updater.initialize("1.0",test_url, "update" ,test_channel, test_version);
  154. updater.startChecking();
  155. updater.initialize("1.0", "other_url", "update", test_channel, test_version);
  156. }
  157. catch(LLUpdaterService::UsageError)
  158. {
  159. got_usage_error = true;
  160. }
  161. ensure("Caught params while running", got_usage_error);
  162. }
  163. template<> template<>
  164. void llupdaterservice_object::test<3>()
  165. {
  166. DEBUG;
  167. LLUpdaterService updater;
  168. updater.initialize("1.0", test_url, "update", test_channel, test_version);
  169. updater.startChecking();
  170. ensure(updater.isChecking());
  171. updater.stopChecking();
  172. ensure(!updater.isChecking());
  173. }
  174. }