• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device 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 #ifdef RELATIONAL_STORE
16 #include "cloud/cloud_sync_tag_assets.h"
17 #include <gtest/gtest.h>
18 
19 using namespace testing::ext;
20 using namespace DistributedDB;
21 using namespace std;
22 
23 namespace {
24 class DistributedDBCloudSimpleAssetTest : public testing::Test {
25 public:
26     static void SetUpTestCase(void);
27     static void TearDownTestCase(void);
28     void SetUp();
29     void TearDown();
30 };
31 
SetUpTestCase()32 void DistributedDBCloudSimpleAssetTest::SetUpTestCase()
33 {
34 }
35 
TearDownTestCase()36 void DistributedDBCloudSimpleAssetTest::TearDownTestCase()
37 {
38 }
39 
SetUp()40 void DistributedDBCloudSimpleAssetTest::SetUp()
41 {
42 }
43 
TearDown()44 void DistributedDBCloudSimpleAssetTest::TearDown()
45 {
46 }
47 
48 /*
49  * @tc.name: DownloadAssetForDupDataTest001
50  * @tc.desc: Test tag asset with diff hash and downloading.
51  * @tc.type: FUNC
52  * @tc.require:
53  * @tc.author: zqq
54  */
55 HWTEST_F(DistributedDBCloudSimpleAssetTest, TagAsset001, TestSize.Level0)
56 {
57     /**
58      * @tc.steps:step1. Local asset is downloading.
59      */
60     Asset asset;
61     asset.name = "test";
62     asset.hash = "insert";
63     asset.status = static_cast<int64_t>(AssetStatus::DOWNLOADING);
64     VBucket beCovered;
65     Assets beCoveredAssets;
66     beCoveredAssets.push_back(asset);
67     beCovered["field"] = beCoveredAssets;
68     /**
69      * @tc.steps:step2. Cloud asset has diff hash.
70      */
71     VBucket covered;
72     Assets coveredAssets;
73     asset.hash = "update";
74     asset.status = static_cast<int64_t>(AssetStatus::NORMAL);
75     coveredAssets.push_back(asset);
76     covered["field"] = coveredAssets;
77     /**
78      * @tc.steps:step3. Tag assets.
79      * @tc.expected: step3. Local asset change hash
80      */
81     Field field;
82     field.colName = "field";
83     field.type = TYPE_INDEX<Assets>;
84     int errCode = E_OK;
85     TagAssetsInfo tagAssetsInfo = {covered, beCovered, false, false};
86     Assets res = TagAssetsInSingleCol(tagAssetsInfo, field, errCode);
87     for (const auto &item : res) {
88         EXPECT_EQ(item.hash, asset.hash);
89     }
90 }
91 }
92 #endif