path_utils_unittest.cc 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "base/android/path_utils.h"
  5. #include "base/files/file_path.h"
  6. #include "base/files/file_util.h"
  7. #include "base/strings/string_util.h"
  8. #include "testing/gtest/include/gtest/gtest.h"
  9. namespace base {
  10. namespace android {
  11. typedef testing::Test PathUtilsTest;
  12. namespace {
  13. void ExpectEither(const std::string& expected1,
  14. const std::string& expected2,
  15. const std::string& actual) {
  16. EXPECT_TRUE(expected1 == actual || expected2 == actual)
  17. << "Value of: " << actual << std::endl
  18. << "Expected either: " << expected1 << std::endl
  19. << "or: " << expected2;
  20. }
  21. } // namespace
  22. TEST_F(PathUtilsTest, TestGetDataDirectory) {
  23. // The string comes from the Java side and depends on the APK
  24. // we are running in. Assumes that we are packaged in
  25. // org.chromium.native_test
  26. FilePath path;
  27. GetDataDirectory(&path);
  28. ExpectEither("/data/data/org.chromium.native_test/app_chrome",
  29. "/data/user/0/org.chromium.native_test/app_chrome",
  30. path.value());
  31. }
  32. TEST_F(PathUtilsTest, TestGetCacheDirectory) {
  33. // The string comes from the Java side and depends on the APK
  34. // we are running in. Assumes that we are packaged in
  35. // org.chromium.native_test
  36. FilePath path;
  37. GetCacheDirectory(&path);
  38. ExpectEither("/data/data/org.chromium.native_test/cache",
  39. "/data/user/0/org.chromium.native_test/cache",
  40. path.value());
  41. }
  42. TEST_F(PathUtilsTest, TestGetNativeLibraryDirectory) {
  43. // The string comes from the Java side and depends on the APK
  44. // we are running in. Assumes that the directory contains
  45. // the base tests shared object.
  46. FilePath path;
  47. GetNativeLibraryDirectory(&path);
  48. EXPECT_TRUE(
  49. base::PathExists(path.Append("libbase_unittests.so")) ||
  50. base::PathExists(path.Append("libbase_unittests.cr.so")) ||
  51. base::PathExists(path.Append("libbase_unittests__library.so")) ||
  52. base::PathExists(path.Append("libbase_unittests__library.cr.so")));
  53. }
  54. } // namespace android
  55. } // namespace base