summaryrefslogtreecommitdiff
path: root/Tests/LibC/TestLibCDirEnt.cpp
blob: b7f85d7528d3f385d71f9249e97b301d80d6466d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/*
 * Copyright (c) 2021, Brian Gianforcaro <bgianf@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include <LibTest/TestCase.h>
#include <dirent.h>
#include <string.h>

TEST_CASE(scandir_basic_scenario)
{
    struct dirent** namelist = nullptr;
    auto entries = scandir("/etc", &namelist, nullptr, nullptr);
    EXPECT(entries > 0);
    EXPECT_NE(namelist, nullptr);

    bool found_passwd = false;
    for (auto i = 0; i < entries; i++) {
        if (strcmp(namelist[i]->d_name, "passwd") == 0) {
            found_passwd = true;
        }
        free(namelist[i]);
    }
    EXPECT(found_passwd);
    free(namelist);
}