/*! * \file test_spi_bb.cpp * * Copyright (C) 2018 Christos Choutouridis * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . * */ #include #include namespace test_spi { using namespace utl; // derived class stub class SPI : public spi_bb_i { friend spi_bb_i; void MOSI (bool st) { } // Imaginary pin functionality bool MISO () { return true; } // All reads become 0xFF void SCLK (bool st) { } // Imaginary pin functionality void delay (uint32_t nsec) { }// Imaginary delay functionality public: SPI (uint32_t clk =100000) noexcept : // expect 100000 default constructed clock spi_bb_i(clk) { } }; // fixture class Test_spi_bb : public ::testing::Test { protected: //void SetUp() override { } //void TearDown() override { } SPI spi {}; }; TEST_F(Test_spi_bb, TestConcept) { EXPECT_EQ(Spi_i, true); } TEST_F(Test_spi_bb, TestConstruction) { EXPECT_EQ(spi.clock(), 100000UL); } TEST_F (Test_spi_bb, 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