parent
34330daadf
commit
37041b810f
@ -1 +1,3 @@ |
|||||||
idf_component_register(SRCS "test_storage.cpp" INCLUDE_DIRS "." REQUIRES catch2 cmock drivers) |
idf_component_register( |
||||||
|
SRCS "test_storage.cpp" "test_gpio_expander.cpp" "test_battery.cpp" "test_dac.cpp" |
||||||
|
INCLUDE_DIRS "." REQUIRES catch2 cmock drivers) |
||||||
|
@ -0,0 +1,10 @@ |
|||||||
|
#pragma once |
||||||
|
|
||||||
|
#include "catch2/catch.hpp" |
||||||
|
#include "i2c.hpp" |
||||||
|
|
||||||
|
class I2CFixture { |
||||||
|
public: |
||||||
|
I2CFixture() { REQUIRE(drivers::init_i2c() == ESP_OK); } |
||||||
|
~I2CFixture() { drivers::deinit_i2c(); } |
||||||
|
}; |
@ -0,0 +1,10 @@ |
|||||||
|
#pragma once |
||||||
|
|
||||||
|
#include "catch2/catch.hpp" |
||||||
|
#include "spi.hpp" |
||||||
|
|
||||||
|
class SpiFixture { |
||||||
|
public: |
||||||
|
SpiFixture() { REQUIRE(drivers::init_spi() == ESP_OK); } |
||||||
|
~SpiFixture() { drivers::deinit_spi(); } |
||||||
|
}; |
@ -0,0 +1,18 @@ |
|||||||
|
#include <cstdint> |
||||||
|
#include "battery.hpp" |
||||||
|
|
||||||
|
#include "catch2/catch.hpp" |
||||||
|
|
||||||
|
namespace drivers { |
||||||
|
|
||||||
|
TEST_CASE("battery measurement", "[integration]") { |
||||||
|
REQUIRE(drivers::init_adc() == ESP_OK); |
||||||
|
|
||||||
|
SECTION("voltage is within range") { |
||||||
|
uint32_t voltage = read_battery_voltage(); |
||||||
|
REQUIRE(voltage <= 2200); // Plugged in, no battery.
|
||||||
|
REQUIRE(voltage >= 1000); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} // namespace drivers
|
@ -0,0 +1,21 @@ |
|||||||
|
#include <cstdint> |
||||||
|
#include "dac.hpp" |
||||||
|
#include "gpio-expander.hpp" |
||||||
|
#include "i2c.hpp" |
||||||
|
#include "i2c_fixture.hpp" |
||||||
|
|
||||||
|
#include "catch2/catch.hpp" |
||||||
|
|
||||||
|
namespace drivers { |
||||||
|
|
||||||
|
TEST_CASE("dac configuration", "[integration]") { |
||||||
|
I2CFixture i2c; |
||||||
|
GpioExpander expander; |
||||||
|
std::unique_ptr<AudioDac> dac = AudioDac::create(&expander).value(); |
||||||
|
|
||||||
|
auto power_state = dac->ReadPowerState(); |
||||||
|
|
||||||
|
REQUIRE(power_state.first == true); // booted
|
||||||
|
} |
||||||
|
|
||||||
|
} // namespace drivers
|
@ -0,0 +1,53 @@ |
|||||||
|
#include "gpio-expander.hpp" |
||||||
|
#include "i2c.hpp" |
||||||
|
#include "i2c_fixture.hpp" |
||||||
|
|
||||||
|
#include "catch2/catch.hpp" |
||||||
|
|
||||||
|
namespace drivers { |
||||||
|
|
||||||
|
TEST_CASE("gpio expander", "[integration]") { |
||||||
|
I2CFixture i2c; |
||||||
|
GpioExpander expander; |
||||||
|
SECTION("with() writes when ") { |
||||||
|
// Initial value.
|
||||||
|
expander.Read(); |
||||||
|
REQUIRE(expander.get_input(GpioExpander::GPIO_1) == true); |
||||||
|
|
||||||
|
expander.with( |
||||||
|
[&](auto& gpio) { gpio.set_pin(GpioExpander::GPIO_1, false); }); |
||||||
|
|
||||||
|
expander.Read(); |
||||||
|
REQUIRE(expander.get_input(GpioExpander::GPIO_1) == false); |
||||||
|
} |
||||||
|
|
||||||
|
SECTION("setting individual pins") { |
||||||
|
expander.set_pin(GpioExpander::GPIO_1, true); |
||||||
|
expander.set_pin(GpioExpander::GPIO_2, false); |
||||||
|
expander.set_pin(GpioExpander::GPIO_3, false); |
||||||
|
expander.set_pin(GpioExpander::GPIO_4, true); |
||||||
|
|
||||||
|
expander.Write(); |
||||||
|
expander.Read(); |
||||||
|
|
||||||
|
REQUIRE(expander.get_input(GpioExpander::GPIO_1) == true); |
||||||
|
REQUIRE(expander.get_input(GpioExpander::GPIO_2) == false); |
||||||
|
REQUIRE(expander.get_input(GpioExpander::GPIO_3) == false); |
||||||
|
REQUIRE(expander.get_input(GpioExpander::GPIO_4) == true); |
||||||
|
|
||||||
|
expander.set_pin(GpioExpander::GPIO_1, false); |
||||||
|
expander.set_pin(GpioExpander::GPIO_2, true); |
||||||
|
expander.set_pin(GpioExpander::GPIO_3, true); |
||||||
|
expander.set_pin(GpioExpander::GPIO_4, false); |
||||||
|
|
||||||
|
expander.Write(); |
||||||
|
expander.Read(); |
||||||
|
|
||||||
|
REQUIRE(expander.get_input(GpioExpander::GPIO_1) == false); |
||||||
|
REQUIRE(expander.get_input(GpioExpander::GPIO_2) == true); |
||||||
|
REQUIRE(expander.get_input(GpioExpander::GPIO_3) == true); |
||||||
|
REQUIRE(expander.get_input(GpioExpander::GPIO_4) == false); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} // namespace drivers
|
Loading…
Reference in new issue