|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: NAT FW SDP Provider test interface & implementations |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef NSPTEST_H |
|
19 #define NSPTEST_H |
|
20 |
|
21 #include <e32std.h> |
|
22 #include <e32cons.h> |
|
23 #include <s32strm.h> |
|
24 #include "nsptestconsolemacros.h" |
|
25 |
|
26 class CConsoleBase; |
|
27 class MNSPTest; |
|
28 class CNSPTest; |
|
29 class CNSPReleaseTest; |
|
30 |
|
31 /** |
|
32 * General visitor interface. |
|
33 */ |
|
34 class MNSPTestVisitor |
|
35 { |
|
36 public: // Methods |
|
37 |
|
38 virtual void VisitL( MNSPTest& aTest ) = 0; |
|
39 |
|
40 virtual void VisitL( CNSPTest& aTest ) = 0; |
|
41 |
|
42 virtual void VisitL( CNSPReleaseTest& aTest ) = 0; |
|
43 |
|
44 }; |
|
45 |
|
46 |
|
47 /** |
|
48 * Abstract interface for tests. |
|
49 */ |
|
50 class MNSPTest |
|
51 { |
|
52 public: // Methods |
|
53 |
|
54 /** |
|
55 * Start test |
|
56 */ |
|
57 virtual void StartL( CConsoleBase& aConsole ) = 0; |
|
58 |
|
59 /** |
|
60 * Cancel test |
|
61 */ |
|
62 virtual void Cancel() = 0; |
|
63 |
|
64 /** |
|
65 * Visitor's accept method |
|
66 */ |
|
67 virtual void AcceptL( MNSPTestVisitor& aVisitor ) = 0; |
|
68 |
|
69 }; |
|
70 |
|
71 |
|
72 /** |
|
73 * Test 'state' implementation. |
|
74 */ |
|
75 class CNSPTest : public CBase, public MNSPTest |
|
76 { |
|
77 public: // Methods |
|
78 |
|
79 inline virtual ~CNSPTest() |
|
80 { |
|
81 } |
|
82 |
|
83 |
|
84 |
|
85 inline void StartL( CConsoleBase& aConsole ) |
|
86 { |
|
87 iResult.iState = TResult::ERunning; // Can be re-run, prev result overwritten. |
|
88 TRAPD( err, SetupL() ); |
|
89 START( err, aConsole, iResult.iDescription ); |
|
90 |
|
91 if ( KErrNone == err ) |
|
92 { |
|
93 TRAP( err, ExecuteL( aConsole ) ); |
|
94 Teardown(); |
|
95 } |
|
96 |
|
97 iResult.iState = ( TResult::ERunning != iResult.iState && KErrNone == err ? |
|
98 iResult.iState : ( KErrNone == err ? |
|
99 TResult::EPass : ( KAssertFailure == err ? |
|
100 TResult::EFail : (TResult::TState) err ) ) ); |
|
101 END( aConsole, iResult.iDescription, iResult.iState ); |
|
102 User::LeaveIfError( KErrCancel == err ? KErrCancel : KErrNone ); |
|
103 } |
|
104 |
|
105 virtual void SetupL() = 0; |
|
106 |
|
107 virtual void Teardown() = 0; |
|
108 |
|
109 inline virtual void ExecuteL( CConsoleBase& /*aConsole*/ ) |
|
110 { |
|
111 User::Leave( KErrTotalLossOfPrecision ); |
|
112 } |
|
113 |
|
114 inline virtual void AcceptL( MNSPTestVisitor& aVisitor ) |
|
115 { |
|
116 aVisitor.VisitL( *this ); |
|
117 } |
|
118 |
|
119 inline void ExternalizeL( RWriteStream& aOutStream ) |
|
120 { |
|
121 aOutStream.WriteL( TPckgC<TResult>( iResult ) ); |
|
122 } |
|
123 |
|
124 public: // Methods |
|
125 |
|
126 inline TResult::TState State() const |
|
127 { |
|
128 return iResult.iState; |
|
129 } |
|
130 |
|
131 protected: // Data |
|
132 |
|
133 TResult iResult; |
|
134 |
|
135 }; |
|
136 |
|
137 #endif // NSPTEST_H |