1 /*
2 * Copyright (C) 2016 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 #include <gtest/gtest.h>
18
19 #include <stdio.h>
20 #include <stdlib.h>
21
22 #include <hardware/hardware.h>
23 #include <hardware/lights.h>
24
25 #include <iostream>
26
27 using namespace std;
28
29 namespace {
30
31 // VTS structural testcase for HAL Lights basic functionalities.
32 class VtsStructuralTestHalLightsBasicTest : public ::testing::Test {
33 protected:
VtsStructuralTestHalLightsBasicTest()34 VtsStructuralTestHalLightsBasicTest() {
35 int rc = hw_get_module_by_class(LIGHTS_HARDWARE_MODULE_ID, NULL, &module_);
36 if (rc || !module_) {
37 cerr << "could not find any lights HAL module." << endl;
38 module_ = NULL;
39 return;
40 }
41
42 rc = module_->methods->open(
43 module_, LIGHT_ID_NOTIFICATIONS,
44 reinterpret_cast<struct hw_device_t**>(&device_));
45 if (rc || !device_) {
46 cerr << "could not open a lights HAL device." << endl;
47 module_ = NULL;
48 return;
49 }
50 }
51
~VtsStructuralTestHalLightsBasicTest()52 virtual ~VtsStructuralTestHalLightsBasicTest() {}
53
SetUp()54 virtual void SetUp() {
55 // define operations to execute before running each testcase.
56 }
57
TearDown()58 virtual void TearDown() {
59 // define operations to execute after running each testcase.
60 }
61
62 // a light device which is open.
63 struct light_device_t* device_;
64
65 private:
66 const struct hw_module_t* module_;
67 };
68
TEST_F(VtsStructuralTestHalLightsBasicTest,example)69 TEST_F(VtsStructuralTestHalLightsBasicTest, example) {
70 ASSERT_TRUE(device_);
71 struct light_state_t* arg =
72 (struct light_state_t*)malloc(sizeof(struct light_state_t));
73 arg->color = 0x80ff8000;
74 arg->flashMode = LIGHT_FLASH_NONE;
75 arg->flashOnMS = 0;
76 arg->flashOffMS = 0;
77 arg->brightnessMode = BRIGHTNESS_MODE_USER;
78 EXPECT_EQ(0, device_->set_light(device_, arg));
79 }
80
81 } // namespace
82