TestLibCDirEnt.cpp 643 B

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