keeganwitt / gmock

Automatically exported from code.google.com/p/gmock
6 stars 2 forks source link

Gmock can't mock method parameter with both operator bool() and operator int() methods implemented #130

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. take a class:
class ParClass {
public:
    operator int() const;
    operator bool() const;
}

2. now we want to mock a method accepting ParClass as on of the parameters

Than you get an error like this:

In file included from /usr/include/gtest/gtest.h:57:0,
                 from ../../../../third-party/gmock_1_6_0/include/gmock/internal/gmock-internal-utils.h:47,
                 from ../../../../third-party/gmock_1_6_0/include/gmock/gmock-actions.h:46,
                 from ../../../../third-party/gmock_1_6_0/include/gmock/gmock.h:58,
                 from test/GatewayTest.cc:12:
/usr/include/gtest/internal/gtest-internal.h: In instantiation of ‘const bool 
testing::internal::ImplicitlyConvertible<ParClass &, long long int>::value’:
/usr/include/gtest/gtest-printers.h:201:3:   instantiated from 
‘std::basic_ostream<CharT1, Tr>& 
testing::internal2::operator<<(std::basic_ostream<CharT1, Tr>&, const T&) [with 
Char = char, CharTraits = std::char_traits<char>, T = ParClass]’
/usr/include/gtest/gtest-printers.h:245:3:   instantiated from ‘void 
testing_internal::DefaultPrintNonContainerTo(const T&, std::ostream*) [with T = 
ParClass, std::ostream = std::basic_ostream<char>]’
/usr/include/gtest/gtest-printers.h:338:3:   instantiated from ‘void 
testing::internal::DefaultPrintTo(testing::internal::IsNotContainer, 
testing::internal::false_type, const T&, std::ostream*) [with T = ParClass, 
testing::internal::IsNotContainer = char, testing::internal::false_type = 
testing::internal::bool_constant<false>, std::ostream = 
std::basic_ostream<char>]’
/usr/include/gtest/gtest-printers.h:376:3:   instantiated from ‘void 
testing::internal::PrintTo(const T&, std::ostream*) [with T = ParClass, 
std::ostream = std::basic_ostream<char>]’
/usr/include/gtest/gtest-printers.h:600:5:   instantiated from ‘static void 
testing::internal::UniversalPrinter<T>::Print(const T&, std::ostream*) [with T 
= ParClass, std::ostream = std::basic_ostream<char>]’
/usr/include/gtest/gtest-printers.h:718:5:   [ skipping 2 instantiation 
contexts ]
/usr/include/gtest/gtest-printers.h:768:3:   instantiated from ‘void 
testing::internal::PrintTupleTo(const T&, std::ostream*) [with T = 
std::tr1::tuple<ParClass>, std::ostream = std::basic_ostream<char>]’
/usr/include/gtest/gtest-printers.h:513:3:   instantiated from ‘void 
testing::internal::PrintTo(const std::tr1::tuple<A1, A2, A3>&, std::ostream*) 
[with T1 = bc::InstrumentId&, T2 = ParClass, T3 = unsigned int, std::ostream = 
std::basic_ostream<char>]’
/usr/include/gtest/gtest-printers.h:600:5:   instantiated from ‘static void 
testing::internal::UniversalPrinter<T>::Print(const T&, std::ostream*) [with T 
= std::tr1::tuple<ParClass>, std::ostream = std::basic_ostream<char>]’
/usr/include/gtest/gtest-printers.h:697:3:   instantiated from ‘void 
testing::internal::UniversalPrint(const T&, std::ostream*) [with T = 
std::tr1::tuple<ParClass>, std::ostream = std::basic_ostream<char>]’
../../../../third-party/gmock_1_6_0/include/gmock/gmock-spec-builders.h:1563:5: 
  instantiated from ‘void 
testing::internal::FunctionMockerBase<F>::UntypedDescribeUninterestingCall(const
 void*, std::ostream*) const [with F = void(ParClass), std::ostream = 
std::basic_ostream<char>]’
test/GatewayTest.cc:240:1:   instantiated from here
/usr/include/gtest/internal/gtest-internal.h:890:60: error: conversion from 
‘const ParClass’ to ‘long long int’ is ambiguous
/usr/include/gtest/internal/gtest-internal.h:890:60: note: candidates are:
../../common/ParClass .h:89:5: note: ParClass ::operator bool() const
../../common/ParClass .h:88:5: note: ParClass ::operator int() const
/usr/include/gtest/internal/gtest-internal.h:867:15: error:   initializing 
argument 1 of ‘static char testing::internal::ImplicitlyConvertible<From, 
To>::Helper(To) [with From = const ParClass&, To = long long int]’

What is the expected output? What do you see instead?

What version of the product are you using? On what operating system?

gmock_1_6_0, ubuntu 11.10

Please provide any additional information below.

Original issue reported on code.google.com by iRy...@gmail.com on 11 May 2012 at 3:03

GoogleCodeExporter commented 8 years ago
Problem can be solved by implementing ostream << (ostream, ParClass), so 
actually issue is not big.

Original comment by iRy...@gmail.com on 11 May 2012 at 3:19

GoogleCodeExporter commented 8 years ago
O-o-o-o-ps, it's not gmock, it's google mock... sorry... just close the issue :)

Original comment by iRy...@gmail.com on 11 May 2012 at 3:34

GoogleCodeExporter commented 8 years ago

Original comment by JohnnyJianHY on 12 May 2012 at 2:24