~thomas-voss/qtubuntu-sensors/add-minimal-standalone-location-test-case

« back to all changes in this revision

Viewing changes to tests/test_sensor_api_mock.cpp

  • Committer: CI bot
  • Author(s): Ricardo Mendoza
  • Date: 2014-06-23 17:21:21 UTC
  • mfrom: (57.3.9 new-orientation)
  • Revision ID: ps-jenkins@lists.canonical.com-20140623172121-w7zralxiu0gxixbd
New orientation sensing code, borrow from Android for low pass filtering and smart tilt detection. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
246
246
    EXPECT_FLOAT_EQ(reading->z(), -0.5);
247
247
})
248
248
 
249
 
TESTP_F(SimBackendTest, OrientationEvents, {
250
 
        /* test some "parallel to coordinate axes" conditions, as well as some
251
 
         * ~ 45 degrees angles; we want a hysteresis there, i. e. it should not
252
 
         * flip back and forth when wiggling around the diagonals but only when
253
 
         * it's mostly pointing towards an axis
254
 
         * coordinate system:
255
 
         * http://qt-project.org/doc/qt-5.1/qtsensors/qaccelerometerreading.html
256
 
         */
257
 
    set_data("create accel -500 500 0.1\n"
258
 
             "10 accel 0 9.8 0\n"  // TopUp
259
 
             "100 accel 6.9 6.9 0\n"  // turning left
260
 
             "150 accel 8.1 2.3 0\n"  // almost turned left, should trigger RightUp
261
 
             "50 accel -7.1 6.9 0\n"  // turn right, wiggle around diagonal several times
262
 
             "30 accel -6.5 7.1 0\n" 
263
 
             "30 accel -7.0 6.0 0\n"
264
 
             "30 accel -7.0 6.0 0\n"
265
 
             "30 accel -8.0 3.0 0\n"  // finally turn right enough to trigger LeftUp
266
 
             "30 accel 0 -9.8 0\n"    // TopDown
267
 
             "30 accel 0 0 9.8\n"    // FaceUp
268
 
             "30 accel 0 0 -9.8\n"    // FaceDown
269
 
             );
270
 
 
271
 
    orientation_sensor->setIdentifier("core.orientation");
272
 
 
273
 
    QObject::connect(orientation_sensor, &QOrientationSensor::readingChanged, [=]() { 
274
 
        auto r = orientation_sensor->reading();
275
 
        orientation_events.push({r->orientation(), chrono::system_clock::now()});
276
 
    });
277
 
 
278
 
    EXPECT_EQ(orientation_sensor->start(), true);
279
 
 
280
 
    start_time = chrono::system_clock::now();
281
 
    run_events(550);  // must be long enough to catch all events
282
 
 
283
 
    EXPECT_EQ(orientation_events.size(), 6);
284
 
 
285
 
    check_orientation_event(QOrientationReading::TopUp, 10);
286
 
    check_orientation_event(QOrientationReading::RightUp, 260);
287
 
    check_orientation_event(QOrientationReading::LeftUp, 430);
288
 
    check_orientation_event(QOrientationReading::TopDown, 460);
289
 
    check_orientation_event(QOrientationReading::FaceUp, 490);
290
 
    check_orientation_event(QOrientationReading::FaceDown, 520);
291
 
})
292
 
 
293
249
TESTP_F(SimBackendTest, OrientationReading, {
294
 
    set_data("create accel -500 500 0.1\n"
295
 
             "10 accel 0 9.8 0\n"  // TopUp
296
 
             "20 accel 6.9 6.9 0\n"  // turning left
297
 
             "20 accel 8.1 2.3 0\n"  // almost turned left, should trigger RightUp
 
250
    set_data("create accel -500 500 0.001\n"
 
251
             "70 accel 0.347 9.768 0.162\n"
 
252
             "70 accel -0.600 9.947 0.174\n"
 
253
             "70 accel -0.885 11.061 -0.177\n"
 
254
             "70 accel -2.121 10.397 -0.468\n"
 
255
             "70 accel -4.242 8.664 -0.023\n"
 
256
             "70 accel -5.882 7.633 0.169\n"
 
257
             "70 accel -7.031 5.822 -0.268\n"
 
258
             "70 accel -8.138 3.775 0.564\n"
 
259
             "70 accel -9.616 1.854 1.981\n"
 
260
             "70 accel -9.562 -0.195 1.138\n"
 
261
             "70 accel -10.373 -0.597 1.802\n"
298
262
             );
299
263
 
 
264
 
300
265
    orientation_sensor->setIdentifier("core.orientation");
301
266
 
302
267
    EXPECT_EQ(orientation_sensor->start(), true);
304
269
    // initial value
305
270
    EXPECT_EQ(orientation_sensor->reading()->orientation(), QOrientationReading::Undefined);
306
271
 
307
 
    // TopUp after first event
308
 
    run_events(20);
309
 
    EXPECT_EQ(orientation_sensor->reading()->orientation(), QOrientationReading::TopUp);
310
 
 
311
 
    // not changed for "turning left" yet
312
 
    run_events(20);
313
 
    EXPECT_EQ(orientation_sensor->reading()->orientation(), QOrientationReading::TopUp);
314
 
 
315
 
    // but changed after "almost turned left"
316
 
    run_events(20);
317
 
    EXPECT_EQ(orientation_sensor->reading()->orientation(), QOrientationReading::RightUp);
 
272
    // Right up after stream of svents
 
273
    run_events(1000);
 
274
    EXPECT_EQ(orientation_sensor->reading()->orientation(), QOrientationReading::LeftUp);
318
275
})