Hi, I am currently working my way through the quickstart guide to get a feel for your library. Very interesting so far.
In the chapter Argument Matching the given examples do not compile
I guess instead of
When(Method(mock,foo).Using(Gt(1)).Return(1);
it should be
When(Method(mock,foo).Using(Gt(1))).Return(1);
Hello eranpeer.
Recently I've read about your framework at github and I thought it could be really useful on my projects.
For now, I'm trying to compile your example from the Quickstart page, but I'm having a problem on it: the g++ compiler gives
fakeit.hpp:9297:9: error: expected constructor, destructor, or type conversion before ‘(’ token
When(call)
^
main.cpp:15:1: note: in expansion of macro ‘When’
When(Method(mock,foo)).Return(1);
when trying to compile this source:
#include <string>
#include "catch.hpp"
#include "fakeit.hpp"
using namespace std;
using namespace fakeit;
struct SomeInterface {
virtual int foo(int) = 0;
virtual int bar(string) = 0;
};
Mock<SomeInterface> mock;
When(Method(mock,foo)).Return(1);
Could you please help me with this? I apologize if the solution to the problem is something obvious that I should've known before writing this question.
Hi
I opened eranpeer/FakeIt#134 for supporting
#include <string>
#include "tpunit++.hpp"
#include "fakeit.hpp"
using namespace fakeit;
struct OperatorBoolTests : tpunit::TestFixture {
OperatorBoolTests() :
tpunit::TestFixture(
TEST(OperatorBoolTests::enum_class_arg)
)
{
}
struct SomeInterface {
virtual operator bool() = 0;
};
void enum_class_arg() {
Mock<SomeInterface> mock;
//When(Method(mock, operator())).AlwaysReturn(true);
When(OverloadedMethod(mock, operator(), bool(void))).AlwaysReturn(true);
mock.get().operator bool();
//Verify(OverloadedMethodMethod(mock, operator(), bool(void))).Exactly(1);
}
} __OperatorBoolTests;
I get compilation error
In member function ‘void OperatorBoolTests::enum_class_arg()’:
cc1plus: error: ‘operator()’ is not a member of ‘std::remove_reference<OperatorBoolTests::SomeInterface&>::type {aka OperatorBoolTests::SomeInterface}’
Thx for help
Hi all, I want to test my own library that uses a 3rd party library. So I want to mock that 3rd party libary using fakeit. Is there a way to mock methods of the 3rd party class definition? I want to test that calling MyTest.begin()
results in ExternLib.someFunc
being called. Currently I am trying the following, but that results in 'fakeit::SequenceVerificationException
because mock.someFunc isn't being called:
MyTest dt;
Mock<ExternLib> mock;
Fake(Method(mock, someFunc));
ExternLib& el = mock.get();
dt.begin();
Verify(Method(mock, someFunc));
return 0;
#include "Externlib.h"
class MyTest {
public:
int result = 3;
MyTest(){
_manager = new ExternLib();
};
virtual void begin() {
result = _manager->someFunc();
};
private:
ExternLib *_manager;
};
And I made my own ExternLib implementation (only the bare essential public functions implemented with empty functions):
#include "Externlib.h"
ExternLib:: ExternLib() {}
int ExternLib::someFunc() {
return 5;
}