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 <dirent.h>
17#include "functionalext.h"
18#include <stdlib.h>
19#include "../../../../../src/dirent/__dirent.h"
20
21/**
22 * @tc.name      : readdir_0100
23 * @tc.desc      : The parameter is valid and can return the next directory entry
24 *                 point of the parameter dir directory stream.
25 * @tc.level     : Level 0
26 */
27void readdir_0100(void)
28{
29    DIR *dir;
30    struct dirent *ret;
31    dir = opendir("/etc");
32    ret = readdir(dir);
33    EXPECT_TRUE("readdir_0100", ret != NULL);
34    closedir(dir);
35}
36
37/**
38 * @tc.name      : readdir_0200
39 * @tc.desc      : The parameter is invalid, cannot return the next directory entry
40 *                 point of the parameter dir directory stream.
41 * @tc.level     : Level 2
42 */
43void readdir_0200(void)
44{
45    struct __dirstream *dir = (struct __dirstream *)calloc(1 ,sizeof(struct __dirstream));
46    if (dir == NULL) {
47        EXPECT_PTRNE("readdir_0200", dir, NULL);
48        return;
49    }
50    struct dirent *ret;
51    ret = readdir(dir);
52    EXPECT_TRUE(" readdir_0200", NULL == ret);
53
54    free(dir);
55}
56
57int main(int argc, char *argv[])
58{
59    readdir_0100();
60    readdir_0200();
61
62    return t_status;
63}