os/ossrv/genericopenlibs/cstdlib/TSTLIB/TMISC2.C
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/cstdlib/TSTLIB/TMISC2.C	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,136 @@
     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 +* Test code for miscellaneous functions implemented via the MSystemInterface
    1.19 +* This differs from TMISC in that the functions must be tested twice, once with
    1.20 +* the local interface and once with the CPosixServer.
    1.21 +* 
    1.22 +*
    1.23 +*/
    1.24 +
    1.25 +
    1.26 +
    1.27 +#include <stdlib.h>
    1.28 +#include <stdio.h>
    1.29 +#include <string.h>
    1.30 +#include <unistd.h>
    1.31 +
    1.32 +#include "CTEST.H"	/* includes C interface to EPOC32 threads, and SpawnPosixServer */
    1.33 +
    1.34 +test_Data;
    1.35 +
    1.36 +void env_check(char* name, char* correct_value)
    1.37 +	{
    1.38 +	char* value = getenv(name);
    1.39 +	test(value!=0);
    1.40 +	test(strcmp(value,correct_value)==0);
    1.41 +	}
    1.42 +
    1.43 +/**
    1.44 +@SYMTestCaseID          SYSLIB-STDLIB-CT-1070
    1.45 +@SYMTestCaseDesc	    Tests for environment variables
    1.46 +@SYMTestPriority 	    High
    1.47 +@SYMTestActions  	    Tests for getting and setting the environment variables
    1.48 +@SYMTestExpectedResults Test must not fail
    1.49 +@SYMREQ                 REQ0000
    1.50 +*/		
    1.51 +void environment()
    1.52 +	{
    1.53 +	char* value;
    1.54 +	int ret;
    1.55 +
    1.56 +	test_Next("Environment variables");
    1.57 +	value=getenv("not_present");
    1.58 +	test(value==0);
    1.59 +
    1.60 +	ret=setenv("TEST1","value1",0);
    1.61 +	test(ret==0);
    1.62 +	value=getenv("not_present");
    1.63 +	test(value==0);
    1.64 +	env_check("TEST1","value1");
    1.65 +
    1.66 +	ret=setenv("TEST2","value2",0);
    1.67 +	test(ret==0);
    1.68 +	env_check("TEST2","value2");
    1.69 +	
    1.70 +	unsetenv("not_present");
    1.71 +	env_check("TEST1","value1");
    1.72 +	env_check("TEST2","value2");
    1.73 +
    1.74 +	ret=setenv("TEST1","different_value",0);	/* no rewrite */
    1.75 +	test(ret==0);	/* apparently this isn't an error */
    1.76 +	env_check("TEST1","value1");
    1.77 +	env_check("TEST2","value2");
    1.78 +
    1.79 +	ret=setenv("TEST1","different_value",1);	/* with rewrite */
    1.80 +	test(ret==0);
    1.81 +	env_check("TEST1","different_value");
    1.82 +	env_check("TEST2","value2");
    1.83 +
    1.84 +	ret=setenv("TEST2","value2.1",1);
    1.85 +	test(ret==0);
    1.86 +	env_check("TEST1","different_value");
    1.87 +	env_check("TEST2","value2.1");
    1.88 +
    1.89 +	unsetenv("TEST1");
    1.90 +	value=getenv("TEST1");
    1.91 +	test(value==0);
    1.92 +	env_check("TEST2","value2.1");
    1.93 +
    1.94 +	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);
    1.95 +	test(ret==0);
    1.96 +	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");
    1.97 +	env_check("TEST2","value2.1");
    1.98 +
    1.99 +	}
   1.100 +
   1.101 +int close_console=0;
   1.102 +void allTests()
   1.103 +	{
   1.104 +	environment();
   1.105 +
   1.106 +	if (close_console)
   1.107 +		{
   1.108 +		test_Close();
   1.109 +		close(0);
   1.110 +		close(1);
   1.111 +		close(2);
   1.112 +		}
   1.113 +	}
   1.114 +
   1.115 +int main()
   1.116 +	{
   1.117 +	void* client;
   1.118 +	int err;
   1.119 +
   1.120 +	test_Title("Misc MSystemInterface functions");
   1.121 +
   1.122 +	allTests();
   1.123 +
   1.124 +	test_Next("Do it again using the CPosixServer (for them, not me)");
   1.125 +	close_console=1;
   1.126 +
   1.127 +	start_posix_server();	/* calls SpawnPosixServer from C++ code */
   1.128 +
   1.129 +
   1.130 +	client=create_thread(allTests, "TMISC2 tests");
   1.131 +	test(client!=0);
   1.132 +	start_thread(client);
   1.133 +	err=wait_for_thread(client);
   1.134 +	test(err==0);
   1.135 +
   1.136 +	test_Close();
   1.137 +
   1.138 +	return 0;
   1.139 +	}