/*!
* \file test_spi_impl.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
/*!
* \warning
* This is not right way of testing communication interfaces. We have to
* implement a Mock object to simulate the slave's behavior. Until then
* we have the following.
*/
namespace test_spi {
using namespace utl;
// implementer 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_impl : public ::testing::Test {
protected:
//void SetUp() override { }
//void TearDown() override { }
SPI spi {};
};
TEST_F(Test_spi_impl, TestConcept) {
EXPECT_EQ(Spi_i, 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