From f233e4266e20ea5ac06d51865b4da040b8e12fa9 Mon Sep 17 00:00:00 2001 From: Lincoln Ramsay Date: Mon, 4 Jun 2012 12:14:59 +1000 Subject: setDataRates clobbers user-set data rate Under normal conditions, dataRate is set/checked like so. QSensor::setDataRate records the data rate. It can't be evaluated because we have no backend. Upon getting a backend, we are notified of the available data rates. Re-evaluate the previously-set dataRate after connecting to a backend. The problem is that connectToBackend did not save the dataRate value until after setDataRates was called and setDataRates was clobbering the dataRate property. Two fixes will be made. connectToBackend will save the dataRate before creating the backend and setDataRates will stop clobbering dataRate. Also, setDataRates is now banned from being called outside of the constructor because otherwise an available data rate may disappear during use. Add a test case to verify that a previously-set data rate is not clobbered. Change-Id: I9632b2c8ffcc6d48d9bc91f263b99028ee997ff9 Reviewed-by: Lorn Potter --- tests/auto/qsensor/tst_qsensor.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tests') diff --git a/tests/auto/qsensor/tst_qsensor.cpp b/tests/auto/qsensor/tst_qsensor.cpp index 92cb281a..8025ab21 100644 --- a/tests/auto/qsensor/tst_qsensor.cpp +++ b/tests/auto/qsensor/tst_qsensor.cpp @@ -353,6 +353,28 @@ private slots: QCOMPARE(actual, expected); } + // Test that a previously-set, valid data rate is retained + { + TestSensor sensor; + sensor.setDataRate(100); + sensor.setProperty("doThis", "rates"); + sensor.connectToBackend(); + int actual = sensor.dataRate(); + int expected = 100; + QCOMPARE(actual, expected); + } + + // Test that a previously-set, invalid data rate is reset to 0 + { + TestSensor sensor; + sensor.setDataRate(50); + sensor.setProperty("doThis", "rates"); + sensor.connectToBackend(); + int actual = sensor.dataRate(); + int expected = 0; + QCOMPARE(actual, expected); + } + { TestSensor sensor; sensor.setProperty("doThis", "rates(0)"); -- cgit v1.2.3