Skip to content

Commit

Permalink
Use brstd::function instead of std::function
Browse files Browse the repository at this point in the history
  • Loading branch information
amaher-ms committed Oct 21, 2023
1 parent ec6df8f commit 154b912
Show file tree
Hide file tree
Showing 29 changed files with 714 additions and 714 deletions.
16 changes: 8 additions & 8 deletions include/fakeit/Action.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
#pragma once

#include <functional>
#include <Platform/brstd/functional.h>
#include <atomic>
#include <tuple>
#include <type_traits>
Expand All @@ -32,11 +32,11 @@ namespace fakeit {
struct Repeat : Action<R, arglist...> {
virtual ~Repeat() = default;

Repeat(std::function<R(typename fakeit::test_arg<arglist>::type...)> func) :
Repeat(brstd::function<R(typename fakeit::test_arg<arglist>::type...)> func) :
f(func), times(1) {
}

Repeat(std::function<R(typename fakeit::test_arg<arglist>::type...)> func, long t) :
Repeat(brstd::function<R(typename fakeit::test_arg<arglist>::type...)> func, long t) :
f(func), times(t) {
}

Expand All @@ -50,7 +50,7 @@ namespace fakeit {
}

private:
std::function<R(typename fakeit::test_arg<arglist>::type...)> f;
brstd::function<R(typename fakeit::test_arg<arglist>::type...)> f;
long times;
};

Expand All @@ -59,7 +59,7 @@ namespace fakeit {

virtual ~RepeatForever() = default;

RepeatForever(std::function<R(typename fakeit::test_arg<arglist>::type...)> func) :
RepeatForever(brstd::function<R(typename fakeit::test_arg<arglist>::type...)> func) :
f(func) {
}

Expand All @@ -72,7 +72,7 @@ namespace fakeit {
}

private:
std::function<R(typename fakeit::test_arg<arglist>::type...)> f;
brstd::function<R(typename fakeit::test_arg<arglist>::type...)> f;
};

template<typename R, typename ... arglist>
Expand All @@ -91,7 +91,7 @@ namespace fakeit {
template<typename R, typename ... arglist>
struct ReturnDelegateValue : public Action<R, arglist...> {

ReturnDelegateValue(std::function<R(const typename fakeit::test_arg<arglist>::type...)> delegate) : _delegate(delegate) { }
ReturnDelegateValue(brstd::function<R(const typename fakeit::test_arg<arglist>::type...)> delegate) : _delegate(delegate) { }

virtual ~ReturnDelegateValue() = default;

Expand All @@ -104,7 +104,7 @@ namespace fakeit {
}

private:
std::function<R(const typename fakeit::test_arg<arglist>::type...)> _delegate;
brstd::function<R(const typename fakeit::test_arg<arglist>::type...)> _delegate;
};

}
2 changes: 1 addition & 1 deletion include/fakeit/ActionSequence.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace fakeit {
std::shared_ptr<Destructible> destructablePtr = _recordedActions.front();
Destructible &destructable = *destructablePtr;
Action<R, arglist...> &action = dynamic_cast<Action<R, arglist...> &>(destructable);
std::function<void()> finallyClause = [&]() -> void {
brstd::function<void()> finallyClause = [&]() -> void {
if (action.isDone())
{
_recordedActions.erase(_recordedActions.begin());
Expand Down
2 changes: 1 addition & 1 deletion include/fakeit/FakeitEvents.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
#pragma once

#include <functional>
#include <Platform/brstd/functional.h>
#include <memory>

#include "fakeit/Sequence.hpp"
Expand Down
2 changes: 1 addition & 1 deletion include/fakeit/MatchersCollector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
#pragma once

#include <functional>
#include <Platform/brstd/functional.h>
#include <type_traits>
#include <tuple>
#include <memory>
Expand Down
36 changes: 18 additions & 18 deletions include/fakeit/MethodMockingContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
#pragma once

#include <functional>
#include <Platform/brstd/functional.h>
#include <utility>
#include <type_traits>
#include <tuple>
Expand Down Expand Up @@ -52,15 +52,15 @@ namespace fakeit {
/**
* Return the original method. not the mock.
*/
virtual typename std::function<R(arglist&...)> getOriginalMethodCopyArgs() = 0;
virtual typename std::function<R(arglist&...)> getOriginalMethodForwardArgs() = 0;
virtual typename brstd::function<R(arglist&...)> getOriginalMethodCopyArgs() = 0;
virtual typename brstd::function<R(arglist&...)> getOriginalMethodForwardArgs() = 0;

virtual std::string getMethodName() = 0;

virtual void addMethodInvocationHandler(typename ActualInvocation<arglist...>::Matcher *matcher,
ActualInvocationHandler<R, arglist...> *invocationHandler) = 0;

virtual void scanActualInvocations(const std::function<void(ActualInvocation<arglist...> &)> &scanner) = 0;
virtual void scanActualInvocations(const brstd::function<void(ActualInvocation<arglist...> &)> &scanner) = 0;

virtual void setMethodDetails(std::string mockName, std::string methodName) = 0;

Expand Down Expand Up @@ -141,7 +141,7 @@ namespace fakeit {
getRecordedActionSequence().AppendDo(action);
}

void setMethodBodyByAssignment(std::function<R(const typename fakeit::test_arg<arglist>::type...)> method) {
void setMethodBodyByAssignment(brstd::function<R(const typename fakeit::test_arg<arglist>::type...)> method) {
appendAction(new RepeatForever<R, arglist...>(method));
commit();
}
Expand All @@ -154,11 +154,11 @@ namespace fakeit {
into.push_back(&getStubbingContext().getInvolvedMock());
}

typename std::function<R(arglist &...)> getOriginalMethodCopyArgs() {
typename brstd::function<R(arglist &...)> getOriginalMethodCopyArgs() {
return getStubbingContext().getOriginalMethodCopyArgs();
}

typename std::function<R(arglist &...)> getOriginalMethodForwardArgs() {
typename brstd::function<R(arglist &...)> getOriginalMethodForwardArgs() {
return getStubbingContext().getOriginalMethodForwardArgs();
}

Expand Down Expand Up @@ -227,7 +227,7 @@ namespace fakeit {
_impl->setMethodDetails(mockName, methodName);
}

void setMatchingCriteria(const std::function<bool(arglist &...)>& predicate) {
void setMatchingCriteria(const brstd::function<bool(arglist &...)>& predicate) {
typename ActualInvocation<arglist...>::Matcher *matcher{
new UserDefinedInvocationMatcher<arglist...>(predicate)};
_impl->setInvocationMatcher(matcher);
Expand All @@ -246,7 +246,7 @@ namespace fakeit {
_impl->appendAction(action);
}

void setMethodBodyByAssignment(std::function<R(const typename fakeit::test_arg<arglist>::type...)> method) {
void setMethodBodyByAssignment(brstd::function<R(const typename fakeit::test_arg<arglist>::type...)> method) {
_impl->setMethodBodyByAssignment(method);
}

Expand All @@ -264,11 +264,11 @@ namespace fakeit {

private:

typename std::function<R(arglist&...)> getOriginalMethodCopyArgs() override {
typename brstd::function<R(arglist&...)> getOriginalMethodCopyArgs() override {
return _impl->getOriginalMethodCopyArgs();
}

typename std::function<R(arglist&...)> getOriginalMethodForwardArgs() override {
typename brstd::function<R(arglist&...)> getOriginalMethodForwardArgs() override {
return _impl->getOriginalMethodForwardArgs();
}

Expand Down Expand Up @@ -303,7 +303,7 @@ namespace fakeit {
return *this;
}

MockingContext<R, arglist...> &Matching(const std::function<bool(arglist &...)>& matcher) {
MockingContext<R, arglist...> &Matching(const brstd::function<bool(arglist &...)>& matcher) {
MethodMockingContext<R, arglist...>::setMatchingCriteria(matcher);
return *this;
}
Expand All @@ -313,12 +313,12 @@ namespace fakeit {
return *this;
}

MockingContext<R, arglist...> &operator()(const std::function<bool(arglist &...)>& matcher) {
MockingContext<R, arglist...> &operator()(const brstd::function<bool(arglist &...)>& matcher) {
MethodMockingContext<R, arglist...>::setMatchingCriteria(matcher);
return *this;
}

void operator=(std::function<R(arglist &...)> method) {
void operator=(brstd::function<R(arglist &...)> method) {
MethodMockingContext<R, arglist...>::setMethodBodyByAssignment(method);
}

Expand Down Expand Up @@ -363,7 +363,7 @@ namespace fakeit {
return *this;
}

MockingContext<void, arglist...> &Matching(const std::function<bool(arglist &...)>& matcher) {
MockingContext<void, arglist...> &Matching(const brstd::function<bool(arglist &...)>& matcher) {
MethodMockingContext<void, arglist...>::setMatchingCriteria(matcher);
return *this;
}
Expand All @@ -373,12 +373,12 @@ namespace fakeit {
return *this;
}

MockingContext<void, arglist...> &operator()(const std::function<bool(arglist &...)>& matcher) {
MockingContext<void, arglist...> &operator()(const brstd::function<bool(arglist &...)>& matcher) {
MethodMockingContext<void, arglist...>::setMatchingCriteria(matcher);
return *this;
}

void operator=(std::function<void(arglist &...)> method) {
void operator=(brstd::function<void(arglist &...)> method) {
MethodMockingContext<void, arglist...>::setMethodBodyByAssignment(method);
}

Expand All @@ -397,7 +397,7 @@ namespace fakeit {
DtorMockingContext(DtorMockingContext &&other) : MethodMockingContext<void>(std::move(other)) {
}

void operator=(std::function<void()> method) {
void operator=(brstd::function<void()> method) {
MethodMockingContext<void>::setMethodBodyByAssignment(method);
}

Expand Down
14 changes: 7 additions & 7 deletions include/fakeit/MockImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ namespace fakeit {
getRecordedMethodBody().addMethodInvocationHandler(matcher, invocationHandler);
}

void scanActualInvocations(const std::function<void(ActualInvocation<arglist...> &)> &scanner) {
void scanActualInvocations(const brstd::function<void(ActualInvocation<arglist...> &)> &scanner) {
getRecordedMethodBody().scanActualInvocations(scanner);
}

Expand Down Expand Up @@ -181,7 +181,7 @@ namespace fakeit {
}

template<typename ... T, typename std::enable_if<all_true<smart_is_copy_constructible<T>::value...>::value, int>::type = 0>
std::function<R(arglist&...)> getOriginalMethodCopyArgsInternal(int) {
brstd::function<R(arglist&...)> getOriginalMethodCopyArgsInternal(int) {
void *mPtr = MethodMockingContextBase<R, arglist...>::_mock.getOriginalMethod(_vMethod);
C * instance = &(MethodMockingContextBase<R, arglist...>::_mock.get());
return [=](arglist&... args) -> R {
Expand All @@ -192,16 +192,16 @@ namespace fakeit {

/* LCOV_EXCL_START */
template<typename ... T>
[[noreturn]] std::function<R(arglist&...)> getOriginalMethodCopyArgsInternal(long) {
[[noreturn]] brstd::function<R(arglist&...)> getOriginalMethodCopyArgsInternal(long) {
std::abort(); // Shouldn't ever be called, Spy() should static_assert an error before.
}
/* LCOV_EXCL_STOP */

std::function<R(arglist&...)> getOriginalMethodCopyArgs() override {
brstd::function<R(arglist&...)> getOriginalMethodCopyArgs() override {
return getOriginalMethodCopyArgsInternal<arglist...>(0);
}

std::function<R(arglist&...)> getOriginalMethodForwardArgs() override {
brstd::function<R(arglist&...)> getOriginalMethodForwardArgs() override {
void *mPtr = MethodMockingContextBase<R, arglist...>::_mock.getOriginalMethod(_vMethod);
C * instance = &(MethodMockingContextBase<R, arglist...>::_mock.get());
return [=](arglist&... args) -> R {
Expand Down Expand Up @@ -245,12 +245,12 @@ namespace fakeit {
: MethodMockingContextBase<void>(mock) {
}

std::function<void()> getOriginalMethodCopyArgs() override {
brstd::function<void()> getOriginalMethodCopyArgs() override {
return [=]() -> void {
};
}

std::function<void()> getOriginalMethodForwardArgs() override {
brstd::function<void()> getOriginalMethodForwardArgs() override {
return [=]() -> void {
};
}
Expand Down
2 changes: 1 addition & 1 deletion include/fakeit/Quantifier.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
#pragma once

#include <functional>
#include <Platform/brstd/functional.h>
#include <type_traits>

namespace fakeit {
Expand Down
4 changes: 2 additions & 2 deletions include/fakeit/RecordedMethodBody.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#pragma once

#include <vector>
#include <functional>
#include <Platform/brstd/functional.h>
#include <tuple>

#include "mockutils/TupleDispatcher.hpp"
Expand Down Expand Up @@ -149,7 +149,7 @@ namespace fakeit {
throw e;
}

void scanActualInvocations(const std::function<void(ActualInvocation<arglist...> &)> &scanner) {
void scanActualInvocations(const brstd::function<void(ActualInvocation<arglist...> &)> &scanner) {
for (auto destructablePtr : _actualInvocations) {
ActualInvocation<arglist...> &invocation = asActualInvocation(*destructablePtr);
scanner(invocation);
Expand Down
4 changes: 2 additions & 2 deletions include/fakeit/SpyingContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace fakeit {
struct SpyingContext : Xaction {
virtual void appendAction(Action<R, arglist...> *action) = 0;

virtual std::function<R(arglist&...)> getOriginalMethodCopyArgs() = 0;
virtual std::function<R(arglist&...)> getOriginalMethodForwardArgs() = 0;
virtual brstd::function<R(arglist&...)> getOriginalMethodCopyArgs() = 0;
virtual brstd::function<R(arglist&...)> getOriginalMethodForwardArgs() = 0;
};
}
2 changes: 1 addition & 1 deletion include/fakeit/StubbingImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
#pragma once

#include <functional>
#include <Platform/brstd/functional.h>
#include <type_traits>
#include <memory>
#include <iosfwd>
Expand Down
Loading

0 comments on commit 154b912

Please sign in to comment.