|
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 // EventLogger - copying EventLogger test files from Z: to C: |
|
15 // Please, ensure that t_logenvcreate test is executed before the other EventLogger component tests |
|
16 // |
|
17 // |
|
18 |
|
19 #include <e32test.h> |
|
20 #include <bautils.h> |
|
21 |
|
22 RTest TheTest(_L("t_logenvcreate - copying EventLogger test files to C:")); |
|
23 |
|
24 _LIT(KContactsServerName, "!CNTSRV"); |
|
25 |
|
26 _LIT(KContactsServerPrivateDirC, "c:\\private\\10003a73\\"); |
|
27 |
|
28 _LIT(KZFileName1, "z:\\private\\101f401d\\CntModel.ini"); |
|
29 _LIT(KZFileName2, "z:\\private\\101f401d\\SQLite__Contacts.cdb"); |
|
30 |
|
31 _LIT(KCFileName1, "c:\\private\\10003a73\\CntModel.ini"); |
|
32 _LIT(KCFileName2, "c:\\private\\10003a73\\SQLite__Contacts.cdb"); |
|
33 |
|
34 /////////////////////////////////////////////////////////////////////////////////////// |
|
35 /////////////////////////////////////////////////////////////////////////////////////// |
|
36 //Test macros and functions |
|
37 static void Check(TInt aValue, TInt aExpected, TInt aLine) |
|
38 { |
|
39 if(aValue != aExpected) |
|
40 { |
|
41 RDebug::Print(_L("*** Expected error: %d, got: %d\r\n"), aExpected, aValue); |
|
42 TheTest(EFalse, aLine); |
|
43 } |
|
44 } |
|
45 #define TEST2(aValue, aExpected) ::Check(aValue, aExpected, __LINE__) |
|
46 |
|
47 /////////////////////////////////////////////////////////////////////////////////////// |
|
48 |
|
49 static void KillProcess(const TDesC& aProcessName) |
|
50 { |
|
51 TFullName name; |
|
52 TheTest.Printf(_L(":: Find and kill \"%S\" process.\n"), &aProcessName); |
|
53 TBuf<64> pattern(aProcessName); |
|
54 TInt length = pattern.Length(); |
|
55 pattern += _L("*"); |
|
56 TFindProcess procFinder(pattern); |
|
57 |
|
58 while (procFinder.Next(name) == KErrNone) |
|
59 { |
|
60 if (name.Length() > length) |
|
61 {//If found name is a string containing aProcessName string. |
|
62 TChar c(name[length]); |
|
63 if (c.IsAlphaDigit() || c == TChar('_') || c == TChar('-')) |
|
64 { |
|
65 // If the found name is other valid application name |
|
66 // starting with aProcessName string. |
|
67 TheTest.Printf(_L(":: Process name: \"%S\".\n"), &name); |
|
68 continue; |
|
69 } |
|
70 } |
|
71 RProcess proc; |
|
72 if (proc.Open(name) == KErrNone) |
|
73 { |
|
74 proc.Kill(0); |
|
75 TheTest.Printf(_L(":: \"%S\" process killed.\n"), &name); |
|
76 } |
|
77 proc.Close(); |
|
78 } |
|
79 } |
|
80 |
|
81 void DoRun() |
|
82 { |
|
83 RFs fs; |
|
84 TInt err = fs.Connect(); |
|
85 TEST2(err, KErrNone); |
|
86 |
|
87 TheTest.Start(_L(" @SYMTestCaseID: PDS-LOGENG-CT-4048 Copy EventLogger test files from Z: to C: ")); |
|
88 |
|
89 err = BaflUtils::CopyFile(fs, KZFileName1, KCFileName1); |
|
90 TEST2(err, KErrNone); |
|
91 err = fs.SetAtt(KCFileName1, 0, KEntryAttReadOnly); |
|
92 TEST2(err, KErrNone); |
|
93 |
|
94 err = BaflUtils::CopyFile(fs, KZFileName2, KCFileName2); |
|
95 TEST2(err, KErrNone); |
|
96 err = fs.SetAtt(KCFileName2, 0, KEntryAttReadOnly); |
|
97 TEST2(err, KErrNone); |
|
98 fs.Close(); |
|
99 } |
|
100 |
|
101 void CreateContactsServerPrivateDir() |
|
102 { |
|
103 RFs fs; |
|
104 TInt err = fs.Connect(); |
|
105 TEST2(err, KErrNone); |
|
106 |
|
107 TRAP(err, BaflUtils::EnsurePathExistsL(fs, KContactsServerPrivateDirC)); |
|
108 TEST2(err, KErrNone); |
|
109 |
|
110 fs.Close(); |
|
111 } |
|
112 |
|
113 TInt E32Main() |
|
114 { |
|
115 TheTest.Title(); |
|
116 |
|
117 CTrapCleanup* tc = CTrapCleanup::New(); |
|
118 |
|
119 __UHEAP_MARK; |
|
120 |
|
121 KillProcess(KContactsServerName); |
|
122 |
|
123 CreateContactsServerPrivateDir(); |
|
124 |
|
125 DoRun(); |
|
126 |
|
127 __UHEAP_MARKEND; |
|
128 |
|
129 TheTest.End(); |
|
130 TheTest.Close(); |
|
131 |
|
132 delete tc; |
|
133 |
|
134 User::Heap().Check(); |
|
135 return KErrNone; |
|
136 } |