• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * This file is part of the openHiTLS project.
3  *
4  * openHiTLS is licensed under the Mulan PSL v2.
5  * You can use this software according to the terms and conditions of the Mulan PSL v2.
6  * You may obtain a copy of Mulan PSL v2 at:
7  *
8  *     http://license.coscl.org.cn/MulanPSL2
9  *
10  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
11  * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
12  * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
13  * See the Mulan PSL v2 for more details.
14  */
15 
16 /* BEGIN_HEADER */
17 
18 #include "bsl_user_data.h"
19 #include "bsl_sal.h"
20 #include "bsl_errno.h"
21 
22 /* END_HEADER */
23 
Stub_BSL_USER_ExDataFree(void * parent,void * ptr,BSL_USER_ExData * ad,int idx,long argl,void * argp)24 void Stub_BSL_USER_ExDataFree(void *parent, void *ptr, BSL_USER_ExData *ad, int idx, long argl, void *argp)
25 {
26     (void)parent;
27     (void)idx;
28     (void)argl;
29     (void)argp;
30     for (int32_t i = 0; i < BSL_MAX_EX_DATA; i++) {
31         if (ad->sk[i] == ptr) {
32             BSL_SAL_FREE(ad->sk[i]);
33         }
34     }
35     return;
36 }
37 
38 /**
39  * @test  SDV_BSL_USERDATA_API_TC001
40  * @title  Find tlv value pos test
41  * @precon  nan
42  * @brief
43  *    1. Invoke BSL_USER_GetExDataNewIndex to new a index. Expected result 1 is obtained.
44  *    2. Invoke BSL_USER_SetExData to set a userdata. Expected result 2 is obtained.
45  *    3. Invoke BSL_USER_FreeExDataIndex to free userdata, and invoke to get userdata. Expected result 3 is obtained.
46  * @expect
47  *    1. Expected -1
48  *    2. Expected success
49  *    3. Expected NULL
50  */
51 /* BEGIN_CASE */
SDV_BSL_USERDATA_API_TC001(void)52 void SDV_BSL_USERDATA_API_TC001(void)
53 {
54     int ret;
55     void *ctx = NULL;
56     void *newCtx = NULL;
57     BSL_USER_ExData exdata = { 0 };
58     int idx = BSL_USER_GetExDataNewIndex(BSL_USER_DATA_EX_INDEX_SSL, 0, NULL, NULL, NULL, Stub_BSL_USER_ExDataFree);
59     ASSERT_TRUE(idx != -1);
60 
61     ctx = BSL_SAL_Calloc(1u, 1024);
62     ret = BSL_USER_SetExData(&exdata, idx, ctx);
63     ASSERT_TRUE(ret == BSL_SUCCESS);
64 
65     BSL_USER_FreeExDataIndex(BSL_USER_DATA_EX_INDEX_SSL, NULL, &exdata);
66     newCtx = BSL_USER_GetExData(&exdata, idx);
67     ASSERT_TRUE(newCtx == NULL);
68 EXIT:
69     return;
70 }
71 /* END_CASE */
72