TEST(getcwd, auto_full) { // If we let the library do all the work, everything's fine.
errno = 0; char* cwd = getcwd(nullptr, 0);
ASSERT_TRUE(cwd != nullptr);
ASSERT_ERRNO(0);
ASSERT_GE(strlen(cwd), 1U);
free(cwd);
}
TEST(getcwd, auto_reasonable) { // If we ask the library to allocate a reasonable buffer, everything's fine.
errno = 0; char* cwd = getcwd(nullptr, PATH_MAX);
ASSERT_TRUE(cwd != nullptr);
ASSERT_ERRNO(0);
ASSERT_GE(strlen(cwd), 1U);
free(cwd);
}
TEST(getcwd, auto_too_small) { // If we ask the library to allocate a too-small buffer, ERANGE.
ASSERT_ERRNO_FAILURE(ERANGE, nullptr, getcwd(nullptr, 1));
}
TEST(getcwd, auto_too_large) {
SKIP_WITH_HWASAN << "allocation size too large"; // If we ask the library to allocate an unreasonably large buffer, ERANGE.
ASSERT_ERRNO_FAILURE(ENOMEM, nullptr, getcwd(nullptr, static_cast<size_t>(-1)));
}
TEST(getcwd, manual_too_small) { // If we allocate a too-small buffer, ERANGE. char tiny_buf[1];
ASSERT_ERRNO_FAILURE(ERANGE, nullptr, getcwd(tiny_buf, sizeof(tiny_buf)));
}
TEST(getcwd, manual_zero) { // If we allocate a zero-length buffer, EINVAL. char tiny_buf[1];
ASSERT_ERRNO_FAILURE(EINVAL, nullptr, getcwd(tiny_buf, 0));
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.