|
1 /* |
|
2 * Copyright (c) 2009 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: |
|
15 * |
|
16 */ |
|
17 #include "ut_logsforegroundwatcher.h" |
|
18 #include "logsforegroundwatcher.h" |
|
19 |
|
20 #include <QtTest/QtTest> |
|
21 #include <coemain.h> |
|
22 #include <apacmdln.h> |
|
23 |
|
24 CCoeEnv* testEnv = 0; |
|
25 bool testCommandlineExists = false; |
|
26 bool testCommandLineCommandBg = false; |
|
27 bool testCommandLineSetForProcess = false; |
|
28 |
|
29 CCoeEnv* CCoeEnv::Static() |
|
30 { |
|
31 if ( !testEnv ){ |
|
32 testEnv = new CCoeEnv(); |
|
33 } |
|
34 return testEnv; |
|
35 } |
|
36 |
|
37 CCoeEnv::CCoeEnv() : CActive(EPriorityNormal) |
|
38 { |
|
39 |
|
40 } |
|
41 |
|
42 CCoeEnv::~CCoeEnv() |
|
43 { |
|
44 } |
|
45 |
|
46 void CCoeEnv::AddForegroundObserverL(MCoeForegroundObserver& /*aForegroundObserver*/) |
|
47 { |
|
48 |
|
49 } |
|
50 |
|
51 void CCoeEnv::RemoveForegroundObserver(MCoeForegroundObserver& /*aForegroundObserver*/) |
|
52 { |
|
53 |
|
54 } |
|
55 |
|
56 TInt CApaCommandLine::GetCommandLineFromProcessEnvironment(CApaCommandLine*& aCommandLine) |
|
57 { |
|
58 if ( testCommandlineExists ){ |
|
59 aCommandLine = CApaCommandLine::NewL(); |
|
60 if ( testCommandLineCommandBg ){ |
|
61 TRAP_IGNORE( aCommandLine->SetCommandL(EApaCommandBackground) ) |
|
62 } else { |
|
63 TRAP_IGNORE( aCommandLine->SetCommandL(EApaCommandRun) ) |
|
64 } |
|
65 } else { |
|
66 aCommandLine = 0; |
|
67 } |
|
68 return KErrNone; |
|
69 } |
|
70 |
|
71 void CApaCommandLine::SetProcessEnvironmentL(RProcess& /*aProcess*/) const |
|
72 { |
|
73 if ( Command() == EApaCommandBackground ){ |
|
74 testCommandLineSetForProcess = true; |
|
75 } |
|
76 } |
|
77 |
|
78 void UT_LogsForegroundWatcher::initTestCase() |
|
79 { |
|
80 } |
|
81 |
|
82 void UT_LogsForegroundWatcher::cleanupTestCase() |
|
83 { |
|
84 delete testEnv; |
|
85 testEnv = 0; |
|
86 } |
|
87 |
|
88 void UT_LogsForegroundWatcher::init() |
|
89 { |
|
90 mWatcher = new LogsForegroundWatcher(); |
|
91 } |
|
92 |
|
93 void UT_LogsForegroundWatcher::cleanup() |
|
94 { |
|
95 delete mWatcher; |
|
96 } |
|
97 |
|
98 void UT_LogsForegroundWatcher::testConstructor() |
|
99 { |
|
100 QVERIFY( mWatcher ); |
|
101 } |
|
102 |
|
103 void UT_LogsForegroundWatcher::testHandleLosingForeground() |
|
104 { |
|
105 QSignalSpy spyGaining( mWatcher, SIGNAL(gainingForeground()) ); |
|
106 QSignalSpy spyLosing( mWatcher, SIGNAL(losingForeground()) ); |
|
107 mWatcher->HandleLosingForeground(); |
|
108 QVERIFY( spyGaining.count() == 0 ); |
|
109 QVERIFY( spyLosing.count() == 1 ); |
|
110 } |
|
111 |
|
112 void UT_LogsForegroundWatcher::testHandleGainingForeground() |
|
113 { |
|
114 QSignalSpy spyGaining( mWatcher, SIGNAL(gainingForeground()) ); |
|
115 QSignalSpy spyLosing( mWatcher, SIGNAL(losingForeground()) ); |
|
116 mWatcher->HandleGainingForeground(); |
|
117 QVERIFY( spyGaining.count() == 1 ); |
|
118 QVERIFY( spyLosing.count() == 0 ); |
|
119 } |
|
120 |
|
121 void UT_LogsForegroundWatcher::testEnsureBackgroundStartup() |
|
122 { |
|
123 // No commandline |
|
124 mWatcher->ensureBackgroundStartup(); |
|
125 QVERIFY( !testCommandLineSetForProcess ); |
|
126 |
|
127 // Command line already has bg command |
|
128 testCommandlineExists = true; |
|
129 testCommandLineCommandBg = true; |
|
130 mWatcher->ensureBackgroundStartup(); |
|
131 QVERIFY( !testCommandLineSetForProcess ); |
|
132 |
|
133 // Command line does not have bg command |
|
134 testCommandLineCommandBg = false; |
|
135 mWatcher->ensureBackgroundStartup(); |
|
136 QVERIFY( testCommandLineSetForProcess ); |
|
137 } |
|
138 |