uTL
micro Template library
test_spi_impl.cpp
Go to the documentation of this file.
1 
20 #include <gtest/gtest.h>
21 #include <utl/com/spi_bb.h>
22 
23 
30 namespace test_spi {
31  using namespace utl;
32 
33  // implementer class stub
34  class SPI : public spi_bb_i<SPI, spi::cpol::LOW, spi::cpha::LOW> {
36  void MOSI (bool st) { (void)st; } // Imaginary pin functionality
37  bool MISO () { return true; } // All reads become 0xFF
38  void SCLK (bool st) { (void)st; } // Imaginary pin functionality
39  void delay (uint32_t nsec) { (void)nsec; } // Imaginary delay functionality
40 
41  public:
42  SPI (uint32_t clk =100000) noexcept : // expect 100000 default constructed clock
43  spi_bb_i<SPI, spi::cpol::LOW, spi::cpha::LOW>(clk) {
44  }
45  };
46 
47  // fixture
48  class Test_spi_impl : public ::testing::Test {
49  protected:
50  //void SetUp() override { }
51  //void TearDown() override { }
52  SPI spi {};
53  };
54 
55  TEST_F(Test_spi_impl, TestConcept) {
56 // EXPECT_EQ(Spi_i<SPI>, true);
57  }
58 
59  TEST_F(Test_spi_impl, TestConstruction) {
60  EXPECT_EQ(spi.clock(), 100000UL);
61  }
62 
63  TEST_F (Test_spi_impl, TestFunctionality) {
64  uint8_t b = 42;
65  uint8_t bb[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
66  uint8_t bbb[sizeof bb];
67 
68  spi.clock(500000UL);
69  EXPECT_EQ(spi.clock(), 500000UL);
70 
71  EXPECT_EQ(spi.tx_data(b), 0xFF);
72  EXPECT_EQ(spi.tx_data(bb, bbb, sizeof(bb)), sizeof (bb));
73  EXPECT_EQ(spi.rx_data(), 0xFF);
74 
75  spi.rx_data(bbb, sizeof bb);
76  for (unsigned int i=0 ; i<sizeof bb ; ++i) {
77  EXPECT_EQ (bbb[i], 0xFF);
78  }
79  }
80 }
cpol
Definition: spi.h:47
TEST_F(Test_spi_impl, TestConcept)
cpha
Definition: spi.h:54
STL&#39;s core language concepts.
Definition: _1wire.h:30
A bit banking implementation of spi bus inherited from spi_i base class.
Definition: spi_bb.h:56
A bit banking implementation of spi bus inherited from spi_i base class.
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:16643
SPI(uint32_t clk=100000) noexcept