Converting V4 API to V5

Top  Previous  Next

This page shows a table of conversion between V4 API and V5.

 

Version 4

Version 5

class MyTest : public  ::testing::Test

{

  virtual void TearDown()

  { 

     ISOLATOR_CLEANUP();

  }

}

 

 

 

not required

TEST_F(Examples, Faking)

{

   // Arrange

   MyClass* fake = FAKE<MyClass>();

  

   WHEN_CALLED(fake->GetAgeFromFile()).Return(1);

 

 

}

TEST_F(Examples, Faking)

{

   // Arrange

   auto a = Isolator(); 

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

  

   a.fake(livePerson->GetAgeFromFile()).WillReturn(1);

 

 }

 

Here are all the APIs:

 

Version 4

Version 5

MyClass* fakeMyClass = FAKE<MyClass>();

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

MyClass* fakeMyClass = FAKE<MyClass>(FakeOptions::CallOriginal);

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

FAKE_GLOBAL(fopen);

a.Testable.GlobalFunction(fopen);

FAKE_STATICS<MyClass>();

a.Fake.Statics<MyClass>();

FAKE_ALL<MyClass>();

a.Fake.All<MyClass>();

 

 

WHEN_CALLED(fakeMyClass->getSum()).Return(7);

a.CallTo(fakeMyClass->getSum()).WillReturn(7);

WHEN_CALLED(fakeMyClass->getSum()).Ignore();

a.CallTo(fakeMyClass->getSum()).WillBeIgnored();

WHEN_CALLED(fakeMyClass->getSum()).Throw(szMessage);

a.CallTo(fakeMyClass->getSum()).WillThrow(szMessage);

WHEN_CALLED(fakeMyClass->getSum()).ReturnFake();

a.CallTo(fakeMyClass->getSum()).WillReturnFake();

WHEN_CALLED(fakeMyClass->getSum()).CallOriginal();

a.CallTo(fakeMyClass->getSum()).WillCallOriginal();

WHEN_CALLED(fakeMyClass->getSum()).CallOriginal().Return(5);

a.CallTo(fakeMyClass->getSum()).WillCallOriginal().AndThenReturn(5);

static int function() { 

  Person* context = (Person*)GET_EXTRA_DATA();

  return 20; 

WHEN_CALLED(fakeMyClass->getSum()).DoStaticOrGlobalInstead(function,context);

a.CallTo([&](){ fakeMyClass->getSum() }).WillDoInstead([&]() 

  return 20;

} );

 

 

PRIVATE_WHEN_CALLED(fakeMyClass,Init).Ignore();

a.CallToPrivate(A::Member(fakeMyClass, Init)).WillBeIgnored()

PRIVATE_WHEN_CALLED(_, House::CanRing, TYPEOF(bool)).Return(true);

a.CallToPrivate(A::Global(House::CanRing), A::Type<bool>()).WillReturn(true)

 

 

WHEN_CALLED(GetSystemTime(RET(&fakeTime))).Ignore();

a.CallTo(GetSystemTime(A::SetOut(fakeTime)));

WHEN_CALLED(GetSystemTime(RET(BY_REF(1)))).Ignore();

a.CallTo(GetSystemTime(A::SetOut(1)));

WHEN_CALLED(fake->Foo(RET_IF(EQ(&value), &out)).Return(1)

a.CallTo(GetSystemTime(A::SetOut(&fakeTime).WhenIn(A::EQ(1)))});

 

 

ANY_VAL()

A::Any()

ANY_REF()

A::Any()

EQ(1)

A.Eq(1) or A.EqRef(1)

NE(1)

A.Ne(1) or A.NeRef(1)

BY_REF

not required

BY_VAL

not required

TYPEOF(int)

A::Type<int>()

RET_IF

A.SetOut(&fakeTime).WhenIn()

 

 

IS(<char*>([](char* s) {return  !strcmp(s, "typemock");}))

A::Matches([](char *s) { return  !strcmp(s, "typemock");})

IS_REF(<const char*>([](const char* s) {return  !strcmp(s, "typemock");}))

A::MatchesRef([](char *s) { return  !strcmp(s, "typemock");})

 

 

ASSERT_WAS_CALLED(person->GetAddress());

a.CallTo(person->GetAddress()).VerifyWasCalled();

ASSERT_NOT_CALLED((fakePerson->GoToWork());

a.CallTo(fakePerson->GoToWork()).VerifyWasNotCalled();

TIMES_CALLED(fakePerson->GoToWork());

a.CallTo(fakePerson->GoToWork()).GetTimesCalled();

 

 

ISOLATOR_INVOKE_FUNCTION(retVar,&instance,PrivateMemeber, args...)

retVar = a.Invoke<int>(A::Member(instance, PrivateMemeber), args...));

ISOLATOR_INVOKE_FUNCTION(retVar,_,MyClass::PrivateMemeber, args...);

a.Invoke(A::Global(MyClass::PrivateMemeber), args...);

ISOLATOR_INVOKE_CONSTRUCTOR(fakeMyClass, 1);

a.Invoke(A::Ctor(fakeMyClass), 1);

 

 

ISOLATOR_SET_VARIABLE(person, m_id, 10);

a.Variable.Set(person, "m_id", 10);

ISOLATOR_SET_VARIABLE(_, Person::m_id, 10);

a.Variable.Set(pPerson::m_id, 10);

ISOLATOR_GET_VARIABLE(person, m_id, result)

result = a.Variable.Get<int>( person, "m_id"));

 

 

Typemock::IsolatorConfiguration::FakeOnlyOnTestThread = true

Isolator a(IsolatorConfiguration::FakeOnlyOnTestThread);

 

You can find in the examples ConvertTests.ps1 that can help with a basic conversion.
You will have to manually add type to a.Variable.Get and arguments to WillDoInstead.

 
To run and convert all test files within PowerShell:

 

 
Set-ExecutionPolicy RemoteSigned
.\ConvertTest.ps1 <input director> <output directory>
 


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