PageRenderTime 63ms CodeModel.GetById 36ms app.highlight 23ms RepoModel.GetById 1ms app.codeStats 1ms

/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
  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
 29#include <tut/tut.hpp>
 30#include "linden_common.h"
 31#include "lltut.h"
 32#include "llsaleinfo.h"
 33
 34namespace tut
 35{
 36	struct llsaleinfo_tut
 37	{
 38	};
 39	typedef test_group<llsaleinfo_tut> llsaleinfo_tut_t;
 40	typedef llsaleinfo_tut_t::object llsaleinfo_test_t;
 41	tut::llsaleinfo_tut_t tut_llsaleinfo_test("llsaleinfo");
 42
 43	template<> template<>
 44	void llsaleinfo_test_t::test<1>()
 45	{
 46		//test case for getSaleType(), getSalePrice(), getCRC32() fn.
 47		//test case for setSaleType(), setSalePrice() fn.
 48
 49		S32 sale_price = 10000;
 50		LLSaleInfo llsaleinfo(LLSaleInfo::FS_COPY, sale_price);
 51		const char* sale= "copy";
 52
 53		LLSD llsd_obj1 = ll_create_sd_from_sale_info(llsaleinfo);
 54		LLSaleInfo saleinfo1 = ll_sale_info_from_sd(llsd_obj1);
 55		
 56		ensure("1. The getSaleType() fn failed", LLSaleInfo::FS_COPY == llsaleinfo.getSaleType());
 57		ensure("2. LLSaleInfo::isForSale() fn failed", TRUE == llsaleinfo.isForSale());
 58		ensure("3. The getSalePrice() fn failed", sale_price == llsaleinfo.getSalePrice());
 59		ensure("4. The getCRC32() fn failed", 235833404 == llsaleinfo.getCRC32());
 60		ensure("5. LLSaleInfo::lookup(const char* name) fn failed", LLSaleInfo::FS_COPY == llsaleinfo.lookup(sale));
 61		ensure_equals("6. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSalePrice(), saleinfo1.getSalePrice());
 62		ensure_equals("7. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSaleType(), saleinfo1.getSaleType());
 63
 64		llsaleinfo.setSalePrice(10000000);
 65		llsaleinfo.setSaleType(LLSaleInfo::FS_ORIGINAL);
 66		sale = "cntn";
 67		llsd_obj1 = ll_create_sd_from_sale_info(llsaleinfo);
 68		saleinfo1 = ll_sale_info_from_sd(llsd_obj1);
 69
 70		ensure("8. The getSaleType() and setSaleType() fn failed", LLSaleInfo::FS_ORIGINAL == llsaleinfo.getSaleType());
 71		ensure("9. LLSaleInfo::isForSale() fn failed", TRUE == llsaleinfo.isForSale());
 72		ensure("10. The getSalePrice() fn failed", 10000000 == llsaleinfo.getSalePrice());
 73		ensure("11. The getCRC32() fn failed", 127911702 == llsaleinfo.getCRC32());
 74		ensure("12. LLSaleInfo::lookup(const char* name) fn failed", LLSaleInfo::FS_CONTENTS == llsaleinfo.lookup(sale));
 75		ensure_equals("13. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSalePrice(), saleinfo1.getSalePrice());
 76		ensure_equals("14. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSaleType(), saleinfo1.getSaleType());
 77
 78		llsaleinfo.setSalePrice(55000550);
 79		llsaleinfo.setSaleType(LLSaleInfo::FS_CONTENTS);
 80		sale = "orig";
 81		llsd_obj1 = ll_create_sd_from_sale_info(llsaleinfo);
 82		saleinfo1 = ll_sale_info_from_sd(llsd_obj1);
 83
 84		ensure("15. The getSaleType() and setSaleType() fn failed", LLSaleInfo::FS_CONTENTS == llsaleinfo.getSaleType());
 85		ensure("16. LLSaleInfo::isForSale() fn failed", TRUE == llsaleinfo.isForSale());
 86		ensure("17. The getSalePrice() fn failed", 55000550 == llsaleinfo.getSalePrice());
 87		ensure("18. The getCRC32() fn failed", 408735656 == llsaleinfo.getCRC32());
 88		ensure("19. LLSaleInfo::lookup(const char* name) fn failed", LLSaleInfo::FS_ORIGINAL == llsaleinfo.lookup(sale));
 89		ensure_equals("20. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSalePrice(), saleinfo1.getSalePrice());
 90		ensure_equals("21. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSaleType(), saleinfo1.getSaleType());
 91
 92		llsaleinfo.setSalePrice(-6432);
 93		llsaleinfo.setSaleType(LLSaleInfo::FS_NOT);
 94		sale = "not";
 95		llsd_obj1 = ll_create_sd_from_sale_info(llsaleinfo);
 96		saleinfo1 = ll_sale_info_from_sd(llsd_obj1);
 97
 98		ensure("22. The getSaleType() and setSaleType() fn failed", LLSaleInfo::FS_NOT == llsaleinfo.getSaleType());
 99		ensure("23. LLSaleInfo::isForSale() fn failed", FALSE == llsaleinfo.isForSale());
100		ensure("24. The getSalePrice() fn failed", 0 == llsaleinfo.getSalePrice());
101		ensure("25. The getCRC32() fn failed", 0 == llsaleinfo.getCRC32());
102		ensure("26. LLSaleInfo::lookup(const char* name) fn failed", LLSaleInfo::FS_NOT == llsaleinfo.lookup(sale));
103		ensure_equals("27. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSalePrice(), saleinfo1.getSalePrice());
104		ensure_equals("28. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSaleType(), saleinfo1.getSaleType());
105	}
106
107	template<> template<>
108	void llsaleinfo_test_t::test<2>()
109	{
110
111		LLFILE* fp = LLFile::fopen("linden_file.dat","w+");
112		if(!fp)
113		{
114			llerrs << "file could not be opened\n" << llendl;
115			return;
116		}
117			
118		S32 sale_price = 43500;
119		LLSaleInfo llsaleinfo(LLSaleInfo::FS_COPY, sale_price);
120		
121		llsaleinfo.exportFile(fp);
122		fclose(fp);
123
124		LLSaleInfo llsaleinfo1;
125		U32 perm_mask;
126		BOOL has_perm_mask;
127		fp = LLFile::fopen("linden_file.dat","r");
128		
129		if(!fp)
130		{
131			llerrs << "file coudnt be opened\n" << llendl;
132			return;
133		}
134		
135		llsaleinfo1.importFile(fp, has_perm_mask, perm_mask);
136		fclose(fp);
137		
138		ensure("importFile() fn failed ", llsaleinfo.getSaleType() == llsaleinfo1.getSaleType() &&
139								     llsaleinfo.getSalePrice() == llsaleinfo1.getSalePrice());				
140	}
141
142	template<> template<>
143	void llsaleinfo_test_t::test<3>()
144	{
145		S32 sale_price = 525452;
146		LLSaleInfo llsaleinfo(LLSaleInfo::FS_ORIGINAL, sale_price);
147		
148		std::ostringstream ostream;
149		llsaleinfo.exportLegacyStream(ostream);
150		
151		std::istringstream istream(ostream.str());
152		LLSaleInfo llsaleinfo1;
153		U32 perm_mask = 0;
154		BOOL has_perm_mask = FALSE;
155		llsaleinfo1.importLegacyStream(istream, has_perm_mask, perm_mask);
156					
157		ensure("importLegacyStream() fn failed ", llsaleinfo.getSalePrice() == llsaleinfo1.getSalePrice() &&
158										       llsaleinfo.getSaleType() == llsaleinfo1.getSaleType());		
159	}
160
161	template<> template<>
162	void llsaleinfo_test_t::test<4>()
163	{
164		// Deleted LLSaleInfo::exportFileXML() and LLSaleInfo::importXML()
165		// because I can't find any non-test code references to it. 2009-05-04 JC
166	}
167
168	template<> template<>
169	void llsaleinfo_test_t::test<5>()
170	{	
171		S32 sale_price = 99000;
172		LLSaleInfo saleinfo(LLSaleInfo::FS_ORIGINAL, sale_price);
173		
174		LLSD sd_result = saleinfo.asLLSD();
175		
176		U32 perm_mask = 0 ;
177		BOOL has_perm_mask = FALSE;
178
179		LLSaleInfo saleinfo1;
180		saleinfo1.fromLLSD( sd_result, has_perm_mask, perm_mask);	
181
182		ensure_equals("asLLSD and fromLLSD failed", saleinfo.getSalePrice(), saleinfo1.getSalePrice());
183		ensure_equals("asLLSD and fromLLSD failed", saleinfo.getSaleType(), saleinfo1.getSaleType());
184	}
185
186	//static EForSale lookup(const char* name) fn test
187	template<> template<>
188	void llsaleinfo_test_t::test<6>()
189	{
190		S32 sale_price = 233223;
191		LLSaleInfo::EForSale ret_type = LLSaleInfo::lookup("orig");
192		
193		ensure_equals("lookup(const char* name) fn failed", ret_type, LLSaleInfo::FS_ORIGINAL);
194
195		LLSaleInfo saleinfo(LLSaleInfo::FS_COPY, sale_price);
196		const char* result = LLSaleInfo::lookup(LLSaleInfo::FS_COPY);
197		ensure("char* lookup(EForSale type) fn failed", 0 == strcmp("copy", result));
198	}
199
200	//void LLSaleInfo::accumulate(const LLSaleInfo& sale_info) fn test
201	template<> template<>
202	void llsaleinfo_test_t::test<7>()
203	{
204		S32 sale_price = 20;
205		LLSaleInfo saleinfo(LLSaleInfo::FS_COPY, sale_price);
206		LLSaleInfo saleinfo1(LLSaleInfo::FS_COPY, sale_price);
207		saleinfo1.accumulate(saleinfo);
208		ensure_equals("LLSaleInfo::accumulate(const LLSaleInfo& sale_info) fn failed", saleinfo1.getSalePrice(), 40);
209				
210	}
211
212	// test cases of bool operator==(const LLSaleInfo &rhs) fn
213	// test case of bool operator!=(const LLSaleInfo &rhs) fn
214	template<> template<>
215	void llsaleinfo_test_t::test<8>()
216	{
217		S32 sale_price = 55000;
218		LLSaleInfo saleinfo(LLSaleInfo::FS_ORIGINAL, sale_price);
219		LLSaleInfo saleinfoequal(LLSaleInfo::FS_ORIGINAL, sale_price);
220		LLSaleInfo saleinfonotequal(LLSaleInfo::FS_ORIGINAL, sale_price*2);
221		
222		ensure("operator == fn. failed", true == (saleinfo == saleinfoequal));
223		ensure("operator != fn. failed", true == (saleinfo != saleinfonotequal));
224	}			
225
226	template<> template<>
227	void llsaleinfo_test_t::test<9>()
228	{
229
230		//TBD: void LLSaleInfo::packMessage(LLMessageSystem* msg) const
231		//TBD: void LLSaleInfo::unpackMessage(LLMessageSystem* msg, const char* block)
232		//TBD: void LLSaleInfo::unpackMultiMessage(LLMessageSystem* msg, const char* block, S32 block_num)
233	}
234
235}