feat: added Sysfs reader stub and tests, builds cleanly
This commit is contained in:
parent
17133281d2
commit
f04de7ea34
15
src/core/SysfsRead.cxx
Normal file
15
src/core/SysfsRead.cxx
Normal 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;
|
||||||
|
}
|
||||||
@ -3,3 +3,75 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
#include "SysfsRead.hpp"
|
#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);
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user