|
-
- #include <gtest/gtest.h>
- #include <utl/com/spi_bb.h>
-
-
-
- namespace test_spi {
- using namespace utl;
-
-
- 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) { }
- bool MISO () { return true; }
- void SCLK (bool st) { }
- void delay (uint32_t nsec) { }
-
- public:
- SPI (uint32_t clk =100000) noexcept :
- spi_bb_i<SPI, spi::cpol::LOW, spi::cpha::LOW>(clk) {
- }
- };
-
-
- class Test_spi_impl : public ::testing::Test {
- protected:
-
-
- 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);
- }
- }
- }
|