2019-05-03 18:52:54 -04:00
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Test Object Helper Macros
|
|
|
|
***********************************************************************************************************************************/
|
|
|
|
#include "common/debug.h"
|
|
|
|
#include "common/log.h"
|
|
|
|
#include "common/memContext.h"
|
|
|
|
|
|
|
|
/***********************************************************************************************************************************
|
|
|
|
TestObject Type
|
|
|
|
***********************************************************************************************************************************/
|
|
|
|
#define TEST_OBJECT_TYPE TestObject
|
|
|
|
#define TEST_OBJECT_PREFIX testObject
|
|
|
|
|
|
|
|
typedef struct TestObject
|
|
|
|
{
|
|
|
|
MemContext *memContext; // Mem context
|
|
|
|
} TestObject;
|
|
|
|
|
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Macros for function logging
|
|
|
|
***********************************************************************************************************************************/
|
|
|
|
#define FUNCTION_LOG_TEST_OBJECT_TYPE \
|
|
|
|
TestObject *
|
|
|
|
#define FUNCTION_LOG_TEST_OBJECT_FORMAT(value, buffer, bufferSize) \
|
|
|
|
objToLog(value, STRINGIFY(TestObject), buffer, bufferSize)
|
|
|
|
|
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Free object
|
|
|
|
***********************************************************************************************************************************/
|
|
|
|
void testObjectFree(TestObject *this);
|
|
|
|
|
2019-08-30 14:36:02 -04:00
|
|
|
OBJECT_DEFINE_MOVE(TEST_OBJECT);
|
2019-05-03 18:52:54 -04:00
|
|
|
OBJECT_DEFINE_FREE(TEST_OBJECT);
|
|
|
|
|
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Free object resource
|
|
|
|
***********************************************************************************************************************************/
|
|
|
|
bool testObjectFreeResourceCalled = false;
|
|
|
|
|
|
|
|
static void testObjectFreeResource(void *thisVoid);
|
|
|
|
|
|
|
|
OBJECT_DEFINE_FREE_RESOURCE_BEGIN(TEST_OBJECT, LOG, logLevelTrace)
|
|
|
|
{
|
|
|
|
testObjectFreeResourceCalled = true;
|
|
|
|
}
|
|
|
|
OBJECT_DEFINE_FREE_RESOURCE_END(LOG);
|
|
|
|
|
|
|
|
/***********************************************************************************************************************************
|
|
|
|
New object
|
|
|
|
***********************************************************************************************************************************/
|
|
|
|
TestObject *
|
|
|
|
testObjectNew(void)
|
|
|
|
{
|
|
|
|
FUNCTION_LOG_VOID(logLevelTrace);
|
|
|
|
|
|
|
|
TestObject *this = NULL;
|
|
|
|
|
|
|
|
MEM_CONTEXT_NEW_BEGIN(STRINGIFY(TestObject))
|
|
|
|
{
|
|
|
|
this = memNew(sizeof(TestObject));
|
|
|
|
this->memContext = memContextCurrent();
|
|
|
|
|
|
|
|
memContextCallbackSet(this->memContext, testObjectFreeResource, (void *)1);
|
|
|
|
}
|
|
|
|
MEM_CONTEXT_NEW_END();
|
|
|
|
|
|
|
|
FUNCTION_LOG_RETURN(TEST_OBJECT, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Test Run
|
|
|
|
***********************************************************************************************************************************/
|
|
|
|
void
|
|
|
|
testRun(void)
|
|
|
|
{
|
|
|
|
FUNCTION_HARNESS_VOID();
|
|
|
|
|
|
|
|
// *****************************************************************************************************************************
|
|
|
|
if (testBegin("OBJECT_DEFINE*()"))
|
|
|
|
{
|
|
|
|
TestObject *testObject = NULL;
|
|
|
|
|
2019-08-30 14:36:02 -04:00
|
|
|
MEM_CONTEXT_TEMP_BEGIN()
|
|
|
|
{
|
|
|
|
TEST_ASSIGN(testObject, testObjectNew(), "new test object");
|
2020-01-17 13:29:49 -07:00
|
|
|
TEST_RESULT_VOID(testObjectMove(testObject, memContextPrior()), "move object to parent context");
|
|
|
|
TEST_RESULT_VOID(testObjectMove(NULL, memContextPrior()), "move null object");
|
2019-08-30 14:36:02 -04:00
|
|
|
}
|
|
|
|
MEM_CONTEXT_TEMP_END();
|
|
|
|
|
2019-05-03 18:52:54 -04:00
|
|
|
TEST_RESULT_VOID(testObjectFree(testObject), " free object");
|
|
|
|
TEST_RESULT_BOOL(testObjectFreeResourceCalled, true, " check callback");
|
|
|
|
}
|
|
|
|
|
|
|
|
FUNCTION_HARNESS_RESULT_VOID();
|
|
|
|
}
|