|
1 // Copyright (c) 2006-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 // TS_RConnPanic.CPP |
|
15 // File Created in order to automate Test50, Contains the starting point for the thread that |
|
16 // will panic on starting a connection |
|
17 // @file TS_RConnPanic.CPP |
|
18 // @internalComponent |
|
19 // |
|
20 // |
|
21 |
|
22 |
|
23 #include "TE_RConnectionStep.h" |
|
24 #include <commdbconnpref.h> |
|
25 #include <dummynifvar.h> |
|
26 #include <c32root.h> |
|
27 #include <comms-infras/esocktestutils.h> |
|
28 #include <cs_subconparams.h> |
|
29 #include <cs_subconevents.h> |
|
30 #include <ecom/ecom.h> |
|
31 |
|
32 |
|
33 #ifdef _DEBUG |
|
34 // Panic category for "absolutely impossible!" vanilla ASSERT()-type panics from this module |
|
35 // (if it could happen through user error then you should give it an explicit, documented, category + code) |
|
36 _LIT(KSpecAssert_ESockTestTERCnPn, "ESockTestTERCnPn"); |
|
37 #endif |
|
38 |
|
39 struct TRConnParams |
|
40 { |
|
41 TRConnParams(TInt aTimeOut, TInt aEchoPort): |
|
42 iTimeOut(aTimeOut), |
|
43 iEchoPort(aEchoPort) |
|
44 { |
|
45 } |
|
46 TInt iTimeOut; |
|
47 TInt iEchoPort; |
|
48 }; |
|
49 |
|
50 class PanicTestThread : public CBase |
|
51 { |
|
52 public: |
|
53 static void EntryPoint(TRConnParams* aParams) |
|
54 { |
|
55 |
|
56 //ASSERT(aParams); |
|
57 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
58 CActiveScheduler* Sched = new (ELeave) CActiveScheduler; |
|
59 CActiveScheduler::Install(Sched); |
|
60 TRAPD(err, PanicTestThread* self = PanicTestThread::NewLC(); |
|
61 self->DoItL(aParams->iTimeOut, aParams->iEchoPort); |
|
62 CleanupStack::PopAndDestroy(self); |
|
63 ); |
|
64 __ASSERT_DEBUG(err == KErrNone, User::Panic(KSpecAssert_ESockTestTERCnPn, 1)); |
|
65 CActiveScheduler::Install(NULL); |
|
66 delete Sched; |
|
67 delete cleanup; |
|
68 } |
|
69 |
|
70 static PanicTestThread* NewLC() |
|
71 { |
|
72 PanicTestThread* self = new (ELeave) PanicTestThread; |
|
73 CleanupStack::PushL(self); |
|
74 return self; |
|
75 } |
|
76 |
|
77 void DoItL(TInt aTimeOut, TInt aEchoPort) |
|
78 { |
|
79 TInt err; |
|
80 |
|
81 RSocketServ ss1, ss2; |
|
82 RConnection conn1, conn2; |
|
83 RSocket sock; |
|
84 |
|
85 err = ss1.Connect(); |
|
86 __ASSERT_DEBUG(KErrNone == err, User::Panic(KSpecAssert_ESockTestTERCnPn, 2)); |
|
87 CleanupClosePushL(ss1); |
|
88 |
|
89 err = ss2.Connect(); |
|
90 __ASSERT_DEBUG(KErrNone == err, User::Panic(KSpecAssert_ESockTestTERCnPn, 3)); |
|
91 CleanupClosePushL(ss2); |
|
92 |
|
93 err = conn1.Open(ss1); |
|
94 __ASSERT_DEBUG(KErrNone == err, User::Panic(KSpecAssert_ESockTestTERCnPn, 4)); |
|
95 CleanupClosePushL(conn1); |
|
96 |
|
97 err = conn2.Open(ss2); |
|
98 __ASSERT_DEBUG(KErrNone == err, User::Panic(KSpecAssert_ESockTestTERCnPn, 5)); |
|
99 CleanupClosePushL(conn2); |
|
100 |
|
101 // this should error but not panic (connection not started yet) |
|
102 err = OpenUdpSocketExplicitL(sock, ss1, conn1, aEchoPort); |
|
103 __ASSERT_DEBUG(KErrNotReady == err, User::Panic(KSpecAssert_ESockTestTERCnPn, 6)); |
|
104 |
|
105 // this should panic because the connection is in a different socket server from that supplied |
|
106 err = OpenUdpSocketExplicitL(sock, ss1, conn2, aEchoPort); |
|
107 |
|
108 /* |
|
109 * Tidy up, although should never reach here |
|
110 */ |
|
111 |
|
112 conn2.Close(); |
|
113 CleanupStack::Pop(); |
|
114 |
|
115 conn1.Close(); |
|
116 CleanupStack::Pop(); |
|
117 |
|
118 ss2.Close(); |
|
119 CleanupStack::Pop(); |
|
120 |
|
121 ss1.Close(); |
|
122 CleanupStack::Pop(); |
|
123 |
|
124 User::After(aTimeOut); |
|
125 } |
|
126 private: |
|
127 |
|
128 TInt OpenUdpSocketExplicitL(RSocket& sock, RSocketServ& ss, RConnection& conn, TInt aEchoPortNum) |
|
129 { |
|
130 TInt err; |
|
131 TInt ret = KErrNone; |
|
132 err = sock.Open(ss, KAfInet, KSockDatagram, KProtocolInetUdp, conn); |
|
133 if(err!= KErrNone) |
|
134 { |
|
135 return err; |
|
136 } |
|
137 |
|
138 err = sock.SetOpt(KSoReuseAddr, KSolInetIp, 1); |
|
139 if(err!= KErrNone) |
|
140 { |
|
141 return err; |
|
142 } |
|
143 |
|
144 err = sock.SetLocalPort(aEchoPortNum); |
|
145 if(err!= KErrNone) |
|
146 { |
|
147 return err; |
|
148 } |
|
149 return ret; |
|
150 } |
|
151 |
|
152 }; |
|
153 |