diff options
Diffstat (limited to 'linden/indra/test/llsaleinfo_tut.cpp')
-rw-r--r-- | linden/indra/test/llsaleinfo_tut.cpp | 248 |
1 files changed, 248 insertions, 0 deletions
diff --git a/linden/indra/test/llsaleinfo_tut.cpp b/linden/indra/test/llsaleinfo_tut.cpp new file mode 100644 index 0000000..9dc7f77 --- /dev/null +++ b/linden/indra/test/llsaleinfo_tut.cpp | |||
@@ -0,0 +1,248 @@ | |||
1 | /** | ||
2 | * @file LLSaleInfo_tut.cpp | ||
3 | * @author Adroit | ||
4 | * @date 2007-03 | ||
5 | * @brief Test cases of llsaleinfo.h | ||
6 | * | ||
7 | * Copyright (c) 2007-2007, Linden Research, Inc. | ||
8 | * | ||
9 | * Second Life Viewer Source Code | ||
10 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
11 | * to you under the terms of the GNU General Public License, version 2.0 | ||
12 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
13 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
14 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
15 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
16 | * | ||
17 | * There are special exceptions to the terms and conditions of the GPL as | ||
18 | * it is applied to this Source Code. View the full text of the exception | ||
19 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
20 | * online at http://secondlife.com/developers/opensource/flossexception | ||
21 | * | ||
22 | * By copying, modifying or distributing this software, you acknowledge | ||
23 | * that you have read and understood your obligations described above, | ||
24 | * and agree to abide by those obligations. | ||
25 | * | ||
26 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
27 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
28 | * COMPLETENESS OR PERFORMANCE. | ||
29 | */ | ||
30 | |||
31 | #include <tut/tut.h> | ||
32 | #include "lltut.h" | ||
33 | #include "linden_common.h" | ||
34 | #include "llsaleinfo.h" | ||
35 | |||
36 | namespace tut | ||
37 | { | ||
38 | struct llsaleinfo_tut | ||
39 | { | ||
40 | }; | ||
41 | typedef test_group<llsaleinfo_tut> llsaleinfo_tut_t; | ||
42 | typedef llsaleinfo_tut_t::object llsaleinfo_test_t; | ||
43 | tut::llsaleinfo_tut_t tut_llsaleinfo_test("llsaleinfo"); | ||
44 | |||
45 | template<> template<> | ||
46 | void llsaleinfo_test_t::test<1>() | ||
47 | { | ||
48 | //test case for getSaleType(), getSalePrice(), getCRC32() fn. | ||
49 | //test case for setSaleType(), setSalePrice() fn. | ||
50 | |||
51 | S32 sale_price = 10000; | ||
52 | LLSaleInfo llsaleinfo(LLSaleInfo::FS_COPY, sale_price); | ||
53 | char* sale= "copy"; | ||
54 | |||
55 | LLSD llsd_obj1 = ll_create_sd_from_sale_info(llsaleinfo); | ||
56 | LLSaleInfo saleinfo1 = ll_sale_info_from_sd(llsd_obj1); | ||
57 | |||
58 | ensure("1. The getSaleType() fn failed", LLSaleInfo::FS_COPY == llsaleinfo.getSaleType()); | ||
59 | ensure("2. LLSaleInfo::isForSale() fn failed", TRUE == llsaleinfo.isForSale()); | ||
60 | ensure("3. The getSalePrice() fn failed", sale_price == llsaleinfo.getSalePrice()); | ||
61 | ensure("4. The getCRC32() fn failed", 235833404 == llsaleinfo.getCRC32()); | ||
62 | ensure("5. LLSaleInfo::lookup(const char* name) fn failed", LLSaleInfo::FS_COPY == llsaleinfo.lookup(sale)); | ||
63 | ensure_equals("6. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSalePrice(), saleinfo1.getSalePrice()); | ||
64 | ensure_equals("7. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSaleType(), saleinfo1.getSaleType()); | ||
65 | |||
66 | llsaleinfo.setSalePrice(10000000); | ||
67 | llsaleinfo.setSaleType(LLSaleInfo::FS_ORIGINAL); | ||
68 | sale = "cntn"; | ||
69 | llsd_obj1 = ll_create_sd_from_sale_info(llsaleinfo); | ||
70 | saleinfo1 = ll_sale_info_from_sd(llsd_obj1); | ||
71 | |||
72 | ensure("8. The getSaleType() and setSaleType() fn failed", LLSaleInfo::FS_ORIGINAL == llsaleinfo.getSaleType()); | ||
73 | ensure("9. LLSaleInfo::isForSale() fn failed", TRUE == llsaleinfo.isForSale()); | ||
74 | ensure("10. The getSalePrice() fn failed", 10000000 == llsaleinfo.getSalePrice()); | ||
75 | ensure("11. The getCRC32() fn failed", 127911702 == llsaleinfo.getCRC32()); | ||
76 | ensure("12. LLSaleInfo::lookup(const char* name) fn failed", LLSaleInfo::FS_CONTENTS == llsaleinfo.lookup(sale)); | ||
77 | ensure_equals("13. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSalePrice(), saleinfo1.getSalePrice()); | ||
78 | ensure_equals("14. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSaleType(), saleinfo1.getSaleType()); | ||
79 | |||
80 | llsaleinfo.setSalePrice(55000550); | ||
81 | llsaleinfo.setSaleType(LLSaleInfo::FS_CONTENTS); | ||
82 | sale = "orig"; | ||
83 | llsd_obj1 = ll_create_sd_from_sale_info(llsaleinfo); | ||
84 | saleinfo1 = ll_sale_info_from_sd(llsd_obj1); | ||
85 | |||
86 | ensure("15. The getSaleType() and setSaleType() fn failed", LLSaleInfo::FS_CONTENTS == llsaleinfo.getSaleType()); | ||
87 | ensure("16. LLSaleInfo::isForSale() fn failed", TRUE == llsaleinfo.isForSale()); | ||
88 | ensure("17. The getSalePrice() fn failed", 55000550 == llsaleinfo.getSalePrice()); | ||
89 | ensure("18. The getCRC32() fn failed", 408735656 == llsaleinfo.getCRC32()); | ||
90 | ensure("19. LLSaleInfo::lookup(const char* name) fn failed", LLSaleInfo::FS_ORIGINAL == llsaleinfo.lookup(sale)); | ||
91 | ensure_equals("20. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSalePrice(), saleinfo1.getSalePrice()); | ||
92 | ensure_equals("21. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSaleType(), saleinfo1.getSaleType()); | ||
93 | |||
94 | llsaleinfo.setSalePrice(-6432); | ||
95 | llsaleinfo.setSaleType(LLSaleInfo::FS_NOT); | ||
96 | sale = "not"; | ||
97 | llsd_obj1 = ll_create_sd_from_sale_info(llsaleinfo); | ||
98 | saleinfo1 = ll_sale_info_from_sd(llsd_obj1); | ||
99 | |||
100 | ensure("22. The getSaleType() and setSaleType() fn failed", LLSaleInfo::FS_NOT == llsaleinfo.getSaleType()); | ||
101 | ensure("23. LLSaleInfo::isForSale() fn failed", FALSE == llsaleinfo.isForSale()); | ||
102 | ensure("24. The getSalePrice() fn failed", 0 == llsaleinfo.getSalePrice()); | ||
103 | ensure("25. The getCRC32() fn failed", 0 == llsaleinfo.getCRC32()); | ||
104 | ensure("26. LLSaleInfo::lookup(const char* name) fn failed", LLSaleInfo::FS_NOT == llsaleinfo.lookup(sale)); | ||
105 | ensure_equals("27. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSalePrice(), saleinfo1.getSalePrice()); | ||
106 | ensure_equals("28. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSaleType(), saleinfo1.getSaleType()); | ||
107 | } | ||
108 | |||
109 | template<> template<> | ||
110 | void llsaleinfo_test_t::test<2>() | ||
111 | { | ||
112 | |||
113 | FILE* fp = fopen("linden_file.dat","w+"); | ||
114 | if(!fp) | ||
115 | { | ||
116 | llerrs << "file could not be opened\n" << llendl; | ||
117 | return; | ||
118 | } | ||
119 | |||
120 | S32 sale_price = 43500; | ||
121 | LLSaleInfo llsaleinfo(LLSaleInfo::FS_COPY, sale_price); | ||
122 | |||
123 | llsaleinfo.exportFile(fp); | ||
124 | fclose(fp); | ||
125 | |||
126 | LLSaleInfo llsaleinfo1; | ||
127 | U32 perm_mask; | ||
128 | BOOL has_perm_mask; | ||
129 | fp = fopen("linden_file.dat","r"); | ||
130 | |||
131 | if(!fp) | ||
132 | { | ||
133 | llerrs << "file coudnt be opened\n" << llendl; | ||
134 | return; | ||
135 | } | ||
136 | |||
137 | llsaleinfo1.importFile(fp, has_perm_mask, perm_mask); | ||
138 | fclose(fp); | ||
139 | |||
140 | ensure("importFile() fn failed ", llsaleinfo.getSaleType() == llsaleinfo1.getSaleType() && | ||
141 | llsaleinfo.getSalePrice() == llsaleinfo1.getSalePrice()); | ||
142 | } | ||
143 | |||
144 | template<> template<> | ||
145 | void llsaleinfo_test_t::test<3>() | ||
146 | { | ||
147 | S32 sale_price = 525452; | ||
148 | LLSaleInfo llsaleinfo(LLSaleInfo::FS_ORIGINAL, sale_price); | ||
149 | |||
150 | std::ostringstream ostream; | ||
151 | llsaleinfo.exportLegacyStream(ostream); | ||
152 | |||
153 | std::istringstream istream(ostream.str()); | ||
154 | LLSaleInfo llsaleinfo1; | ||
155 | U32 perm_mask = 0; | ||
156 | BOOL has_perm_mask = FALSE; | ||
157 | llsaleinfo1.importLegacyStream(istream, has_perm_mask, perm_mask); | ||
158 | |||
159 | ensure("importLegacyStream() fn failed ", llsaleinfo.getSalePrice() == llsaleinfo1.getSalePrice() && | ||
160 | llsaleinfo.getSaleType() == llsaleinfo1.getSaleType()); | ||
161 | } | ||
162 | |||
163 | template<> template<> | ||
164 | void llsaleinfo_test_t::test<4>() | ||
165 | { | ||
166 | // LLXMLNode is teh suck. | ||
167 | #if 0 | ||
168 | S32 sale_price = 23445; | ||
169 | LLSaleInfo saleinfo(LLSaleInfo::FS_CONTENTS, sale_price); | ||
170 | |||
171 | LLXMLNode* x_node = saleinfo.exportFileXML(); | ||
172 | |||
173 | LLSaleInfo saleinfo1(LLSaleInfo::FS_NOT, 0); | ||
174 | |||
175 | saleinfo1.importXML(x_node); | ||
176 | ensure_equals("1.importXML() fn failed", saleinfo.getSalePrice(), saleinfo1.getSalePrice()); | ||
177 | ensure_equals("2.importXML() fn failed", saleinfo.getSaleType(), saleinfo1.getSaleType()); | ||
178 | #endif | ||
179 | } | ||
180 | |||
181 | template<> template<> | ||
182 | void llsaleinfo_test_t::test<5>() | ||
183 | { | ||
184 | S32 sale_price = 99000; | ||
185 | LLSaleInfo saleinfo(LLSaleInfo::FS_ORIGINAL, sale_price); | ||
186 | |||
187 | LLSD sd_result = saleinfo.asLLSD(); | ||
188 | |||
189 | U32 perm_mask = 0 ; | ||
190 | BOOL has_perm_mask = FALSE; | ||
191 | |||
192 | LLSaleInfo saleinfo1; | ||
193 | saleinfo1.fromLLSD( sd_result, has_perm_mask, perm_mask); | ||
194 | |||
195 | ensure_equals("asLLSD and fromLLSD failed", saleinfo.getSalePrice(), saleinfo1.getSalePrice()); | ||
196 | ensure_equals("asLLSD and fromLLSD failed", saleinfo.getSaleType(), saleinfo1.getSaleType()); | ||
197 | } | ||
198 | |||
199 | //static EForSale lookup(const char* name) fn test | ||
200 | template<> template<> | ||
201 | void llsaleinfo_test_t::test<6>() | ||
202 | { | ||
203 | S32 sale_price = 233223; | ||
204 | LLSaleInfo::EForSale ret_type = LLSaleInfo::lookup("orig"); | ||
205 | |||
206 | ensure_equals("lookup(const char* name) fn failed", ret_type, LLSaleInfo::FS_ORIGINAL); | ||
207 | |||
208 | LLSaleInfo saleinfo(LLSaleInfo::FS_COPY, sale_price); | ||
209 | const char* result = LLSaleInfo::lookup(LLSaleInfo::FS_COPY); | ||
210 | ensure("char* lookup(EForSale type) fn failed", 0 == strcmp("copy", result)); | ||
211 | } | ||
212 | |||
213 | //void LLSaleInfo::accumulate(const LLSaleInfo& sale_info) fn test | ||
214 | template<> template<> | ||
215 | void llsaleinfo_test_t::test<7>() | ||
216 | { | ||
217 | S32 sale_price = 20; | ||
218 | LLSaleInfo saleinfo(LLSaleInfo::FS_COPY, sale_price); | ||
219 | LLSaleInfo saleinfo1(LLSaleInfo::FS_COPY, sale_price); | ||
220 | saleinfo1.accumulate(saleinfo); | ||
221 | ensure_equals("LLSaleInfo::accumulate(const LLSaleInfo& sale_info) fn failed", saleinfo1.getSalePrice(), 40); | ||
222 | |||
223 | } | ||
224 | |||
225 | // test cases of bool operator==(const LLSaleInfo &rhs) fn | ||
226 | // test case of bool operator!=(const LLSaleInfo &rhs) fn | ||
227 | template<> template<> | ||
228 | void llsaleinfo_test_t::test<8>() | ||
229 | { | ||
230 | S32 sale_price = 55000; | ||
231 | LLSaleInfo saleinfo(LLSaleInfo::FS_ORIGINAL, sale_price); | ||
232 | LLSaleInfo saleinfoequal(LLSaleInfo::FS_ORIGINAL, sale_price); | ||
233 | LLSaleInfo saleinfonotequal(LLSaleInfo::FS_ORIGINAL, sale_price*2); | ||
234 | |||
235 | ensure("operator == fn. failed", true == (saleinfo == saleinfoequal)); | ||
236 | ensure("operator != fn. failed", true == (saleinfo != saleinfonotequal)); | ||
237 | } | ||
238 | |||
239 | template<> template<> | ||
240 | void llsaleinfo_test_t::test<9>() | ||
241 | { | ||
242 | |||
243 | //TBD: void LLSaleInfo::packMessage(LLMessageSystem* msg) const | ||
244 | //TBD: void LLSaleInfo::unpackMessage(LLMessageSystem* msg, const char* block) | ||
245 | //TBD: void LLSaleInfo::unpackMultiMessage(LLMessageSystem* msg, const char* block, S32 block_num) | ||
246 | } | ||
247 | |||
248 | } | ||