1 /*
2 * Copyright (c) 2021 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 <gtest/gtest.h>
17 #include <memory>
18
19 #include "anonymous_string.h"
20 #include "distributed_hardware_log.h"
21
22 #include "dcamera_capture_info_cmd.h"
23 #include "dcamera_channel_info_cmd.h"
24 #include "dcamera_event_cmd.h"
25 #include "dcamera_info_cmd.h"
26 #include "dcamera_metadata_setting_cmd.h"
27 #include "dcamera_protocol.h"
28 #include "dcamera_utils_tools.h"
29 #include "distributed_camera_constants.h"
30 #include "distributed_camera_errno.h"
31
32 using namespace testing::ext;
33
34 namespace OHOS {
35 namespace DistributedHardware {
36 class DCameraProtocolTest : public testing::Test {
37 public:
38 static void SetUpTestCase(void);
39 static void TearDownTestCase(void);
40 void SetUp();
41 void TearDown();
42 };
43
44 static std::string g_testDeviceId;
45 static const std::string TEST_CAPTURE_INFO_CMD_JSON = R"({
46 "Type": "OPERATION",
47 "dhId": "camrea_0",
48 "Command": "CAPTURE",
49 "Value": [
50 {"Width": 1920, "Height": 1080, "Format": 1, "DataSpace": 1,
51 "IsCapture":true, "EncodeType": 1, "StreamType": 1,
52 "CaptureSettings": [{"SettingType": 1, "SettingValue": "TestSetting"}]}
53 ]
54 })";
55
56 static const std::string TEST_CHANNEL_INFO_CMD_JSON = R"({
57 "Type": "OPERATION",
58 "dhId": "camrea_0",
59 "Command": "CHANNEL_NEG",
60 "Value": {"SourceDevId": "TestDevId", "Detail": [{"DataSessionFlag": "TestFlag", "StreamType": 1}]}
61 })";
62
63 static const std::string TEST_EVENT_CMD_JSON = R"({
64 "Type": "MESSAGE",
65 "dhId": "camrea_0",
66 "Command": "STATE_NOTIFY",
67 "Value": {"EventType": 1, "EventResult": 1, "EventContent": "TestContent"}
68 })";
69
70 static const std::string TEST_INFO_CMD_JSON = R"({
71 "Type": "OPERATION",
72 "dhId": "camrea_0",
73 "Command": "GET_INFO",
74 "Value": {"State": 1}
75 })";
76
77 static const std::string TEST_METADATA_SETTING_CMD_JSON = R"({
78 "Type": "MESSAGE",
79 "dhId": "camrea_0",
80 "Command": "UPDATE_METADATA",
81 "Value": [{"SettingType": 1, "SettingValue": "TestSetting"}]
82 })";
83
SetUpTestCase(void)84 void DCameraProtocolTest::SetUpTestCase(void)
85 {
86 GetLocalDeviceNetworkId(g_testDeviceId);
87 }
88
TearDownTestCase(void)89 void DCameraProtocolTest::TearDownTestCase(void)
90 {
91 }
92
SetUp(void)93 void DCameraProtocolTest::SetUp(void)
94 {
95 }
96
TearDown(void)97 void DCameraProtocolTest::TearDown(void)
98 {
99 }
100
101 /**
102 * @tc.name: dcamera_protocol_test_001
103 * @tc.desc: Verify Get ServiceAbility.
104 * @tc.type: FUNC
105 * @tc.require: AR000GK6MH
106 */
107 HWTEST_F(DCameraProtocolTest, dcamera_protocol_test_001, TestSize.Level1)
108 {
109 int32_t ret = DCAMERA_OK;
110 EXPECT_EQ(DCAMERA_OK, ret);
111 }
112
113 /**
114 * @tc.name: dcamera_protocol_test_002
115 * @tc.desc: Verify CaptureInfoCmd Json.
116 * @tc.type: FUNC
117 * @tc.require: AR000GK6MH
118 */
119 HWTEST_F(DCameraProtocolTest, dcamera_protocol_test_002, TestSize.Level1)
120 {
121 DCameraCaptureInfoCmd cmd;
122 int32_t ret = cmd.Unmarshal(TEST_CAPTURE_INFO_CMD_JSON);
123 EXPECT_EQ(DCAMERA_OK, ret);
124
125 std::string jsonStr;
126 ret = cmd.Marshal(jsonStr);
127 EXPECT_EQ(DCAMERA_OK, ret);
128 }
129
130 /**
131 * @tc.name: dcamera_protocol_test_003
132 * @tc.desc: Verify ChannelInfoCmd Json.
133 * @tc.type: FUNC
134 * @tc.require: AR000GK6MI
135 */
136 HWTEST_F(DCameraProtocolTest, dcamera_protocol_test_003, TestSize.Level1)
137 {
138 DCameraChannelInfoCmd cmd;
139 int32_t ret = cmd.Unmarshal(TEST_CHANNEL_INFO_CMD_JSON);
140 EXPECT_EQ(DCAMERA_OK, ret);
141
142 std::string jsonStr;
143 ret = cmd.Marshal(jsonStr);
144 EXPECT_EQ(DCAMERA_OK, ret);
145 }
146
147 /**
148 * @tc.name: dcamera_protocol_test_004
149 * @tc.desc: Verify EventCmd Json.
150 * @tc.type: FUNC
151 * @tc.require: AR000GK6MI
152 */
153 HWTEST_F(DCameraProtocolTest, dcamera_protocol_test_004, TestSize.Level1)
154 {
155 DCameraEventCmd cmd;
156 int32_t ret = cmd.Unmarshal(TEST_EVENT_CMD_JSON);
157 EXPECT_EQ(DCAMERA_OK, ret);
158
159 std::string jsonStr;
160 ret = cmd.Marshal(jsonStr);
161 EXPECT_EQ(DCAMERA_OK, ret);
162 }
163
164 /**
165 * @tc.name: dcamera_protocol_test_005
166 * @tc.desc: Verify CameraInfoCmd Json.
167 * @tc.type: FUNC
168 * @tc.require: AR000GS3AA
169 */
170 HWTEST_F(DCameraProtocolTest, dcamera_protocol_test_005, TestSize.Level1)
171 {
172 DCameraInfoCmd cmd;
173 int32_t ret = cmd.Unmarshal(TEST_INFO_CMD_JSON);
174 EXPECT_EQ(DCAMERA_OK, ret);
175
176 std::string jsonStr;
177 ret = cmd.Marshal(jsonStr);
178 EXPECT_EQ(DCAMERA_OK, ret);
179 }
180
181 /**
182 * @tc.name: dcamera_protocol_test_006
183 * @tc.desc: Verify MetaDataSettingCmd Json.
184 * @tc.type: FUNC
185 * @tc.require: AR000GS3AA
186 */
187 HWTEST_F(DCameraProtocolTest, dcamera_protocol_test_006, TestSize.Level1)
188 {
189 DCameraMetadataSettingCmd cmd;
190 int32_t ret = cmd.Unmarshal(TEST_METADATA_SETTING_CMD_JSON);
191 EXPECT_EQ(DCAMERA_OK, ret);
192
193 std::string jsonStr;
194 ret = cmd.Marshal(jsonStr);
195 EXPECT_EQ(DCAMERA_OK, ret);
196 }
197 } // namespace DistributedHardware
198 } // namespace OHOS
199