#ifdef WITH_TESTS #include "../../Tests.h" #include "../../../sensors/offline/FileReader.h" #include "../../../sensors/offline/FileWriter.h" TEST(Offline, readWrite) { std::string fileName = "/tmp/test.dat"; Offline::FileWriter out; out.open(fileName); const GPSData gps(Timestamp::fromMS(1), 2, 3, 4); out.add(Timestamp::fromMS(11), gps); const CompassData compass(4, 2); out.add(Timestamp::fromMS(13), compass); const BarometerData baro(3); out.add(Timestamp::fromMS(15), baro); const AccelerometerData acc(3,4,5); out.add(Timestamp::fromMS(17), acc); const GravityData grav(5,9,7); out.add(Timestamp::fromMS(19), grav); const GyroscopeData gyro(8, 5,11); out.add(Timestamp::fromMS(21), gyro); const LinearAccelerationData lina(13, 12, 11); out.add(Timestamp::fromMS(23), lina); WiFiMeasurements w1; w1.entries.push_back(WiFiMeasurement(AccessPoint(MACAddress("11:22:33:44:55:66")), -70)); w1.entries.push_back(WiFiMeasurement(AccessPoint(MACAddress("11:22:33:44:55:67")), -72)); w1.entries.push_back(WiFiMeasurement(AccessPoint(MACAddress("11:22:33:44:55:68")), -74)); out.add(Timestamp::fromMS(25), w1); WiFiMeasurements w2; w2.entries.push_back(WiFiMeasurement(AccessPoint(MACAddress("11:22:33:44:aa:66")), -60)); w2.entries.push_back(WiFiMeasurement(AccessPoint(MACAddress("11:22:33:44:aa:67")), -62)); w2.entries.push_back(WiFiMeasurement(AccessPoint(MACAddress("11:22:33:44:aa:68")), -64)); out.add(Timestamp::fromMS(27), w2); out.close(); Offline::FileReader reader; reader.open(fileName); // check number of entries ASSERT_EQ(1, reader.getGPS().size()); ASSERT_EQ(1, reader.getCompass().size()); ASSERT_EQ(1, reader.getBarometer().size()); ASSERT_EQ(1, reader.getAccelerometer().size()); ASSERT_EQ(1, reader.getGravity().size()); ASSERT_EQ(1, reader.getGyroscope().size()); ASSERT_EQ(1, reader.getLinearAcceleration().size()); ASSERT_EQ(2, reader.getWiFiGroupedByTime().size()); // check timestamps ASSERT_EQ(11, reader.getGPS().front().ts); ASSERT_EQ(13, reader.getCompass().front().ts); ASSERT_EQ(15, reader.getBarometer().front().ts); ASSERT_EQ(17, reader.getAccelerometer().front().ts); ASSERT_EQ(19, reader.getGravity().front().ts); ASSERT_EQ(21, reader.getGyroscope().front().ts); ASSERT_EQ(23, reader.getLinearAcceleration().front().ts); ASSERT_EQ(25, reader.getWiFiGroupedByTime().front().ts); ASSERT_EQ(27, reader.getWiFiGroupedByTime().back().ts); // check content ASSERT_EQ(gps, reader.getGPS().front().data); ASSERT_EQ(compass, reader.getCompass().front().data); ASSERT_EQ(baro, reader.getBarometer().front().data); ASSERT_EQ(acc, reader.getAccelerometer().front().data); ASSERT_EQ(grav, reader.getGravity().front().data); ASSERT_EQ(gyro, reader.getGyroscope().front().data); ASSERT_EQ(lina, reader.getLinearAcceleration().front().data); int i = 0; (void) i; } #endif