os/ossrv/genericopenlibs/cstdlib/TSTLIB/CTEST.C
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/cstdlib/TSTLIB/CTEST.C	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,80 @@
     1.4 +/*
     1.5 +* Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description:
    1.18 +* ANSI C version of the RTest facilities, specifically
    1.19 +* Start(char *title)
    1.20 +* Next(char *title)
    1.21 +* Test(int line);
    1.22 +* As a simplification we don't do the levels of nesting.
    1.23 +* 
    1.24 +*
    1.25 +*/
    1.26 +
    1.27 +
    1.28 +
    1.29 +#include <stdio.h>
    1.30 +#include <stdlib.h>
    1.31 +#include <sys/errno.h>
    1.32 +#include "CTEST.H"
    1.33 +
    1.34 +static void failed(struct __testdata* td, int line)
    1.35 +	{
    1.36 +	printf("Test %d.%d failed, line %d\n", td->iCheck, td->iSubtest, line);
    1.37 +	printf("Press any key to exit\n");
    1.38 +	fflush(stdout);
    1.39 +	getchar();
    1.40 +	exit(84);
    1.41 +	}
    1.42 +
    1.43 +EXPORT_C void td_Title(struct __testdata* td, char *title)
    1.44 +	{
    1.45 +	
    1.46 +	printf("%s\n\n", title);
    1.47 +	td->iCheck=0;
    1.48 +	td->iSubtest=0;
    1.49 +	}
    1.50 +
    1.51 +EXPORT_C void td_Next(struct __testdata* td, char *testname)
    1.52 +	{
    1.53 +	printf("%03d: %s\n", ++(td->iCheck), testname);
    1.54 +	td->iSubtest=0;
    1.55 +	}
    1.56 +
    1.57 +EXPORT_C void td_Test(struct __testdata* td, int line, int mustBeTrue)
    1.58 +	{
    1.59 +	(td->iSubtest)++;
    1.60 +	if (mustBeTrue)
    1.61 +		return;
    1.62 +	failed(td, line);
    1.63 +	}
    1.64 +
    1.65 +EXPORT_C void td_TestErrno(struct __testdata* td, int line, int mustBeTrue, int expectedErrno)
    1.66 +	{
    1.67 +	(td->iSubtest)++;
    1.68 +	td->iErrno = errno;
    1.69 +	if (mustBeTrue)
    1.70 +		{
    1.71 +		if (expectedErrno==td->iErrno)
    1.72 +			return;
    1.73 +		printf("Test %d.%d failed, line %d : expected errno = %d, not %d\n",
    1.74 +			td->iCheck, td->iSubtest, line, expectedErrno, td->iErrno);
    1.75 +		}
    1.76 +	failed(td, line);
    1.77 +	}
    1.78 +
    1.79 +EXPORT_C void td_Close()
    1.80 +	{
    1.81 +	printf("\n\nCompleted OK\n");
    1.82 +	fflush(stdout);
    1.83 +	}