os/ossrv/genericopenlibs/cstdlib/TSTLIB/TMISC2.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
* Test code for miscellaneous functions implemented via the MSystemInterface
sl@0
    16
* This differs from TMISC in that the functions must be tested twice, once with
sl@0
    17
* the local interface and once with the CPosixServer.
sl@0
    18
* 
sl@0
    19
*
sl@0
    20
*/
sl@0
    21
sl@0
    22
sl@0
    23
sl@0
    24
#include <stdlib.h>
sl@0
    25
#include <stdio.h>
sl@0
    26
#include <string.h>
sl@0
    27
#include <unistd.h>
sl@0
    28
sl@0
    29
#include "CTEST.H"	/* includes C interface to EPOC32 threads, and SpawnPosixServer */
sl@0
    30
sl@0
    31
test_Data;
sl@0
    32
sl@0
    33
void env_check(char* name, char* correct_value)
sl@0
    34
	{
sl@0
    35
	char* value = getenv(name);
sl@0
    36
	test(value!=0);
sl@0
    37
	test(strcmp(value,correct_value)==0);
sl@0
    38
	}
sl@0
    39
sl@0
    40
/**
sl@0
    41
@SYMTestCaseID          SYSLIB-STDLIB-CT-1070
sl@0
    42
@SYMTestCaseDesc	    Tests for environment variables
sl@0
    43
@SYMTestPriority 	    High
sl@0
    44
@SYMTestActions  	    Tests for getting and setting the environment variables
sl@0
    45
@SYMTestExpectedResults Test must not fail
sl@0
    46
@SYMREQ                 REQ0000
sl@0
    47
*/		
sl@0
    48
void environment()
sl@0
    49
	{
sl@0
    50
	char* value;
sl@0
    51
	int ret;
sl@0
    52
sl@0
    53
	test_Next("Environment variables");
sl@0
    54
	value=getenv("not_present");
sl@0
    55
	test(value==0);
sl@0
    56
sl@0
    57
	ret=setenv("TEST1","value1",0);
sl@0
    58
	test(ret==0);
sl@0
    59
	value=getenv("not_present");
sl@0
    60
	test(value==0);
sl@0
    61
	env_check("TEST1","value1");
sl@0
    62
sl@0
    63
	ret=setenv("TEST2","value2",0);
sl@0
    64
	test(ret==0);
sl@0
    65
	env_check("TEST2","value2");
sl@0
    66
	
sl@0
    67
	unsetenv("not_present");
sl@0
    68
	env_check("TEST1","value1");
sl@0
    69
	env_check("TEST2","value2");
sl@0
    70
sl@0
    71
	ret=setenv("TEST1","different_value",0);	/* no rewrite */
sl@0
    72
	test(ret==0);	/* apparently this isn't an error */
sl@0
    73
	env_check("TEST1","value1");
sl@0
    74
	env_check("TEST2","value2");
sl@0
    75
sl@0
    76
	ret=setenv("TEST1","different_value",1);	/* with rewrite */
sl@0
    77
	test(ret==0);
sl@0
    78
	env_check("TEST1","different_value");
sl@0
    79
	env_check("TEST2","value2");
sl@0
    80
sl@0
    81
	ret=setenv("TEST2","value2.1",1);
sl@0
    82
	test(ret==0);
sl@0
    83
	env_check("TEST1","different_value");
sl@0
    84
	env_check("TEST2","value2.1");
sl@0
    85
sl@0
    86
	unsetenv("TEST1");
sl@0
    87
	value=getenv("TEST1");
sl@0
    88
	test(value==0);
sl@0
    89
	env_check("TEST2","value2.1");
sl@0
    90
sl@0
    91
	ret=setenv("TEST1","a third value which is a really long one so I can force it to realloc some more memory when it does the conversion",0);
sl@0
    92
	test(ret==0);
sl@0
    93
	env_check("TEST1","a third value which is a really long one so I can force it to realloc some more memory when it does the conversion");
sl@0
    94
	env_check("TEST2","value2.1");
sl@0
    95
sl@0
    96
	}
sl@0
    97
sl@0
    98
int close_console=0;
sl@0
    99
void allTests()
sl@0
   100
	{
sl@0
   101
	environment();
sl@0
   102
sl@0
   103
	if (close_console)
sl@0
   104
		{
sl@0
   105
		test_Close();
sl@0
   106
		close(0);
sl@0
   107
		close(1);
sl@0
   108
		close(2);
sl@0
   109
		}
sl@0
   110
	}
sl@0
   111
sl@0
   112
int main()
sl@0
   113
	{
sl@0
   114
	void* client;
sl@0
   115
	int err;
sl@0
   116
sl@0
   117
	test_Title("Misc MSystemInterface functions");
sl@0
   118
sl@0
   119
	allTests();
sl@0
   120
sl@0
   121
	test_Next("Do it again using the CPosixServer (for them, not me)");
sl@0
   122
	close_console=1;
sl@0
   123
sl@0
   124
	start_posix_server();	/* calls SpawnPosixServer from C++ code */
sl@0
   125
sl@0
   126
sl@0
   127
	client=create_thread(allTests, "TMISC2 tests");
sl@0
   128
	test(client!=0);
sl@0
   129
	start_thread(client);
sl@0
   130
	err=wait_for_thread(client);
sl@0
   131
	test(err==0);
sl@0
   132
sl@0
   133
	test_Close();
sl@0
   134
sl@0
   135
	return 0;
sl@0
   136
	}