llsaleinfo_tut.cpp

Go to the documentation of this file.
00001 
00034 #include <tut/tut.h>
00035 #include "linden_common.h"
00036 #include "lltut.h"
00037 #include "llsaleinfo.h"
00038 
00039 namespace tut
00040 {
00041         struct llsaleinfo_tut
00042         {
00043         };
00044         typedef test_group<llsaleinfo_tut> llsaleinfo_tut_t;
00045         typedef llsaleinfo_tut_t::object llsaleinfo_test_t;
00046         tut::llsaleinfo_tut_t tut_llsaleinfo_test("llsaleinfo");
00047 
00048         template<> template<>
00049         void llsaleinfo_test_t::test<1>()
00050         {
00051                 //test case for getSaleType(), getSalePrice(), getCRC32() fn.
00052                 //test case for setSaleType(), setSalePrice() fn.
00053 
00054                 S32 sale_price = 10000;
00055                 LLSaleInfo llsaleinfo(LLSaleInfo::FS_COPY, sale_price);
00056                 char* sale= "copy";
00057 
00058                 LLSD llsd_obj1 = ll_create_sd_from_sale_info(llsaleinfo);
00059                 LLSaleInfo saleinfo1 = ll_sale_info_from_sd(llsd_obj1);
00060                 
00061                 ensure("1. The getSaleType() fn failed", LLSaleInfo::FS_COPY == llsaleinfo.getSaleType());
00062                 ensure("2. LLSaleInfo::isForSale() fn failed", TRUE == llsaleinfo.isForSale());
00063                 ensure("3. The getSalePrice() fn failed", sale_price == llsaleinfo.getSalePrice());
00064                 ensure("4. The getCRC32() fn failed", 235833404 == llsaleinfo.getCRC32());
00065                 ensure("5. LLSaleInfo::lookup(const char* name) fn failed", LLSaleInfo::FS_COPY == llsaleinfo.lookup(sale));
00066                 ensure_equals("6. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSalePrice(), saleinfo1.getSalePrice());
00067                 ensure_equals("7. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSaleType(), saleinfo1.getSaleType());
00068 
00069                 llsaleinfo.setSalePrice(10000000);
00070                 llsaleinfo.setSaleType(LLSaleInfo::FS_ORIGINAL);
00071                 sale = "cntn";
00072                 llsd_obj1 = ll_create_sd_from_sale_info(llsaleinfo);
00073                 saleinfo1 = ll_sale_info_from_sd(llsd_obj1);
00074 
00075                 ensure("8. The getSaleType() and setSaleType() fn failed", LLSaleInfo::FS_ORIGINAL == llsaleinfo.getSaleType());
00076                 ensure("9. LLSaleInfo::isForSale() fn failed", TRUE == llsaleinfo.isForSale());
00077                 ensure("10. The getSalePrice() fn failed", 10000000 == llsaleinfo.getSalePrice());
00078                 ensure("11. The getCRC32() fn failed", 127911702 == llsaleinfo.getCRC32());
00079                 ensure("12. LLSaleInfo::lookup(const char* name) fn failed", LLSaleInfo::FS_CONTENTS == llsaleinfo.lookup(sale));
00080                 ensure_equals("13. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSalePrice(), saleinfo1.getSalePrice());
00081                 ensure_equals("14. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSaleType(), saleinfo1.getSaleType());
00082 
00083                 llsaleinfo.setSalePrice(55000550);
00084                 llsaleinfo.setSaleType(LLSaleInfo::FS_CONTENTS);
00085                 sale = "orig";
00086                 llsd_obj1 = ll_create_sd_from_sale_info(llsaleinfo);
00087                 saleinfo1 = ll_sale_info_from_sd(llsd_obj1);
00088 
00089                 ensure("15. The getSaleType() and setSaleType() fn failed", LLSaleInfo::FS_CONTENTS == llsaleinfo.getSaleType());
00090                 ensure("16. LLSaleInfo::isForSale() fn failed", TRUE == llsaleinfo.isForSale());
00091                 ensure("17. The getSalePrice() fn failed", 55000550 == llsaleinfo.getSalePrice());
00092                 ensure("18. The getCRC32() fn failed", 408735656 == llsaleinfo.getCRC32());
00093                 ensure("19. LLSaleInfo::lookup(const char* name) fn failed", LLSaleInfo::FS_ORIGINAL == llsaleinfo.lookup(sale));
00094                 ensure_equals("20. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSalePrice(), saleinfo1.getSalePrice());
00095                 ensure_equals("21. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSaleType(), saleinfo1.getSaleType());
00096 
00097                 llsaleinfo.setSalePrice(-6432);
00098                 llsaleinfo.setSaleType(LLSaleInfo::FS_NOT);
00099                 sale = "not";
00100                 llsd_obj1 = ll_create_sd_from_sale_info(llsaleinfo);
00101                 saleinfo1 = ll_sale_info_from_sd(llsd_obj1);
00102 
00103                 ensure("22. The getSaleType() and setSaleType() fn failed", LLSaleInfo::FS_NOT == llsaleinfo.getSaleType());
00104                 ensure("23. LLSaleInfo::isForSale() fn failed", FALSE == llsaleinfo.isForSale());
00105                 ensure("24. The getSalePrice() fn failed", 0 == llsaleinfo.getSalePrice());
00106                 ensure("25. The getCRC32() fn failed", 0 == llsaleinfo.getCRC32());
00107                 ensure("26. LLSaleInfo::lookup(const char* name) fn failed", LLSaleInfo::FS_NOT == llsaleinfo.lookup(sale));
00108                 ensure_equals("27. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSalePrice(), saleinfo1.getSalePrice());
00109                 ensure_equals("28. ll_create_sd_from_sale_info() fn failed", llsaleinfo.getSaleType(), saleinfo1.getSaleType());
00110         }
00111 
00112         template<> template<>
00113         void llsaleinfo_test_t::test<2>()
00114         {
00115 
00116                 FILE* fp = fopen("linden_file.dat","w+");
00117                 if(!fp)
00118                 {
00119                         llerrs << "file could not be opened\n" << llendl;
00120                         return;
00121                 }
00122                         
00123                 S32 sale_price = 43500;
00124                 LLSaleInfo llsaleinfo(LLSaleInfo::FS_COPY, sale_price);
00125                 
00126                 llsaleinfo.exportFile(fp);
00127                 fclose(fp);
00128 
00129                 LLSaleInfo llsaleinfo1;
00130                 U32 perm_mask;
00131                 BOOL has_perm_mask;
00132                 fp = fopen("linden_file.dat","r");
00133                 
00134                 if(!fp)
00135                 {
00136                         llerrs << "file coudnt be opened\n" << llendl;
00137                         return;
00138                 }
00139                 
00140                 llsaleinfo1.importFile(fp, has_perm_mask, perm_mask);
00141                 fclose(fp);
00142                 
00143                 ensure("importFile() fn failed ", llsaleinfo.getSaleType() == llsaleinfo1.getSaleType() &&
00144                                                                      llsaleinfo.getSalePrice() == llsaleinfo1.getSalePrice());                          
00145         }
00146 
00147         template<> template<>
00148         void llsaleinfo_test_t::test<3>()
00149         {
00150                 S32 sale_price = 525452;
00151                 LLSaleInfo llsaleinfo(LLSaleInfo::FS_ORIGINAL, sale_price);
00152                 
00153                 std::ostringstream ostream;
00154                 llsaleinfo.exportLegacyStream(ostream);
00155                 
00156                 std::istringstream istream(ostream.str());
00157                 LLSaleInfo llsaleinfo1;
00158                 U32 perm_mask = 0;
00159                 BOOL has_perm_mask = FALSE;
00160                 llsaleinfo1.importLegacyStream(istream, has_perm_mask, perm_mask);
00161                                         
00162                 ensure("importLegacyStream() fn failed ", llsaleinfo.getSalePrice() == llsaleinfo1.getSalePrice() &&
00163                                                                                        llsaleinfo.getSaleType() == llsaleinfo1.getSaleType());          
00164         }
00165 
00166         template<> template<>
00167         void llsaleinfo_test_t::test<4>()
00168         {
00169 // LLXMLNode is teh suck.
00170 #if 0           
00171                 S32 sale_price = 23445;
00172                 LLSaleInfo saleinfo(LLSaleInfo::FS_CONTENTS, sale_price);
00173                 
00174                 LLXMLNode* x_node = saleinfo.exportFileXML();
00175 
00176                 LLSaleInfo saleinfo1(LLSaleInfo::FS_NOT, 0);
00177                 
00178                 saleinfo1.importXML(x_node);
00179                 ensure_equals("1.importXML() fn failed", saleinfo.getSalePrice(), saleinfo1.getSalePrice());
00180                 ensure_equals("2.importXML() fn failed", saleinfo.getSaleType(), saleinfo1.getSaleType());
00181 #endif
00182         }
00183 
00184         template<> template<>
00185         void llsaleinfo_test_t::test<5>()
00186         {       
00187                 S32 sale_price = 99000;
00188                 LLSaleInfo saleinfo(LLSaleInfo::FS_ORIGINAL, sale_price);
00189                 
00190                 LLSD sd_result = saleinfo.asLLSD();
00191                 
00192                 U32 perm_mask = 0 ;
00193                 BOOL has_perm_mask = FALSE;
00194 
00195                 LLSaleInfo saleinfo1;
00196                 saleinfo1.fromLLSD( sd_result, has_perm_mask, perm_mask);       
00197 
00198                 ensure_equals("asLLSD and fromLLSD failed", saleinfo.getSalePrice(), saleinfo1.getSalePrice());
00199                 ensure_equals("asLLSD and fromLLSD failed", saleinfo.getSaleType(), saleinfo1.getSaleType());
00200         }
00201 
00202         //static EForSale lookup(const char* name) fn test
00203         template<> template<>
00204         void llsaleinfo_test_t::test<6>()
00205         {
00206                 S32 sale_price = 233223;
00207                 LLSaleInfo::EForSale ret_type = LLSaleInfo::lookup("orig");
00208                 
00209                 ensure_equals("lookup(const char* name) fn failed", ret_type, LLSaleInfo::FS_ORIGINAL);
00210 
00211                 LLSaleInfo saleinfo(LLSaleInfo::FS_COPY, sale_price);
00212                 const char* result = LLSaleInfo::lookup(LLSaleInfo::FS_COPY);
00213                 ensure("char* lookup(EForSale type) fn failed", 0 == strcmp("copy", result));
00214         }
00215 
00216         //void LLSaleInfo::accumulate(const LLSaleInfo& sale_info) fn test
00217         template<> template<>
00218         void llsaleinfo_test_t::test<7>()
00219         {
00220                 S32 sale_price = 20;
00221                 LLSaleInfo saleinfo(LLSaleInfo::FS_COPY, sale_price);
00222                 LLSaleInfo saleinfo1(LLSaleInfo::FS_COPY, sale_price);
00223                 saleinfo1.accumulate(saleinfo);
00224                 ensure_equals("LLSaleInfo::accumulate(const LLSaleInfo& sale_info) fn failed", saleinfo1.getSalePrice(), 40);
00225                                 
00226         }
00227 
00228         // test cases of bool operator==(const LLSaleInfo &rhs) fn
00229         // test case of bool operator!=(const LLSaleInfo &rhs) fn
00230         template<> template<>
00231         void llsaleinfo_test_t::test<8>()
00232         {
00233                 S32 sale_price = 55000;
00234                 LLSaleInfo saleinfo(LLSaleInfo::FS_ORIGINAL, sale_price);
00235                 LLSaleInfo saleinfoequal(LLSaleInfo::FS_ORIGINAL, sale_price);
00236                 LLSaleInfo saleinfonotequal(LLSaleInfo::FS_ORIGINAL, sale_price*2);
00237                 
00238                 ensure("operator == fn. failed", true == (saleinfo == saleinfoequal));
00239                 ensure("operator != fn. failed", true == (saleinfo != saleinfonotequal));
00240         }                       
00241 
00242         template<> template<>
00243         void llsaleinfo_test_t::test<9>()
00244         {
00245 
00246                 //TBD: void LLSaleInfo::packMessage(LLMessageSystem* msg) const
00247                 //TBD: void LLSaleInfo::unpackMessage(LLMessageSystem* msg, const char* block)
00248                 //TBD: void LLSaleInfo::unpackMultiMessage(LLMessageSystem* msg, const char* block, S32 block_num)
00249         }
00250 
00251 }

Generated on Thu Jul 1 06:09:05 2010 for Second Life Viewer by  doxygen 1.4.7