-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeviceTest.cpp
More file actions
123 lines (109 loc) · 4.32 KB
/
deviceTest.cpp
File metadata and controls
123 lines (109 loc) · 4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
* Copyright 2025 Comcast Cable Communications Management, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "json_types/device.h"
#include "firebolt/firebolt.h"
#include "json_engine.h"
#include "utils.h"
#include <gtest/gtest.h>
#include <iostream>
class DeviceCTest : public ::testing::Test
{
protected:
void SetUp() override { eventReceived = false; }
std::condition_variable cv;
std::mutex mtx;
bool eventReceived;
JsonEngine jsonEngine;
};
TEST_F(DeviceCTest, ChipsetId)
{
auto expectedValue = jsonEngine.get_value("Device.chipsetId");
auto result = Firebolt::IFireboltAccessor::Instance().DeviceInterface().chipsetId();
ASSERT_TRUE(result) << "DeviceImpl::chipsetId() returned an error";
EXPECT_EQ(*result, expectedValue);
}
TEST_F(DeviceCTest, DeviceClass)
{
auto expectedValue = jsonEngine.get_value("Device.deviceClass");
auto result = Firebolt::IFireboltAccessor::Instance().DeviceInterface().deviceClass();
ASSERT_TRUE(result) << "DeviceImpl::deviceClass() returned an error";
EXPECT_EQ(static_cast<int>(*result), static_cast<int>(Firebolt::Device::JsonData::DeviceClassEnum.at(expectedValue)));
}
TEST_F(DeviceCTest, Hdr)
{
auto expectedValue = jsonEngine.get_value("Device.hdr");
auto result = Firebolt::IFireboltAccessor::Instance().DeviceInterface().hdr();
ASSERT_TRUE(result) << "DeviceImpl::hdr() returned an error";
EXPECT_EQ(result->hdr10, expectedValue["hdr10"].get<bool>());
EXPECT_EQ(result->hdr10Plus, expectedValue["hdr10Plus"].get<bool>());
EXPECT_EQ(result->dolbyVision, expectedValue["dolbyVision"].get<bool>());
EXPECT_EQ(result->hlg, expectedValue["hlg"].get<bool>());
}
TEST_F(DeviceCTest, TimeInActiveState)
{
auto expectedValue = jsonEngine.get_value("Device.timeInActiveState");
auto result = Firebolt::IFireboltAccessor::Instance().DeviceInterface().timeInActiveState();
ASSERT_TRUE(result) << "DeviceImpl::timeInActiveState() returned an error";
if (expectedValue.empty())
{
std::cout << "[ !!! ] Expected is empty, received: " << *result << std::endl;
return;
}
EXPECT_EQ(*result, expectedValue);
}
TEST_F(DeviceCTest, Uid)
{
auto expectedValue = jsonEngine.get_value("Device.uid");
auto result = Firebolt::IFireboltAccessor::Instance().DeviceInterface().uid();
ASSERT_TRUE(result) << "DeviceImpl::uid() returned an error";
EXPECT_EQ(*result, expectedValue);
}
TEST_F(DeviceCTest, Uptime)
{
auto expectedValue = jsonEngine.get_value("Device.uptime");
auto result = Firebolt::IFireboltAccessor::Instance().DeviceInterface().uptime();
ASSERT_TRUE(result) << "DeviceImpl::uptime() returned an error";
if (expectedValue.empty())
{
std::cout << "[ !!! ] Expected is empty, received: " << *result << std::endl;
return;
}
EXPECT_EQ(*result, expectedValue);
}
TEST_F(DeviceCTest, SubscribeOnHdrChanged)
{
auto id = Firebolt::IFireboltAccessor::Instance().DeviceInterface().subscribeOnHdrChanged(
[&](const Firebolt::Device::HDRFormat& value)
{
std::cout << "[Subscription] Device HDR changed" << std::endl;
EXPECT_EQ(value.hdr10, true);
EXPECT_EQ(value.hdr10Plus, true);
EXPECT_EQ(value.dolbyVision, true);
EXPECT_EQ(value.hlg, true);
{
std::lock_guard<std::mutex> lock(mtx);
eventReceived = true;
}
cv.notify_one();
});
verifyEventSubscription(id);
triggerEvent("Device.onHdrChanged", R"({"hdr10": true, "hdr10Plus": true, "dolbyVision": true, "hlg": true})");
verifyEventReceived(mtx, cv, eventReceived);
auto result = Firebolt::IFireboltAccessor::Instance().DeviceInterface().unsubscribe(id.value());
verifyUnsubscribeResult(result);
}