summaryrefslogtreecommitdiffstats
path: root/tests/auto/qsystembatteryinfo/tst_qsystembatteryinfo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qsystembatteryinfo/tst_qsystembatteryinfo.cpp')
-rw-r--r--tests/auto/qsystembatteryinfo/tst_qsystembatteryinfo.cpp464
1 files changed, 331 insertions, 133 deletions
diff --git a/tests/auto/qsystembatteryinfo/tst_qsystembatteryinfo.cpp b/tests/auto/qsystembatteryinfo/tst_qsystembatteryinfo.cpp
index ea5c824efe..1305a38906 100644
--- a/tests/auto/qsystembatteryinfo/tst_qsystembatteryinfo.cpp
+++ b/tests/auto/qsystembatteryinfo/tst_qsystembatteryinfo.cpp
@@ -45,6 +45,10 @@
#include "qsystembatteryinfo.h"
#include <QDebug>
+#ifdef TESTR
+#include "qsysteminfo_simulator_p.h"
+#endif
+
QTM_USE_NAMESPACE
Q_DECLARE_METATYPE(QSystemBatteryInfo::BatteryStatus);
Q_DECLARE_METATYPE(QSystemBatteryInfo::ChargingState);
@@ -58,31 +62,64 @@ Q_DECLARE_METATYPE(QSystemBatteryInfo::EnergyUnit);
* \return \p true if the requested signal was received
* \p false on timeout
*/
-//static bool waitForSignal(QObject *obj, const char *signal, int timeout = 0)
-//{
-// QEventLoop loop;
-// QObject::connect(obj, signal, &loop, SLOT(quit()));
-// QTimer timer;
-// QSignalSpy timeoutSpy(&timer, SIGNAL(timeout()));
-// if (timeout > 0) {
-// QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
-// timer.setSingleShot(true);
-// timer.start(timeout);
-// }
-// loop.exec();
-// return timeoutSpy.isEmpty();
-//}
-
-//class ChangeBatteryThread : public QThread
-//{
-//public:
-// void run()
-// {
-// QSystemBatteryInfo bi;
-// QSystemBatteryInfoPrivate *bip = bi.priv;
-// }
+#ifdef TESTR
+static bool waitForSignal(QObject *obj, const char *signal, int timeout = 0)
+{
+ QEventLoop loop;
+ QObject::connect(obj, signal, &loop, SLOT(quit()));
+ QTimer timer;
+ QSignalSpy timeoutSpy(&timer, SIGNAL(timeout()));
+ if (timeout > 0) {
+ QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
+ timer.setSingleShot(true);
+ timer.start(timeout);
+ }
+ loop.exec();
+ return timeoutSpy.isEmpty();
+}
-//};
+class ChangeBatteryThread : public QThread
+{
+public:
+ void run()
+ {
+ QMutexLocker locker(&mutex);
+ SystemInfoConnection si;
+ QSystemBatteryInfoPrivate *d = si.batteryInfoPrivate();
+
+ d->setBatteryStatus(currentBatStatus);
+ d->setChargerType(curChargeType);
+ d->setChargingState(curChargeState);
+
+ d->setNominalCapacity(capacity);
+ d->setRemainingCapacityPercent(currentBatLevelPercent);
+ d->setRemainingCapacity(remainingCapacity);
+
+ d->setVoltage(currentVoltage);
+ d->setRemainingChargingTime(remainingEnergy);
+ d->setCurrentFlow(dischargeRate);
+// d->setRemainingCapacityBars(int v);
+// d->setMaxBars(int v);
+
+
+ this->exit();
+ }
+ QMutex mutex;
+ QSystemBatteryInfo::BatteryStatus currentBatStatus;
+ QSystemBatteryInfo::ChargingState curChargeState;
+ QSystemBatteryInfo::ChargerType curChargeType;
+ QVariantMap pMap;
+
+ int currentBatLevelPercent;
+ int currentVoltage;
+ int dischargeRate;
+ int capacity;
+ int timeToFull;
+ int remainingEnergy;
+ int remainingCapacity;
+// int capBars;
+};
+#endif
class tst_QSystemBatteryInfo : public QObject
{
@@ -112,55 +149,73 @@ private slots:
void tst_batteryStatus();
void tst_energyMeasurementUnit();
-
+#ifdef TESTR
//signal tests
-// void tst_batteryLevelChanged();
-// void tst_batteryStatusChanged();
+ void tst_batteryStatusChanged_data();
+ void tst_batteryStatusChanged();
+ void tst_chargingStateChanged_data();
+ void tst_chargingStateChanged();
-// void tst_chargingStateChanged();
-// void tst_chargerTypeChanged();
+ void tst_chargerTypeChanged_data();
+ void tst_chargerTypeChanged();
-// void tst_nominalCapacityChanged();
-// void tst_remainingCapacityPercentChanged();
-// void tst_remainingCapacityChanged();
-// void tst_voltageChanged();
+ void tst_nominalCapacityChanged_data();
+ void tst_nominalCapacityChanged();
-// void tst_currentFlowChanged();
-// void tst_cumulativeCurrentFlowChanged();
-// void tst_remainingCapacityBarsChanged();
-// void tst_remainingChargingTimeChanged();
+ void tst_remainingCapacityPercentChanged_data();
+ void tst_remainingCapacityPercentChanged();
+ void tst_remainingCapacityChanged_data();
+ void tst_remainingCapacityChanged();
-// //signals
-// void batteryLevelChanged(int level);
-// void batteryStatusChanged(QSystemBatteryInfo::BatteryStatus batteryStatus);
+ void tst_currentFlowChanged_data();
+ void tst_currentFlowChanged();
+ void tst_remainingCapacityBarsChanged();
+ void tst_remainingChargingTimeChanged();
-// void chargingStateChanged(QSystemBatteryInfo::ChargingState chargingState);
-// void chargerTypeChanged(QSystemBatteryInfo::ChargerType chargerType);
-// void nominalCapacityChanged(int);
-// void remainingCapacityPercentChanged(int);
-// void remainingCapacityChanged(int);
+ //signals
+ void batteryStatusChanged(QSystemBatteryInfo::BatteryStatus batteryStatus);
-// void currentFlowChanged(int);
-// void cumulativeCurrentFlowChanged(int);
-// void remainingCapacityBarsChanged(int);
-// void remainingChargingTimeChanged(int);
+ void chargingStateChanged(QSystemBatteryInfo::ChargingState chargingState);
+ void chargerTypeChanged(QSystemBatteryInfo::ChargerType chargerType);
-// ChangeBatteryThread *changeBatteryThread;
+ void nominalCapacityChanged(int);
+ void remainingCapacityPercentChanged(int);
+ void remainingCapacityChanged(int);
+
+ void currentFlowChanged(int);
+// void remainingCapacityBarsChanged(int);
+// void remainingChargingTimeChanged(int);
+#endif
+
+private:
+
+#ifdef TESTR
+ QSystemBatteryInfo::BatteryStatus currentBatStatus;
+ QSystemBatteryInfo::ChargingState curChargeState;
+ QSystemBatteryInfo::ChargerType curChargeType;
+
+ int currentBatLevelPercent;
+ int currentVoltage;
+ int dischargeRate;
+ int capacity;
+ int timeToFull;
+ int remainingEnergy;
+ int remainingCapacity;
+// int capBars;
+#endif
};
tst_QSystemBatteryInfo::tst_QSystemBatteryInfo()
{
- // changeBatteryThread = new ChangeBatteryThread();
}
tst_QSystemBatteryInfo::~tst_QSystemBatteryInfo()
{
- //delete changeBatteryThread, changeBatteryThread = 0;
}
/*
SystemInfoConnection si;
@@ -229,7 +284,6 @@ void tst_QSystemBatteryInfo::tst_nominalCapacity()
QVERIFY(nom == -1);
} else {
QVERIFY(nom != -1);
-
}
}
@@ -337,135 +391,279 @@ void tst_QSystemBatteryInfo::tst_energyMeasurementUnit()
}
}
-////signal tests
-//void tst_QSystemBatteryInfo::tst_batteryLevelChanged()
-//{
-// QSystemBatteryInfo bi;
+#ifdef TESTR
+//signal tests
+void tst_QSystemBatteryInfo::tst_batteryStatusChanged_data()
+{
+ QTest::addColumn<QSystemBatteryInfo::BatteryStatus>("batterystatus");
-//}
+ QTest::newRow("BatteryUnknown") << QSystemBatteryInfo::BatteryUnknown;
+ QTest::newRow("BatteryEmpty") << QSystemBatteryInfo::BatteryEmpty;
+ QTest::newRow("BatteryCritical") << QSystemBatteryInfo::BatteryCritical;
+ QTest::newRow("BatteryVeryLow") << QSystemBatteryInfo::BatteryVeryLow;
-//void tst_QSystemBatteryInfo::tst_batteryStatusChanged()
-//{
-// QSystemBatteryInfo bi;
+ QTest::newRow("BatteryLow") << QSystemBatteryInfo::BatteryLow;
+ QTest::newRow("BatteryOk") << QSystemBatteryInfo::BatteryOk;
+ QTest::newRow("BatteryFull") << QSystemBatteryInfo::BatteryFull;
+}
-//}
+void tst_QSystemBatteryInfo::tst_batteryStatusChanged()
+{
+ QSystemBatteryInfo bi;
+ ChangeBatteryThread *changeBatThread = new ChangeBatteryThread();
-//void tst_QSystemBatteryInfo::tst_chargingStateChanged()
-//{
-// QSystemBatteryInfo bi;
+ connect(&bi,SIGNAL(batteryStatusChanged(QSystemBatteryInfo::BatteryStatus)),
+ this,SLOT(batteryStatusChanged(QSystemBatteryInfo::BatteryStatus)));
-//}
+ QFETCH(QSystemBatteryInfo::BatteryStatus, batterystatus);
-//void tst_QSystemBatteryInfo::tst_chargerTypeChanged()
-//{
-// QSystemBatteryInfo bi;
+ changeBatThread->currentBatStatus = currentBatStatus = batterystatus;
+ changeBatThread->start();
-//}
+ QSignalSpy errorSpy(&bi, SIGNAL(batteryStatusChanged(QSystemBatteryInfo::BatteryStatus)));
+ QVERIFY(::waitForSignal(&bi, SIGNAL(batteryStatusChanged(QSystemBatteryInfo::BatteryStatus)), 10 * 1000));
-//void tst_QSystemBatteryInfo::tst_nominalCapacityChanged()
-//{
-// QSystemBatteryInfo bi;
+ QVERIFY(errorSpy.count() == 1);
+}
-//}
+void tst_QSystemBatteryInfo::tst_chargingStateChanged_data()
+{
+ QTest::addColumn<QSystemBatteryInfo::ChargingState>("chargingstate");
-//void tst_QSystemBatteryInfo::tst_remainingCapacityPercentChanged()
-//{
-// QSystemBatteryInfo bi;
+ QTest::newRow("ChargingError") << QSystemBatteryInfo::ChargingError;
+ QTest::newRow("NotCharging") << QSystemBatteryInfo::NotCharging;
+ QTest::newRow("Charging") << QSystemBatteryInfo::Charging;
+}
-//}
+void tst_QSystemBatteryInfo::tst_chargingStateChanged()
+{
+ QSystemBatteryInfo bi;
+ ChangeBatteryThread *changeBatThread = new ChangeBatteryThread();
-//void tst_QSystemBatteryInfo::tst_remainingCapacityChanged()
-//{
-// QSystemBatteryInfo bi;
+ connect(&bi,SIGNAL(chargingStateChanged(QSystemBatteryInfo::ChargingState)),
+ this,SLOT(chargingStateChanged(QSystemBatteryInfo::ChargingState)));
-//}
+ QFETCH(QSystemBatteryInfo::ChargingState, chargingstate);
-//void tst_QSystemBatteryInfo::tst_voltageChanged()
-//{
-// QSystemBatteryInfo bi;
+ changeBatThread->curChargeState = curChargeState = chargingstate;
+ changeBatThread->start();
-//}
+ QSignalSpy errorSpy(&bi, SIGNAL(chargingStateChanged(QSystemBatteryInfo::ChargingState)));
+ QVERIFY(::waitForSignal(&bi, SIGNAL(chargingStateChanged(QSystemBatteryInfo::ChargingState)), 10 * 1000));
-//void tst_QSystemBatteryInfo::tst_currentFlowChanged()
-//{
-// QSystemBatteryInfo bi;
+ QVERIFY(errorSpy.count() == 1);
+}
-//}
+void tst_QSystemBatteryInfo::tst_chargerTypeChanged_data()
+{
+ QTest::addColumn<QSystemBatteryInfo::ChargerType>("chargertype");
-//void tst_QSystemBatteryInfo::tst_cumulativeCurrentFlowChanged()
-//{
-// QSystemBatteryInfo bi;
+ QTest::newRow("UnknownCharger") << QSystemBatteryInfo::UnknownCharger;
+ QTest::newRow("NoCharger") << QSystemBatteryInfo::NoCharger;
+ QTest::newRow("WallCharger") << QSystemBatteryInfo::WallCharger;
-//}
+ QTest::newRow("USBCharger") << QSystemBatteryInfo::USBCharger;
+ QTest::newRow("USB_500mACharger") << QSystemBatteryInfo::USB_500mACharger;
+ QTest::newRow("USB_100mACharger") << QSystemBatteryInfo::USB_100mACharger;
-//void tst_QSystemBatteryInfo::tst_remainingCapacityBarsChanged()
-//{
-// QSystemBatteryInfo bi;
+ QTest::newRow("VariableCurrentCharger") << QSystemBatteryInfo::VariableCurrentCharger;
+}
-//}
+void tst_QSystemBatteryInfo::tst_chargerTypeChanged()
+{
+ QSystemBatteryInfo bi;
+ ChangeBatteryThread *changeBatThread = new ChangeBatteryThread();
-//void tst_QSystemBatteryInfo::tst_remainingChargingTimeChanged()
-//{
-// QSystemBatteryInfo bi;
+ connect(&bi,SIGNAL(chargerTypeChanged(QSystemBatteryInfo::ChargerType)),
+ this,SLOT(chargerTypeChanged(QSystemBatteryInfo::ChargerType)));
-//}
+ QFETCH(QSystemBatteryInfo::ChargerType, chargertype);
-////signals
-//void tst_QSystemBatteryInfo::batteryLevelChanged(int level)
-//{
+ changeBatThread->curChargeType = curChargeType = chargertype;
+ changeBatThread->start();
-//}
+ QSignalSpy errorSpy(&bi, SIGNAL(chargerTypeChanged(QSystemBatteryInfo::ChargerType)));
+ QVERIFY(::waitForSignal(&bi, SIGNAL(chargerTypeChanged(QSystemBatteryInfo::ChargerType)), 10 * 1000));
-//void tst_QSystemBatteryInfo::batteryStatusChanged(QSystemBatteryInfo::BatteryStatus batteryStatus)
-//{
+ QVERIFY(errorSpy.count() == 1);
+}
-//}
+void tst_QSystemBatteryInfo::tst_nominalCapacityChanged_data()
+{
+ QTest::addColumn<int>("intdata");
-//void tst_QSystemBatteryInfo::chargingStateChanged(QSystemBatteryInfo::ChargingState chargingState)
-//{
+ QTest::newRow("1") << 1;
+ QTest::newRow("2") << 1234;
+ QTest::newRow("3") << 4321;
+ QTest::newRow("4") << 9990;
+ QTest::newRow("5") << -1;
+}
-//}
+void tst_QSystemBatteryInfo::tst_nominalCapacityChanged()
+{
+ QSystemBatteryInfo bi;
+ ChangeBatteryThread *changeBatThread = new ChangeBatteryThread();
-//void tst_QSystemBatteryInfo::chargerTypeChanged(QSystemBatteryInfo::ChargerType chargerType)
-//{
+ connect(&bi,SIGNAL(nominalCapacityChanged(int)),
+ this,SLOT(nominalCapacityChanged(int)));
-//}
+ QFETCH(int, intdata);
-//void tst_QSystemBatteryInfo::nominalCapacityChanged(int)
-//{
+ changeBatThread->capacity = capacity = intdata;
+ changeBatThread->start();
-//}
+ QSignalSpy errorSpy(&bi, SIGNAL(nominalCapacityChanged(int)));
+ QVERIFY(::waitForSignal(&bi, SIGNAL(nominalCapacityChanged(int)), 10 * 1000));
-//void tst_QSystemBatteryInfo::remainingCapacityPercentChanged(int)
-//{
+ QVERIFY(errorSpy.count() == 1);
+}
-//}
+void tst_QSystemBatteryInfo::tst_remainingCapacityPercentChanged_data()
+{
+ QTest::addColumn<int>("batPercent");
-//void tst_QSystemBatteryInfo::remainingCapacityChanged(int)
-//{
+ QTest::newRow("1") << 1;
+ QTest::newRow("2") << 3;
+ QTest::newRow("3") << 5;
+ QTest::newRow("4") << 10;
+ QTest::newRow("5") << 12;
+ QTest::newRow("6") << 40;
-//}
+ QTest::newRow("4") << 41;
+ QTest::newRow("5") << 98;
+ QTest::newRow("6") << 99;
+ QTest::newRow("7") << 100;
-//void tst_QSystemBatteryInfo::currentFlowChanged(int)
-//{
+}
+void tst_QSystemBatteryInfo::tst_remainingCapacityPercentChanged()
+{
+ QSystemBatteryInfo bi;
+ ChangeBatteryThread *changeBatThread = new ChangeBatteryThread();
-//}
+ connect(&bi,SIGNAL(remainingCapacityPercentChanged(int)),
+ this,SLOT(remainingCapacityPercentChanged(int)));
-//void tst_QSystemBatteryInfo::cumulativeCurrentFlowChanged(int)
-//{
+ QFETCH(int, batPercent);
-//}
+ changeBatThread->currentBatLevelPercent = currentBatLevelPercent = batPercent;
+ changeBatThread->start();
+
+ QSignalSpy errorSpy(&bi, SIGNAL(remainingCapacityPercentChanged(int)));
+ QVERIFY(::waitForSignal(&bi, SIGNAL(remainingCapacityPercentChanged(int)), 10 * 1000));
+
+ QVERIFY(errorSpy.count() == 1);
+}
+
+void tst_QSystemBatteryInfo::tst_remainingCapacityChanged_data()
+{
+ tst_nominalCapacityChanged_data();
+}
+
+void tst_QSystemBatteryInfo::tst_remainingCapacityChanged()
+{
+ QSystemBatteryInfo bi;
+ ChangeBatteryThread *changeBatThread = new ChangeBatteryThread();
+
+ connect(&bi,SIGNAL(remainingCapacityChanged(int)),
+ this,SLOT(remainingCapacityChanged(int)));
+
+ QFETCH(int, intdata);
+
+ changeBatThread->remainingCapacity = remainingCapacity = intdata;
+ changeBatThread->start();
+
+ QSignalSpy errorSpy(&bi, SIGNAL(remainingCapacityChanged(int)));
+ QVERIFY(::waitForSignal(&bi, SIGNAL(remainingCapacityChanged(int)), 10 * 1000));
+
+ QVERIFY(errorSpy.count() == 1);
+
+}
+
+void tst_QSystemBatteryInfo::tst_currentFlowChanged_data()
+{
+ tst_nominalCapacityChanged_data();
+}
+
+void tst_QSystemBatteryInfo::tst_currentFlowChanged()
+{
+ QSystemBatteryInfo bi;
+ ChangeBatteryThread *changeBatThread = new ChangeBatteryThread();
+
+ connect(&bi,SIGNAL(currentFlowChanged(int)),
+ this,SLOT(currentFlowChanged(int)));
+
+ QFETCH(int, intdata);
-//void tst_QSystemBatteryInfo::remainingCapacityBarsChanged(int)
+ changeBatThread->dischargeRate = dischargeRate = intdata;
+ changeBatThread->start();
+
+ QSignalSpy errorSpy(&bi, SIGNAL(currentFlowChanged(int)));
+ QVERIFY(::waitForSignal(&bi, SIGNAL(currentFlowChanged(int)), 10 * 1000));
+
+ QVERIFY(errorSpy.count() == 1);
+}
+
+void tst_QSystemBatteryInfo::tst_remainingCapacityBarsChanged()
+{
+ // QSystemBatteryInfo bi;
+
+}
+
+void tst_QSystemBatteryInfo::tst_remainingChargingTimeChanged()
+{
+ // QSystemBatteryInfo bi;
+
+}
+
+//signals
+void tst_QSystemBatteryInfo::batteryStatusChanged(QSystemBatteryInfo::BatteryStatus batStatus)
+{
+ QVERIFY(batStatus == currentBatStatus);
+}
+
+void tst_QSystemBatteryInfo::chargingStateChanged(QSystemBatteryInfo::ChargingState chargState)
+{
+ QVERIFY(chargState == curChargeState);
+
+}
+
+void tst_QSystemBatteryInfo::chargerTypeChanged(QSystemBatteryInfo::ChargerType chargType)
+{
+ QVERIFY(chargType == curChargeType);
+}
+
+void tst_QSystemBatteryInfo::nominalCapacityChanged(int cap)
+{
+ QVERIFY(cap == capacity);
+}
+
+void tst_QSystemBatteryInfo::remainingCapacityPercentChanged(int cap)
+{
+ QVERIFY(cap == currentBatLevelPercent);
+}
+
+void tst_QSystemBatteryInfo::remainingCapacityChanged(int cap)
+{
+ QVERIFY(cap == remainingCapacity);
+}
+
+void tst_QSystemBatteryInfo::currentFlowChanged(int flow)
+{
+ QVERIFY(flow == dischargeRate);
+}
+
+//void tst_QSystemBatteryInfo::remainingCapacityBarsChanged(int cap)
//{
+// QVERIFY(cap == currentBatStatus);
//}
-//void tst_QSystemBatteryInfo::remainingChargingTimeChanged(int)
+//void tst_QSystemBatteryInfo::remainingChargingTimeChanged(int time)
//{
+// QVERIFY(time == currentBatStatus);
//}
-
+#endif
QTEST_MAIN(tst_QSystemBatteryInfo)
#include "tst_qsystembatteryinfo.moc"