fake_platform_sensor_fusion.cc 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "services/device/generic_sensor/fake_platform_sensor_fusion.h"
  5. #include "services/device/generic_sensor/platform_sensor_fusion_algorithm.h"
  6. #include "testing/gtest/include/gtest/gtest.h"
  7. namespace device {
  8. FakePlatformSensorFusion::FakePlatformSensorFusion(
  9. std::unique_ptr<PlatformSensorFusionAlgorithm> fusion_algorithm)
  10. : PlatformSensorFusion(nullptr,
  11. nullptr,
  12. std::move(fusion_algorithm),
  13. SourcesMap()) {}
  14. bool FakePlatformSensorFusion::GetSourceReading(mojom::SensorType type,
  15. SensorReading* result) {
  16. auto it = sensor_readings_.find(type);
  17. EXPECT_TRUE(it != sensor_readings_.end());
  18. if (it == sensor_readings_.end())
  19. return false;
  20. if (!it->second.second)
  21. return false;
  22. *result = it->second.first;
  23. return true;
  24. }
  25. void FakePlatformSensorFusion::SetSensorReading(mojom::SensorType type,
  26. SensorReading reading,
  27. bool sensor_reading_success) {
  28. sensor_readings_[type] = std::make_pair(reading, sensor_reading_success);
  29. }
  30. FakePlatformSensorFusion::~FakePlatformSensorFusion() = default;
  31. } // namespace device