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_attest_common.h"
21
22 namespace OHOS {
23 namespace DistributedHardware {
24
SetUp()25 void DmAuthAttestCommonTest::SetUp()
26 {
27 }
TearDown()28 void DmAuthAttestCommonTest::TearDown()
29 {
30 }
SetUpTestCase()31 void DmAuthAttestCommonTest::SetUpTestCase()
32 {
33 }
TearDownTestCase()34 void DmAuthAttestCommonTest::TearDownTestCase()
35 {
36 }
37
38 /**
39 * @tc.name: SerializeDmCertChain_001
40 * @tc.type: FUNC
41 */
42 HWTEST_F(DmAuthAttestCommonTest, SerializeDmCertChain_001, testing::ext::TestSize.Level1) {
43 AuthAttestCommon authAttestCommon;
44 DmCertChain *chain = nullptr;
45 std::string result = authAttestCommon.SerializeDmCertChain(chain);
46 EXPECT_EQ(result, "{}");
47 }
48
49 /**
50 * @tc.name: DeserializeDmCertChain_001
51 * @tc.type: FUNC
52 */
53 HWTEST_F(DmAuthAttestCommonTest, DeserializeDmCertChain_001, testing::ext::TestSize.Level1) {
54 AuthAttestCommon authAttestCommon;
55 std::string data = R"({"certCount":2,"cert":["cert1","cert2"]})";
56 DmCertChain *outChain = nullptr;
57
58 bool result = authAttestCommon.DeserializeDmCertChain(data, outChain);
59
60 EXPECT_FALSE(result);
61 }
62
63 /**
64 * @tc.name: DeserializeDmCertChain_002
65 * @tc.type: FUNC
66 */
67 HWTEST_F(DmAuthAttestCommonTest, DeserializeDmCertChain_002, testing::ext::TestSize.Level1) {
68 AuthAttestCommon authAttestCommon;
69 std::string data = "";
70 DmCertChain outChain;
71
72 bool result = authAttestCommon.DeserializeDmCertChain(data, &outChain);
73
74 EXPECT_FALSE(result);
75 }
76 }
77 }