feat: added Sysfs reader stub and tests, builds cleanly

This commit is contained in:
unai_71 2026-03-10 16:24:35 +00:00
parent 17133281d2
commit f04de7ea34
2 changed files with 87 additions and 0 deletions

15
src/core/SysfsRead.cxx Normal file
View File

@ -0,0 +1,15 @@
// SysfsRead.cxx
// SPDX-License-Identifier: GPL-3.0-or-later
// Author: Unai Blazquez <unaibg2000@gmail.com>
#include "SysfsRead.hpp"
SysfsReader::SysfsReader(const std::filesystem::path& input_path)
: m_path(input_path)
{
}
SysfsStatus SysfsReader::read_status() const
{
return SysfsStatus::UnexpectedValue;
}

View File

@ -3,3 +3,75 @@
#include <fstream>
#include "SysfsRead.hpp"
TEST(SysfsReaderTest, ReturnsEnabledWhenFileContainsOne)
{
// Arrange create the file and write "1\n" into it.
{
std::ofstream out("fake_sysfs_input");
out << "1\n";
// out is closed automatically at the end of this scope
}
// 2) Act: construct the reader and read the status.
SysfsReader reader{"fake_sysfs_input"};
SysfsStatus status = reader.read_status();
// 3) Assert: we expect Enabled.
EXPECT_EQ(status, SysfsStatus::Enabled);
}
TEST(SysfsReaderTest, ReturnsEmptyWhenFileIsEmpty)
{
// Arrange: create the file and don't write anything
{
std::ofstream out("fake_sysfs_input");
out << "";
}
SysfsReader reader{"fake_sysfs_input"};
SysfsStatus status1 = reader.read_status();
{
std::ofstream out("fake_sysfs_input");
out << " ";
}
SysfsReader reader_2{"fake_sysfs_input"};
SysfsStatus status2 = reader_2.read_status();
// Assert
EXPECT_EQ(status1, SysfsStatus::Empty);
EXPECT_EQ(status2, SysfsStatus::Empty);
}
TEST(SysfsReaderTest, ReturnsUnexpectedValue)
{
{
std::ofstream out("fake_sysfs_input");
out << "tdd development";
}
SysfsReader reader{"fake_sysfs_input"};
SysfsStatus status = reader.read_status();
// Assert
EXPECT_EQ(status, SysfsStatus::UnexpectedValue);
}
TEST(SysfsReaderTest, ReturnsErrorTempTooHigh)
{
{
std::ofstream out("fake_sysfs_input");
out << "error: temp too high";
}
SysfsReader reader{"fake_sysfs_input"};
SysfsStatus status = reader.read_status();
// Assert
EXPECT_EQ(status, SysfsStatus::ErrorTempTooHigh);
}
TEST(SysfsReaderTest, ReturnsUnreachableWhenDoesntExist)
{
SysfsReader reader{"nonexistent_sysfs_input"};
SysfsStatus status = reader.read_status();
// Assert
EXPECT_EQ(status, SysfsStatus::Unreachable);
}