|
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 // |
|
15 |
|
16 #include <c32comm.h> |
|
17 #include <test/testexecutelog.h> |
|
18 #include "te_c32utilsteps.h" |
|
19 |
|
20 class TTruncateOverflow16 : public TDes16Overflow |
|
21 { |
|
22 public: |
|
23 virtual void Overflow(TDes16&) |
|
24 { |
|
25 } |
|
26 }; |
|
27 |
|
28 class TTruncateOverflow8 : public TDes8Overflow |
|
29 { |
|
30 public: |
|
31 virtual void Overflow(TDes8&) |
|
32 { |
|
33 } |
|
34 }; |
|
35 |
|
36 void CTestStepC32Util::Log(TRefByValue<const TDesC16> aFormat, ...) |
|
37 { |
|
38 VA_LIST vaList; |
|
39 VA_START( vaList, aFormat ); |
|
40 |
|
41 TTruncateOverflow16 truncateOverflow; |
|
42 TBuf<512> buf; |
|
43 buf.AppendFormatList( aFormat, vaList, &truncateOverflow ); |
|
44 Logger().Write(buf); |
|
45 } |
|
46 |
|
47 void CTestStepC32Util::Log(TRefByValue<const TDesC8> aFormat, ...) |
|
48 { |
|
49 VA_LIST vaList; |
|
50 VA_START( vaList, aFormat ); |
|
51 |
|
52 TTruncateOverflow8 truncateOverflow; |
|
53 TBuf8<512> buf; |
|
54 buf.AppendFormatList( aFormat, vaList, &truncateOverflow ); |
|
55 Logger().Write(buf); |
|
56 } |
|
57 |
|
58 |
|
59 |
|
60 CTestStepLoadC32::CTestStepLoadC32() |
|
61 { |
|
62 SetTestStepName(KTestStepLoadC32); |
|
63 } |
|
64 |
|
65 /* virtual */ TVerdict CTestStepLoadC32::doTestStepL() |
|
66 { |
|
67 TVerdict verdict = EPass; |
|
68 |
|
69 TInt err(C32Loader::LoadC32(this)); |
|
70 if(err!=KErrNone) |
|
71 { |
|
72 verdict = EFail; |
|
73 INFO_PRINTF2(_L("LoadC32 returned error %d"), err); |
|
74 } |
|
75 return verdict; |
|
76 } |
|
77 |
|
78 CTestStepUnloadC32::CTestStepUnloadC32(CommsFW::TCFShutdownType aType, TLeak aLeak): |
|
79 iType(aType), |
|
80 iLeak(aLeak) |
|
81 { |
|
82 SetTestStepName(KTestStepUnloadC32); |
|
83 } |
|
84 |
|
85 /* virtual */ TVerdict CTestStepUnloadC32::doTestStepL() |
|
86 { |
|
87 TInt err(C32Loader::UnloadC32(iType, this)); |
|
88 |
|
89 switch (err) |
|
90 { |
|
91 case KErrNone: |
|
92 { |
|
93 if (iLeak == ELeaks) |
|
94 { |
|
95 INFO_PRINTF1(_L("We were expecting a leak and non occurred : check that the leak-detecion mechanism is working.")); |
|
96 SetTestStepResult(EFail); |
|
97 } |
|
98 break; |
|
99 } |
|
100 case KErrSessionClosed: |
|
101 { |
|
102 INFO_PRINTF2(_L("UnloadC32 returned %d. C32 had still had unclosed sessions when exiting."), err); |
|
103 SetTestStepResult(EFail); |
|
104 break; |
|
105 } |
|
106 case C32Loader::KModuleLeaked: |
|
107 { |
|
108 INFO_PRINTF1(_L("A memory leak was detected on shutdown.")); |
|
109 INFO_PRINTF1(_L("Expect leaks if a panic occurred - Check the epocwind.out.")); |
|
110 if (iLeak == ENoLeak) |
|
111 { |
|
112 SetTestStepResult(EFail); |
|
113 } |
|
114 break; |
|
115 } |
|
116 default: |
|
117 { |
|
118 INFO_PRINTF2(_L("UnloadC32 returned error %d"), err); |
|
119 SetTestStepResult(EFail); |
|
120 } |
|
121 } |
|
122 |
|
123 return TestStepResult(); |
|
124 } |
|
125 |
|
126 CTestStepInjectMemLeakC32::CTestStepInjectMemLeakC32() |
|
127 { |
|
128 SetTestStepName(KTestStepInjectMemLeakC32); |
|
129 } |
|
130 |
|
131 /* virtual */ TVerdict CTestStepInjectMemLeakC32::doTestStepL() |
|
132 { |
|
133 // inject memory leak to test memory leak detection mechanism working: |
|
134 |
|
135 _LIT(KCsyName,"LOOPBACK.CSY"); |
|
136 _LIT(KPortName0,"LOOPBACK::0"); |
|
137 _LIT8(KMemLeakToken, "--MemoryLeakToken--"); |
|
138 |
|
139 RCommServ commServ; |
|
140 |
|
141 TInt ret=commServ.Connect(); |
|
142 TESTCHECKL(ret,KErrNone); |
|
143 |
|
144 ret=commServ.LoadCommModule(KCsyName); |
|
145 TESTCHECKL(ret,KErrNone); |
|
146 |
|
147 ret=iSerialPortList[1].Open(commServ,KPortName0,ECommShared); |
|
148 TESTCHECKL(ret,KErrNone); |
|
149 |
|
150 TRequestStatus stat0; |
|
151 |
|
152 TBuf8<20> writeBuf; |
|
153 writeBuf.Append(KMemLeakToken); |
|
154 |
|
155 iSerialPortList[1].Write(stat0,writeBuf); |
|
156 |
|
157 User::WaitForRequest(stat0); |
|
158 TESTCHECKL(stat0.Int(), KErrNone); |
|
159 |
|
160 iSerialPortList[1].Close(); |
|
161 |
|
162 commServ.Close(); |
|
163 |
|
164 return TestStepResult(); |
|
165 } |
|
166 |