• 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 <gtest/gtest.h>
17 
18 #include "distributed_camera_source_service.h"
19 #include "distributed_camera_errno.h"
20 #include "distributed_hardware_log.h"
21 
22 using namespace testing::ext;
23 
24 namespace OHOS {
25 namespace DistributedHardware {
26 class DistributedCameraSourceServiceTest : public testing::Test {
27 public:
28     static void SetUpTestCase(void);
29     static void TearDownTestCase(void);
30     void SetUp();
31     void TearDown();
32 
33     std::shared_ptr<DistributedCameraSourceService> testSrcService_;
34 };
35 
36 namespace {
37 const std::string TEST_DEVICE_ID = "bb536a637105409e904d4da83790a4a7";
38 const std::string TEST_CAMERA_DH_ID_0 = "camera_0";
39 const std::string TEST_REQID = "bb536a637105409e904d4da83790a4a7";
40 }
41 
SetUpTestCase(void)42 void DistributedCameraSourceServiceTest::SetUpTestCase(void)
43 {
44     DHLOGI("DistributedCameraSourceServiceTest::SetUpTestCase");
45 }
46 
TearDownTestCase(void)47 void DistributedCameraSourceServiceTest::TearDownTestCase(void)
48 {
49     DHLOGI("DistributedCameraSourceServiceTest::TearDownTestCase");
50 }
51 
SetUp(void)52 void DistributedCameraSourceServiceTest::SetUp(void)
53 {
54     DHLOGI("DistributedCameraSourceServiceTest::SetUp");
55     testSrcService_ = std::make_shared<DistributedCameraSourceService>(DISTRIBUTED_HARDWARE_CAMERA_SOURCE_SA_ID, true);
56 }
57 
TearDown(void)58 void DistributedCameraSourceServiceTest::TearDown(void)
59 {
60     DHLOGI("DistributedCameraSourceServiceTest::TearDown");
61     testSrcService_ = nullptr;
62 }
63 
64 /**
65  * @tc.name: dcamera_source_service_test_001
66  * @tc.desc: Verify the RegisterDistributedHardware UnregisterDistributedHardware function.
67  * @tc.type: FUNC
68  * @tc.require: issue
69  */
70 HWTEST_F(DistributedCameraSourceServiceTest, dcamera_source_service_test_001, TestSize.Level1)
71 {
72     DHLOGI("DistributedCameraSourceServiceTest::dcamera_source_service_test_001");
73     EXPECT_EQ(false, testSrcService_ == nullptr);
74 
75     EnableParam param;
76     int32_t ret = testSrcService_->RegisterDistributedHardware(TEST_DEVICE_ID, TEST_CAMERA_DH_ID_0, TEST_REQID, param);
77     EXPECT_EQ(DCAMERA_OK, ret);
78 
79     ret = testSrcService_->UnregisterDistributedHardware(TEST_DEVICE_ID, TEST_CAMERA_DH_ID_0, TEST_REQID);
80     EXPECT_EQ(DCAMERA_OK, ret);
81 }
82 
83 /**
84  * @tc.name: dcamera_source_service_test_002
85  * @tc.desc: Verify the DCameraNotify function.
86  * @tc.type: FUNC
87  * @tc.require: issue
88  */
89 HWTEST_F(DistributedCameraSourceServiceTest, dcamera_source_service_test_002, TestSize.Level1)
90 {
91     DHLOGI("DistributedCameraSourceServiceTest::dcamera_source_service_test_002");
92     EXPECT_EQ(false, testSrcService_ == nullptr);
93 
94     std::string events;
95     int32_t ret = testSrcService_->DCameraNotify(TEST_DEVICE_ID, TEST_CAMERA_DH_ID_0, events);
96     EXPECT_EQ(DCAMERA_BAD_VALUE, ret);
97 }
98 
99 /**
100  * @tc.name: dcamera_source_service_test_003
101  * @tc.desc: Verify the Dump function.
102  * @tc.type: FUNC
103  * @tc.require: issue
104  */
105 HWTEST_F(DistributedCameraSourceServiceTest, dcamera_source_service_test_003, TestSize.Level1)
106 {
107     DHLOGI("DistributedCameraSourceServiceTest::dcamera_source_service_test_003");
108     EXPECT_EQ(false, testSrcService_ == nullptr);
109 
110     int32_t fd = 0;
111     std::vector<std::u16string> args;
112     std::u16string str(u"");
113     args.push_back(str);
114     int ret = testSrcService_->Dump(fd, args);
115     EXPECT_EQ(DCAMERA_OK, ret);
116 }
117 } // namespace DistributedHardware
118 } // namespace OHOS