• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
18 #include "hks_generate_random_test.h"
19 
20 #include "hks_api.h"
21 #include "hks_param.h"
22 #include "hks_test_api_performance.h"
23 #include "hks_test_common.h"
24 #include "hks_test_log.h"
25 #include "hks_type.h"
26 
27 using namespace testing::ext;
28 namespace {
29 class HksGenerateRandomTest : public testing::Test {
30 public:
31     static void SetUpTestCase(void);
32 
33     static void TearDownTestCase(void);
34 
35     void SetUp();
36 
37     void TearDown();
38 };
39 
SetUpTestCase(void)40 void HksGenerateRandomTest::SetUpTestCase(void)
41 {
42 }
43 
TearDownTestCase(void)44 void HksGenerateRandomTest::TearDownTestCase(void)
45 {
46 }
47 
SetUp()48 void HksGenerateRandomTest::SetUp()
49 {
50     EXPECT_EQ(HksInitialize(), 0);
51 }
52 
TearDown()53 void HksGenerateRandomTest::TearDown()
54 {
55 }
56 
57 const struct HksTestGenRandomParams g_testGenRandomParams[] = {
58     /* normal case */
59     { 0, HKS_SUCCESS, { true, HKS_MAX_RANDOM_LEN, true, HKS_MAX_RANDOM_LEN } },
60 };
61 /**
62  * @tc.name: HksGenerateRandomTest.HksGenerateRandomTest001
63  * @tc.desc: The static function will return true;
64  * @tc.type: FUNC
65  */
66 HWTEST_F(HksGenerateRandomTest, HksGenerateRandomTest001, TestSize.Level1)
67 {
68     int32_t ret;
69     struct HksBlob *random = NULL;
70 
71     ret = TestConstructBlobOut(&random,
72         g_testGenRandomParams[0].randomParams.blobExist,
73         g_testGenRandomParams[0].randomParams.blobSize,
74         g_testGenRandomParams[0].randomParams.blobDataExist,
75         g_testGenRandomParams[0].randomParams.blobDataSize);
76     HKS_TEST_ASSERT(ret == 0);
77 
78     ret = HksGenerateRandomRun(random, 1);
79     if (ret != g_testGenRandomParams[0].expectResult) {
80         HKS_TEST_LOG_I("HksGenerateRandomRun failed, ret[%u] = %d", g_testGenRandomParams[0].testId, ret);
81     }
82     HKS_TEST_ASSERT(ret == g_testGenRandomParams[0].expectResult);
83 
84     TestFreeBlob(&random);
85     ASSERT_TRUE(ret == 0);
86 }
87 }