• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 
16 #include "distributed_test_helper.h"
17 
18 using namespace OHOS;
19 using namespace testing::ext;
20 using namespace OHOS::DistributedKv;
21 using namespace OHOS::DistributeSystemTest;
22 using namespace OHOS::HiviewDFX;
23 
SetUpTestCase(void)24 void DistributedTestHelper::SetUpTestCase(void)
25 {}
26 
TearDownTestCase(void)27 void DistributedTestHelper::TearDownTestCase(void)
28 {}
29 
SetUp()30 void DistributedTestHelper::SetUp()
31 {}
32 
TearDown()33 void DistributedTestHelper::TearDown()
34 {}
35 
TestBody()36 void DistributedTestHelper::TestBody()
37 {}
38 
GetRemote(const Key & key,Value & value)39 Status DistributedTestHelper::GetRemote(const Key &key, Value &value)
40 {
41     std::string msg = "get";
42     msg += ",";
43     msg += key.ToString();
44     Status status;
45     SendMessage(AGENT_NO::ONE, msg, msg.size(), [&](const std::string &buf, int len)->bool {
46         auto index = buf.find(",");
47         std::string temp = buf.substr(0, index);
48         value = temp;
49         temp = buf.substr(index + 1);
50         status = Status(std::stoi(temp));
51         return true;
52     });
53     return status;
54 }
55 
PutRemote(const Key & key,const Value & value)56 Status DistributedTestHelper::PutRemote(const Key &key, const Value &value)
57 {
58     std::string command = "put";
59     std::string args = key.ToString();
60     args += ",";
61     args += value.ToString();
62     RunCmdOnAgent(AGENT_NO::ONE, command, args, "0");
63     Status status = Status(GetReturnVal());
64     return status;
65 }
66 
DeleteRemote(const Key & key)67 Status DistributedTestHelper::DeleteRemote(const Key &key)
68 {
69     std::string command = "delete";
70     std::string skey = key.ToString();
71     RunCmdOnAgent(AGENT_NO::ONE, command, skey, "0");
72     Status status = Status(GetReturnVal());
73     return status;
74 }
75 
RemoveDeviceDataRemote()76 Status DistributedTestHelper::RemoveDeviceDataRemote()
77 {
78     std::string command = "removedevicedata";
79     RunCmdOnAgent(AGENT_NO::ONE, command, "0", "0");
80     Status status = Status(GetReturnVal());
81     return status;
82 }
83 
SyncRemote(SyncMode mode,uint32_t delay)84 Status DistributedTestHelper::SyncRemote(SyncMode mode, uint32_t delay)
85 {
86     std::string command = "sync";
87     std::string sdelay = std::to_string(delay);
88     RunCmdOnAgent(AGENT_NO::ONE, command, sdelay, "0");
89     Status status = Status(GetReturnVal());
90     return status;
91 }