diff options
author | Elliott Hughes <enh@google.com> | 2013-03-01 16:59:46 -0800 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2013-03-01 17:11:39 -0800 |
commit | f0777843c03deb26b1f78c8edd17c557041696e9 (patch) | |
tree | c6daa38f29aa9a327b094eda31340251fdedef11 /tests/stdlib_test.cpp | |
parent | c5c6cb3f13642386e08acf687b4bc39f568bad0c (diff) |
Move realpath.c to upstream-freebsd.
This is actually a slightly newer upstream version than the one I
originally pulled. Hopefully now it's in upstream-freebsd it will
be easier to track upstream, though I still need to sit down and
write the necessary scripts at some point.
Bug: 5110679
Change-Id: I87e563f0f95aa8e68b45578e2a8f448bbf827a33
Diffstat (limited to 'tests/stdlib_test.cpp')
-rw-r--r-- | tests/stdlib_test.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/stdlib_test.cpp b/tests/stdlib_test.cpp index 8735100d4..fed39f87b 100644 --- a/tests/stdlib_test.cpp +++ b/tests/stdlib_test.cpp @@ -17,6 +17,8 @@ #include <gtest/gtest.h> #include <errno.h> +#include <libgen.h> +#include <limits.h> #include <stdint.h> #include <stdlib.h> @@ -70,3 +72,40 @@ TEST(stdlib, posix_memalign) { // Can't align to a non-power of 2. ASSERT_EQ(EINVAL, posix_memalign(&p, 81, 128)); } + +TEST(stdlib, realpath__NULL_filename) { + errno = 0; + char* p = realpath(NULL, NULL); + ASSERT_TRUE(p == NULL); + ASSERT_EQ(EINVAL, errno); +} + +TEST(stdlib, realpath__empty_filename) { + errno = 0; + char* p = realpath("", NULL); + ASSERT_TRUE(p == NULL); + ASSERT_EQ(ENOENT, errno); +} + +TEST(stdlib, realpath__ENOENT) { + errno = 0; + char* p = realpath("/this/directory/path/almost/certainly/does/not/exist", NULL); + ASSERT_TRUE(p == NULL); + ASSERT_EQ(ENOENT, errno); +} + +TEST(stdlib, realpath) { + // Get the name of this executable. + char executable_path[PATH_MAX]; + int rc = readlink("/proc/self/exe", executable_path, sizeof(executable_path)); + ASSERT_NE(rc, -1); + executable_path[rc] = '\0'; + + char buf[PATH_MAX + 1]; + char* p = realpath("/proc/self/exe", buf); + ASSERT_STREQ(executable_path, p); + + p = realpath("/proc/self/exe", NULL); + ASSERT_STREQ(executable_path, p); + free(p); +} |