|
1 // Copyright (c) 2010 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 #include "t_logutil.h" |
|
16 |
|
17 //Define "TheTest" variable used in the test cpp files |
|
18 extern RTest TheTest; |
|
19 |
|
20 TPtrC FileName(const TText* aFile) |
|
21 { |
|
22 TPtrC p(aFile); |
|
23 TInt ix=p.LocateReverse('\\'); |
|
24 if (ix<0) |
|
25 ix=p.LocateReverse('/'); |
|
26 if (ix>=0) |
|
27 p.Set(p.Mid(1+ix)); |
|
28 return p; |
|
29 } |
|
30 |
|
31 void LogTestBoolExpr(TBool aRes, const TText* aFile, TInt aLine, TBool aPrintThreadName) |
|
32 { |
|
33 if(!aRes) |
|
34 { |
|
35 TPtrC fname(FileName(aFile)); |
|
36 if(aPrintThreadName) |
|
37 { |
|
38 RThread th; |
|
39 TName name = th.Name(); |
|
40 RDebug::Print(_L("*** Boolean expression evaluated to false, file: %S-%d\r\n"), &fname, aLine); |
|
41 User::Panic(_L("t_logutil-1"), 1); |
|
42 } |
|
43 else |
|
44 { |
|
45 TheTest.Printf(_L("*** Boolean expression evaluated to false, file: %S-%d\r\n"), &fname, aLine); |
|
46 TheTest(EFalse, aLine); |
|
47 } |
|
48 } |
|
49 } |
|
50 |
|
51 void LogCheck(TInt aValue, TInt aExpected, const TText* aFile, TInt aLine, TBool aPrintThreadName) |
|
52 { |
|
53 if(aValue != aExpected) |
|
54 { |
|
55 TPtrC fname(FileName(aFile)); |
|
56 if(aPrintThreadName) |
|
57 { |
|
58 RThread th; |
|
59 TName name = th.Name(); |
|
60 RDebug::Print(_L("*** Expected error: %d, got: %d, file: %S-%d\r\n"), aExpected, aValue, &fname, aLine); |
|
61 User::Panic(_L("t_logutil-2"), 2); |
|
62 } |
|
63 else |
|
64 { |
|
65 TheTest.Printf(_L("*** Expected error: %d, got: %d, file: %S-%d\r\n"), aExpected, aValue, &fname, aLine); |
|
66 TheTest(EFalse, aLine); |
|
67 } |
|
68 } |
|
69 } |
|
70 |
|
71 void LogCheckU(TUint aValue, TUint aExpected, const TText* aFile, TInt aLine, TBool aPrintThreadName) |
|
72 { |
|
73 if(aValue != aExpected) |
|
74 { |
|
75 TPtrC fname(FileName(aFile)); |
|
76 if(aPrintThreadName) |
|
77 { |
|
78 RThread th; |
|
79 TName name = th.Name(); |
|
80 RDebug::Print(_L("*** Expected error: %u, got: %u, file: %S-%d\r\n"), aExpected, aValue, &fname, aLine); |
|
81 User::Panic(_L("t_logutil-3"), 3); |
|
82 } |
|
83 else |
|
84 { |
|
85 TheTest.Printf(_L("*** Expected error: %u, got: %u, file: %S-%d\r\n"), aExpected, aValue, &fname, aLine); |
|
86 TheTest(EFalse, aLine); |
|
87 } |
|
88 } |
|
89 } |
|
90 |
|
91 void LogLeave(TInt aErr, const TText* aFile, const TInt aLine) |
|
92 { |
|
93 TPtrC fname(FileName(aFile)); |
|
94 TheTest.Printf(_L("*** LogEng test leave, err=%d, file: %S-%d\r\n"), aErr, &fname, aLine); |
|
95 User::Leave(aErr); |
|
96 } |
|
97 |
|
98 void LogPanic(const TDesC& aCategory, TInt aErr, const TText* aFile, TInt aLine) |
|
99 { |
|
100 TPtrC fname(FileName(aFile)); |
|
101 TheTest.Printf(_L("*** LogEng test panic'd with err=%d, category=%S, file: %S-%d\r\n"), aErr, &aCategory, &fname, aLine); |
|
102 User::Panic(aCategory, aErr); |
|
103 } |
|
104 |
|
105 TInt KillProcess(const TDesC& aProcessName) |
|
106 { |
|
107 TFullName name; |
|
108 |
|
109 TheTest.Printf(_L("Find and kill \"%S\" process.\n"), &aProcessName); |
|
110 |
|
111 TBuf<64> pattern(aProcessName); |
|
112 TInt length = pattern.Length(); |
|
113 pattern += _L("*"); |
|
114 TFindProcess procFinder(pattern); |
|
115 |
|
116 while (procFinder.Next(name) == KErrNone) |
|
117 { |
|
118 if (name.Length() > length) |
|
119 {//If found name is a string containing aProcessName string. |
|
120 TChar c(name[length]); |
|
121 if (c.IsAlphaDigit() || |
|
122 c == TChar('_') || |
|
123 c == TChar('-')) |
|
124 { |
|
125 // If the found name is other valid application name |
|
126 // starting with aProcessName string. |
|
127 TheTest.Printf(_L(":: Process name: \"%S\".\n"), &name); |
|
128 continue; |
|
129 } |
|
130 } |
|
131 RProcess proc; |
|
132 if (proc.Open(name) == KErrNone) |
|
133 { |
|
134 proc.Kill(0); |
|
135 TheTest.Printf(_L("\"%S\" process killed.\n"), &name); |
|
136 } |
|
137 proc.Close(); |
|
138 } |
|
139 return KErrNone; |
|
140 } |