• 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 <search.h>
17 #include "functionalext.h"
18 
19 const size_t SIZE = 2;
20 static char *data[] = {"hsearch_r_0100", "hsearch_r_0200"};
21 
22 /**
23  * @tc.name      : hsearch_r_0100
24  * @tc.desc      : Verify hsearch_r process success
25  * @tc.level     : Level 0
26  */
hsearch_r_0100(void)27 void hsearch_r_0100(void)
28 {
29     struct hsearch_data h_data = {};
30     int ret;
31     EXPECT_NE("hsearch_r_0100", hcreate_r(SIZE, &h_data), 0);
32     ENTRY e, *ep;
33     for (int i = 0; i < SIZE; i++) {
34         e.key = data[i];
35         e.data = (void *)&i;
36         ret = hsearch_r(e, ENTER, &ep, &h_data);
37         EXPECT_NE("hsearch_r_0100", ret, 0);
38     }
39     hdestroy_r(&h_data);
40 }
41 
42 /**
43  * @tc.name      : hsearch_r_0200
44  * @tc.desc      : Verify hsearch_r process success
45  * @tc.level     : Level 2
46  */
hsearch_r_0200(void)47 void hsearch_r_0200(void)
48 {
49     struct hsearch_data h_data = {};
50     int ret;
51     EXPECT_NE("hsearch_r_0100", hcreate_r(SIZE, &h_data), 0);
52     ENTRY e, *ep;
53     for (int i = 0; i < SIZE; i++) {
54         e.key = data[i];
55         ret = hsearch_r(e, FIND, &ep, &h_data);
56         EXPECT_EQ("hsearch_r_0100", ret, 0);
57     }
58     hdestroy_r(&h_data);
59 }
60 
main(void)61 int main(void)
62 {
63     hsearch_r_0100();
64     hsearch_r_0200();
65     return t_status;
66 }
67