• 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 #include <memory>
18 #include <string>
19 
20 #include "constant_common.h"
21 #include "random_mbedtls.h"
22 
23 using namespace testing::ext;
24 
25 namespace OHOS {
26 namespace Security {
27 namespace AccessToken {
28 class CommonTest : public testing::Test  {
29 public:
30     static void SetUpTestCase();
31     static void TearDownTestCase();
32 
33     void SetUp();
34     void TearDown();
35 };
36 
SetUpTestCase()37 void CommonTest::SetUpTestCase() {}
TearDownTestCase()38 void CommonTest::TearDownTestCase() {}
SetUp()39 void CommonTest::SetUp() {}
TearDown()40 void CommonTest::TearDown() {}
41 
42 /**
43  * @tc.name: EncryptDevId001
44  * @tc.desc: Test EncryptDevId001 function.
45  * @tc.type: FUNC
46  * @tc.require: issueI5RUCC
47  */
48 HWTEST_F(CommonTest, EncryptDevId001, TestSize.Level1)
49 {
50     std::string res;
51     res = ConstantCommon::EncryptDevId("");
52     EXPECT_EQ(res, "");
53 
54     res = ConstantCommon::EncryptDevId("12345");
55     EXPECT_EQ(res, "1*******");
56 
57     res = ConstantCommon::EncryptDevId("123454321");
58     EXPECT_EQ(res, "1234****4321");
59 }
60 
61 /*
62  * @tc.name: GenerateRandomArray001
63  * @tc.desc: RandomMbedtls::GenerateRandomArray function test randStr is null
64  * @tc.type: FUNC
65  * @tc.require: issueI6024A
66  */
67 HWTEST_F(CommonTest, GenerateRandomArray001, TestSize.Level1)
68 {
69     unsigned char *randStr = nullptr;
70     unsigned int len = 0;
71     EXPECT_NE(0, RandomMbedtls::GetInstance().GenerateRandomArray(randStr, len));
72 }
73 } // namespace AccessToken
74 } // namespace Security
75 } // namespace OHOS
76