Ignored Parameters

Top  Previous  Next

When using Isolator++ Professional, you don't need to worry about the values of parameters passed in. By disregarding the parameters at runtime, the tests become less fragile, and do not require a precise setup. In fact, with functions with multiple arguments, the tests become clearer and more readable.

 

Generally, you can use the predefined placeholders: '_'  instead of parameter values you don't care about.

 

TEST_F(Examples, IgnoredParameters)

{

   Person* livePerson = new Person();

   

   WHEN_CALLED(livePerson->Login(_,_)).Return(TRUE);

   

   ASSERT_TRUE(livePerson->Login("user","password"));

 

   ISOLATOR_CLEANUP();

}

 

In some cases though, the '_' placeholder is not enough to help the compiler understand the underlying type. It works well for primitives and pointers. But for compound types and enums, we'll need to use the ANY_VAL macro for inbound arguments, and ANY_REF for outbound arguments. In the following example, we override the exception, by using ANY_VAL and ANY_REF respectively.

 

typedef enum {

  Bad,

  Good,

  Great

} QualityStatus;

 

public QualityHelper

{

 void SetQuality(QualityStatus qs) { throw; }

 void GetQuality(QualityStatus& qs) { throw; }

}

 

TEST_F(MyTests, UsingAnyVal)

{

   QualityHelper* qh = new QualityHelper();

 

   WHEN_CALLED(SetQuality(ANY_VAL(QualityStatus))).Ignore();

   qh->SetStatus(Bad);

 

   WHEN_CALLED(GetQuality(ANY_REF(QualityStatus))).Ignore();   

   

   QualityStatus dummy;

   qh->GetStatus(dummy);

 

   ISOLATOR_CLEANUP();

}


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