Home | History | Annotate | Download | only in utility
      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 #include <type_traits>
     17 
     18 /** @file Use HIDL generated toString methods to pretty print gtest errors */
     19 
     20 namespace detail {
     21 
     22 // Print the value of an enum as hex
     23 template <class Enum>
     24 inline void printUnderlyingValue(Enum value, ::std::ostream* os) {
     25     *os << std::hex << " (0x" << static_cast<std::underlying_type_t<Enum>>(value) << ")";
     26 }
     27 
     28 } // namespace detail
     29 
     30 namespace android {
     31 namespace hardware {
     32 namespace audio {
     33 namespace V2_0 {
     34 
     35 inline void PrintTo(const Result& result, ::std::ostream* os) {
     36     *os << toString(result);
     37     detail::printUnderlyingValue(result, os);
     38 }
     39 
     40 } // namespace V2_0
     41 namespace common {
     42 namespace V2_0 {
     43 
     44 inline void PrintTo(const AudioConfig& config, ::std::ostream* os) {
     45     *os << toString(config);
     46 }
     47 
     48 inline void PrintTo(const AudioDevice& device, ::std::ostream* os) {
     49     *os << toString(device);
     50     detail::printUnderlyingValue(device, os);
     51 }
     52 
     53 inline void PrintTo(const AudioChannelMask& channelMask, ::std::ostream* os) {
     54     *os << toString(channelMask);
     55     detail::printUnderlyingValue(channelMask, os);
     56 }
     57 
     58 } // namespace V2_0
     59 } // namespace common
     60 } // namespace audio
     61 } // namespace hardware
     62 } // namespace android
     63