|
1 // Copyright (c) 2004-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 // Contains IPC Test 01 |
|
15 // |
|
16 // |
|
17 |
|
18 // EPOC includes |
|
19 #include <e32base.h> |
|
20 |
|
21 // Test system includes |
|
22 |
|
23 #include "Test01IPCStreamConnection.h" |
|
24 |
|
25 const TDesC& CTest01IPCStreamConnection::GetTestName() |
|
26 { |
|
27 _LIT(ret,"IPCTest01"); |
|
28 return ret; |
|
29 } |
|
30 |
|
31 enum TVerdict CTest01IPCStreamConnection::InternalDoTestStepL(void) |
|
32 { |
|
33 |
|
34 //-------------------substep 00----------------------------- |
|
35 _LIT(aLog00,"00 Open socket server:");Logger().Write(aLog00); |
|
36 |
|
37 TInt err; |
|
38 RSocketServ ss; |
|
39 CleanupClosePushL(ss); |
|
40 |
|
41 if ( (err = OptimalConnect(ss)) != KErrNone ) |
|
42 { |
|
43 Logger().WriteFormat(_L("Connecting to socket server failed with %d"), err); |
|
44 User::Leave(EFail); |
|
45 } |
|
46 |
|
47 //-------------------substep 01----------------------------- |
|
48 _LIT(aLog01,"01 Open server socket, set port & listen:"); |
|
49 Logger().Write(aLog01); |
|
50 RSocket aServerSock; |
|
51 CleanupClosePushL(aServerSock); |
|
52 if ( (err=aServerSock.Open(ss, iProt)) != KErrNone) |
|
53 { |
|
54 _LIT(aLog,"Error:Could not open server socket. err = %d"); |
|
55 Logger().WriteFormat(aLog, err); |
|
56 User::Leave(EFail); |
|
57 } |
|
58 |
|
59 if ( (err=aServerSock.SetLocalPort(1)) != KErrNone) |
|
60 { |
|
61 _LIT(aLog,"Error:Could not set port. err = %d"); |
|
62 Logger().WriteFormat(aLog, err); |
|
63 User::Leave(EFail); |
|
64 } |
|
65 |
|
66 if ( (err=aServerSock.Listen(1)) != KErrNone) |
|
67 { |
|
68 _LIT(aLog,"Error:Could not set up socket to listen. err = %d"); |
|
69 Logger().WriteFormat(aLog, err); |
|
70 User::Leave(EFail); |
|
71 } |
|
72 |
|
73 //-------------------substep 02----------------------------- |
|
74 _LIT(aLog02,"02 Create blank socket and marry it (with accept) to the server socket:"); |
|
75 Logger().Write(aLog02); |
|
76 RSocket aNewConn; |
|
77 CleanupClosePushL(aNewConn); |
|
78 if ( (err=aNewConn.Open(ss)) != KErrNone) |
|
79 { |
|
80 _LIT(aLog,"Error:Could not open blank socket. err = %d"); |
|
81 Logger().WriteFormat(aLog, err); |
|
82 User::Leave(EFail); |
|
83 } |
|
84 |
|
85 TRequestStatus aAcceptStat; |
|
86 aServerSock.Accept(aNewConn, aAcceptStat); |
|
87 |
|
88 //-------------------substep 03----------------------------- |
|
89 _LIT(aLog03,"03 Create client socket and connect it to the server"); |
|
90 Logger().Write(aLog03); |
|
91 RSocket aClientSock; |
|
92 CleanupClosePushL(aClientSock); |
|
93 if ( (err=aClientSock.Open(ss, iProt)) != KErrNone) |
|
94 { |
|
95 _LIT(aLog,"Error:Could not open client socket. err = %d"); |
|
96 Logger().WriteFormat(aLog, err); |
|
97 User::Leave(EFail); |
|
98 } |
|
99 |
|
100 TSockAddr aAddr; |
|
101 aAddr.SetPort(1); |
|
102 TRequestStatus aConnectStat; |
|
103 aClientSock.Connect(aAddr, aConnectStat); |
|
104 |
|
105 //-------------------substep 04----------------------------- |
|
106 _LIT(aLog04,"04 Check the status of the connection at the both ends:"); |
|
107 Logger().Write(aLog04); |
|
108 User::WaitForRequest(aConnectStat); |
|
109 User::WaitForRequest(aAcceptStat); |
|
110 TVerdict verdict = EPass; |
|
111 |
|
112 err = aConnectStat.Int(); |
|
113 if (err != KErrNone) |
|
114 { |
|
115 _LIT(aLog,"Error:Client socket not connected. err = %d"); |
|
116 Logger().WriteFormat(aLog, err); |
|
117 verdict = EFail; |
|
118 } |
|
119 |
|
120 err = aAcceptStat.Int(); |
|
121 if (err != KErrNone) |
|
122 { |
|
123 _LIT(aLog,"Error:Connection not accepted on server side. err = %d"); |
|
124 Logger().WriteFormat(aLog, err); |
|
125 verdict = EFail; |
|
126 } |
|
127 |
|
128 if (verdict == EFail) |
|
129 User::Leave(EFail); |
|
130 |
|
131 //-------------------substep 05----------------------------- |
|
132 _LIT(aLog05,"05 Close all sockets. Close socket server:"); Logger().WriteFormat(aLog05); |
|
133 CleanupStack::PopAndDestroy(4, &ss); |
|
134 return verdict; |
|
135 } |
|
136 |
|
137 |