blob: 6b152c002407265de7e57c052a10ceed663924d3 [file] [log] [blame]
Harvey Yang9260b662019-08-12 15:48:03 +08001// Copyright 2019 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <gtest/gtest.h>
6
7#include "libmems/common_types.h"
8#include "libmems/test_fakes.h"
9
10namespace libmems {
11
12namespace {
13
14constexpr char kFakeDeviceName[] = "iio:device0";
15constexpr int kFakeDeviceId = 0;
16
17constexpr char kTrigger0Attr[] = "trigger0";
18constexpr char kTrigger1Attr[] = "trigger1";
19constexpr char kTrigger12Attr[] = "trigger12";
20
21constexpr char kDevice0Attr[] = "iio:device0";
22constexpr char kDevice1Attr[] = "iio:device1";
23constexpr char kDevice12Attr[] = "iio:device12";
24
25class IioDeviceTest : public fakes::FakeIioDevice, public ::testing::Test {
26 public:
27 static base::Optional<int> GetIdAfterPrefix(const char* id_str,
28 const char* prefix) {
29 return IioDevice::GetIdAfterPrefix(id_str, prefix);
30 }
31
32 IioDeviceTest()
33 : fakes::FakeIioDevice(nullptr, kFakeDeviceName, kFakeDeviceId),
34 ::testing::Test() {}
35};
36
37TEST_F(IioDeviceTest, GetIdAfterPrefixTest) {
38 EXPECT_EQ(GetIdAfterPrefix(kTrigger0Attr, kTriggerIdPrefix), 0);
39 EXPECT_EQ(GetIdAfterPrefix(kTrigger1Attr, kTriggerIdPrefix), 1);
40 EXPECT_EQ(GetIdAfterPrefix(kTrigger12Attr, kTriggerIdPrefix), 12);
41
42 EXPECT_EQ(GetIdAfterPrefix(kDevice0Attr, kDeviceIdPrefix), 0);
43 EXPECT_EQ(GetIdAfterPrefix(kDevice1Attr, kDeviceIdPrefix), 1);
44 EXPECT_EQ(GetIdAfterPrefix(kDevice12Attr, kDeviceIdPrefix), 12);
45}
46
47} // namespace
48
49} // namespace libmems