Chromium Code Reviews| Index: device/generic_sensor/platform_sensor_and_provider_unittest_win.cc |
| diff --git a/device/generic_sensor/platform_sensor_and_provider_unittest_win.cc b/device/generic_sensor/platform_sensor_and_provider_unittest_win.cc |
| index 8f3eb366c826b1dbc73191b689d3dac2b7503139..6337b79d1bda028d3f2337a103d9ce6505d0504c 100644 |
| --- a/device/generic_sensor/platform_sensor_and_provider_unittest_win.cc |
| +++ b/device/generic_sensor/platform_sensor_and_provider_unittest_win.cc |
| @@ -3,7 +3,8 @@ |
| // found in the LICENSE file. |
| #include <SensorsApi.h> |
| -#include <Sensors.h> // NOLINT |
| +#include <Sensors.h> // NOLINT |
| +#include <Propvarutil.h> // NOLINT |
| #include "base/bind.h" |
| #include "base/memory/ptr_util.h" |
| @@ -333,7 +334,8 @@ class PlatformSensorAndProviderTestWin : public ::testing::Test { |
| return false; |
| } |
| }; |
| - using SensorData = std::map<PROPERTYKEY, double, PropertyKeyCompare>; |
| + |
| + using SensorData = std::map<PROPERTYKEY, PROPVARIANT, PropertyKeyCompare>; |
| // Generates OnDataUpdated event and creates ISensorDataReport with fake |
| // |value| for property with |key|. |
| @@ -363,8 +365,7 @@ class PlatformSensorAndProviderTestWin : public ::testing::Test { |
| if (it == values.end()) |
| return E_FAIL; |
| - variant->vt = VT_R8; |
| - variant->dblVal = it->second; |
| + *variant = it->second; |
| return S_OK; |
| }))); |
| @@ -479,9 +480,13 @@ TEST_F(PlatformSensorAndProviderTestWin, SensorStarted) { |
| EXPECT_TRUE(StartListening(sensor, client.get(), configuration)); |
| EXPECT_CALL(*client, OnSensorReadingChanged()).Times(1); |
| - GenerateDataUpdatedEvent({{SENSOR_DATA_TYPE_LIGHT_LEVEL_LUX, 3.14}}); |
| + PROPVARIANT pvLux; |
| + InitPropVariantFromDouble(3.14, &pvLux); |
| + GenerateDataUpdatedEvent({{SENSOR_DATA_TYPE_LIGHT_LEVEL_LUX, pvLux }}); |
| base::RunLoop().RunUntilIdle(); |
| EXPECT_TRUE(sensor->StopListening(client.get(), configuration)); |
| + |
| + PropVariantClear(&pvLux); |
| } |
| // Tests that OnSensorError is called when sensor is disconnected. |
| @@ -567,9 +572,15 @@ TEST_F(PlatformSensorAndProviderTestWin, CheckAccelerometerReadingConversion) { |
| double x_accel = 0.25; |
| double y_accel = -0.25; |
| double z_accel = -0.5; |
| - GenerateDataUpdatedEvent({{SENSOR_DATA_TYPE_ACCELERATION_X_G, x_accel}, |
| - {SENSOR_DATA_TYPE_ACCELERATION_Y_G, y_accel}, |
| - {SENSOR_DATA_TYPE_ACCELERATION_Z_G, z_accel}}); |
| + |
| + PROPVARIANT pvX, pvY, pvZ; |
| + InitPropVariantFromDouble(x_accel, &pvX); |
| + InitPropVariantFromDouble(y_accel, &pvY); |
| + InitPropVariantFromDouble(z_accel, &pvZ); |
| + |
| + GenerateDataUpdatedEvent({{SENSOR_DATA_TYPE_ACCELERATION_X_G, pvX}, |
| + {SENSOR_DATA_TYPE_ACCELERATION_Y_G, pvY}, |
| + {SENSOR_DATA_TYPE_ACCELERATION_Z_G, pvZ}}); |
| base::RunLoop().RunUntilIdle(); |
| SensorReadingSharedBuffer* buffer = |
| @@ -578,6 +589,10 @@ TEST_F(PlatformSensorAndProviderTestWin, CheckAccelerometerReadingConversion) { |
| EXPECT_THAT(buffer->reading.values[1], -y_accel * kMeanGravity); |
| EXPECT_THAT(buffer->reading.values[2], -z_accel * kMeanGravity); |
| EXPECT_TRUE(sensor->StopListening(client.get(), configuration)); |
| + |
| + PropVariantClear(&pvX); |
| + PropVariantClear(&pvY); |
| + PropVariantClear(&pvZ); |
|
Reilly Grant (use Gerrit)
2017/03/21 18:25:06
Please use base::win::ScopedPropVariant to ensure
shalamov
2017/03/23 13:35:29
Done.
|
| } |
| // Tests that Gyroscope readings are correctly converted. |
| @@ -601,10 +616,15 @@ TEST_F(PlatformSensorAndProviderTestWin, CheckGyroscopeReadingConversion) { |
| double y_ang_accel = -1.8; |
| double z_ang_accel = -98.7; |
| + PROPVARIANT pvX, pvY, pvZ; |
| + InitPropVariantFromDouble(x_ang_accel, &pvX); |
| + InitPropVariantFromDouble(y_ang_accel, &pvY); |
| + InitPropVariantFromDouble(z_ang_accel, &pvZ); |
| + |
| GenerateDataUpdatedEvent( |
| - {{SENSOR_DATA_TYPE_ANGULAR_VELOCITY_X_DEGREES_PER_SECOND, x_ang_accel}, |
| - {SENSOR_DATA_TYPE_ANGULAR_VELOCITY_Y_DEGREES_PER_SECOND, y_ang_accel}, |
| - {SENSOR_DATA_TYPE_ANGULAR_VELOCITY_Z_DEGREES_PER_SECOND, z_ang_accel}}); |
| + {{SENSOR_DATA_TYPE_ANGULAR_VELOCITY_X_DEGREES_PER_SECOND, pvX}, |
| + {SENSOR_DATA_TYPE_ANGULAR_VELOCITY_Y_DEGREES_PER_SECOND, pvY}, |
| + {SENSOR_DATA_TYPE_ANGULAR_VELOCITY_Z_DEGREES_PER_SECOND, pvZ}}); |
| base::RunLoop().RunUntilIdle(); |
| SensorReadingSharedBuffer* buffer = |
| @@ -613,6 +633,10 @@ TEST_F(PlatformSensorAndProviderTestWin, CheckGyroscopeReadingConversion) { |
| EXPECT_THAT(buffer->reading.values[1], -y_ang_accel * kRadiansInDegrees); |
| EXPECT_THAT(buffer->reading.values[2], -z_ang_accel * kRadiansInDegrees); |
| EXPECT_TRUE(sensor->StopListening(client.get(), configuration)); |
| + |
| + PropVariantClear(&pvX); |
| + PropVariantClear(&pvY); |
| + PropVariantClear(&pvZ); |
| } |
| // Tests that Magnetometer readings are correctly converted. |
| @@ -636,10 +660,15 @@ TEST_F(PlatformSensorAndProviderTestWin, CheckMagnetometerReadingConversion) { |
| double y_magn_field = -162.0; |
| double z_magn_field = 457.0; |
| + PROPVARIANT pvX, pvY, pvZ; |
| + InitPropVariantFromDouble(x_magn_field, &pvX); |
| + InitPropVariantFromDouble(y_magn_field, &pvY); |
| + InitPropVariantFromDouble(z_magn_field, &pvZ); |
| + |
| GenerateDataUpdatedEvent( |
| - {{SENSOR_DATA_TYPE_MAGNETIC_FIELD_STRENGTH_X_MILLIGAUSS, x_magn_field}, |
| - {SENSOR_DATA_TYPE_MAGNETIC_FIELD_STRENGTH_Y_MILLIGAUSS, y_magn_field}, |
| - {SENSOR_DATA_TYPE_MAGNETIC_FIELD_STRENGTH_Z_MILLIGAUSS, z_magn_field}}); |
| + {{SENSOR_DATA_TYPE_MAGNETIC_FIELD_STRENGTH_X_MILLIGAUSS, pvX}, |
| + {SENSOR_DATA_TYPE_MAGNETIC_FIELD_STRENGTH_Y_MILLIGAUSS, pvY}, |
| + {SENSOR_DATA_TYPE_MAGNETIC_FIELD_STRENGTH_Z_MILLIGAUSS, pvZ}}); |
| base::RunLoop().RunUntilIdle(); |
| SensorReadingSharedBuffer* buffer = |
| @@ -651,6 +680,52 @@ TEST_F(PlatformSensorAndProviderTestWin, CheckMagnetometerReadingConversion) { |
| EXPECT_THAT(buffer->reading.values[2], |
| -z_magn_field * kMicroteslaInMilligauss); |
| EXPECT_TRUE(sensor->StopListening(client.get(), configuration)); |
| + |
| + PropVariantClear(&pvX); |
| + PropVariantClear(&pvY); |
| + PropVariantClear(&pvZ); |
| +} |
| + |
| +// Tests that DeviceOrientation readings are correctly converted. |
| +TEST_F(PlatformSensorAndProviderTestWin, |
| + CheckDeviceOrientationReadingConversion) { |
| + mojo::ScopedSharedBufferHandle handle = |
| + PlatformSensorProviderWin::GetInstance()->CloneSharedBufferHandle(); |
| + mojo::ScopedSharedBufferMapping mapping = handle->MapAtOffset( |
| + sizeof(SensorReadingSharedBuffer), |
| + SensorReadingSharedBuffer::GetOffset(SensorType::ABSOLUTE_ORIENTATION)); |
| + |
| + SetSupportedSensor(SENSOR_TYPE_AGGREGATED_DEVICE_ORIENTATION); |
| + auto sensor = CreateSensor(SensorType::ABSOLUTE_ORIENTATION); |
| + EXPECT_TRUE(sensor); |
| + |
| + auto client = base::MakeUnique<NiceMock<MockPlatformSensorClient>>(sensor); |
| + PlatformSensorConfiguration configuration(10); |
| + EXPECT_TRUE(StartListening(sensor, client.get(), configuration)); |
| + EXPECT_CALL(*client, OnSensorReadingChanged()).Times(1); |
| + |
| + double x = -0.5; |
| + double y = -0.5; |
| + double z = 0.5; |
| + double w = 0.5; |
| + float quat_elements[4] = {x, y, z, w}; |
| + |
| + PROPVARIANT pvQuat; |
| + InitPropVariantFromGUIDAsBuffer(SENSOR_DATA_TYPE_QUATERNION.fmtid, &pvQuat); |
|
Reilly Grant (use Gerrit)
2017/03/21 18:25:06
Can you add a comment explaining that the Windows
shalamov
2017/03/23 13:35:29
Done.
|
| + memcpy(pvQuat.caub.pElems, &quat_elements, sizeof(quat_elements)); |
| + GenerateDataUpdatedEvent({{SENSOR_DATA_TYPE_QUATERNION, pvQuat}}); |
| + |
| + base::RunLoop().RunUntilIdle(); |
| + SensorReadingSharedBuffer* buffer = |
| + static_cast<SensorReadingSharedBuffer*>(mapping.get()); |
| + |
| + EXPECT_THAT(buffer->reading.values[0], -x); |
| + EXPECT_THAT(buffer->reading.values[1], -y); |
| + EXPECT_THAT(buffer->reading.values[2], -z); |
| + EXPECT_THAT(buffer->reading.values[3], w); |
| + EXPECT_TRUE(sensor->StopListening(client.get(), configuration)); |
| + |
| + PropVariantClear(&pvQuat); |
| } |
| } // namespace device |