1*23dee383SShawn McCarney /**
2*23dee383SShawn McCarney * Copyright © 2024 IBM Corporation
3*23dee383SShawn McCarney *
4*23dee383SShawn McCarney * Licensed under the Apache License, Version 2.0 (the "License");
5*23dee383SShawn McCarney * you may not use this file except in compliance with the License.
6*23dee383SShawn McCarney * You may obtain a copy of the License at
7*23dee383SShawn McCarney *
8*23dee383SShawn McCarney * http://www.apache.org/licenses/LICENSE-2.0
9*23dee383SShawn McCarney *
10*23dee383SShawn McCarney * Unless required by applicable law or agreed to in writing, software
11*23dee383SShawn McCarney * distributed under the License is distributed on an "AS IS" BASIS,
12*23dee383SShawn McCarney * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*23dee383SShawn McCarney * See the License for the specific language governing permissions and
14*23dee383SShawn McCarney * limitations under the License.
15*23dee383SShawn McCarney */
16*23dee383SShawn McCarney #include "../utils.hpp"
17*23dee383SShawn McCarney
18*23dee383SShawn McCarney #include <stdexcept>
19*23dee383SShawn McCarney #include <tuple>
20*23dee383SShawn McCarney
21*23dee383SShawn McCarney #include <gtest/gtest.h>
22*23dee383SShawn McCarney
23*23dee383SShawn McCarney using namespace utils;
24*23dee383SShawn McCarney
TEST(TestUtils,getDeviceName)25*23dee383SShawn McCarney TEST(TestUtils, getDeviceName)
26*23dee383SShawn McCarney {
27*23dee383SShawn McCarney auto ret = getDeviceName("");
28*23dee383SShawn McCarney EXPECT_TRUE(ret.empty());
29*23dee383SShawn McCarney
30*23dee383SShawn McCarney ret = getDeviceName("/sys/bus/i2c/devices/3-0069");
31*23dee383SShawn McCarney EXPECT_EQ("3-0069", ret);
32*23dee383SShawn McCarney
33*23dee383SShawn McCarney ret = getDeviceName("/sys/bus/i2c/devices/3-0069/");
34*23dee383SShawn McCarney EXPECT_EQ("3-0069", ret);
35*23dee383SShawn McCarney }
36*23dee383SShawn McCarney
TEST(TestUtils,parseDeviceName)37*23dee383SShawn McCarney TEST(TestUtils, parseDeviceName)
38*23dee383SShawn McCarney {
39*23dee383SShawn McCarney auto [id, addr] = parseDeviceName("3-0068");
40*23dee383SShawn McCarney EXPECT_EQ(3, id);
41*23dee383SShawn McCarney EXPECT_EQ(0x68, addr);
42*23dee383SShawn McCarney
43*23dee383SShawn McCarney std::tie(id, addr) = parseDeviceName("11-0069");
44*23dee383SShawn McCarney EXPECT_EQ(11, id);
45*23dee383SShawn McCarney EXPECT_EQ(0x69, addr);
46*23dee383SShawn McCarney
47*23dee383SShawn McCarney EXPECT_THROW(parseDeviceName("no-number"), std::invalid_argument);
48*23dee383SShawn McCarney
49*23dee383SShawn McCarney EXPECT_DEATH(parseDeviceName("invalid"), "");
50*23dee383SShawn McCarney }
51