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.
     1 /*
     2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description:
    15 * TMISC2.C
    16 * Test code for miscellaneous functions implemented via the MSystemInterface
    17 * This differs from TMISC in that the functions must be tested twice, once with
    18 * the local interface and once with the CPosixServer.
    19 * 
    20 *
    21 */
    22 
    23 
    24 
    25 #include <stdlib.h>
    26 #include <stdio.h>
    27 #include <string.h>
    28 #include <unistd.h>
    29 
    30 
    31 #include "CTEST.H"	/* includes C interface to EPOC32 threads, and SpawnPosixServer */
    32 
    33 test_Data;
    34 
    35 void env_check(wchar_t* name, wchar_t* correct_value)
    36 	{
    37 	wchar_t* value = wgetenv(name);
    38 	test(value!=0);
    39 	test(wcscmp(value,correct_value)==0);
    40 	}
    41 
    42 /**
    43 @SYMTestCaseID          SYSLIB-STDLIB-CT-1097
    44 @SYMTestCaseDesc	    Tests for environment variables
    45 @SYMTestPriority 	    High
    46 @SYMTestActions  	    Tests for getting and setting the environment variables
    47 @SYMTestExpectedResults Test must not fail
    48 @SYMREQ                 REQ0000
    49 */		
    50 void environment()
    51 	{
    52 	wchar_t* value;
    53 	int ret;
    54 
    55 	test_Next("Environment variables");
    56 	value=wgetenv((wchar_t*)L"not_present");
    57 	test(value==0);
    58 
    59 	ret=wsetenv((wchar_t*)L"TEST1",(wchar_t*)L"value1",0);
    60 	test(ret==0);
    61 	value=wgetenv((wchar_t*)L"not_present");
    62 	test(value==0);
    63 	env_check((wchar_t*)L"TEST1",(wchar_t*)L"value1");
    64 
    65 	ret=wsetenv((wchar_t*)L"TEST2",(wchar_t*)L"value2",0);
    66 	test(ret==0);
    67 	env_check((wchar_t*)L"TEST2",(wchar_t*)L"value2");
    68 	
    69 	wunsetenv((wchar_t*)L"not_present");
    70 	env_check((wchar_t*)L"TEST1",(wchar_t*)L"value1");
    71 	env_check((wchar_t*)L"TEST2",(wchar_t*)L"value2");
    72 
    73 	ret=wsetenv((wchar_t*)L"TEST1",(wchar_t*)L"different_value",0);	/* no rewrite */
    74 	test(ret==0);	/* apparently this isn't an error */
    75 	env_check((wchar_t*)L"TEST1",(wchar_t*)L"value1");
    76 	env_check((wchar_t*)L"TEST2",(wchar_t*)L"value2");
    77 
    78 	ret=wsetenv((wchar_t*)L"TEST1",(wchar_t*)L"different_value",1);	/* with rewrite */
    79 	test(ret==0);
    80 	env_check((wchar_t*)L"TEST1",(wchar_t*)L"different_value");
    81 	env_check((wchar_t*)L"TEST2",(wchar_t*)L"value2");
    82 
    83 	ret=wsetenv((wchar_t*)L"TEST2",(wchar_t*)L"value2.1",1);
    84 	test(ret==0);
    85 	env_check((wchar_t*)L"TEST1",(wchar_t*)L"different_value");
    86 	env_check((wchar_t*)L"TEST2",(wchar_t*)L"value2.1");
    87 
    88 	wunsetenv((wchar_t*)L"TEST1");
    89 	value=wgetenv((wchar_t*)L"TEST1");
    90 	test(value==0);
    91 	env_check((wchar_t*)L"TEST2",(wchar_t*)L"value2.1");
    92 
    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);
    94 	test(ret==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");
    96 	env_check((wchar_t*)L"TEST2",(wchar_t*)L"value2.1");
    97 
    98 	}
    99 
   100 int close_console=0;
   101 void allTests()
   102 	{
   103 	environment();
   104 
   105 	if (close_console)
   106 		{
   107 		test_Close();
   108 		close(0);
   109 		close(1);
   110 		close(2);
   111 		}
   112 	}
   113 
   114 int main()
   115 	{
   116 	void* client;
   117 	int err;
   118 
   119 	test_Title("Misc MSystemInterface functions");
   120 
   121 	allTests();
   122 
   123 	test_Next("Do it again using the CPosixServer (for them, not me)");
   124 	close_console=1;
   125 
   126 	start_posix_server();	/* calls SpawnPosixServer from C++ code */
   127 
   128 	client=create_thread(allTests, "TMISC2 tests");
   129 	test(client!=0);
   130 	start_thread(client);
   131 	err=wait_for_thread(client);
   132 	test(err==0);
   133 
   134 	test_Close();
   135 	return 0;
   136 	}