sl@0
|
1 |
// Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// Test of the ESTW32 facilities for accessing Win32 stdin/stdout/stderr
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include <e32std.h>
|
sl@0
|
19 |
#include <e32base.h>
|
sl@0
|
20 |
#include <e32svr.h>
|
sl@0
|
21 |
#include <estw32.h>
|
sl@0
|
22 |
|
sl@0
|
23 |
void failed(int line, TInt aExpected, TInt aResult)
|
sl@0
|
24 |
{
|
sl@0
|
25 |
TBuf<80> buf;
|
sl@0
|
26 |
buf.Format(_L("Failed line %d: expected %d, got %d"), line, aExpected, aResult);
|
sl@0
|
27 |
for(;;)
|
sl@0
|
28 |
{
|
sl@0
|
29 |
User::InfoPrint(buf);
|
sl@0
|
30 |
User::After(5*1000000); // 5 seconds
|
sl@0
|
31 |
}
|
sl@0
|
32 |
}
|
sl@0
|
33 |
|
sl@0
|
34 |
#define test(err,expected) if (err!=expected) failed(__LINE__,expected,err)
|
sl@0
|
35 |
#define test_status(status,expected) if (status.Int()!=expected) failed(__LINE__,expected,status.Int())
|
sl@0
|
36 |
|
sl@0
|
37 |
/**
|
sl@0
|
38 |
@SYMTestCaseID SYSLIB-STDLIB-CT-1042
|
sl@0
|
39 |
@SYMTestCaseDesc Tests for the ESTW32 facilities for accessing Win32 stdin/stdout/stderr
|
sl@0
|
40 |
@SYMTestPriority High
|
sl@0
|
41 |
@SYMTestActions Open RWin32Stream::stdin,stdout,stderr and test writing to these streams.
|
sl@0
|
42 |
Check for KErrNone flag
|
sl@0
|
43 |
@SYMTestExpectedResults Test must not fail
|
sl@0
|
44 |
@SYMREQ REQ0000
|
sl@0
|
45 |
*/
|
sl@0
|
46 |
void DoTest()
|
sl@0
|
47 |
{
|
sl@0
|
48 |
RWin32Stream::StartServer();
|
sl@0
|
49 |
|
sl@0
|
50 |
RWin32Stream stdin;
|
sl@0
|
51 |
RWin32Stream stdout;
|
sl@0
|
52 |
RWin32Stream stderr;
|
sl@0
|
53 |
|
sl@0
|
54 |
TRequestStatus status;
|
sl@0
|
55 |
TInt err;
|
sl@0
|
56 |
err=stdin.Open(Kstdin);
|
sl@0
|
57 |
test(err,KErrNone);
|
sl@0
|
58 |
err=stdout.Open(Kstdout);
|
sl@0
|
59 |
test(err,KErrNone);
|
sl@0
|
60 |
err=stderr.Open(Kstderr);
|
sl@0
|
61 |
test(err,KErrNone);
|
sl@0
|
62 |
|
sl@0
|
63 |
TBuf8<80> outbuf;
|
sl@0
|
64 |
|
sl@0
|
65 |
// stderr
|
sl@0
|
66 |
|
sl@0
|
67 |
outbuf=_L8("Writing to stderr\n");
|
sl@0
|
68 |
stderr.Write(status,outbuf);
|
sl@0
|
69 |
User::WaitForRequest(status);
|
sl@0
|
70 |
test_status(status,KErrNone);
|
sl@0
|
71 |
|
sl@0
|
72 |
outbuf=_L8("1234XXX89");
|
sl@0
|
73 |
stderr.Write(status,outbuf,4);
|
sl@0
|
74 |
User::WaitForRequest(status);
|
sl@0
|
75 |
test_status(status,KErrNone);
|
sl@0
|
76 |
|
sl@0
|
77 |
// stdout
|
sl@0
|
78 |
|
sl@0
|
79 |
outbuf=_L8("Writing to stdout\n");
|
sl@0
|
80 |
stdout.Write(status,outbuf);
|
sl@0
|
81 |
User::WaitForRequest(status);
|
sl@0
|
82 |
test_status(status,KErrNone);
|
sl@0
|
83 |
|
sl@0
|
84 |
outbuf=_L8("1234XXX89");
|
sl@0
|
85 |
stdout.Write(status,outbuf,4);
|
sl@0
|
86 |
User::WaitForRequest(status);
|
sl@0
|
87 |
test_status(status,KErrNone);
|
sl@0
|
88 |
|
sl@0
|
89 |
FOREVER
|
sl@0
|
90 |
{
|
sl@0
|
91 |
stdin.Read(status,outbuf);
|
sl@0
|
92 |
User::WaitForRequest(status);
|
sl@0
|
93 |
|
sl@0
|
94 |
TRequestStatus outStatus;
|
sl@0
|
95 |
TBuf8<80> commentary;
|
sl@0
|
96 |
commentary.Format(_L8("\nread %d, status %d\n"), outbuf.Length(), status.Int());
|
sl@0
|
97 |
stderr.Write(outStatus,commentary);
|
sl@0
|
98 |
User::WaitForRequest(outStatus);
|
sl@0
|
99 |
test_status(outStatus,KErrNone);
|
sl@0
|
100 |
|
sl@0
|
101 |
if (status.Int()==KErrEof)
|
sl@0
|
102 |
break;
|
sl@0
|
103 |
|
sl@0
|
104 |
stdout.Write(outStatus,outbuf);
|
sl@0
|
105 |
User::WaitForRequest(outStatus);
|
sl@0
|
106 |
test_status(outStatus,KErrNone);
|
sl@0
|
107 |
}
|
sl@0
|
108 |
|
sl@0
|
109 |
outbuf=_L8("Stdin closed\n");
|
sl@0
|
110 |
stderr.Write(status,outbuf);
|
sl@0
|
111 |
User::WaitForRequest(status);
|
sl@0
|
112 |
test_status(status,KErrNone);
|
sl@0
|
113 |
|
sl@0
|
114 |
}
|
sl@0
|
115 |
|
sl@0
|
116 |
IMPORT_C void RegisterWsExe(const TDesC &aName);
|
sl@0
|
117 |
|
sl@0
|
118 |
GLDEF_C TInt E32Main()
|
sl@0
|
119 |
{
|
sl@0
|
120 |
CTrapCleanup* TheTrapCleanup=CTrapCleanup::New();
|
sl@0
|
121 |
|
sl@0
|
122 |
#ifdef USE_FULL_GRAPHICAL_ENVIRONMENT
|
sl@0
|
123 |
// Cause the Eikon environment to come into existence
|
sl@0
|
124 |
RSemaphore sem;
|
sl@0
|
125 |
sem.CreateGlobal(_L("WsExeSem"),0);
|
sl@0
|
126 |
RegisterWsExe(sem.FullName());
|
sl@0
|
127 |
|
sl@0
|
128 |
DoTest();
|
sl@0
|
129 |
User::InfoPrint(_L("Test passed"));
|
sl@0
|
130 |
|
sl@0
|
131 |
sem.Wait(); // continue running Eikon until that exits as well
|
sl@0
|
132 |
#else
|
sl@0
|
133 |
DoTest();
|
sl@0
|
134 |
User::InfoPrint(_L("Test passed"));
|
sl@0
|
135 |
#endif
|
sl@0
|
136 |
|
sl@0
|
137 |
return(KErrNone);
|
sl@0
|
138 |
}
|