1 /* 2 * Copyright (c) 2023 iSoftStone Information Technology (Group) Co.,Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "gtest/gtest.h" 17 18 #include "frameworks/core/common/sharedata/share_data.h" 19 #include "base/memory/ace_type.h" 20 21 #include <functional> 22 #include <set> 23 #include <string> 24 #include <map> 25 26 using namespace testing; 27 using namespace testing::ext; 28 29 namespace OHOS::Ace { 30 class ShareDataTest : public testing::Test { 31 public: SetUpTestCase()32 static void SetUpTestCase() {} TearDownTestCase()33 static void TearDownTestCase() {} SetUp()34 void SetUp() {} TearDown()35 void TearDown() {} 36 }; 37 38 /** 39 * @tc.name: CastToShareDataTest001 40 * @tc.desc: Test cast to sharedata. 41 * @tc.type: FUNC 42 */ 43 HWTEST_F(ShareDataTest, CastToShareDataTest001, TestSize.Level1) 44 { 45 /** 46 * @tc.steps: step1. call the InsertBuffer and set bufferId is 0, set dataArray is {1, 2}. 47 * @tc.steps: step2. call the GetShareBufferById. 48 * @tc.expected: step2. return expect result. 49 */ 50 int32_t bufferId = 0; 51 int32_t errorBufferId = 1; 52 53 std::shared_ptr<std::vector<uint8_t>> dataArray = std::make_shared<std::vector<uint8_t>>(); 54 dataArray->push_back(1); 55 dataArray->push_back(2); 56 57 ShareData::InsertBuffer(bufferId, dataArray); 58 std::shared_ptr<std::vector<uint8_t>> retData = ShareData::GetShareBufferById(bufferId); 59 EXPECT_EQ(retData->at(0), 1); 60 61 /** 62 * @tc.steps: step3. call the ReleaseShareBufferById. 63 * @tc.steps: step4. call the GetShareBufferById. 64 * @tc.expected: step4. the return value is null. 65 */ 66 ShareData::ReleaseShareBufferById(bufferId); 67 std::shared_ptr<std::vector<uint8_t>> retEraseData = ShareData::GetShareBufferById(bufferId); 68 EXPECT_EQ(retEraseData, nullptr); 69 70 /** 71 * @tc.steps: step5. call the GetShareBufferById and set the wrong id. 72 * @tc.expected: step5. the return value is null. 73 */ 74 std::shared_ptr<std::vector<uint8_t>> retErrorData = ShareData::GetShareBufferById(errorBufferId); 75 EXPECT_EQ(retErrorData, nullptr); 76 77 /** 78 * @tc.steps: step6. call the ReleaseShareBufferById and set the wrong id. 79 * @tc.expected: step6. the id is not found. 80 */ 81 ShareData::ReleaseShareBufferById(errorBufferId); 82 } 83 } // namespace OHOS::Ace 84