brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · 10bbe2a Raw
44 lines · cpp
1//===-- Unittests for getcwd ----------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "src/__support/CPP/string_view.h"10#include "src/stdlib/getenv.h"11#include "src/unistd/getcwd.h"12 13#include "test/IntegrationTest/test.h"14 15#include <errno.h>16#include <stdlib.h> // For malloc and free17 18using LIBC_NAMESPACE::cpp::string_view;19 20TEST_MAIN([[maybe_unused]] int argc, [[maybe_unused]] char **argv,21          [[maybe_unused]] char **envp) {22  char buffer[1024];23  ASSERT_TRUE(string_view(LIBC_NAMESPACE::getenv("PWD")) ==24              LIBC_NAMESPACE::getcwd(buffer, 1024));25 26  // nullptr buffer27  char *cwd = LIBC_NAMESPACE::getcwd(nullptr, 0);28  ASSERT_TRUE(string_view(LIBC_NAMESPACE::getenv("PWD")) == cwd);29  free(cwd);30 31  // Bad size32  cwd = LIBC_NAMESPACE::getcwd(buffer, 0);33  ASSERT_TRUE(cwd == nullptr);34  ASSERT_ERRNO_EQ(EINVAL);35 36  // Insufficient size37  errno = 0;38  cwd = LIBC_NAMESPACE::getcwd(buffer, 2);39  ASSERT_TRUE(cwd == nullptr);40  ASSERT_ERRNO_EQ(ERANGE);41 42  return 0;43}44