chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes

Trial.h

#pragma once  

int XPLMGetDatavi(void* inDataRef, int* outValues, int inOffset, int inCount);  

Trial.cpp
#include "Trial.h"  
int main()  
{  
   return 0;  
}  
int XPLMGetDatavi(void* inDataRef, int* outValues, int inOffset, int inCount)  
{  
   // Ensure the function signature is correct and matches expected syntax.  
outValues[0] = 1; // Mocking the return value for demonstration purposes
   return 0;  
}
Test Code
#include "CppUnitTest.h"
#include "isolator5.h"
#include "Trial.h"
#include "Trial.cpp"
using namespace Typemock;
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace PluginTests1
{
TEST_CLASS(PluginTests1)
{
public:
Isolator* a = nullptr;
TEST_METHOD_INITIALIZE(Initialize)
{
// Initialize the isolator
a = new Isolator();
}
TEST_METHOD_CLEANUP(Cleanup)
{
// Cleanup the isolator
if (a)
{
delete a;
a = nullptr;
}
}
TEST_METHOD(TestTrial2)
{
// Another test for the Trial class with mocking
int dr = 1;
void * dref = &dr;
int values[1] = { 0 };
a->CallTo(XPLMGetDatavi(A::Any(), A::Any(), A::Any(), A::Any()))
.WillDoInstead([](void * inDataRef, int* outValues, int inOffset, int inCount)
{
Assert::AreEqual(1, *(int*)inDataRef);
outValues[0] = 1; // Mocking the return value
Assert::AreEqual(1, *(int*)inDataRef);
return 1; // Mocking the count
});
int count = XPLMGetDatavi(&dr, values, 0, 1);
Assert::AreEqual(1, count);
Assert::AreEqual(1, values[0]);
}
};
}
if you debug the lambada line 1 in a quickwatch shows that the memory has been corrupted and if you run line 1 of the lambada it crashes with a stack overflow!
Thanks John
asked ago by John Clapson (1.6k points)

1 Answer

0 votes
Hi John,

Thank you for the input.
We will investigate this and keep you posted on what we find.

Best,
Alon Sapozhnikov
Support Specialist.
answered ago by Alon_TypeMock (10.6k points)
...