brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.6 KiB · 06f85f8 Raw
82 lines · c
1// Copyright 2015, Google Inc.2// All rights reserved.3//4// Redistribution and use in source and binary forms, with or without5// modification, are permitted provided that the following conditions are6// met:7//8//     * Redistributions of source code must retain the above copyright9// notice, this list of conditions and the following disclaimer.10//     * Redistributions in binary form must reproduce the above11// copyright notice, this list of conditions and the following disclaimer12// in the documentation and/or other materials provided with the13// distribution.14//     * Neither the name of Google Inc. nor the names of its15// contributors may be used to endorse or promote products derived from16// this software without specific prior written permission.17//18// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS19// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT20// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR21// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT22// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT24// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,25// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY26// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT27// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE28// 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 local31// installation of gTest.32// It will be included from gtest-printers.h and the overrides in this file33// will be visible to everyone.34//35// Injection point for custom user configurations. See README for details36//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_SUPPORT43#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.51namespace llvm {52inline void PrintTo(llvm::StringRef S, std::ostream *OS) {53  *OS << ::testing::PrintToString(S.str());54}55// We need both SmallString<N> and SmallVectorImpl<char> overloads:56//  - the SmallString<N> template is needed as overload resolution will57//    instantiate generic PrintTo<T> rather than do derived-to-base conversion58//  - but SmallVectorImpl<char> is sometimes the actual static type, in code59//    that erases the small size60template <unsigned N>61inline void PrintTo(const SmallString<N> &S, std::ostream *OS) {62  *OS << ::testing::PrintToString(std::string(S.data(), S.size()));63}64inline void PrintTo(const SmallVectorImpl<char> &S, std::ostream *OS) {65  *OS << ::testing::PrintToString(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 V70// because of the needed derived-to-base conversion.71namespace detail {72template <typename K, typename V>73inline 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 detail77 78} // namespace llvm79#endif // !GTEST_NO_LLVM_SUPPORT80 81#endif  // GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_82