• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
5 #include "base/android/path_utils.h"
6 #include "base/files/file_path.h"
7 #include "base/files/file_util.h"
8 #include "base/strings/string_util.h"
9 
10 #include "testing/gtest/include/gtest/gtest.h"
11 
12 namespace base {
13 namespace android {
14 
15 typedef testing::Test PathUtilsTest;
16 
17 namespace {
ExpectEither(const std::string & expected1,const std::string & expected2,const std::string & actual)18 void ExpectEither(const std::string& expected1,
19                   const std::string& expected2,
20                   const std::string& actual) {
21   EXPECT_TRUE(expected1 == actual || expected2 == actual)
22       << "Value of: " << actual << std::endl
23       << "Expected either: " << expected1 << std::endl
24       << "or: " << expected2;
25 }
26 }  // namespace
27 
TEST_F(PathUtilsTest,TestGetDataDirectory)28 TEST_F(PathUtilsTest, TestGetDataDirectory) {
29   // The string comes from the Java side and depends on the APK
30   // we are running in. Assumes that we are packaged in
31   // org.chromium.native_test
32   FilePath path;
33   GetDataDirectory(&path);
34 
35   ExpectEither("/data/data/org.chromium.native_test/app_chrome",
36                "/data/user/0/org.chromium.native_test/app_chrome",
37                path.value());
38 }
39 
TEST_F(PathUtilsTest,TestGetCacheDirectory)40 TEST_F(PathUtilsTest, TestGetCacheDirectory) {
41   // The string comes from the Java side and depends on the APK
42   // we are running in. Assumes that we are packaged in
43   // org.chromium.native_test
44   FilePath path;
45   GetCacheDirectory(&path);
46   ExpectEither("/data/data/org.chromium.native_test/cache",
47                "/data/user/0/org.chromium.native_test/cache",
48                path.value());
49 }
50 
TEST_F(PathUtilsTest,TestGetNativeLibraryDirectory)51 TEST_F(PathUtilsTest, TestGetNativeLibraryDirectory) {
52   // The string comes from the Java side and depends on the APK
53   // we are running in. Assumes that the directory contains
54   // the base tests shared object.
55   FilePath path;
56   GetNativeLibraryDirectory(&path);
57   EXPECT_TRUE(
58       base::PathExists(path.Append("libbase_unittests.so")) ||
59       base::PathExists(path.Append("libbase_unittests.cr.so")) ||
60       base::PathExists(path.Append("lib_base_unittests__library.so")) ||
61       base::PathExists(path.Append("lib_base_unittests__library.cr.so")));
62 }
63 
64 }  // namespace android
65 }  // namespace base
66