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