1 /*
2 * Copyright (c) 2025 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 "dm_auth_cert.h"
18 #include "dm_error_type.h"
19 #include "dm_log.h"
20 #include "UTTest_dm_auth_cert.h"
21
22 namespace OHOS {
23 namespace DistributedHardware {
24
SetUp()25 void DmAuthCertTest::SetUp()
26 {
27 }
TearDown()28 void DmAuthCertTest::TearDown()
29 {
30 }
SetUpTestCase()31 void DmAuthCertTest::SetUpTestCase()
32 {
33 }
TearDownTestCase()34 void DmAuthCertTest::TearDownTestCase()
35 {
36 }
37
38 /**
39 * @tc.name : VerifyCertificate_ShouldReturnFailed_WhenCertModuleNotLoaded
40 * @tc.number: VerifyCertificateTest_001
41 * @tc.desc : 测试当认证证书模块未加载时,VerifyCertificate 函数应返回 ERR_DM_FAILED
42 */
43 HWTEST_F(DmAuthCertTest, VerifyCertificate_001, testing::ext::TestSize.Level1) {
44 DmCertChain dmCertChain;
45 AuthCert authCert;
46 const char *deviceIdHash = "testDeviceIdHash";
47 int32_t result = authCert.VerifyCertificate(dmCertChain, deviceIdHash);
48 EXPECT_NE(result, ERR_DM_INPUT_PARA_INVALID);
49 }
50
51 /**
52 * @tc.name: IsDMAdapterAuthCertLoaded_001
53 * @tc.type: FUNC
54 */
55 HWTEST_F(DmAuthCertTest, IsDMAdapterAuthCertLoaded_001, testing::ext::TestSize.Level1) {
56 AuthCert authCert;
57 authCert.isAdapterAuthCertSoLoaded_ = false;
58 bool result = authCert.IsDMAdapterAuthCertLoaded();
59 EXPECT_EQ(result, false);
60 }
61
62 /**
63 * @tc.name: IsDMAdapterAuthCertLoaded_002
64 * @tc.type: FUNC
65 */
66 HWTEST_F(DmAuthCertTest, IsDMAdapterAuthCertLoaded_002, testing::ext::TestSize.Level1) {
67 AuthCert authCert;
68 authCert.isAdapterAuthCertSoLoaded_ = true;
69 authCert.dmAuthCertExt_ = std::shared_ptr<IDMAuthCertExt>();
70 bool result = authCert.IsDMAdapterAuthCertLoaded();
71 EXPECT_NE(result, true);
72 }
73
74 /**
75 * @tc.name: GenerateCertificate_001
76 * @tc.type: FUNC
77 */
78 HWTEST_F(DmAuthCertTest, GenerateCertificate_001, testing::ext::TestSize.Level1) {
79 AuthCert authCert;
80 DmCertChain dmCertChain;
81 int32_t result = authCert.GenerateCertificate(dmCertChain);
82 int32_t errCode = -10005;
83 EXPECT_NE(result, errCode);
84 }
85 }
86 }