sl@0: // Copyright (c) 1999-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 of the ESTW32 facilities for accessing Win32 stdin/stdout/stderr sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: void failed(int line, TInt aExpected, TInt aResult) sl@0: { sl@0: TBuf<80> buf; sl@0: buf.Format(_L("Failed line %d: expected %d, got %d"), line, aExpected, aResult); sl@0: for(;;) sl@0: { sl@0: User::InfoPrint(buf); sl@0: User::After(5*1000000); // 5 seconds sl@0: } sl@0: } sl@0: sl@0: #define test(err,expected) if (err!=expected) failed(__LINE__,expected,err) sl@0: #define test_status(status,expected) if (status.Int()!=expected) failed(__LINE__,expected,status.Int()) sl@0: sl@0: /** sl@0: @SYMTestCaseID SYSLIB-STDLIB-CT-1042 sl@0: @SYMTestCaseDesc Tests for the ESTW32 facilities for accessing Win32 stdin/stdout/stderr sl@0: @SYMTestPriority High sl@0: @SYMTestActions Open RWin32Stream::stdin,stdout,stderr and test writing to these streams. sl@0: Check for KErrNone flag sl@0: @SYMTestExpectedResults Test must not fail sl@0: @SYMREQ REQ0000 sl@0: */ sl@0: void DoTest() sl@0: { sl@0: RWin32Stream::StartServer(); sl@0: sl@0: RWin32Stream stdin; sl@0: RWin32Stream stdout; sl@0: RWin32Stream stderr; sl@0: sl@0: TRequestStatus status; sl@0: TInt err; sl@0: err=stdin.Open(Kstdin); sl@0: test(err,KErrNone); sl@0: err=stdout.Open(Kstdout); sl@0: test(err,KErrNone); sl@0: err=stderr.Open(Kstderr); sl@0: test(err,KErrNone); sl@0: sl@0: TBuf8<80> outbuf; sl@0: sl@0: // stderr sl@0: sl@0: outbuf=_L8("Writing to stderr\n"); sl@0: stderr.Write(status,outbuf); sl@0: User::WaitForRequest(status); sl@0: test_status(status,KErrNone); sl@0: sl@0: outbuf=_L8("1234XXX89"); sl@0: stderr.Write(status,outbuf,4); sl@0: User::WaitForRequest(status); sl@0: test_status(status,KErrNone); sl@0: sl@0: // stdout sl@0: sl@0: outbuf=_L8("Writing to stdout\n"); sl@0: stdout.Write(status,outbuf); sl@0: User::WaitForRequest(status); sl@0: test_status(status,KErrNone); sl@0: sl@0: outbuf=_L8("1234XXX89"); sl@0: stdout.Write(status,outbuf,4); sl@0: User::WaitForRequest(status); sl@0: test_status(status,KErrNone); sl@0: sl@0: FOREVER sl@0: { sl@0: stdin.Read(status,outbuf); sl@0: User::WaitForRequest(status); sl@0: sl@0: TRequestStatus outStatus; sl@0: TBuf8<80> commentary; sl@0: commentary.Format(_L8("\nread %d, status %d\n"), outbuf.Length(), status.Int()); sl@0: stderr.Write(outStatus,commentary); sl@0: User::WaitForRequest(outStatus); sl@0: test_status(outStatus,KErrNone); sl@0: sl@0: if (status.Int()==KErrEof) sl@0: break; sl@0: sl@0: stdout.Write(outStatus,outbuf); sl@0: User::WaitForRequest(outStatus); sl@0: test_status(outStatus,KErrNone); sl@0: } sl@0: sl@0: outbuf=_L8("Stdin closed\n"); sl@0: stderr.Write(status,outbuf); sl@0: User::WaitForRequest(status); sl@0: test_status(status,KErrNone); sl@0: sl@0: } sl@0: sl@0: IMPORT_C void RegisterWsExe(const TDesC &aName); sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: CTrapCleanup* TheTrapCleanup=CTrapCleanup::New(); sl@0: sl@0: #ifdef USE_FULL_GRAPHICAL_ENVIRONMENT sl@0: // Cause the Eikon environment to come into existence sl@0: RSemaphore sem; sl@0: sem.CreateGlobal(_L("WsExeSem"),0); sl@0: RegisterWsExe(sem.FullName()); sl@0: sl@0: DoTest(); sl@0: User::InfoPrint(_L("Test passed")); sl@0: sl@0: sem.Wait(); // continue running Eikon until that exits as well sl@0: #else sl@0: DoTest(); sl@0: User::InfoPrint(_L("Test passed")); sl@0: #endif sl@0: sl@0: return(KErrNone); sl@0: }