43
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 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 <QDate>
|
|
18 |
#include <QTest>
|
|
19 |
#include <QDebug>
|
|
20 |
#include <QSignalSpy>
|
|
21 |
#include <QThread>
|
|
22 |
|
|
23 |
#include "cxetestutils.h"
|
|
24 |
#include "cxefakesettings.h"
|
|
25 |
#include "cxesysutil.h"
|
|
26 |
#include "cxediskmonitor.h"
|
|
27 |
#include "unittest_cxediskmonitor.h"
|
|
28 |
|
|
29 |
UnitTestCxeDiskMonitor::UnitTestCxeDiskMonitor()
|
|
30 |
: mFakeSettings(NULL),
|
|
31 |
mDiskMonitor(NULL)
|
|
32 |
{
|
|
33 |
}
|
|
34 |
|
|
35 |
UnitTestCxeDiskMonitor::~UnitTestCxeDiskMonitor()
|
|
36 |
{
|
|
37 |
cleanup();
|
|
38 |
}
|
|
39 |
|
|
40 |
// Run before each individual test case
|
|
41 |
void UnitTestCxeDiskMonitor::init()
|
|
42 |
{
|
|
43 |
CX_DEBUG_ENTER_FUNCTION();
|
|
44 |
|
|
45 |
mFakeSettings = new CxeFakeSettings();
|
|
46 |
mDiskMonitor = new CxeDiskMonitor(*mFakeSettings);
|
|
47 |
|
|
48 |
CX_DEBUG_EXIT_FUNCTION();
|
|
49 |
}
|
|
50 |
|
|
51 |
// Run after each individual test case
|
|
52 |
void UnitTestCxeDiskMonitor::cleanup()
|
|
53 |
{
|
|
54 |
CX_DEBUG_ENTER_FUNCTION();
|
|
55 |
delete mDiskMonitor;
|
|
56 |
mDiskMonitor = NULL;
|
|
57 |
|
|
58 |
delete mFakeSettings;
|
|
59 |
mFakeSettings = NULL;
|
|
60 |
|
|
61 |
CX_DEBUG_EXIT_FUNCTION();
|
|
62 |
}
|
|
63 |
|
|
64 |
void UnitTestCxeDiskMonitor::testStart()
|
|
65 |
{
|
|
66 |
CX_DEBUG_ENTER_FUNCTION();
|
|
67 |
mDiskMonitor->start();
|
|
68 |
mDiskMonitor->start(); // testing double run - should not crash
|
|
69 |
QVERIFY(mDiskMonitor->isMonitoring() == true);
|
|
70 |
CX_DEBUG_EXIT_FUNCTION();
|
|
71 |
}
|
|
72 |
|
|
73 |
void UnitTestCxeDiskMonitor::testStop()
|
|
74 |
{
|
|
75 |
CX_DEBUG_ENTER_FUNCTION();
|
|
76 |
mDiskMonitor->stop();
|
|
77 |
QVERIFY(mDiskMonitor->isMonitoring() == false);
|
|
78 |
CX_DEBUG_EXIT_FUNCTION();
|
|
79 |
}
|
|
80 |
|
|
81 |
void UnitTestCxeDiskMonitor::testIsMonitoring()
|
|
82 |
{
|
|
83 |
CX_DEBUG_ENTER_FUNCTION();
|
|
84 |
mDiskMonitor->start();
|
|
85 |
mDiskMonitor->start();
|
|
86 |
QVERIFY(mDiskMonitor->isMonitoring() == true);
|
|
87 |
|
|
88 |
mDiskMonitor->stop();
|
|
89 |
QVERIFY(mDiskMonitor->isMonitoring() == false);
|
|
90 |
CX_DEBUG_EXIT_FUNCTION();
|
|
91 |
}
|
|
92 |
|
|
93 |
void UnitTestCxeDiskMonitor::testFree()
|
|
94 |
{
|
|
95 |
CX_DEBUG_ENTER_FUNCTION();
|
|
96 |
CxeSysUtil::setSpaceAvailable(0);
|
|
97 |
QVERIFY(mDiskMonitor->free(false) == 0);
|
|
98 |
CxeSysUtil::setSpaceAvailable(100000);
|
|
99 |
QVERIFY(mDiskMonitor->free(false) == 100000);
|
|
100 |
QVERIFY(mDiskMonitor->free(true) == 100000);
|
|
101 |
CX_DEBUG_EXIT_FUNCTION();
|
|
102 |
}
|
|
103 |
|
|
104 |
void UnitTestCxeDiskMonitor::testSetLowWarningLevelZero()
|
|
105 |
{
|
|
106 |
CX_DEBUG_ENTER_FUNCTION();
|
|
107 |
mDiskMonitor->setLowWarningLevel(0);
|
|
108 |
CX_DEBUG_EXIT_FUNCTION();
|
|
109 |
}
|
|
110 |
|
|
111 |
void UnitTestCxeDiskMonitor::testSetLowWarningLevelTenMegabytes()
|
|
112 |
{
|
|
113 |
CX_DEBUG_ENTER_FUNCTION();
|
|
114 |
mDiskMonitor->setLowWarningLevel(10485760);
|
|
115 |
CX_DEBUG_EXIT_FUNCTION();
|
|
116 |
}
|
|
117 |
|
|
118 |
void UnitTestCxeDiskMonitor::testSetLowWarningLevelFiveGigabyte()
|
|
119 |
{
|
|
120 |
CX_DEBUG_ENTER_FUNCTION();
|
|
121 |
mDiskMonitor->setLowWarningLevel(5368709120);
|
|
122 |
CX_DEBUG_EXIT_FUNCTION();
|
|
123 |
}
|
|
124 |
|
|
125 |
void UnitTestCxeDiskMonitor::testLowLevelWarningSignal()
|
|
126 |
{
|
|
127 |
CX_DEBUG_ENTER_FUNCTION();
|
|
128 |
QSignalSpy spy(mDiskMonitor, SIGNAL(diskSpaceLow()));
|
|
129 |
mDiskMonitor->stop();
|
|
130 |
mDiskMonitor->setLowWarningLevel(100);
|
|
131 |
mDiskMonitor->start();
|
|
132 |
CxeSysUtil::setSpaceAvailable(90);
|
|
133 |
CxeTestUtils::waitForSignal(spy, 10000, 1, true);
|
|
134 |
QVERIFY(spy.count() > 0);
|
|
135 |
CX_DEBUG_EXIT_FUNCTION();
|
|
136 |
}
|
|
137 |
|
|
138 |
void UnitTestCxeDiskMonitor::testFreeSpaceChangedSignal()
|
|
139 |
{
|
|
140 |
CX_DEBUG_ENTER_FUNCTION();
|
|
141 |
QSignalSpy spy(mDiskMonitor, SIGNAL(diskSpaceChanged()));
|
|
142 |
mDiskMonitor->stop();
|
|
143 |
mDiskMonitor->setLowWarningLevel(100);
|
|
144 |
mDiskMonitor->start();
|
|
145 |
CxeSysUtil::setSpaceAvailable(110);
|
|
146 |
CxeSysUtil::setSpaceAvailable(120);
|
|
147 |
CxeTestUtils::waitForSignal(spy, 10000, 1, true);
|
|
148 |
QVERIFY(spy.count() > 0);
|
|
149 |
CX_DEBUG_EXIT_FUNCTION();
|
|
150 |
}
|
|
151 |
|
|
152 |
QTEST_MAIN(UnitTestCxeDiskMonitor);
|
|
153 |
|