diff options
author | Elliott Hughes <enh@google.com> | 2014-08-19 14:30:30 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2014-08-19 14:30:30 -0700 |
commit | 09c39d6df0e952620f8c1751377b559a04e023aa (patch) | |
tree | 1ca25e04d3ed7ebea1dde6f4d3baaeee9526c0e5 /tests/string_test.cpp | |
parent | c5d6df6f2fe57fd5aadbd9ebb131023234c30a0c (diff) |
Implement the GNU basename(3) in addition to the POSIX one.
Code like perf(1) needs this.
Bug: 11860789
Change-Id: I907eb448052a7b165e4012d74303330d32328cb2
Diffstat (limited to 'tests/string_test.cpp')
-rw-r--r-- | tests/string_test.cpp | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/tests/string_test.cpp b/tests/string_test.cpp index 73c94c602..a3c6abb7d 100644 --- a/tests/string_test.cpp +++ b/tests/string_test.cpp @@ -14,12 +14,12 @@ * limitations under the License. */ -#include <gtest/gtest.h> +#include <string.h> #include <errno.h> +#include <gtest/gtest.h> #include <malloc.h> #include <math.h> -#include <string.h> #include "buffer_tests.h" @@ -1287,3 +1287,22 @@ TEST(string, strchr_align) { TEST(string, strchr_overread) { RunSingleBufferOverreadTest(DoStrchrTest); } + +static void TestBasename(const char* in, const char* expected_out) { + errno = 0; + const char* out = basename(in); + ASSERT_STREQ(expected_out, out) << in; + ASSERT_EQ(0, errno) << in; +} + +TEST(string, __gnu_basename) { + TestBasename("", ""); + TestBasename("/usr/lib", "lib"); + TestBasename("/usr/", ""); + TestBasename("usr", "usr"); + TestBasename("/", ""); + TestBasename(".", "."); + TestBasename("..", ".."); + TestBasename("///", ""); + TestBasename("//usr//lib//", ""); +} |