Commit f94ee1e6 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Assert sensor creation in PlatformSensorAndProviderLinuxTest.

The test only checks the sensor pointer with EXPECT_TRUE() and then
dereferences the pointer. On failure, this will blow through the
EXPECT_TRUE() and crash the test program. Switch to ASSERT_TRUE() to
fail without crashing.

Change-Id: I18a8b9c2ea7e300b93a11cc6108f195a895bec04
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1733039Reviewed-by: default avatarRaphael Kubo da Costa <raphael.kubo.da.costa@intel.com>
Reviewed-by: default avatarTim Volodine <timvolodine@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#684353}
parent efcb8d21
...@@ -340,7 +340,7 @@ TEST_F(PlatformSensorAndProviderLinuxTest, SensorIsSupported) { ...@@ -340,7 +340,7 @@ TEST_F(PlatformSensorAndProviderLinuxTest, SensorIsSupported) {
SetServiceStart(); SetServiceStart();
auto sensor = CreateSensor(SensorType::AMBIENT_LIGHT); auto sensor = CreateSensor(SensorType::AMBIENT_LIGHT);
EXPECT_TRUE(sensor); ASSERT_TRUE(sensor);
EXPECT_EQ(SensorType::AMBIENT_LIGHT, sensor->GetType()); EXPECT_EQ(SensorType::AMBIENT_LIGHT, sensor->GetType());
} }
...@@ -354,7 +354,7 @@ TEST_F(PlatformSensorAndProviderLinuxTest, StartFails) { ...@@ -354,7 +354,7 @@ TEST_F(PlatformSensorAndProviderLinuxTest, StartFails) {
SetServiceStart(); SetServiceStart();
auto sensor = CreateSensor(SensorType::AMBIENT_LIGHT); auto sensor = CreateSensor(SensorType::AMBIENT_LIGHT);
EXPECT_TRUE(sensor); ASSERT_TRUE(sensor);
auto client = auto client =
std::make_unique<NiceMock<LinuxMockPlatformSensorClient>>(sensor); std::make_unique<NiceMock<LinuxMockPlatformSensorClient>>(sensor);
...@@ -372,7 +372,7 @@ TEST_F(PlatformSensorAndProviderLinuxTest, SensorStarted) { ...@@ -372,7 +372,7 @@ TEST_F(PlatformSensorAndProviderLinuxTest, SensorStarted) {
SetServiceStart(); SetServiceStart();
auto sensor = CreateSensor(SensorType::AMBIENT_LIGHT); auto sensor = CreateSensor(SensorType::AMBIENT_LIGHT);
EXPECT_TRUE(sensor); ASSERT_TRUE(sensor);
auto client = auto client =
std::make_unique<NiceMock<LinuxMockPlatformSensorClient>>(sensor); std::make_unique<NiceMock<LinuxMockPlatformSensorClient>>(sensor);
...@@ -391,7 +391,7 @@ TEST_F(PlatformSensorAndProviderLinuxTest, SensorRemoved) { ...@@ -391,7 +391,7 @@ TEST_F(PlatformSensorAndProviderLinuxTest, SensorRemoved) {
SetServiceStart(); SetServiceStart();
auto sensor = CreateSensor(SensorType::AMBIENT_LIGHT); auto sensor = CreateSensor(SensorType::AMBIENT_LIGHT);
EXPECT_TRUE(sensor); ASSERT_TRUE(sensor);
auto client = auto client =
std::make_unique<NiceMock<LinuxMockPlatformSensorClient>>(sensor); std::make_unique<NiceMock<LinuxMockPlatformSensorClient>>(sensor);
...@@ -476,7 +476,7 @@ TEST_F(PlatformSensorAndProviderLinuxTest, GetMaximumSupportedFrequency) { ...@@ -476,7 +476,7 @@ TEST_F(PlatformSensorAndProviderLinuxTest, GetMaximumSupportedFrequency) {
SetServiceStart(); SetServiceStart();
auto sensor = CreateSensor(SensorType::ACCELEROMETER); auto sensor = CreateSensor(SensorType::ACCELEROMETER);
EXPECT_TRUE(sensor); ASSERT_TRUE(sensor);
EXPECT_THAT(sensor->GetMaximumSupportedFrequency(), EXPECT_THAT(sensor->GetMaximumSupportedFrequency(),
kAccelerometerFrequencyValue); kAccelerometerFrequencyValue);
} }
...@@ -492,7 +492,7 @@ TEST_F(PlatformSensorAndProviderLinuxTest, ...@@ -492,7 +492,7 @@ TEST_F(PlatformSensorAndProviderLinuxTest,
SetServiceStart(); SetServiceStart();
auto sensor = CreateSensor(SensorType::AMBIENT_LIGHT); auto sensor = CreateSensor(SensorType::AMBIENT_LIGHT);
EXPECT_TRUE(sensor); ASSERT_TRUE(sensor);
EXPECT_EQ(SensorType::AMBIENT_LIGHT, sensor->GetType()); EXPECT_EQ(SensorType::AMBIENT_LIGHT, sensor->GetType());
EXPECT_THAT(sensor->GetMaximumSupportedFrequency(), EXPECT_THAT(sensor->GetMaximumSupportedFrequency(),
SensorTraits<SensorType::AMBIENT_LIGHT>::kDefaultFrequency); SensorTraits<SensorType::AMBIENT_LIGHT>::kDefaultFrequency);
...@@ -513,7 +513,7 @@ TEST_F(PlatformSensorAndProviderLinuxTest, CheckAmbientLightReadings) { ...@@ -513,7 +513,7 @@ TEST_F(PlatformSensorAndProviderLinuxTest, CheckAmbientLightReadings) {
SetServiceStart(); SetServiceStart();
auto sensor = CreateSensor(SensorType::AMBIENT_LIGHT); auto sensor = CreateSensor(SensorType::AMBIENT_LIGHT);
EXPECT_TRUE(sensor); ASSERT_TRUE(sensor);
EXPECT_EQ(sensor->GetReportingMode(), mojom::ReportingMode::ON_CHANGE); EXPECT_EQ(sensor->GetReportingMode(), mojom::ReportingMode::ON_CHANGE);
auto client = auto client =
...@@ -555,7 +555,7 @@ TEST_F(PlatformSensorAndProviderLinuxTest, ...@@ -555,7 +555,7 @@ TEST_F(PlatformSensorAndProviderLinuxTest,
SetServiceStart(); SetServiceStart();
auto sensor = CreateSensor(SensorType::ACCELEROMETER); auto sensor = CreateSensor(SensorType::ACCELEROMETER);
EXPECT_TRUE(sensor); ASSERT_TRUE(sensor);
// The reporting mode is ON_CHANGE only for this test. // The reporting mode is ON_CHANGE only for this test.
EXPECT_EQ(sensor->GetReportingMode(), mojom::ReportingMode::ON_CHANGE); EXPECT_EQ(sensor->GetReportingMode(), mojom::ReportingMode::ON_CHANGE);
...@@ -616,7 +616,7 @@ TEST_F(PlatformSensorAndProviderLinuxTest, CheckLinearAcceleration) { ...@@ -616,7 +616,7 @@ TEST_F(PlatformSensorAndProviderLinuxTest, CheckLinearAcceleration) {
SetServiceStart(); SetServiceStart();
auto sensor = CreateSensor(SensorType::LINEAR_ACCELERATION); auto sensor = CreateSensor(SensorType::LINEAR_ACCELERATION);
EXPECT_TRUE(sensor); ASSERT_TRUE(sensor);
EXPECT_EQ(sensor->GetReportingMode(), mojom::ReportingMode::CONTINUOUS); EXPECT_EQ(sensor->GetReportingMode(), mojom::ReportingMode::CONTINUOUS);
auto client = auto client =
...@@ -662,7 +662,7 @@ TEST_F(PlatformSensorAndProviderLinuxTest, CheckGyroscopeReadingConversion) { ...@@ -662,7 +662,7 @@ TEST_F(PlatformSensorAndProviderLinuxTest, CheckGyroscopeReadingConversion) {
SetServiceStart(); SetServiceStart();
auto sensor = CreateSensor(SensorType::GYROSCOPE); auto sensor = CreateSensor(SensorType::GYROSCOPE);
EXPECT_TRUE(sensor); ASSERT_TRUE(sensor);
// The reporting mode is ON_CHANGE only for this test. // The reporting mode is ON_CHANGE only for this test.
EXPECT_EQ(sensor->GetReportingMode(), mojom::ReportingMode::ON_CHANGE); EXPECT_EQ(sensor->GetReportingMode(), mojom::ReportingMode::ON_CHANGE);
...@@ -716,7 +716,7 @@ TEST_F(PlatformSensorAndProviderLinuxTest, CheckMagnetometerReadingConversion) { ...@@ -716,7 +716,7 @@ TEST_F(PlatformSensorAndProviderLinuxTest, CheckMagnetometerReadingConversion) {
SetServiceStart(); SetServiceStart();
auto sensor = CreateSensor(SensorType::MAGNETOMETER); auto sensor = CreateSensor(SensorType::MAGNETOMETER);
EXPECT_TRUE(sensor); ASSERT_TRUE(sensor);
// The reporting mode is ON_CHANGE only for this test. // The reporting mode is ON_CHANGE only for this test.
EXPECT_EQ(sensor->GetReportingMode(), mojom::ReportingMode::ON_CHANGE); EXPECT_EQ(sensor->GetReportingMode(), mojom::ReportingMode::ON_CHANGE);
...@@ -760,7 +760,7 @@ TEST_F(PlatformSensorAndProviderLinuxTest, ...@@ -760,7 +760,7 @@ TEST_F(PlatformSensorAndProviderLinuxTest,
SetServiceStart(); SetServiceStart();
auto sensor = CreateSensor(SensorType::AMBIENT_LIGHT); auto sensor = CreateSensor(SensorType::AMBIENT_LIGHT);
EXPECT_TRUE(sensor); ASSERT_TRUE(sensor);
EXPECT_EQ(mojom::ReportingMode::CONTINUOUS, sensor->GetReportingMode()); EXPECT_EQ(mojom::ReportingMode::CONTINUOUS, sensor->GetReportingMode());
auto client = auto client =
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment