summaryrefslogtreecommitdiff
path: root/src/drivers/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/drivers/test')
-rw-r--r--src/drivers/test/CMakeLists.txt2
-rw-r--r--src/drivers/test/test_adc.cpp (renamed from src/drivers/test/test_battery.cpp)8
-rw-r--r--src/drivers/test/test_dac.cpp16
-rw-r--r--src/drivers/test/test_gpio_expander.cpp31
-rw-r--r--src/drivers/test/test_storage.cpp16
5 files changed, 21 insertions, 52 deletions
diff --git a/src/drivers/test/CMakeLists.txt b/src/drivers/test/CMakeLists.txt
index 90e7b3a1..ff1dab0b 100644
--- a/src/drivers/test/CMakeLists.txt
+++ b/src/drivers/test/CMakeLists.txt
@@ -3,5 +3,5 @@
# SPDX-License-Identifier: GPL-3.0-only
idf_component_register(
- SRCS "test_storage.cpp" "test_gpio_expander.cpp" "test_battery.cpp" "test_dac.cpp"
+ SRCS "test_adc.cpp" "test_storage.cpp" "test_dac.cpp"
INCLUDE_DIRS "." REQUIRES catch2 cmock drivers fixtures)
diff --git a/src/drivers/test/test_battery.cpp b/src/drivers/test/test_adc.cpp
index 690eb2b7..df103af3 100644
--- a/src/drivers/test/test_battery.cpp
+++ b/src/drivers/test/test_adc.cpp
@@ -4,7 +4,7 @@
* SPDX-License-Identifier: GPL-3.0-only
*/
-#include "battery.hpp"
+#include "drivers/adc.hpp"
#include <cstdint>
@@ -13,12 +13,12 @@
namespace drivers {
TEST_CASE("battery measurement", "[integration]") {
- Battery battery;
+ AdcBattery battery;
SECTION("voltage is within range") {
uint32_t mv = battery.Millivolts();
- REQUIRE(mv <= 2200); // Plugged in, no battery.
- REQUIRE(mv >= 1000);
+ REQUIRE(mv <= 4210); // Should never be charged above this.
+ REQUIRE(mv >= 3000); // Should never be discharged below this.
}
}
diff --git a/src/drivers/test/test_dac.cpp b/src/drivers/test/test_dac.cpp
index 2269f280..11c69c14 100644
--- a/src/drivers/test/test_dac.cpp
+++ b/src/drivers/test/test_dac.cpp
@@ -4,7 +4,8 @@
* SPDX-License-Identifier: GPL-3.0-only
*/
-#include "dac.hpp"
+#include <stdint.h>
+#include "drivers/wm8523.hpp"
#include <cstdint>
@@ -16,16 +17,15 @@
namespace drivers {
-TEST_CASE("dac configuration", "[integration]") {
+TEST_CASE("dac is present", "[integration]") {
I2CFixture i2c;
- IGpios expander;
- cpp::result<AudioDac*, AudioDac::Error> dac_res = AudioDac::create(&expander);
- REQUIRE(dac_res.has_value());
- std::unique_ptr<AudioDac> dac(dac_res.value());
- auto power_state = dac->ReadPowerState();
+ SECTION("device id is correct") {
+ auto res = wm8523::ReadRegister(wm8523::Register::kReset);
- REQUIRE(power_state.first == true); // booted
+ REQUIRE(res.has_value());
+ REQUIRE(res.value() == 0x8523);
+ }
}
} // namespace drivers
diff --git a/src/drivers/test/test_gpio_expander.cpp b/src/drivers/test/test_gpio_expander.cpp
deleted file mode 100644
index 7c323313..00000000
--- a/src/drivers/test/test_gpio_expander.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright 2023 jacqueline <me@jacqueline.id.au>
- *
- * SPDX-License-Identifier: GPL-3.0-only
- */
-
-#include "drivers/gpios.hpp"
-
-#include "catch2/catch.hpp"
-
-#include "drivers/i2c.hpp"
-#include "i2c_fixture.hpp"
-
-namespace drivers {
-
-TEST_CASE("gpio expander", "[integration]") {
- I2CFixture i2c;
- IGpios expander;
- SECTION("with() writes when ") {
- // Initial value.
- expander.Read();
- REQUIRE(expander.get_input(IGpios::KEY_DOWN) == true);
-
- expander.with([&](auto& gpio) { gpio.set_pin(IGpios::KEY_DOWN, false); });
-
- expander.Read();
- REQUIRE(expander.get_input(IGpios::KEY_DOWN) == false);
- }
-}
-
-} // namespace drivers
diff --git a/src/drivers/test/test_storage.cpp b/src/drivers/test/test_storage.cpp
index f97a0a85..5af40052 100644
--- a/src/drivers/test/test_storage.cpp
+++ b/src/drivers/test/test_storage.cpp
@@ -22,31 +22,31 @@
namespace drivers {
-static const std::pmr::string kTestFilename = "test";
-static const std::pmr::string kTestFilePath =
- std::pmr::string(kStoragePath) + "/" + kTestFilename;
+static const std::string kTestFilename = "test";
+static const std::string kTestFilePath =
+ std::string(kStoragePath) + "/" + kTestFilename;
TEST_CASE("sd card storage", "[integration]") {
I2CFixture i2c;
SpiFixture spi;
- IGpios expander;
+ std::unique_ptr<IGpios> gpios{Gpios::Create(false)};
{
- std::unique_ptr<SdStorage> result(SdStorage::create(&expander).value());
+ std::unique_ptr<SdStorage> result(SdStorage::Create(*gpios).value());
SECTION("write to a file") {
{
std::ofstream test_file;
- test_file.open(kTestFilePath.c_str());
+ test_file.open(kTestFilePath);
test_file << "hello here is some test";
test_file.close();
}
SECTION("read from a file") {
std::ifstream test_file;
- test_file.open(kTestFilePath.c_str());
+ test_file.open(kTestFilePath);
- std::pmr::string line;
+ std::string line;
REQUIRE(std::getline(test_file, line));
REQUIRE(line == "hello here is some test");