Isolator++ API for LLM

Top  Previous 

This is an API page for the use of LLM bots.

 

------------------------------------------------------------

PROMPT EXAMPLE

------------------------------------------------------------

You are an expert Typemock Developer with a deep understanding of MSTest and Typemock Isolator++.

 

Please open the Typemock Isolator++ API summary from www.typemock.com/docs/?book=Ipp&page=llm.htm. Using the API details described there:

 

Generate a C++ unit test for the attached class. The test should meet the following specifications:

 

Frameworks: Use MSTest for testing and Typemock for mocking.

Code Coverage: Include multiple tests for comprehensive coverage.

Structure: Provide full, compilable C++ code, including necessary headers.

New API Usage: Use Typemock Isolator++'s lambda-based API for faking and arranging behavior.

Ensure that all faked methods and behaviors align with the Isolator++ API as summarized in the referenced documentation.

------------------------------------------------------------

 

NAMESPACES, FILES, AND SETUP:

 

- Include <Isolator5.h> to access the Isolator++ APIs.

- Typically integrated into unit tests to fake dependencies and control behavior.

- API is designed around the AAA testing pattern.

- Use the following naming scheme to name tests: MethodUnderTest_Scenario_ExpectedResult.

 

- Example for MS Test:

 

#include <Isolator5.h>

 

TEST_CLASS(MyTestSuite)

{

public:

        TEST_METHOD(MethodUnderTest_Scenario_ExpectedResult)

        {

             // Arrange

           auto a = Isolator();

            a.Fake.Statics<ClassWithStaticCalls>();

            a.CallTo(ClassWithStaticCalls::StaticIntCall("a",2)).WillReturn(1);

     

             // Act

             auto result = ClassWithStaticCalls::StaticIntCall("a",2);

             

             // Assert

             Assert::AreEqual(1, result);

        }

}

 

 

- Example for Google Test:

 

#include <Isolator5.h>

 

class MyTestSuite : public ::testing::Test

{

};

 

 

TEST_F(MyTestSuite, MethodUnderTest_Scenario_ExpectedResult)

{

       // Arrange

     auto a = Isolator();

    a.Fake.Statics<ClassWithStaticCalls>();

    a.CallTo(ClassWithStaticCalls::StaticIntCall("a",2)).WillReturn(1);

     

     // Act

     auto result = ClassWithStaticCalls::StaticIntCall("a",2);

             

     // Assert

     Assert::AreEqual(1, result);

}

 

 

FAKE CREATION API:

- a.Fake.Instance<MyClass>([FakeOptions]): Creates a faked instance of type T. Returns T*.

Example: auto fakeObj = a.Fake.Instance<MyClass>();

 

- a.Fake.All<T>([FakeOptions]): Fakes all current and future instances of type T. Returns T*.

Example: auto fakeAllObj = a.Fake.All<MyClass>();

 

- a.Fake.Statics<T>([FakeOptions]): Fakes all static methods of type T.

Example: a.Fake.Statics<MyClass>();

 

- a.Testable.GlobalFunction(FunctionName): Declares a global (non-member) function for faking.

Example: a.Testable.GlobalFunction(GlobalFunction);

 

 

FAKE OPTIONS (FAKE CREATION BEHAVIOR):

- FakeOptions::Recursive: The default fake option. Faked methods return recursive fakes or default values.

Examples (both are equivalent):        auto fakeObj = a.Fake.Instance<MyClass>();

                                       auto fakeObj = a.Fake.Instance<MyClass>(FakeOptions::Recursive);

 

- FakeOptions::CallOriginal: Faked methods call their original implementation by default.

Example: auto fakeObj = a.Fake.Instance<MyClass>(FakeOptions::CallOriginal);

 

- FakeOptions::HandleExceptionInTest (64-bit only): Exceptions from faked calls are caught in the test code.

Example: auto fakeObj = a.Fake.Instance<MyClass>(FakeOptions::HandleExceptionInTest);

 

 

ARRANGING FAKED BEHAVIOR:

To change the behavior of faked methods from the default one, use the a.CallTo API.

- a.CallTo(fake->Method(...)): Begin defining custom behavior for a faked method.

 

Completing statements after a.CallTo(...):

- .WillReturn(value): Returns a specified value (can only be used for methods that return a value).

- .WillThrow([exception]): Throws an exception.

- .WillCallOriginal(): Calls the original (non-faked) implementation.

- .WillBeIgnored(): Ignores the call (default behavior in recursive mode). Used for methods with a void return type.

- .WillDoInstead(): Calls the specified function instead.

- .WillReturnFake([FakeOptions]): Returns a fake object from this call.

 

Examples:

auto fakeObj = a.Fake.Instance<MyClass>();

a.CallTo(fakeObj->GetValue()).WillReturn(42);

a.CallTo(fakeObj->Compute(1, 2)).WillThrow(new std::exception("Error"));

 

 

 

ARRANGING PRIVATE METHODS:

- a.CallToPrivate(instance, PrivateMethod[, TYPEOF(...)]): Similar to a.CallTo but for private methods.

Example:

auto fakeObj = a.CallTo<MyClass>();

a.CallToPrivate(fakeObj, PrivateMethod).WillReturn(10);

 

 

 

ARGUMENT MATCHING AND CONDITIONS:

- A::Any() match any value/reference of type T.

- A::Type<type>() specifies argument types for overloaded private methods.

- Comparison predicates: A.Eq(1) or A.EqRef(1), A.Ne(1) or A.NeRef(1).

- A.SetOut(&fakeHandle).WhenIn(): Conditional out parameter behavior.

- A::Matches(lambda), A::MatchesRef(lambda): Custom argument validation with a lambda.

 

Example:

a.CallTo(fakeObj->Compute(A.Eq(2), A::Any())).WillReturn(100);

 

 

 

VERIFICATION MACROS (ASSERTIONS):

- a.CallTo(fake->Method(...)).VerifyWasCalled(): Assert that a method was called.

- a.CallTo(fake->Method(...)).VerifyWasNotCalled(): Assert that a method was not called.

- a.CallTo(fake->Method(...)).GetTimesCalled(): Returns how many times a method was called.

 

Example:

a.CallTo(fakeObj->GetValue()).VerifyWasCalled();

int count = a.CallTo(fakeObj->Compute(1, 2)).GetTimesCalled();

ASSERT_EQ(2, count);

 

 

CONFIGURATION:

- Isolator a(IsolatorConfiguration::FakeOnlyOnTestThread);

When true, fakes only apply to the test thread.

 

 

GENERAL USAGE PATTERN (AAA STYLE):

 

Arrange:

auto fakeObj = a.Fake.Instance<MyClass>();

a.CallTo(fakeObj->GetValue()).WillReturn(42);

 

Act:

int result = fakeObj->GetValue();

 

Assert:

a.CallTo(fakeObj->GetValue()).VerifyWasCalled();

ASSERT_EQ(42, result);

 

------------------------------------------------------------

END OF COMPLETE SUMMARY

------------------------------------------------------------

 


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