test_spi_impl.cpp
Go to the documentation of this file.
#include <gtest/gtest.h>
#include <utl/com/spi_bb.h>
namespace test_spi {
using namespace utl;
// implementer class stub
class SPI : public spi_bb_i<SPI, spi::cpol::LOW, spi::cpha::LOW> {
friend spi_bb_i<SPI, spi::cpol::LOW, spi::cpha::LOW>;
void MOSI (bool st) { (void)st; } // Imaginary pin functionality
bool MISO () { return true; } // All reads become 0xFF
void SCLK (bool st) { (void)st; } // Imaginary pin functionality
void delay (uint32_t nsec) { (void)nsec; } // Imaginary delay functionality
public:
SPI (uint32_t clk =100000) noexcept : // expect 100000 default constructed clock
spi_bb_i<SPI, spi::cpol::LOW, spi::cpha::LOW>(clk) {
}
};
// fixture
class Test_spi_impl : public ::testing::Test {
protected:
//void SetUp() override { }
//void TearDown() override { }
SPI spi {};
};
TEST_F(Test_spi_impl, TestConcept) {
// EXPECT_EQ(Spi_i<SPI>, true);
}
TEST_F(Test_spi_impl, TestConstruction) {
EXPECT_EQ(spi.clock(), 100000UL);
}
TEST_F (Test_spi_impl, TestFunctionality) {
uint8_t b = 42;
uint8_t bb[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
uint8_t bbb[sizeof bb];
spi.clock(500000UL);
EXPECT_EQ(spi.clock(), 500000UL);
EXPECT_EQ(spi.tx_data(b), 0xFF);
EXPECT_EQ(spi.tx_data(bb, bbb, sizeof(bb)), sizeof (bb));
EXPECT_EQ(spi.rx_data(), 0xFF);
spi.rx_data(bbb, sizeof bb);
for (unsigned int i=0 ; i<sizeof bb ; ++i) {
EXPECT_EQ (bbb[i], 0xFF);
}
}
}
utl::spi::cpol
cpol
Definition: spi.h:47
test_spi::Test_spi_impl
Definition: test_spi_impl.cpp:48
test_spi::SPI
Definition: test_spi_impl.cpp:34
test_spi
Definition: test_spi_impl.cpp:30
test_spi::TEST_F
TEST_F(Test_spi_impl, TestConcept)
Definition: test_spi_impl.cpp:55
gtest.h
utl::spi::cpha
cpha
Definition: spi.h:54
utl
STL&#39;s core language concepts.
Definition: _1wire.h:30
utl::spi_bb_i
A bit banking implementation of spi bus inherited from spi_i base class.
Definition: spi_bb.h:56
testing::Test
Definition: gtest.h:15014
spi_bb.h
A bit banking implementation of spi bus inherited from spi_i base class.
EXPECT_EQ
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:16643
test_spi::SPI::SPI
SPI(uint32_t clk=100000) noexcept
Definition: test_spi_impl.cpp:42