| 1 | // Copyright 2015, Google Inc. |
| 2 | // All rights reserved. |
| 3 | // |
| 4 | // Redistribution and use in source and binary forms, with or without |
| 5 | // modification, are permitted provided that the following conditions are |
| 6 | // met: |
| 7 | // |
| 8 | // * Redistributions of source code must retain the above copyright |
| 9 | // notice, this list of conditions and the following disclaimer. |
| 10 | // * Redistributions in binary form must reproduce the above |
| 11 | // copyright notice, this list of conditions and the following disclaimer |
| 12 | // in the documentation and/or other materials provided with the |
| 13 | // distribution. |
| 14 | // * Neither the name of Google Inc. nor the names of its |
| 15 | // contributors may be used to endorse or promote products derived from |
| 16 | // this software without specific prior written permission. |
| 17 | // |
| 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | // |
| 30 | // This file provides an injection point for custom printers in a local |
| 31 | // installation of gTest. |
| 32 | // It will be included from gtest-printers.h and the overrides in this file |
| 33 | // will be visible to everyone. |
| 34 | // |
| 35 | // Injection point for custom user configurations. See README for details |
| 36 | // |
| 37 | // ** Custom implementation starts here ** |
| 38 | |
| 39 | #ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_ |
| 40 | #define GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_ |
| 41 | |
| 42 | #if !GTEST_NO_LLVM_SUPPORT |
| 43 | #include "llvm/ADT/DenseMap.h" |
| 44 | #include "llvm/ADT/SmallString.h" |
| 45 | #include "llvm/ADT/StringRef.h" |
| 46 | #include <ostream> |
| 47 | // Printing of llvm String types. |
| 48 | // gtest sees these as containers of char (they have nested iterator types), |
| 49 | // so their operator<< is never considered unless we provide PrintTo(). |
| 50 | // PrintStringTo provides quotes and escaping, at the cost of a copy. |
| 51 | namespace llvm { |
| 52 | inline void PrintTo(llvm::StringRef S, std::ostream *OS) { |
| 53 | *OS << ::testing::PrintToString(value: S.str()); |
| 54 | } |
| 55 | // We need both SmallString<N> and SmallVectorImpl<char> overloads: |
| 56 | // - the SmallString<N> template is needed as overload resolution will |
| 57 | // instantiate generic PrintTo<T> rather than do derived-to-base conversion |
| 58 | // - but SmallVectorImpl<char> is sometimes the actual static type, in code |
| 59 | // that erases the small size |
| 60 | template <unsigned N> |
| 61 | inline void PrintTo(const SmallString<N> &S, std::ostream *OS) { |
| 62 | *OS << ::testing::PrintToString(value: std::string(S.data(), S.size())); |
| 63 | } |
| 64 | inline void PrintTo(const SmallVectorImpl<char> &S, std::ostream *OS) { |
| 65 | *OS << ::testing::PrintToString(value: std::string(S.data(), S.size())); |
| 66 | } |
| 67 | |
| 68 | // DenseMap's entries inherit from std::pair, and should act like pairs. |
| 69 | // However gTest's provided `PrintTo(pair<K,V>)` template won't deduce K and V |
| 70 | // because of the needed derived-to-base conversion. |
| 71 | namespace detail { |
| 72 | template <typename K, typename V> |
| 73 | inline void PrintTo(const DenseMapPair<K, V> &Pair, std::ostream *OS) { |
| 74 | *OS << ::testing::PrintToString(static_cast<const std::pair<K, V> &>(Pair)); |
| 75 | } |
| 76 | } // namespace detail |
| 77 | |
| 78 | } // namespace llvm |
| 79 | #endif // !GTEST_NO_LLVM_SUPPORT |
| 80 | |
| 81 | #endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_ |
| 82 | |