diff options
author | Adam Lesinski <adamlesinski@google.com> | 2017-10-11 16:50:37 -0700 |
---|---|---|
committer | Adam Lesinski <adamlesinski@google.com> | 2017-10-12 16:02:00 -0700 |
commit | 873ef0e2302a1581dbcb83b49cefc95dcc41f5a0 (patch) | |
tree | ef00b0878f81644c2cbb37d7f4e5b5a2fc0a5c0c /libs/androidfw/tests/CommonHelpers.cpp | |
parent | df043ee75cffd64017fd5a571b1e79ee763ea62e (diff) |
libandroidfw_tests: package test data correctly
- Convert to use soong, which allows bundling test data with benchmarks.
- Also separate libandroidfw_benchmarks so that it doesn't depend
on gtest.
Test: manual
Change-Id: I45bd222fafa87172c77b7f5bb2a7a89ddca72361
Diffstat (limited to 'libs/androidfw/tests/CommonHelpers.cpp')
-rw-r--r-- | libs/androidfw/tests/CommonHelpers.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/libs/androidfw/tests/CommonHelpers.cpp b/libs/androidfw/tests/CommonHelpers.cpp new file mode 100644 index 000000000000..faa5350f9ecc --- /dev/null +++ b/libs/androidfw/tests/CommonHelpers.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "CommonHelpers.h" + +#include <iostream> + +#include "android-base/file.h" +#include "android-base/logging.h" +#include "android-base/strings.h" + +namespace android { + +static std::string sTestDataPath; + +void InitializeTest(int* argc, char** argv) { + // Set the default test data path to be the executable path directory + data. + SetTestDataPath(base::GetExecutableDirectory() + "/tests/data"); + + for (int i = 1; i < *argc; i++) { + const std::string arg = argv[i]; + if (base::StartsWith(arg, "--testdata=")) { + SetTestDataPath(arg.substr(strlen("--testdata="))); + for (int j = i; j != *argc; j++) { + argv[j] = argv[j + 1]; + } + --(*argc); + --i; + } else if (arg == "-h" || arg == "--help") { + std::cerr << "\nAdditional options specific to this test:\n" + " --testdata=[PATH]\n" + " Specify the location of test data used within the tests.\n"; + exit(1); + } + } +} + +void SetTestDataPath(const std::string& path) { + sTestDataPath = path; +} + +const std::string& GetTestDataPath() { + CHECK(!sTestDataPath.empty()) << "no test data path set."; + return sTestDataPath; +} + +std::string GetStringFromPool(const ResStringPool* pool, uint32_t idx) { + String8 str = pool->string8ObjectAt(idx); + return std::string(str.string(), str.length()); +} + +} // namespace android |