Serenity Operating System
at master 27 lines 643 B view raw
1/* 2 * Copyright (c) 2021, Brian Gianforcaro <bgianf@serenityos.org> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#include <LibTest/TestCase.h> 8#include <dirent.h> 9#include <string.h> 10 11TEST_CASE(scandir_basic_scenario) 12{ 13 struct dirent** namelist = nullptr; 14 auto entries = scandir("/etc", &namelist, nullptr, nullptr); 15 EXPECT(entries > 0); 16 EXPECT_NE(namelist, nullptr); 17 18 bool found_passwd = false; 19 for (auto i = 0; i < entries; i++) { 20 if (strcmp(namelist[i]->d_name, "passwd") == 0) { 21 found_passwd = true; 22 } 23 free(namelist[i]); 24 } 25 EXPECT(found_passwd); 26 free(namelist); 27}