• 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 "tlv.h"
19 #include "bsl_errno.h"
20 
21 /* END_HEADER */
22 
23 /**
24  * @test  SDV_BSL_TLV_Find_API_TC001
25  * @title  Find tlv value pos test
26  * @precon  nan
27  * @brief
28  *    1. Invoke BSL_TLV_Pack to construct a tlv buffer. Expected result 1 is obtained.
29  *    2. Invoke BSL_TLV_FindValuePos to find a type which valid. Expected result 2 is obtained.
30  *    3. Invoke BSL_TLV_FindValuePos to find a type which invalid. Expected result 3 is obtained.
31  * @expect
32  *    1. Expected success
33  *    2. Expected success
34  *    3. Expected failure
35  */
36 /* BEGIN_CASE */
SDV_BSL_TLV_Find_API_TC001(void)37 void SDV_BSL_TLV_Find_API_TC001(void)
38 {
39     int ret;
40     uint32_t type = 0x0101;
41     uint16_t version = 1;
42 
43     BSL_Tlv tlv = {0};
44     tlv.type = type;
45     tlv.length = sizeof(version);
46     tlv.value = (uint8_t *)&version;
47 
48     uint32_t encLen = 0;
49     uint8_t data[1024] = {0};
50     ret = BSL_TLV_Pack(&tlv, data, sizeof(data), &encLen);
51     ASSERT_TRUE(ret == BSL_SUCCESS);
52 
53     uint32_t offset = 0;
54     uint32_t length = 0;
55     ret = BSL_TLV_FindValuePos(type, data, encLen, &offset, &length);
56     ASSERT_TRUE(ret == BSL_SUCCESS);
57 
58     uint32_t invalidType = 0x0102;
59     ret = BSL_TLV_FindValuePos(invalidType, data, encLen, &offset, &length);
60     ASSERT_TRUE(ret == BSL_TLV_ERR_NO_WANT_TYPE);
61 EXIT:
62     return;
63 }
64 /* END_CASE */