• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
34  protected:
VtsStructuralTestHalLightsBasicTest()35   VtsStructuralTestHalLightsBasicTest() {
36     int rc = hw_get_module_by_class(LIGHTS_HARDWARE_MODULE_ID, NULL, &module_);
37     if (rc || !module_) {
38       cerr << "could not find any lights HAL module." << endl;
39       module_ = NULL;
40       return;
41     }
42 
43     rc = module_->methods->open(
44         module_, LIGHT_ID_NOTIFICATIONS,
45         reinterpret_cast<struct hw_device_t**>(&device_));
46     if (rc || !device_) {
47       cerr << "could not open a lights HAL device." << endl;
48       module_ = NULL;
49       return;
50     }
51   }
52 
~VtsStructuralTestHalLightsBasicTest()53   virtual ~VtsStructuralTestHalLightsBasicTest() {
54   }
55 
SetUp()56   virtual void SetUp() {
57     // define operations to execute before running each testcase.
58   }
59 
TearDown()60   virtual void TearDown() {
61     // define operations to execute after running each testcase.
62   }
63 
64   // a light device which is open.
65   struct light_device_t* device_;
66 
67  private:
68   const struct hw_module_t* module_;
69 };
70 
TEST_F(VtsStructuralTestHalLightsBasicTest,example)71 TEST_F(VtsStructuralTestHalLightsBasicTest, example) {
72   ASSERT_TRUE(device_);
73   struct light_state_t* arg =
74       (struct light_state_t*) malloc(sizeof(struct light_state_t));
75   arg->color = 0x80ff8000;
76   arg->flashMode = LIGHT_FLASH_NONE;
77   arg->flashOnMS = 0;
78   arg->flashOffMS = 0;
79   arg->brightnessMode = BRIGHTNESS_MODE_USER;
80   EXPECT_EQ(0, device_->set_light(device_, arg));
81 }
82 
83 }  // namespace
84