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