os/ossrv/genericopenlibs/cstdlib/TSTLIB/TSTW32.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/cstdlib/TSTLIB/TSTW32.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,138 @@
     1.4 +// Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// Test of the ESTW32 facilities for accessing Win32 stdin/stdout/stderr
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <e32std.h>
    1.22 +#include <e32base.h>
    1.23 +#include <e32svr.h>
    1.24 +#include <estw32.h>
    1.25 +
    1.26 +void failed(int line, TInt aExpected, TInt aResult)
    1.27 +	{
    1.28 +	TBuf<80> buf;
    1.29 +	buf.Format(_L("Failed line %d: expected %d, got %d"), line, aExpected, aResult);
    1.30 +	for(;;)
    1.31 +		{
    1.32 +		User::InfoPrint(buf);
    1.33 +		User::After(5*1000000);	// 5 seconds
    1.34 +		}
    1.35 +	}
    1.36 +
    1.37 +#define test(err,expected)			if (err!=expected) failed(__LINE__,expected,err)
    1.38 +#define test_status(status,expected)	if (status.Int()!=expected) failed(__LINE__,expected,status.Int())
    1.39 +
    1.40 +/**
    1.41 +@SYMTestCaseID          SYSLIB-STDLIB-CT-1042
    1.42 +@SYMTestCaseDesc	    Tests for the ESTW32 facilities for accessing Win32 stdin/stdout/stderr
    1.43 +@SYMTestPriority 	    High
    1.44 +@SYMTestActions  	    Open RWin32Stream::stdin,stdout,stderr and test writing to these streams.
    1.45 +                        Check for KErrNone flag
    1.46 +@SYMTestExpectedResults Test must not fail
    1.47 +@SYMREQ                 REQ0000
    1.48 +*/		
    1.49 +void DoTest()
    1.50 +	{
    1.51 +	RWin32Stream::StartServer();
    1.52 +
    1.53 +	RWin32Stream stdin;
    1.54 +	RWin32Stream stdout;
    1.55 +	RWin32Stream stderr;
    1.56 +
    1.57 +	TRequestStatus status;
    1.58 +	TInt err;
    1.59 +	err=stdin.Open(Kstdin);
    1.60 +	test(err,KErrNone);
    1.61 +	err=stdout.Open(Kstdout);
    1.62 +	test(err,KErrNone);
    1.63 +	err=stderr.Open(Kstderr);
    1.64 +	test(err,KErrNone);
    1.65 +
    1.66 +	TBuf8<80> outbuf;
    1.67 +
    1.68 +	// stderr
    1.69 +
    1.70 +	outbuf=_L8("Writing to stderr\n");
    1.71 +	stderr.Write(status,outbuf);
    1.72 +	User::WaitForRequest(status);
    1.73 +	test_status(status,KErrNone);
    1.74 +
    1.75 +	outbuf=_L8("1234XXX89");
    1.76 +	stderr.Write(status,outbuf,4);
    1.77 +	User::WaitForRequest(status);
    1.78 +	test_status(status,KErrNone);
    1.79 +
    1.80 +	// stdout
    1.81 +
    1.82 +	outbuf=_L8("Writing to stdout\n");
    1.83 +	stdout.Write(status,outbuf);
    1.84 +	User::WaitForRequest(status);
    1.85 +	test_status(status,KErrNone);
    1.86 +
    1.87 +	outbuf=_L8("1234XXX89");
    1.88 +	stdout.Write(status,outbuf,4);
    1.89 +	User::WaitForRequest(status);
    1.90 +	test_status(status,KErrNone);
    1.91 +
    1.92 +	FOREVER
    1.93 +		{
    1.94 +		stdin.Read(status,outbuf);
    1.95 +		User::WaitForRequest(status);
    1.96 +
    1.97 +		TRequestStatus outStatus;
    1.98 +		TBuf8<80> commentary;
    1.99 +		commentary.Format(_L8("\nread %d, status %d\n"), outbuf.Length(), status.Int());
   1.100 +		stderr.Write(outStatus,commentary);
   1.101 +		User::WaitForRequest(outStatus);
   1.102 +		test_status(outStatus,KErrNone);
   1.103 +
   1.104 +		if (status.Int()==KErrEof)
   1.105 +			break;
   1.106 +
   1.107 +		stdout.Write(outStatus,outbuf);
   1.108 +		User::WaitForRequest(outStatus);
   1.109 +		test_status(outStatus,KErrNone);
   1.110 +		}
   1.111 +
   1.112 +	outbuf=_L8("Stdin closed\n");
   1.113 +	stderr.Write(status,outbuf);
   1.114 +	User::WaitForRequest(status);
   1.115 +	test_status(status,KErrNone);
   1.116 +
   1.117 +	}
   1.118 +
   1.119 +IMPORT_C void RegisterWsExe(const TDesC &aName);
   1.120 +
   1.121 +GLDEF_C TInt E32Main()
   1.122 +	{     
   1.123 +	CTrapCleanup* TheTrapCleanup=CTrapCleanup::New();
   1.124 +
   1.125 +#ifdef USE_FULL_GRAPHICAL_ENVIRONMENT
   1.126 +	// Cause the Eikon environment to come into existence
   1.127 +	RSemaphore sem;
   1.128 +	sem.CreateGlobal(_L("WsExeSem"),0);
   1.129 +	RegisterWsExe(sem.FullName());
   1.130 +
   1.131 +	DoTest();
   1.132 +	User::InfoPrint(_L("Test passed"));
   1.133 +
   1.134 +	sem.Wait();	// continue running Eikon until that exits as well
   1.135 +#else
   1.136 +	DoTest();
   1.137 +	User::InfoPrint(_L("Test passed"));
   1.138 +#endif
   1.139 +
   1.140 +	return(KErrNone);
   1.141 +	}