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