os/ossrv/genericopenlibs/cstdlib/TSTLIB/CTEST.C
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description:
    15 * ANSI C version of the RTest facilities, specifically
    16 * Start(char *title)
    17 * Next(char *title)
    18 * Test(int line);
    19 * As a simplification we don't do the levels of nesting.
    20 * 
    21 *
    22 */
    23 
    24 
    25 
    26 #include <stdio.h>
    27 #include <stdlib.h>
    28 #include <sys/errno.h>
    29 #include "CTEST.H"
    30 
    31 static void failed(struct __testdata* td, int line)
    32 	{
    33 	printf("Test %d.%d failed, line %d\n", td->iCheck, td->iSubtest, line);
    34 	printf("Press any key to exit\n");
    35 	fflush(stdout);
    36 	getchar();
    37 	exit(84);
    38 	}
    39 
    40 EXPORT_C void td_Title(struct __testdata* td, char *title)
    41 	{
    42 	
    43 	printf("%s\n\n", title);
    44 	td->iCheck=0;
    45 	td->iSubtest=0;
    46 	}
    47 
    48 EXPORT_C void td_Next(struct __testdata* td, char *testname)
    49 	{
    50 	printf("%03d: %s\n", ++(td->iCheck), testname);
    51 	td->iSubtest=0;
    52 	}
    53 
    54 EXPORT_C void td_Test(struct __testdata* td, int line, int mustBeTrue)
    55 	{
    56 	(td->iSubtest)++;
    57 	if (mustBeTrue)
    58 		return;
    59 	failed(td, line);
    60 	}
    61 
    62 EXPORT_C void td_TestErrno(struct __testdata* td, int line, int mustBeTrue, int expectedErrno)
    63 	{
    64 	(td->iSubtest)++;
    65 	td->iErrno = errno;
    66 	if (mustBeTrue)
    67 		{
    68 		if (expectedErrno==td->iErrno)
    69 			return;
    70 		printf("Test %d.%d failed, line %d : expected errno = %d, not %d\n",
    71 			td->iCheck, td->iSubtest, line, expectedErrno, td->iErrno);
    72 		}
    73 	failed(td, line);
    74 	}
    75 
    76 EXPORT_C void td_Close()
    77 	{
    78 	printf("\n\nCompleted OK\n");
    79 	fflush(stdout);
    80 	}