From 525ed2ae1bc710e2a80de0fc10300da83d594ccb Mon Sep 17 00:00:00 2001 From: jacqueline Date: Tue, 25 Jun 2024 16:09:36 +1000 Subject: Add a basic overview of writing and running tests --- src/drivers/include/drivers/adc.hpp | 4 ++-- src/drivers/test/CMakeLists.txt | 2 +- src/drivers/test/test_adc.cpp | 2 +- src/drivers/test/test_samd.cpp | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 src/drivers/test/test_samd.cpp (limited to 'src/drivers') diff --git a/src/drivers/include/drivers/adc.hpp b/src/drivers/include/drivers/adc.hpp index 3e94a9ee..2fd8a626 100644 --- a/src/drivers/include/drivers/adc.hpp +++ b/src/drivers/include/drivers/adc.hpp @@ -22,12 +22,12 @@ class AdcBattery { public: static auto Create() -> AdcBattery* { return new AdcBattery(); } AdcBattery(); - ~AdcBattery(); + virtual ~AdcBattery(); /** * Returns the current battery level in millivolts. */ - auto Millivolts() -> uint32_t; + virtual auto Millivolts() -> uint32_t; private: adc_oneshot_unit_handle_t adc_handle_; diff --git a/src/drivers/test/CMakeLists.txt b/src/drivers/test/CMakeLists.txt index ff1dab0b..f18dc357 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_adc.cpp" "test_storage.cpp" "test_dac.cpp" + SRCS "test_adc.cpp" "test_storage.cpp" "test_dac.cpp" "test_samd.cpp" INCLUDE_DIRS "." REQUIRES catch2 cmock drivers fixtures) diff --git a/src/drivers/test/test_adc.cpp b/src/drivers/test/test_adc.cpp index df103af3..a8dad4bd 100644 --- a/src/drivers/test/test_adc.cpp +++ b/src/drivers/test/test_adc.cpp @@ -12,7 +12,7 @@ namespace drivers { -TEST_CASE("battery measurement", "[integration]") { +TEST_CASE("battery adc", "[integration]") { AdcBattery battery; SECTION("voltage is within range") { diff --git a/src/drivers/test/test_samd.cpp b/src/drivers/test/test_samd.cpp new file mode 100644 index 00000000..c466d88e --- /dev/null +++ b/src/drivers/test/test_samd.cpp @@ -0,0 +1,32 @@ +/* + * Copyright 2023 jacqueline + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#include "drivers/samd.hpp" + +#include + +#include "catch2/catch.hpp" + +#include "i2c_fixture.hpp" + +namespace drivers { + +TEST_CASE("samd21 interface", "[integration]") { + I2CFixture i2c; + auto samd = std::make_unique(); + + REQUIRE(samd); + + SECTION("usb reports connection") { + samd->UpdateUsbStatus(); + + auto status = samd->GetUsbStatus(); + + REQUIRE(status == Samd::UsbStatus::kAttachedIdle); + } +} + +} // namespace drivers -- cgit v1.2.3