Add GetExecutableDirectory to libbase
Tests will often want to get the executable directory in order to find test data. Test: out/host/linux-x86/nativetest64/libbase_tests/libbase_tests Change-Id: Ica9d211bcd039fcf83a22fd494816abd01b97aa3
This commit is contained in:
parent
58021d15c9
commit
bb3a515f46
|
@ -238,8 +238,11 @@ std::string GetExecutablePath() {
|
|||
#endif
|
||||
}
|
||||
|
||||
std::string Basename(const std::string& path) {
|
||||
std::string GetExecutableDirectory() {
|
||||
return Dirname(GetExecutablePath());
|
||||
}
|
||||
|
||||
std::string Basename(const std::string& path) {
|
||||
// Copy path because basename may modify the string passed in.
|
||||
std::string result(path);
|
||||
|
||||
|
|
|
@ -159,6 +159,14 @@ TEST(file, Readlink) {
|
|||
#endif
|
||||
}
|
||||
|
||||
TEST(file, GetExecutableDirectory) {
|
||||
std::string path = android::base::GetExecutableDirectory();
|
||||
ASSERT_NE("", path);
|
||||
ASSERT_NE(android::base::GetExecutablePath(), path);
|
||||
ASSERT_EQ('/', path[0]);
|
||||
ASSERT_NE('/', path[path.size() - 1]);
|
||||
}
|
||||
|
||||
TEST(file, GetExecutablePath) {
|
||||
ASSERT_NE("", android::base::GetExecutablePath());
|
||||
}
|
||||
|
|
|
@ -51,6 +51,7 @@ bool Readlink(const std::string& path, std::string* result);
|
|||
#endif
|
||||
|
||||
std::string GetExecutablePath();
|
||||
std::string GetExecutableDirectory();
|
||||
|
||||
// Like the regular basename and dirname, but thread-safe on all
|
||||
// platforms and capable of correctly handling exotic Windows paths.
|
||||
|
|
Loading…
Reference in New Issue