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