Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(560)

Side by Side Diff: testing/gmock/include/gmock/gmock-printers.h

Issue 521012: Update gmock and gtest. (Closed)
Patch Set: update readme Created 10 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2007, Google Inc. 1 // Copyright 2007, Google Inc.
2 // All rights reserved. 2 // All rights reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 } 402 }
403 403
404 // Overloads for ::string and ::std::string. 404 // Overloads for ::string and ::std::string.
405 #if GTEST_HAS_GLOBAL_STRING 405 #if GTEST_HAS_GLOBAL_STRING
406 void PrintStringTo(const ::string&s, ::std::ostream* os); 406 void PrintStringTo(const ::string&s, ::std::ostream* os);
407 inline void PrintTo(const ::string& s, ::std::ostream* os) { 407 inline void PrintTo(const ::string& s, ::std::ostream* os) {
408 PrintStringTo(s, os); 408 PrintStringTo(s, os);
409 } 409 }
410 #endif // GTEST_HAS_GLOBAL_STRING 410 #endif // GTEST_HAS_GLOBAL_STRING
411 411
412 #if GTEST_HAS_STD_STRING
413 void PrintStringTo(const ::std::string&s, ::std::ostream* os); 412 void PrintStringTo(const ::std::string&s, ::std::ostream* os);
414 inline void PrintTo(const ::std::string& s, ::std::ostream* os) { 413 inline void PrintTo(const ::std::string& s, ::std::ostream* os) {
415 PrintStringTo(s, os); 414 PrintStringTo(s, os);
416 } 415 }
417 #endif // GTEST_HAS_STD_STRING
418 416
419 // Overloads for ::wstring and ::std::wstring. 417 // Overloads for ::wstring and ::std::wstring.
420 #if GTEST_HAS_GLOBAL_WSTRING 418 #if GTEST_HAS_GLOBAL_WSTRING
421 void PrintWideStringTo(const ::wstring&s, ::std::ostream* os); 419 void PrintWideStringTo(const ::wstring&s, ::std::ostream* os);
422 inline void PrintTo(const ::wstring& s, ::std::ostream* os) { 420 inline void PrintTo(const ::wstring& s, ::std::ostream* os) {
423 PrintWideStringTo(s, os); 421 PrintWideStringTo(s, os);
424 } 422 }
425 #endif // GTEST_HAS_GLOBAL_WSTRING 423 #endif // GTEST_HAS_GLOBAL_WSTRING
426 424
427 #if GTEST_HAS_STD_WSTRING 425 #if GTEST_HAS_STD_WSTRING
428 void PrintWideStringTo(const ::std::wstring&s, ::std::ostream* os); 426 void PrintWideStringTo(const ::std::wstring&s, ::std::ostream* os);
429 inline void PrintTo(const ::std::wstring& s, ::std::ostream* os) { 427 inline void PrintTo(const ::std::wstring& s, ::std::ostream* os) {
430 PrintWideStringTo(s, os); 428 PrintWideStringTo(s, os);
431 } 429 }
432 #endif // GTEST_HAS_STD_WSTRING 430 #endif // GTEST_HAS_STD_WSTRING
433 431
434 // Overload for ::std::tr1::tuple. Needed for printing function 432 // Overload for ::std::tr1::tuple. Needed for printing function
435 // arguments, which are packed as tuples. 433 // arguments, which are packed as tuples.
436 434
437 typedef ::std::vector<string> Strings;
438
439 // This helper template allows PrintTo() for tuples and
440 // UniversalTersePrintTupleFieldsToStrings() to be defined by
441 // induction on the number of tuple fields. The idea is that
442 // TuplePrefixPrinter<N>::PrintPrefixTo(t, os) prints the first N
443 // fields in tuple t, and can be defined in terms of
444 // TuplePrefixPrinter<N - 1>.
445
446 // The inductive case.
447 template <size_t N>
448 struct TuplePrefixPrinter {
449 // Prints the first N fields of a tuple.
450 template <typename Tuple>
451 static void PrintPrefixTo(const Tuple& t, ::std::ostream* os) {
452 TuplePrefixPrinter<N - 1>::PrintPrefixTo(t, os);
453 *os << ", ";
454 UniversalPrinter<typename ::std::tr1::tuple_element<N - 1, Tuple>::type>
455 ::Print(::std::tr1::get<N - 1>(t), os);
456 }
457
458 // Tersely prints the first N fields of a tuple to a string vector,
459 // one element for each field.
460 template <typename Tuple>
461 static void TersePrintPrefixToStrings(const Tuple& t, Strings* strings) {
462 TuplePrefixPrinter<N - 1>::TersePrintPrefixToStrings(t, strings);
463 ::std::stringstream ss;
464 UniversalTersePrint(::std::tr1::get<N - 1>(t), &ss);
465 strings->push_back(ss.str());
466 }
467 };
468
469 // Base cases.
470 template <>
471 struct TuplePrefixPrinter<0> {
472 template <typename Tuple>
473 static void PrintPrefixTo(const Tuple&, ::std::ostream*) {}
474
475 template <typename Tuple>
476 static void TersePrintPrefixToStrings(const Tuple&, Strings*) {}
477 };
478 template <>
479 template <typename Tuple>
480 void TuplePrefixPrinter<1>::PrintPrefixTo(const Tuple& t, ::std::ostream* os) {
481 UniversalPrinter<typename ::std::tr1::tuple_element<0, Tuple>::type>::
482 Print(::std::tr1::get<0>(t), os);
483 }
484
485 // Helper function for printing a tuple. T must be instantiated with 435 // Helper function for printing a tuple. T must be instantiated with
486 // a tuple type. 436 // a tuple type.
487 template <typename T> 437 template <typename T>
488 void PrintTupleTo(const T& t, ::std::ostream* os) { 438 void PrintTupleTo(const T& t, ::std::ostream* os);
489 *os << "(";
490 TuplePrefixPrinter< ::std::tr1::tuple_size<T>::value>::
491 PrintPrefixTo(t, os);
492 *os << ")";
493 }
494 439
495 // Overloaded PrintTo() for tuples of various arities. We support 440 // Overloaded PrintTo() for tuples of various arities. We support
496 // tuples of up-to 10 fields. The following implementation works 441 // tuples of up-to 10 fields. The following implementation works
497 // regardless of whether tr1::tuple is implemented using the 442 // regardless of whether tr1::tuple is implemented using the
498 // non-standard variadic template feature or not. 443 // non-standard variadic template feature or not.
499 444
500 inline void PrintTo(const ::std::tr1::tuple<>& t, ::std::ostream* os) { 445 inline void PrintTo(const ::std::tr1::tuple<>& t, ::std::ostream* os) {
501 PrintTupleTo(t, os); 446 PrintTupleTo(t, os);
502 } 447 }
503 448
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 663
719 // Prints a value using the type inferred by the compiler. The 664 // Prints a value using the type inferred by the compiler. The
720 // difference between this and UniversalTersePrint() is that for a 665 // difference between this and UniversalTersePrint() is that for a
721 // (const) char pointer, this prints both the pointer and the 666 // (const) char pointer, this prints both the pointer and the
722 // NUL-terminated string. 667 // NUL-terminated string.
723 template <typename T> 668 template <typename T>
724 void UniversalPrint(const T& value, ::std::ostream* os) { 669 void UniversalPrint(const T& value, ::std::ostream* os) {
725 UniversalPrinter<T>::Print(value, os); 670 UniversalPrinter<T>::Print(value, os);
726 } 671 }
727 672
673 typedef ::std::vector<string> Strings;
674
675 // This helper template allows PrintTo() for tuples and
676 // UniversalTersePrintTupleFieldsToStrings() to be defined by
677 // induction on the number of tuple fields. The idea is that
678 // TuplePrefixPrinter<N>::PrintPrefixTo(t, os) prints the first N
679 // fields in tuple t, and can be defined in terms of
680 // TuplePrefixPrinter<N - 1>.
681
682 // The inductive case.
683 template <size_t N>
684 struct TuplePrefixPrinter {
685 // Prints the first N fields of a tuple.
686 template <typename Tuple>
687 static void PrintPrefixTo(const Tuple& t, ::std::ostream* os) {
688 TuplePrefixPrinter<N - 1>::PrintPrefixTo(t, os);
689 *os << ", ";
690 UniversalPrinter<typename ::std::tr1::tuple_element<N - 1, Tuple>::type>
691 ::Print(::std::tr1::get<N - 1>(t), os);
692 }
693
694 // Tersely prints the first N fields of a tuple to a string vector,
695 // one element for each field.
696 template <typename Tuple>
697 static void TersePrintPrefixToStrings(const Tuple& t, Strings* strings) {
698 TuplePrefixPrinter<N - 1>::TersePrintPrefixToStrings(t, strings);
699 ::std::stringstream ss;
700 UniversalTersePrint(::std::tr1::get<N - 1>(t), &ss);
701 strings->push_back(ss.str());
702 }
703 };
704
705 // Base cases.
706 template <>
707 struct TuplePrefixPrinter<0> {
708 template <typename Tuple>
709 static void PrintPrefixTo(const Tuple&, ::std::ostream*) {}
710
711 template <typename Tuple>
712 static void TersePrintPrefixToStrings(const Tuple&, Strings*) {}
713 };
714 template <>
715 template <typename Tuple>
716 void TuplePrefixPrinter<1>::PrintPrefixTo(const Tuple& t, ::std::ostream* os) {
717 UniversalPrinter<typename ::std::tr1::tuple_element<0, Tuple>::type>::
718 Print(::std::tr1::get<0>(t), os);
719 }
720
721 // Helper function for printing a tuple. T must be instantiated with
722 // a tuple type.
723 template <typename T>
724 void PrintTupleTo(const T& t, ::std::ostream* os) {
725 *os << "(";
726 TuplePrefixPrinter< ::std::tr1::tuple_size<T>::value>::
727 PrintPrefixTo(t, os);
728 *os << ")";
729 }
730
728 // Prints the fields of a tuple tersely to a string vector, one 731 // Prints the fields of a tuple tersely to a string vector, one
729 // element for each field. See the comment before 732 // element for each field. See the comment before
730 // UniversalTersePrint() for how we define "tersely". 733 // UniversalTersePrint() for how we define "tersely".
731 template <typename Tuple> 734 template <typename Tuple>
732 Strings UniversalTersePrintTupleFieldsToStrings(const Tuple& value) { 735 Strings UniversalTersePrintTupleFieldsToStrings(const Tuple& value) {
733 Strings result; 736 Strings result;
734 TuplePrefixPrinter< ::std::tr1::tuple_size<Tuple>::value>:: 737 TuplePrefixPrinter< ::std::tr1::tuple_size<Tuple>::value>::
735 TersePrintPrefixToStrings(value, &result); 738 TersePrintPrefixToStrings(value, &result);
736 return result; 739 return result;
737 } 740 }
738 741
739 } // namespace internal 742 } // namespace internal
740 } // namespace testing 743 } // namespace testing
741 744
742 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_PRINTERS_H_ 745 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_PRINTERS_H_
OLDNEW
« no previous file with comments | « testing/gmock/include/gmock/gmock-more-actions.h ('k') | testing/gmock/include/gmock/gmock-spec-builders.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698