PageRenderTime 32ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/test/llsaleinfo_tut.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 235 lines | 157 code | 40 blank | 38 comment | 31 complexity | f9a6369b68c4a92fb1e0211843df6ab1 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file LLSaleInfo_tut.cpp
  3. * @author Adroit
  4. * @date 2007-03
  5. * @brief Test cases of llsaleinfo.h
  6. *
  7. * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  8. * Second Life Viewer Source Code
  9. * Copyright (C) 2010, Linden Research, Inc.
  10. *
  11. * This library is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU Lesser General Public
  13. * License as published by the Free Software Foundation;
  14. * version 2.1 of the License only.
  15. *
  16. * This library is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * Lesser General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Lesser General Public
  22. * License along with this library; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  24. *
  25. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  26. * $/LicenseInfo$
  27. */
  28. #include <tut/tut.hpp>
  29. #include "linden_common.h"
  30. #include "lltut.h"
  31. #include "llsaleinfo.h"
  32. namespace tut
  33. {
  34. struct llsaleinfo_tut
  35. {
  36. };
  37. typedef test_group<llsaleinfo_tut> llsaleinfo_tut_t;
  38. typedef llsaleinfo_tut_t::object llsaleinfo_test_t;
  39. tut::llsaleinfo_tut_t tut_llsaleinfo_test("llsaleinfo");
  40. template<> template<>
  41. void llsaleinfo_test_t::test<1>()
  42. {
  43. //test case for getSaleType(), getSalePrice(), getCRC32() fn.
  44. //test case for setSaleType(), setSalePrice() fn.
  45. S32 sale_price = 10000;
  46. LLSaleInfo llsaleinfo(LLSaleInfo::FS_COPY, sale_price);
  47. const char* sale= "copy";
  48. LLSD llsd_obj1 = ll_create_sd_from_sale_info(llsaleinfo);
  49. LLSaleInfo saleinfo1 = ll_sale_info_from_sd(llsd_obj1);
  50. ensure("1. The getSaleType() fn failed", LLSaleInfo::FS_COPY == llsaleinfo.getSaleType());
  51. ensure("2. LLSaleInfo::isForSale() fn failed", TRUE == llsaleinfo.isForSale());
  52. ensure("3. The getSalePrice() fn failed", sale_price == llsaleinfo.getSalePrice());
  53. ensure("4. The getCRC32() fn failed", 235833404 == llsaleinfo.getCRC32());
  54. ensure("5. LLSaleInfo::lookup(const char* name) fn failed", LLSaleInfo::FS_COPY == llsaleinfo.lookup(sale));
  55. ensure_equals("6. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSalePrice(), saleinfo1.getSalePrice());
  56. ensure_equals("7. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSaleType(), saleinfo1.getSaleType());
  57. llsaleinfo.setSalePrice(10000000);
  58. llsaleinfo.setSaleType(LLSaleInfo::FS_ORIGINAL);
  59. sale = "cntn";
  60. llsd_obj1 = ll_create_sd_from_sale_info(llsaleinfo);
  61. saleinfo1 = ll_sale_info_from_sd(llsd_obj1);
  62. ensure("8. The getSaleType() and setSaleType() fn failed", LLSaleInfo::FS_ORIGINAL == llsaleinfo.getSaleType());
  63. ensure("9. LLSaleInfo::isForSale() fn failed", TRUE == llsaleinfo.isForSale());
  64. ensure("10. The getSalePrice() fn failed", 10000000 == llsaleinfo.getSalePrice());
  65. ensure("11. The getCRC32() fn failed", 127911702 == llsaleinfo.getCRC32());
  66. ensure("12. LLSaleInfo::lookup(const char* name) fn failed", LLSaleInfo::FS_CONTENTS == llsaleinfo.lookup(sale));
  67. ensure_equals("13. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSalePrice(), saleinfo1.getSalePrice());
  68. ensure_equals("14. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSaleType(), saleinfo1.getSaleType());
  69. llsaleinfo.setSalePrice(55000550);
  70. llsaleinfo.setSaleType(LLSaleInfo::FS_CONTENTS);
  71. sale = "orig";
  72. llsd_obj1 = ll_create_sd_from_sale_info(llsaleinfo);
  73. saleinfo1 = ll_sale_info_from_sd(llsd_obj1);
  74. ensure("15. The getSaleType() and setSaleType() fn failed", LLSaleInfo::FS_CONTENTS == llsaleinfo.getSaleType());
  75. ensure("16. LLSaleInfo::isForSale() fn failed", TRUE == llsaleinfo.isForSale());
  76. ensure("17. The getSalePrice() fn failed", 55000550 == llsaleinfo.getSalePrice());
  77. ensure("18. The getCRC32() fn failed", 408735656 == llsaleinfo.getCRC32());
  78. ensure("19. LLSaleInfo::lookup(const char* name) fn failed", LLSaleInfo::FS_ORIGINAL == llsaleinfo.lookup(sale));
  79. ensure_equals("20. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSalePrice(), saleinfo1.getSalePrice());
  80. ensure_equals("21. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSaleType(), saleinfo1.getSaleType());
  81. llsaleinfo.setSalePrice(-6432);
  82. llsaleinfo.setSaleType(LLSaleInfo::FS_NOT);
  83. sale = "not";
  84. llsd_obj1 = ll_create_sd_from_sale_info(llsaleinfo);
  85. saleinfo1 = ll_sale_info_from_sd(llsd_obj1);
  86. ensure("22. The getSaleType() and setSaleType() fn failed", LLSaleInfo::FS_NOT == llsaleinfo.getSaleType());
  87. ensure("23. LLSaleInfo::isForSale() fn failed", FALSE == llsaleinfo.isForSale());
  88. ensure("24. The getSalePrice() fn failed", 0 == llsaleinfo.getSalePrice());
  89. ensure("25. The getCRC32() fn failed", 0 == llsaleinfo.getCRC32());
  90. ensure("26. LLSaleInfo::lookup(const char* name) fn failed", LLSaleInfo::FS_NOT == llsaleinfo.lookup(sale));
  91. ensure_equals("27. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSalePrice(), saleinfo1.getSalePrice());
  92. ensure_equals("28. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSaleType(), saleinfo1.getSaleType());
  93. }
  94. template<> template<>
  95. void llsaleinfo_test_t::test<2>()
  96. {
  97. LLFILE* fp = LLFile::fopen("linden_file.dat","w+");
  98. if(!fp)
  99. {
  100. llerrs << "file could not be opened\n" << llendl;
  101. return;
  102. }
  103. S32 sale_price = 43500;
  104. LLSaleInfo llsaleinfo(LLSaleInfo::FS_COPY, sale_price);
  105. llsaleinfo.exportFile(fp);
  106. fclose(fp);
  107. LLSaleInfo llsaleinfo1;
  108. U32 perm_mask;
  109. BOOL has_perm_mask;
  110. fp = LLFile::fopen("linden_file.dat","r");
  111. if(!fp)
  112. {
  113. llerrs << "file coudnt be opened\n" << llendl;
  114. return;
  115. }
  116. llsaleinfo1.importFile(fp, has_perm_mask, perm_mask);
  117. fclose(fp);
  118. ensure("importFile() fn failed ", llsaleinfo.getSaleType() == llsaleinfo1.getSaleType() &&
  119. llsaleinfo.getSalePrice() == llsaleinfo1.getSalePrice());
  120. }
  121. template<> template<>
  122. void llsaleinfo_test_t::test<3>()
  123. {
  124. S32 sale_price = 525452;
  125. LLSaleInfo llsaleinfo(LLSaleInfo::FS_ORIGINAL, sale_price);
  126. std::ostringstream ostream;
  127. llsaleinfo.exportLegacyStream(ostream);
  128. std::istringstream istream(ostream.str());
  129. LLSaleInfo llsaleinfo1;
  130. U32 perm_mask = 0;
  131. BOOL has_perm_mask = FALSE;
  132. llsaleinfo1.importLegacyStream(istream, has_perm_mask, perm_mask);
  133. ensure("importLegacyStream() fn failed ", llsaleinfo.getSalePrice() == llsaleinfo1.getSalePrice() &&
  134. llsaleinfo.getSaleType() == llsaleinfo1.getSaleType());
  135. }
  136. template<> template<>
  137. void llsaleinfo_test_t::test<4>()
  138. {
  139. // Deleted LLSaleInfo::exportFileXML() and LLSaleInfo::importXML()
  140. // because I can't find any non-test code references to it. 2009-05-04 JC
  141. }
  142. template<> template<>
  143. void llsaleinfo_test_t::test<5>()
  144. {
  145. S32 sale_price = 99000;
  146. LLSaleInfo saleinfo(LLSaleInfo::FS_ORIGINAL, sale_price);
  147. LLSD sd_result = saleinfo.asLLSD();
  148. U32 perm_mask = 0 ;
  149. BOOL has_perm_mask = FALSE;
  150. LLSaleInfo saleinfo1;
  151. saleinfo1.fromLLSD( sd_result, has_perm_mask, perm_mask);
  152. ensure_equals("asLLSD and fromLLSD failed", saleinfo.getSalePrice(), saleinfo1.getSalePrice());
  153. ensure_equals("asLLSD and fromLLSD failed", saleinfo.getSaleType(), saleinfo1.getSaleType());
  154. }
  155. //static EForSale lookup(const char* name) fn test
  156. template<> template<>
  157. void llsaleinfo_test_t::test<6>()
  158. {
  159. S32 sale_price = 233223;
  160. LLSaleInfo::EForSale ret_type = LLSaleInfo::lookup("orig");
  161. ensure_equals("lookup(const char* name) fn failed", ret_type, LLSaleInfo::FS_ORIGINAL);
  162. LLSaleInfo saleinfo(LLSaleInfo::FS_COPY, sale_price);
  163. const char* result = LLSaleInfo::lookup(LLSaleInfo::FS_COPY);
  164. ensure("char* lookup(EForSale type) fn failed", 0 == strcmp("copy", result));
  165. }
  166. //void LLSaleInfo::accumulate(const LLSaleInfo& sale_info) fn test
  167. template<> template<>
  168. void llsaleinfo_test_t::test<7>()
  169. {
  170. S32 sale_price = 20;
  171. LLSaleInfo saleinfo(LLSaleInfo::FS_COPY, sale_price);
  172. LLSaleInfo saleinfo1(LLSaleInfo::FS_COPY, sale_price);
  173. saleinfo1.accumulate(saleinfo);
  174. ensure_equals("LLSaleInfo::accumulate(const LLSaleInfo& sale_info) fn failed", saleinfo1.getSalePrice(), 40);
  175. }
  176. // test cases of bool operator==(const LLSaleInfo &rhs) fn
  177. // test case of bool operator!=(const LLSaleInfo &rhs) fn
  178. template<> template<>
  179. void llsaleinfo_test_t::test<8>()
  180. {
  181. S32 sale_price = 55000;
  182. LLSaleInfo saleinfo(LLSaleInfo::FS_ORIGINAL, sale_price);
  183. LLSaleInfo saleinfoequal(LLSaleInfo::FS_ORIGINAL, sale_price);
  184. LLSaleInfo saleinfonotequal(LLSaleInfo::FS_ORIGINAL, sale_price*2);
  185. ensure("operator == fn. failed", true == (saleinfo == saleinfoequal));
  186. ensure("operator != fn. failed", true == (saleinfo != saleinfonotequal));
  187. }
  188. template<> template<>
  189. void llsaleinfo_test_t::test<9>()
  190. {
  191. //TBD: void LLSaleInfo::packMessage(LLMessageSystem* msg) const
  192. //TBD: void LLSaleInfo::unpackMessage(LLMessageSystem* msg, const char* block)
  193. //TBD: void LLSaleInfo::unpackMultiMessage(LLMessageSystem* msg, const char* block, S32 block_num)
  194. }
  195. }