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