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 <dlfcn.h>
17#include <stdlib.h>
18#include "functionalext.h"
19
20void test1()
21{}
22
23/**
24 * @tc.name      : dladdr_0100
25 * @tc.desc      : Each parameter is valid, you can get the module, name and address where a function is located.
26 * @tc.level     : Level 0
27 */
28void dladdr_0100(void)
29{
30    Dl_info info;
31    info.dli_fname = 0;
32    int num = 0;
33    int ret = dladdr((void *)test1, &info);
34    EXPECT_EQ("dladdr_0100", ret, 1);
35
36    char *name = "dladdr";
37    char *result = strstr(info.dli_fname, name);
38    EXPECT_PTRNE("dladdr_0100", result, NULL);
39}
40
41/**
42 * @tc.name      : dladdr_0200
43 * @tc.desc      : Each parameter is invalid, you can get the module, name and address where a function is located.
44 * @tc.level     : Level 2
45 */
46void dladdr_0200(void)
47{
48    Dl_info info;
49    info.dli_fname = 0;
50    int num = 0;
51    int ret = dladdr(NULL, &info);
52    EXPECT_EQ("dladdr_0100", ret, 0);
53    EXPECT_TRUE("dladdr_0200", info.dli_fname == NULL);
54}
55
56int main(int argc, char *argv[])
57{
58    dladdr_0100();
59    dladdr_0200();
60
61    return t_status;
62}
63