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