1 /* 2 * Copyright (C) 2016 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 "utils/InterfaceSpecUtil.h" 18 19 #include <iostream> 20 #include <sstream> 21 #include <string> 22 23 #include "utils/StringUtil.h" 24 #include "test/vts/proto/ComponentSpecificationMessage.pb.h" 25 26 using namespace std; 27 28 namespace android { 29 namespace vts { 30 GetFunctionNamePrefix(const ComponentSpecificationMessage & message)31string GetFunctionNamePrefix(const ComponentSpecificationMessage& message) { 32 stringstream prefix_ss; 33 if (message.component_class() != HAL_HIDL) { 34 prefix_ss << VTS_INTERFACE_SPECIFICATION_FUNCTION_NAME_PREFIX 35 << message.component_class() << "_" << message.component_type() 36 << "_" << int(message.component_type_version()) << "_"; 37 } else { 38 string package_as_function_name(message.package()); 39 ReplaceSubString(package_as_function_name, ".", "_"); 40 prefix_ss << VTS_INTERFACE_SPECIFICATION_FUNCTION_NAME_PREFIX 41 << message.component_class() << "_" << package_as_function_name << "_" 42 << int(message.component_type_version()) << "_" 43 << message.component_name() << "_"; 44 } 45 return prefix_ss.str(); 46 } 47 48 #define DEFAULT_FACTOR 10000 49 GetVersionString(float version,bool for_macro)50string GetVersionString(float version, bool for_macro) { 51 std::ostringstream out; 52 if (for_macro) { 53 out << "V"; 54 } 55 long version_long = version * DEFAULT_FACTOR; 56 out << (version_long / DEFAULT_FACTOR); 57 if (!for_macro) { 58 out << "."; 59 } else { 60 out << "_"; 61 } 62 version_long -= (version_long / DEFAULT_FACTOR) * DEFAULT_FACTOR; 63 bool first = true; 64 long factor = DEFAULT_FACTOR / 10; 65 while (first || (version_long > 0 && factor > 1)) { 66 out << (version_long / factor); 67 version_long -= (version_long / factor) * factor; 68 factor /= 10; 69 first = false; 70 } 71 return out.str(); 72 } 73 74 } // namespace vts 75 } // namespace android 76