blob: a9572bafb8e6cdb2f68cc127e435e03d9c8ddd18 [file] [log] [blame]
Sanket Agarwalfb636682015-08-11 14:34:29 -07001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef __ANDROID_HAL_VEHICLE_TEST_
18#define __ANDROID_HAL_VEHICLE_TEST_
19
20#include <gtest/gtest.h>
21#include <hardware/hardware.h>
22#include <hardware/vehicle.h>
23
24namespace tests {
25
26static const uint64_t kVersion = HARDWARE_DEVICE_API_VERSION_2(1, 0, 1);
27
28class VehicleModule : public testing::Test {
29public:
30 VehicleModule() :
31 vehicle_module_(NULL) {}
32 ~VehicleModule() {}
33protected:
34 virtual void SetUp() {
35 const hw_module_t *hw_module = NULL;
36 ASSERT_EQ(0, hw_get_module(VEHICLE_HARDWARE_MODULE_ID, &hw_module))
37 << "Can't get vehicle module";
38 ASSERT_TRUE(NULL != hw_module)
39 << "hw_get_module didn't return a valid hardware module";
40
41 vehicle_module_ = reinterpret_cast<const vehicle_module_t*>(hw_module);
42 }
43 const vehicle_module_t* vehicle_module() { return vehicle_module_; }
44private:
45 const vehicle_module_t* vehicle_module_;
46};
47
48
49int VehicleEventCallback(const vehicle_prop_value_t* event_data) {
50 // Print what we got.
51 std::cout << "got some value from callback: "
52 << event_data->prop
53 << " uint32 value: "
54 << event_data->value.int32_value << "\n";
55 return 0;
56}
57
Keun-young Park77761e22016-03-08 15:02:44 -080058 int VehicleErrorCallback(int32_t /*error_code*/, int32_t /*property*/, int32_t /*operation*/) {
Sanket Agarwalfb636682015-08-11 14:34:29 -070059 // Do nothing.
60 return 0;
61}
62
63class VehicleDevice : public VehicleModule {
64public:
65 VehicleDevice() :
66 vehicle_device_(NULL) {}
67 ~VehicleDevice() {}
68protected:
69 virtual void SetUp() {
70 VehicleModule::SetUp();
71 hw_device_t *device = NULL;
72 ASSERT_TRUE(NULL != vehicle_module()->common.methods->open)
73 << "Vehicle open() is unimplemented";
74 ASSERT_EQ(0, vehicle_module()->common.methods->open(
75 (const hw_module_t*)vehicle_module(), NULL, &device))
76 << "Can't open vehicle device";
77 ASSERT_TRUE(NULL != device)
78 << "Vehicle open() returned a NULL device";
79 ASSERT_EQ(kVersion, device->version)
80 << "Unsupported version";
81 vehicle_device_ = reinterpret_cast<vehicle_hw_device_t*>(device);
82 }
83 vehicle_hw_device_t* vehicle_device() { return vehicle_device_; }
84 vehicle_event_callback_fn callback_fn() {
85 return VehicleEventCallback;
86 }
87 vehicle_error_callback_fn error_fn() {
88 return VehicleErrorCallback;
89 }
90
91 private:
92 vehicle_hw_device_t* vehicle_device_;
93};
94
95} // namespace tests
96
97#endif // __ANDROID_HAL_VEHICLE_TEST_