sl@0: /* sl@0: * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * Test code for miscellaneous functions implemented via the MSystemInterface sl@0: * This differs from TMISC in that the functions must be tested twice, once with sl@0: * the local interface and once with the CPosixServer. sl@0: * sl@0: * sl@0: */ sl@0: sl@0: sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #include "CTEST.H" /* includes C interface to EPOC32 threads, and SpawnPosixServer */ sl@0: sl@0: test_Data; sl@0: sl@0: void env_check(char* name, char* correct_value) sl@0: { sl@0: char* value = getenv(name); sl@0: test(value!=0); sl@0: test(strcmp(value,correct_value)==0); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-STDLIB-CT-1070 sl@0: @SYMTestCaseDesc Tests for environment variables sl@0: @SYMTestPriority High sl@0: @SYMTestActions Tests for getting and setting the environment variables sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: void environment() sl@0: { sl@0: char* value; sl@0: int ret; sl@0: sl@0: test_Next("Environment variables"); sl@0: value=getenv("not_present"); sl@0: test(value==0); sl@0: sl@0: ret=setenv("TEST1","value1",0); sl@0: test(ret==0); sl@0: value=getenv("not_present"); sl@0: test(value==0); sl@0: env_check("TEST1","value1"); sl@0: sl@0: ret=setenv("TEST2","value2",0); sl@0: test(ret==0); sl@0: env_check("TEST2","value2"); sl@0: sl@0: unsetenv("not_present"); sl@0: env_check("TEST1","value1"); sl@0: env_check("TEST2","value2"); sl@0: sl@0: ret=setenv("TEST1","different_value",0); /* no rewrite */ sl@0: test(ret==0); /* apparently this isn't an error */ sl@0: env_check("TEST1","value1"); sl@0: env_check("TEST2","value2"); sl@0: sl@0: ret=setenv("TEST1","different_value",1); /* with rewrite */ sl@0: test(ret==0); sl@0: env_check("TEST1","different_value"); sl@0: env_check("TEST2","value2"); sl@0: sl@0: ret=setenv("TEST2","value2.1",1); sl@0: test(ret==0); sl@0: env_check("TEST1","different_value"); sl@0: env_check("TEST2","value2.1"); sl@0: sl@0: unsetenv("TEST1"); sl@0: value=getenv("TEST1"); sl@0: test(value==0); sl@0: env_check("TEST2","value2.1"); sl@0: sl@0: 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); sl@0: test(ret==0); sl@0: 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"); sl@0: env_check("TEST2","value2.1"); sl@0: sl@0: } sl@0: sl@0: int close_console=0; sl@0: void allTests() sl@0: { sl@0: environment(); sl@0: sl@0: if (close_console) sl@0: { sl@0: test_Close(); sl@0: close(0); sl@0: close(1); sl@0: close(2); sl@0: } sl@0: } sl@0: sl@0: int main() sl@0: { sl@0: void* client; sl@0: int err; sl@0: sl@0: test_Title("Misc MSystemInterface functions"); sl@0: sl@0: allTests(); sl@0: sl@0: test_Next("Do it again using the CPosixServer (for them, not me)"); sl@0: close_console=1; sl@0: sl@0: start_posix_server(); /* calls SpawnPosixServer from C++ code */ sl@0: sl@0: sl@0: client=create_thread(allTests, "TMISC2 tests"); sl@0: test(client!=0); sl@0: start_thread(client); sl@0: err=wait_for_thread(client); sl@0: test(err==0); sl@0: sl@0: test_Close(); sl@0: sl@0: return 0; sl@0: }