summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Shi <dshi@google.com>2019-11-04 23:22:06 -0800
committerDan Shi <dshi@google.com>2019-11-06 22:55:34 -0800
commitf32b8dd09464a33f84db152f997e1439d3912b7e (patch)
tree011d7a752ae60d10e36e90c271730b09209726fc
parentbecd44e026ff67cfd3f102fbba543434f5bf5ed2 (diff)
downloadlibhidl-f32b8dd09464a33f84db152f997e1439d3912b7e.tar.gz
Add a method to sanitize a string to be used as test name
Bug: 142397658 Test: atest VtsHalWifiHostapdV1_1TargetTest Change-Id: Ia6dd4c0969265bfb5c737edaa5dd1fb90ae88d41
-rw-r--r--gtest_helper/hidl/GtestPrinter.h30
1 files changed, 26 insertions, 4 deletions
diff --git a/gtest_helper/hidl/GtestPrinter.h b/gtest_helper/hidl/GtestPrinter.h
index c9f5dd3..4b5ac2d 100644
--- a/gtest_helper/hidl/GtestPrinter.h
+++ b/gtest_helper/hidl/GtestPrinter.h
@@ -19,17 +19,39 @@
namespace android {
namespace hardware {
+static inline std::string Sanitize(std::string name) {
+ for (size_t i = 0; i < name.size(); i++) {
+ // gtest test names must only contain alphanumeric characters
+ if (!std::isalnum(name[i])) name[i] = '_';
+ }
+ return name;
+}
+
static inline std::string PrintInstanceNameToString(
const testing::TestParamInfo<std::string>& info) {
// test names need to be unique -> index prefix
std::string name = std::to_string(info.index) + "/" + info.param;
+ return Sanitize(name);
+}
- for (size_t i = 0; i < name.size(); i++) {
- // gtest test names must only contain alphanumeric characters
- if (!std::isalnum(name[i])) name[i] = '_';
+template <typename... T>
+static inline std::string PrintInstanceTupleNameToString(
+ const testing::TestParamInfo<std::tuple<T...>>& info) {
+ std::vector<std::string> instances = std::apply(
+ [](auto&&... elems) {
+ std::vector<std::string> instances;
+ instances.reserve(sizeof...(elems));
+ (instances.push_back(std::forward<decltype(elems)>(elems)), ...);
+ return instances;
+ },
+ info.param);
+ std::string param_string;
+ for (const std::string& instance : instances) {
+ param_string += instance + "_";
}
+ param_string += std::to_string(info.index);
- return name;
+ return Sanitize(param_string);
}
} // namespace hardware