Skip to content

Instantly share code, notes, and snippets.

@rafamanzo
Created January 25, 2016 21:15
Show Gist options
  • Save rafamanzo/196e2d373f2e26ea9fe3 to your computer and use it in GitHub Desktop.
Save rafamanzo/196e2d373f2e26ea9fe3 to your computer and use it in GitHub Desktop.
cmake_minimum_required(VERSION 3.0)
project (Test)
add_definitions("-Wall -pedantic -std=c++11 -g")
enable_testing()
find_package(Boost 1.59.0 REQUIRED)
include_directories(${Boost_INCLUDE_DIRS} FakeIt-master/include FakeIt-master/config/boost)
add_executable(call_test test.cpp)
target_link_libraries(call_test ${Boost_LIBRARIES})
add_test(call_test call_test)
#include <cstdlib>
#include <iostream>
#define BOOST_TEST_MODULE Test
#include <boost/test/included/unit_test.hpp>
#include <fakeit.hpp>
using namespace fakeit;
class Subject{
public:
Subject(){
attr = 0.0;
};
Subject(float _attr){
attr = _attr;
};
float attr;
bool operator==(const Subject &other) const{
std::cout << "Eq Attr: " << attr << " == " << other.attr << std::endl;
return attr == other.attr;
};
};
class Friend{
public:
Friend(){};
virtual void call(const Subject &sub) const{
std::cout << "Sub Attr:" << sub.attr << std::endl;
};
};
class FriendOfFriend{
public:
FriendOfFriend(){
f = NULL;
};
FriendOfFriend(const Friend *_f){
f = _f;
};
const Friend *f;
void call(float x) const{
Subject sub0 = Subject(x);
Subject sub1 = Subject(x + 1.0f);
std::cout << "OK" << std::endl;
f->call(sub0);
std::cout << "OK0" << std::endl;
f->call(sub1);
std::cout << "OK1" << std::endl;
};
};
BOOST_AUTO_TEST_CASE(test_call){
const Subject &s0 = Subject(1.0);
const Subject &s1 = Subject(2.0);
Mock<Friend> friend_mock;
When(Method(friend_mock, call));//.Using(s0));
When(Method(friend_mock, call).Using(s1));
Friend &f = friend_mock.get();
FriendOfFriend fof = FriendOfFriend(&f);
std::cout << "Running" << std::endl;
fof.call(1.0f);
std::cout << "Asserting" << std::endl;
Verify(Method(friend_mock, call).Using(s0)).Once();
Verify(Method(friend_mock, call).Using(s1)).Once();
VerifyNoOtherInvocations(friend_mock);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment