blob: fb92fd7daf9aa156f73b763611d5b596b0ce7815 [file] [log] [blame]
Shawn McCarneya2461b32019-10-24 18:53:01 -05001/**
2 * Copyright © 2019 IBM Corporation
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#include "device.hpp"
Shawn McCarneyafb7fc32019-12-11 19:42:03 -060017#include "i2c_interface.hpp"
18#include "mocked_i2c_interface.hpp"
19
20#include <memory>
21#include <utility>
Shawn McCarneya2461b32019-10-24 18:53:01 -050022
23#include <gtest/gtest.h>
24
25using namespace phosphor::power::regulators;
26
Shawn McCarneyafb7fc32019-12-11 19:42:03 -060027/**
28 * Create an I2CInterface object with hard-coded bus and address values.
29 *
30 * @return I2CInterface object wrapped in a unique_ptr
31 */
32std::unique_ptr<i2c::I2CInterface> createI2CInterface()
33{
34 std::unique_ptr<i2c::I2CInterface> i2cInterface =
35 i2c::create(1, 0x70, i2c::I2CInterface::InitialState::CLOSED);
36 return i2cInterface;
37}
38
Shawn McCarneya2461b32019-10-24 18:53:01 -050039TEST(DeviceTests, Constructor)
40{
Shawn McCarneyafb7fc32019-12-11 19:42:03 -060041 std::unique_ptr<i2c::I2CInterface> i2cInterface = createI2CInterface();
42 i2c::I2CInterface* i2cInterfacePtr = i2cInterface.get();
43 Device device{"vdd_reg", true, "/system/chassis/motherboard/reg2",
44 std::move(i2cInterface)};
45 EXPECT_EQ(device.getID(), "vdd_reg");
46 EXPECT_EQ(device.isRegulator(), true);
47 EXPECT_EQ(device.getFRU(), "/system/chassis/motherboard/reg2");
48 EXPECT_EQ(&(device.getI2CInterface()), i2cInterfacePtr);
Shawn McCarneya2461b32019-10-24 18:53:01 -050049}
50
Shawn McCarney4afb2852019-10-27 18:28:53 -050051TEST(DeviceTests, GetID)
Shawn McCarneya2461b32019-10-24 18:53:01 -050052{
Shawn McCarneyafb7fc32019-12-11 19:42:03 -060053 Device device{"vdd_reg", false, "/system/chassis/motherboard/reg2",
54 std::move(createI2CInterface())};
55 EXPECT_EQ(device.getID(), "vdd_reg");
56}
57
58TEST(DeviceTests, IsRegulator)
59{
60 Device device{"vdd_reg", false, "/system/chassis/motherboard/reg2",
61 std::move(createI2CInterface())};
62 EXPECT_EQ(device.isRegulator(), false);
63}
64
65TEST(DeviceTests, GetFRU)
66{
67 Device device{"vdd_reg", true, "/system/chassis/motherboard/reg2",
68 std::move(createI2CInterface())};
69 EXPECT_EQ(device.getFRU(), "/system/chassis/motherboard/reg2");
70}
71
72TEST(DeviceTests, GetI2CInterface)
73{
74 std::unique_ptr<i2c::I2CInterface> i2cInterface = createI2CInterface();
75 i2c::I2CInterface* i2cInterfacePtr = i2cInterface.get();
76 Device device{"vdd_reg", true, "/system/chassis/motherboard/reg2",
77 std::move(i2cInterface)};
78 EXPECT_EQ(&(device.getI2CInterface()), i2cInterfacePtr);
Shawn McCarneya2461b32019-10-24 18:53:01 -050079}