Custom During Filters

Top  Previous  Next

Custom During Lambda Filter

 

Use custom lambda for conditions not covered by built-ins.

The lambda sends a DuringContext argument that you can use.

 

DuringContext contains the following:

 

1.PCSTR GetCallingModule():
Returns the current module.
2.TID GetThreadId():
Returns the current thread.
3.void IgnoreHigherLevels():
Precedence: Call > Instance > Suite, use IgnoreHigherLevels() to stop broader filters from applying.
4.std::vector<CallStackFrame> GetCallStack():
Returns a vector with retrieved call stack.

 

 

Here is an example for using GetThreadId:

 

TEST(DuringTests, FilterByThreadIdWithCustomLambda)

{

    auto id = GetCurrentThreadId();

 

    auto a = Isolator(During([=](DuringContext& context)

    {

        return context.GetThreadId() == id;

    }));

 

    auto fake = a.Fake.Instance<Person>();

    

    // This is restricted to getName called within current thread

    a.CallTo(fake->GetName()).WillReturn("John");

 

    auto res = fake->GetName();

    ASSERT_TRUE(strcmp(res, "John") == 0);

}

 
Note: It's possible to put any condition within the lambda.


Copyright  Typemock Ltd. 2009-2025.  All Rights Reserved.