From 8db57d6dc5cf5c83cffd393a37ca37bc1a67f1af Mon Sep 17 00:00:00 2001 From: jacqueline Date: Tue, 25 Jun 2024 15:23:51 +1000 Subject: Unbreak the tests build --- src/drivers/test/CMakeLists.txt | 2 +- src/drivers/test/test_adc.cpp | 25 +++++++++++++++++++++++++ src/drivers/test/test_battery.cpp | 25 ------------------------- src/drivers/test/test_dac.cpp | 16 ++++++++-------- src/drivers/test/test_gpio_expander.cpp | 31 ------------------------------- src/drivers/test/test_storage.cpp | 16 ++++++++-------- 6 files changed, 42 insertions(+), 73 deletions(-) create mode 100644 src/drivers/test/test_adc.cpp delete mode 100644 src/drivers/test/test_battery.cpp delete mode 100644 src/drivers/test/test_gpio_expander.cpp (limited to 'src/drivers/test') 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_adc.cpp b/src/drivers/test/test_adc.cpp new file mode 100644 index 00000000..df103af3 --- /dev/null +++ b/src/drivers/test/test_adc.cpp @@ -0,0 +1,25 @@ +/* + * Copyright 2023 jacqueline + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#include "drivers/adc.hpp" + +#include + +#include "catch2/catch.hpp" + +namespace drivers { + +TEST_CASE("battery measurement", "[integration]") { + AdcBattery battery; + + SECTION("voltage is within range") { + uint32_t mv = battery.Millivolts(); + REQUIRE(mv <= 4210); // Should never be charged above this. + REQUIRE(mv >= 3000); // Should never be discharged below this. + } +} + +} // namespace drivers diff --git a/src/drivers/test/test_battery.cpp b/src/drivers/test/test_battery.cpp deleted file mode 100644 index 690eb2b7..00000000 --- a/src/drivers/test/test_battery.cpp +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2023 jacqueline - * - * SPDX-License-Identifier: GPL-3.0-only - */ - -#include "battery.hpp" - -#include - -#include "catch2/catch.hpp" - -namespace drivers { - -TEST_CASE("battery measurement", "[integration]") { - Battery battery; - - SECTION("voltage is within range") { - uint32_t mv = battery.Millivolts(); - REQUIRE(mv <= 2200); // Plugged in, no battery. - REQUIRE(mv >= 1000); - } -} - -} // namespace drivers 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 +#include "drivers/wm8523.hpp" #include @@ -16,16 +17,15 @@ namespace drivers { -TEST_CASE("dac configuration", "[integration]") { +TEST_CASE("dac is present", "[integration]") { I2CFixture i2c; - IGpios expander; - cpp::result dac_res = AudioDac::create(&expander); - REQUIRE(dac_res.has_value()); - std::unique_ptr 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 - * - * 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 gpios{Gpios::Create(false)}; { - std::unique_ptr result(SdStorage::create(&expander).value()); + std::unique_ptr 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"); -- cgit v1.2.3