tstVector.cpp revision f8db050073c46a20de538fb22c33e22952ee7223
/* $Id$ */
/** @file
* IPRT Testcase - Vector container structure.
*/
/*
* Copyright (C) 2011 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <stdlib.h> /* For realloc */
/** Counter of the number of delete calls made so far */
static unsigned s_cDeleteCalls = 0;
/** Record the argument of the delete function here. */
static void *s_apvDeleteArg[10];
/** Dummy delete function for vector-of-void pointer elements */
static void deletePVoid(void **ppv)
{
}
/** Dummy delete by value function for vector-of-void pointer elements */
static void deletePVoidValue(void *pv)
{
}
/* Start by instantiating each function once for syntax checking */
RTVEC_DECL_STRUCT(tstInstance, void *)
RTVEC_DECL_STRUCT(tstInstance2, void *)
RTVEC_DECLFN_SIZE(tstInstance, void *)
RTVEC_DECLFN_BEGIN(tstInstance, void *)
RTVEC_DECLFN_END(tstInstance, void *)
RTVEC_DECLFN_PUSHBACK(tstInstance, void *)
RTVEC_DECLFN_DETACH(tstInstance, void *)
RTVEC_DECL(tstSimple, void *)
{
RTTestISub("Vector structure, no cleanup callback");
void **ppvVal;
/* AssertPtrReturnVoid(ppvVal); */
*ppvVal = (void *)1;
/* AssertPtrReturnVoid(ppvVal); */
*ppvVal = (void *)3;
/* AssertPtrReturnVoid(ppvVal); */
/* AssertPtrReturnVoid(ppvVal); */
/* AssertPtrReturnVoid(ppvVal); */
*ppvVal = (void *)1;
/* AssertPtrReturnVoid(ppvVal); */
*ppvVal = (void *)3;
/* AssertPtrReturnVoid(ppvVal); */
*ppvVal = (void *)2;
}
{
RTTestISub("Vector structure with cleanup by pointer callback");
void **ppvVal;
/* AssertPtrReturnVoid(ppvVal); */
*ppvVal = (void *)1;
/* AssertPtrReturnVoid(ppvVal); */
*ppvVal = (void *)3;
/* AssertPtrReturnVoid(ppvVal); */
*ppvVal = (void *)2;
s_cDeleteCalls = 0;
s_cDeleteCalls = 0;
/* AssertPtrReturnVoid(ppvVal); */
}
{
RTTestISub("Vector structure with cleanup by value callback");
void **ppvVal;
/* AssertPtrReturnVoid(ppvVal); */
*ppvVal = (void *)1;
/* AssertPtrReturnVoid(ppvVal); */
*ppvVal = (void *)3;
/* AssertPtrReturnVoid(ppvVal); */
*ppvVal = (void *)2;
s_cDeleteCalls = 0;
== tstDeleteValueEnd(&myVec));
s_cDeleteCalls = 0;
/* AssertPtrReturnVoid(ppvVal); */
}
int main()
{
if (rcExit != RTEXITCODE_SUCCESS)
return rcExit;
return RTTestSummaryAndDestroy(hTest);
}