From e33448d5eb93422d2a9161f28951162def2d0e9f Mon Sep 17 00:00:00 2001 From: Mnikolenko Productengine Date: Fri, 7 Aug 2020 19:55:18 +0300 Subject: SL-13669 updated tests --- indra/llinventory/tests/inventorymisc_test.cpp | 71 +++++++++++++++++--------- 1 file changed, 47 insertions(+), 24 deletions(-) (limited to 'indra/llinventory/tests/inventorymisc_test.cpp') diff --git a/indra/llinventory/tests/inventorymisc_test.cpp b/indra/llinventory/tests/inventorymisc_test.cpp index 7b15552f24..6eb3f04827 100644 --- a/indra/llinventory/tests/inventorymisc_test.cpp +++ b/indra/llinventory/tests/inventorymisc_test.cpp @@ -28,9 +28,9 @@ #include "linden_common.h" #include "llsd.h" +#include "llsdserialize.h" #include "../llinventory.h" - #include "../test/lltut.h" @@ -320,27 +320,39 @@ namespace tut template<> template<> void inventory_object::test<7>() { - LLFILE* fp = LLFile::fopen("linden_file.dat","w+"); - if(!fp) + std::string filename("linden_file.dat"); + llofstream fileXML(filename.c_str()); + if (!fileXML.is_open()) { LL_ERRS() << "file could not be opened\n" << LL_ENDL; return; } LLPointer src1 = create_random_inventory_item(); - src1->exportFile(fp, TRUE); - fclose(fp); + fileXML << LLSDOStreamer(src1->asLLSD()) << std::endl; + fileXML.close(); - LLPointer src2 = new LLInventoryItem(); - fp = LLFile::fopen("linden_file.dat","r+"); - if(!fp) + + LLPointer src2 = new LLInventoryItem(); + llifstream file(filename.c_str()); + if (!file.is_open()) { LL_ERRS() << "file could not be opened\n" << LL_ENDL; return; } - - src2->importFile(fp); - fclose(fp); + std::string line; + LLPointer parser = new LLSDNotationParser(); + std::getline(file, line); + LLSD s_item; + std::istringstream iss(line); + if (parser->parse(iss, s_item, line.length()) == LLSDParser::PARSE_FAILURE) + { + LL_ERRS()<< "Parsing cache failed" << LL_ENDL; + return; + } + src2->fromLLSD(s_item); + + file.close(); ensure_equals("1.item id::getUUID() failed", src1->getUUID(), src2->getUUID()); ensure_equals("2.parent::getParentUUID() failed", src1->getParentUUID(), src2->getParentUUID()); @@ -457,27 +469,38 @@ namespace tut template<> template<> void inventory_object::test<13>() { - LLFILE* fp = LLFile::fopen("linden_file.dat","w"); - if(!fp) + std::string filename("linden_file.dat"); + llofstream fileXML(filename.c_str()); + if (!fileXML.is_open()) { - LL_ERRS() << "file coudnt be opened\n" << LL_ENDL; + LL_ERRS() << "file could not be opened\n" << LL_ENDL; return; } - + LLPointer src1 = create_random_inventory_cat(); - src1->exportFile(fp, TRUE); - fclose(fp); + fileXML << LLSDOStreamer(ll_create_sd_from_inventory_category(src1)) << std::endl; + fileXML.close(); - LLPointer src2 = new LLInventoryCategory(); - fp = LLFile::fopen("linden_file.dat","r"); - if(!fp) + llifstream file(filename.c_str()); + if (!file.is_open()) { - LL_ERRS() << "file coudnt be opened\n" << LL_ENDL; + LL_ERRS() << "file could not be opened\n" << LL_ENDL; return; } - - src2->importFile(fp); - fclose(fp); + std::string line; + LLPointer parser = new LLSDNotationParser(); + std::getline(file, line); + LLSD s_item; + std::istringstream iss(line); + if (parser->parse(iss, s_item, line.length()) == LLSDParser::PARSE_FAILURE) + { + LL_ERRS()<< "Parsing cache failed" << LL_ENDL; + return; + } + + file.close(); + + LLPointer src2 = ll_create_category_from_sd(s_item); ensure_equals("1.item id::getUUID() failed", src1->getUUID(), src2->getUUID()); ensure_equals("2.parent::getParentUUID() failed", src1->getParentUUID(), src2->getParentUUID()); -- cgit v1.3 From 43941a3d876b854560b06906665d689c3924aed1 Mon Sep 17 00:00:00 2001 From: Mnikolenko Productengine Date: Mon, 10 Aug 2020 20:50:27 +0300 Subject: SL-13669 tests should cover import/export category from llsd --- indra/llinventory/llinventory.cpp | 41 +++++++++++++++++++++++++- indra/llinventory/llinventory.h | 2 ++ indra/llinventory/tests/inventorymisc_test.cpp | 5 ++-- indra/newview/llviewerinventory.cpp | 35 ++-------------------- 4 files changed, 47 insertions(+), 36 deletions(-) (limited to 'indra/llinventory/tests/inventorymisc_test.cpp') diff --git a/indra/llinventory/llinventory.cpp b/indra/llinventory/llinventory.cpp index fcc2e1d173..18bc1b5a91 100644 --- a/indra/llinventory/llinventory.cpp +++ b/indra/llinventory/llinventory.cpp @@ -41,7 +41,7 @@ /// Exported functions ///---------------------------------------------------------------------------- static const std::string INV_ITEM_ID_LABEL("item_id"); -static const std::string INV_FOLDER_ID_LABEL("folder_id"); +static const std::string INV_FOLDER_ID_LABEL("cat_id"); static const std::string INV_PARENT_ID_LABEL("parent_id"); static const std::string INV_ASSET_TYPE_LABEL("type"); static const std::string INV_PREFERRED_TYPE_LABEL("preferred_type"); @@ -1317,6 +1317,45 @@ BOOL LLInventoryCategory::exportLegacyStream(std::ostream& output_stream, BOOL) return TRUE; } +LLSD LLInventoryCategory::exportLLSD() const +{ + LLSD cat_data; + cat_data[INV_FOLDER_ID_LABEL] = mUUID; + cat_data[INV_PARENT_ID_LABEL] = mParentUUID; + cat_data[INV_ASSET_TYPE_LABEL] = LLAssetType::lookup(mType); + cat_data[INV_PREFERRED_TYPE_LABEL] = LLFolderType::lookup(mPreferredType); + cat_data[INV_NAME_LABEL] = mName; + + return cat_data; +} + +bool LLInventoryCategory::importLLSD(const LLSD& cat_data) +{ + if (cat_data.has(INV_FOLDER_ID_LABEL)) + { + setUUID(cat_data[INV_FOLDER_ID_LABEL].asUUID()); + } + if (cat_data.has(INV_PARENT_ID_LABEL)) + { + setParent(cat_data[INV_PARENT_ID_LABEL].asUUID()); + } + if (cat_data.has(INV_ASSET_TYPE_LABEL)) + { + setType(LLAssetType::lookup(cat_data[INV_ASSET_TYPE_LABEL].asString())); + } + if (cat_data.has(INV_PREFERRED_TYPE_LABEL)) + { + setPreferredType(LLFolderType::lookup(cat_data[INV_PREFERRED_TYPE_LABEL].asString())); + } + if (cat_data.has(INV_NAME_LABEL)) + { + mName = cat_data[INV_NAME_LABEL].asString(); + LLStringUtil::replaceNonstandardASCII(mName, ' '); + LLStringUtil::replaceChar(mName, '|', ' '); + } + + return true; +} ///---------------------------------------------------------------------------- /// Local function definitions ///---------------------------------------------------------------------------- diff --git a/indra/llinventory/llinventory.h b/indra/llinventory/llinventory.h index d00c4d43ee..024afc109c 100644 --- a/indra/llinventory/llinventory.h +++ b/indra/llinventory/llinventory.h @@ -269,6 +269,8 @@ public: virtual BOOL importLegacyStream(std::istream& input_stream); virtual BOOL exportLegacyStream(std::ostream& output_stream, BOOL include_asset_key = TRUE) const; + LLSD exportLLSD() const; + bool importLLSD(const LLSD& cat_data); //-------------------------------------------------------------------- // Member Variables //-------------------------------------------------------------------- diff --git a/indra/llinventory/tests/inventorymisc_test.cpp b/indra/llinventory/tests/inventorymisc_test.cpp index 6eb3f04827..e8b063bffe 100644 --- a/indra/llinventory/tests/inventorymisc_test.cpp +++ b/indra/llinventory/tests/inventorymisc_test.cpp @@ -478,7 +478,7 @@ namespace tut } LLPointer src1 = create_random_inventory_cat(); - fileXML << LLSDOStreamer(ll_create_sd_from_inventory_category(src1)) << std::endl; + fileXML << LLSDOStreamer(src1->exportLLSD()) << std::endl; fileXML.close(); llifstream file(filename.c_str()); @@ -500,7 +500,8 @@ namespace tut file.close(); - LLPointer src2 = ll_create_category_from_sd(s_item); + LLPointer src2 = new LLInventoryCategory(); + src2->importLLSD(s_item); ensure_equals("1.item id::getUUID() failed", src1->getUUID(), src2->getUUID()); ensure_equals("2.parent::getParentUUID() failed", src1->getParentUUID(), src2->getParentUUID()); diff --git a/indra/newview/llviewerinventory.cpp b/indra/newview/llviewerinventory.cpp index 6c61c34075..bbed741a33 100644 --- a/indra/newview/llviewerinventory.cpp +++ b/indra/newview/llviewerinventory.cpp @@ -81,11 +81,6 @@ static const char * const LOG_INV("Inventory"); static const char * const LOG_LOCAL("InventoryLocalize"); static const char * const LOG_NOTECARD("copy_inventory_from_notecard"); -static const std::string INV_CAT_ID("cat_id"); -static const std::string INV_PARENT_ID("parent_id"); -static const std::string INV_ASSET_TYPE("type"); -static const std::string INV_PREFERRED_TYPE("pref_type"); -static const std::string INV_NAME("name"); static const std::string INV_OWNER_ID("owner_id"); static const std::string INV_VERSION("version"); @@ -696,12 +691,7 @@ S32 LLViewerInventoryCategory::getViewerDescendentCount() const LLSD LLViewerInventoryCategory::exportLLSD() const { - LLSD cat_data; - cat_data[INV_CAT_ID] = mUUID; - cat_data[INV_PARENT_ID] = mParentUUID; - cat_data[INV_ASSET_TYPE] = LLAssetType::lookup(mType); - cat_data[INV_PREFERRED_TYPE] = LLFolderType::lookup(mPreferredType); - cat_data[INV_NAME] = mName; + LLSD cat_data = LLInventoryCategory::exportLLSD(); cat_data[INV_OWNER_ID] = mOwnerID; cat_data[INV_VERSION] = mVersion; @@ -710,28 +700,7 @@ LLSD LLViewerInventoryCategory::exportLLSD() const bool LLViewerInventoryCategory::importLLSD(const LLSD& cat_data) { - if (cat_data.has(INV_CAT_ID)) - { - setUUID(cat_data[INV_CAT_ID].asUUID()); - } - if (cat_data.has(INV_PARENT_ID)) - { - setParent(cat_data[INV_PARENT_ID].asUUID()); - } - if (cat_data.has(INV_ASSET_TYPE)) - { - setType(LLAssetType::lookup(cat_data[INV_ASSET_TYPE].asString())); - } - if (cat_data.has(INV_PREFERRED_TYPE)) - { - setPreferredType(LLFolderType::lookup(cat_data[INV_PREFERRED_TYPE].asString())); - } - if (cat_data.has(INV_NAME)) - { - mName = cat_data[INV_NAME].asString(); - LLStringUtil::replaceNonstandardASCII(mName, ' '); - LLStringUtil::replaceChar(mName, '|', ' '); - } + LLInventoryCategory::importLLSD(cat_data); if (cat_data.has(INV_OWNER_ID)) { mOwnerID = cat_data[INV_OWNER_ID].asUUID(); -- cgit v1.3