summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'libcutils/tests/fs_config.cpp')
-rw-r--r--libcutils/tests/fs_config.cpp76
1 files changed, 76 insertions, 0 deletions
diff --git a/libcutils/tests/fs_config.cpp b/libcutils/tests/fs_config.cpp
new file mode 100644
index 000000000..3917a0b2e
--- /dev/null
+++ b/libcutils/tests/fs_config.cpp
@@ -0,0 +1,76 @@
1/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <string>
18
19#include <gtest/gtest.h>
20
21#include <android-base/strings.h>
22
23#include <private/android_filesystem_config.h>
24
25extern const struct fs_path_config* __for_testing_only__android_dirs;
26extern const struct fs_path_config* __for_testing_only__android_files;
27
28static void check_one(const struct fs_path_config* paths, const std::string& prefix,
29 const std::string& alternate) {
30 for (size_t idx = 0; paths[idx].prefix; ++idx) {
31 std::string path(paths[idx].prefix);
32 if (android::base::StartsWith(path, prefix.c_str())) {
33 path = alternate + path.substr(prefix.length());
34 size_t second;
35 for (second = 0; paths[second].prefix; ++second) {
36 if (path == paths[second].prefix) break;
37 }
38 if (!paths[second].prefix) {
39 // guaranteed to fail expectations, trigger test failure with
40 // a message that reports the violation as an inequality.
41 EXPECT_STREQ((prefix + path.substr(alternate.length())).c_str(), path.c_str());
42 }
43 }
44 }
45}
46
47static void check_two(const struct fs_path_config* paths, const std::string& prefix) {
48 ASSERT_FALSE(paths == nullptr);
49 std::string alternate = "system/" + prefix;
50 check_one(paths, prefix, alternate);
51 check_one(paths, alternate, prefix);
52}
53
54TEST(fs_config, vendor_dirs_alias) {
55 check_two(__for_testing_only__android_dirs, "vendor/");
56}
57
58TEST(fs_config, vendor_files_alias) {
59 check_two(__for_testing_only__android_files, "vendor/");
60}
61
62TEST(fs_config, oem_dirs_alias) {
63 check_two(__for_testing_only__android_dirs, "oem/");
64}
65
66TEST(fs_config, oem_files_alias) {
67 check_two(__for_testing_only__android_files, "oem/");
68}
69
70TEST(fs_config, odm_dirs_alias) {
71 check_two(__for_testing_only__android_dirs, "odm/");
72}
73
74TEST(fs_config, odm_files_alias) {
75 check_two(__for_testing_only__android_files, "odm/");
76}