5#include <gtest/gtest.h>
13class TemperatureCollectorTest :
public ::testing::Test {
15 void SetUp()
override {
16 collector_ = std::make_unique<temperature_collector>();
17 std::unordered_map<std::string, std::string> config;
25TEST_F(TemperatureCollectorTest, InitializesSuccessfully) {
30TEST_F(TemperatureCollectorTest, ReturnsCorrectMetricTypes) {
31 auto metric_types =
collector_->get_metric_types();
34 EXPECT_FALSE(metric_types.empty());
37 auto contains = [&metric_types](
const std::string& type) {
38 return std::find(metric_types.begin(), metric_types.end(), type) != metric_types.end();
41 EXPECT_TRUE(contains(
"temperature_celsius"));
42 EXPECT_TRUE(contains(
"temperature_critical_threshold"));
43 EXPECT_TRUE(contains(
"temperature_warning_threshold"));
44 EXPECT_TRUE(contains(
"temperature_is_critical"));
45 EXPECT_TRUE(contains(
"temperature_is_warning"));
49TEST_F(TemperatureCollectorTest, ConfigurationOptions) {
50 auto custom_collector = std::make_unique<temperature_collector>();
52 std::unordered_map<std::string, std::string> config = {
53 {
"enabled",
"true"}, {
"collect_thresholds",
"true"}, {
"collect_warnings",
"true"}};
55 EXPECT_TRUE(custom_collector->initialize(config));
59TEST_F(TemperatureCollectorTest, CanBeDisabled) {
60 auto custom_collector = std::make_unique<temperature_collector>();
62 std::unordered_map<std::string, std::string> config = {{
"enabled",
"false"}};
64 custom_collector->initialize(config);
67 auto metrics = custom_collector->collect();
68 EXPECT_TRUE(metrics.empty());
72TEST_F(TemperatureCollectorTest, TracksStatistics) {
76 EXPECT_TRUE(stats.find(
"collection_count") != stats.end());
77 EXPECT_TRUE(stats.find(
"collection_errors") != stats.end());
78 EXPECT_TRUE(stats.find(
"sensors_found") != stats.end());
81 EXPECT_EQ(stats[
"collection_count"], 0.0);
82 EXPECT_EQ(stats[
"collection_errors"], 0.0);
86TEST_F(TemperatureCollectorTest, CollectReturnsMetrics) {
92 EXPECT_GE(stats[
"collection_count"], 1.0);
96TEST_F(TemperatureCollectorTest, GetLastReadings) {
98 auto last_readings =
collector_->get_last_readings();
106TEST_F(TemperatureCollectorTest, ThermalAvailabilityCheck) {
108 bool available =
collector_->is_thermal_available();
113TEST(TemperatureReadingTest, DefaultInitialization) {
114 temperature_reading reading;
116 EXPECT_TRUE(reading.sensor.id.empty());
117 EXPECT_TRUE(reading.sensor.name.empty());
119 EXPECT_EQ(reading.temperature_celsius, 0.0);
120 EXPECT_EQ(reading.critical_threshold_celsius, 0.0);
121 EXPECT_EQ(reading.warning_threshold_celsius, 0.0);
122 EXPECT_FALSE(reading.thresholds_available);
123 EXPECT_FALSE(reading.is_critical);
124 EXPECT_FALSE(reading.is_warning);
128TEST(TemperatureSensorInfoTest, DefaultInitialization) {
129 temperature_sensor_info
info;
131 EXPECT_TRUE(
info.id.empty());
132 EXPECT_TRUE(
info.name.empty());
133 EXPECT_TRUE(
info.zone_path.empty());
138TEST(SensorTypeTest, TypeToStringConversion) {
149TEST(TemperatureInfoCollectorTest, BasicFunctionality) {
150 temperature_info_collector collector;
153 bool available = collector.is_thermal_available();
157 auto sensors = collector.enumerate_sensors();
158 EXPECT_TRUE(sensors.empty());
161 auto sensors = collector.enumerate_sensors();
168TEST(TemperatureInfoCollectorTest, EnumerateSensors) {
169 temperature_info_collector collector;
171 auto sensors = collector.enumerate_sensors();
179TEST_F(TemperatureCollectorTest, MultipleCollectionsAreStable) {
180 for (
int i = 0; i < 5; ++i) {
187 EXPECT_GE(stats[
"collection_count"], 5.0);
188 EXPECT_EQ(stats[
"collection_errors"], 0.0);
192TEST_F(TemperatureCollectorTest, MetricsHaveCorrectTags) {
195 for (
const auto& m : metrics) {
197 if (!m.name.empty()) {
198 EXPECT_TRUE(m.tags.find(
"sensor_id") != m.tags.end());
199 EXPECT_TRUE(m.tags.find(
"sensor_name") != m.tags.end());
200 EXPECT_TRUE(m.tags.find(
"sensor_type") != m.tags.end());
206TEST(TemperatureInfoCollectorTest, ReadAllTemperatures) {
207 temperature_info_collector collector;
209 auto readings = collector.read_all_temperatures();
213 for (
const auto& reading : readings) {
215 EXPECT_FALSE(reading.sensor.id.empty());
std::string sensor_type_to_string(sensor_type type)
Convert sensor_type to string representation.
@ info
Informational, no action required.
@ gpu
GPU temperature sensor.
@ motherboard
Motherboard/chipset sensor.
@ other
Other sensor type.
@ unknown
Unknown sensor type.
@ cpu
CPU temperature sensor.
@ storage
Storage device sensor.
@ ambient
Ambient/case temperature.
Hardware temperature monitoring collector.
TEST(AdapterFunctionalityTest, WorksWithoutLogger)
Test Scenario 1: Adapter with NULL logger.
TEST_F(AdaptiveMonitoringTest, AdaptiveConfigDefaults)
std::unique_ptr< battery_collector > collector_