Micro template library A library for building device drivers
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

74 lignes
2.3 KiB

  1. /*!
  2. * \file test_spi_bb.cpp
  3. *
  4. * Copyright (C) 2018 Christos Choutouridis
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as
  8. * published by the Free Software Foundation, either version 3
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. #include <gtest.h>
  21. #include <utl/com/spi_bb.h>
  22. namespace test_spi {
  23. using namespace utl;
  24. // derived class stub
  25. class SPI : public spi_bb_i<SPI, spi::cpol::LOW, spi::cpha::LOW> {
  26. friend spi_bb_i<SPI, spi::cpol::LOW, spi::cpha::LOW>;
  27. void MOSI (bool st) { } // Imaginary pin functionality
  28. bool MISO () { return true; } // All reads become 0xFF
  29. void SCLK (bool st) { } // Imaginary pin functionality
  30. void delay (uint32_t nsec) { }// Imaginary delay functionality
  31. public:
  32. SPI (uint32_t clk =100000) noexcept : // expect 100000 default constructed clock
  33. spi_bb_i<SPI, spi::cpol::LOW, spi::cpha::LOW>(clk) {
  34. }
  35. };
  36. // fixture
  37. class Test_spi_bb : public ::testing::Test {
  38. protected:
  39. //void SetUp() override { }
  40. //void TearDown() override { }
  41. SPI spi {};
  42. };
  43. TEST_F(Test_spi_bb, TestConcept) {
  44. EXPECT_EQ(Spi_i<SPI>, true);
  45. }
  46. TEST_F(Test_spi_bb, TestConstruction) {
  47. EXPECT_EQ(spi.clock(), 100000UL);
  48. }
  49. TEST_F (Test_spi_bb, TestFunctionality) {
  50. uint8_t b = 42;
  51. uint8_t bb[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
  52. uint8_t bbb[sizeof bb];
  53. spi.clock(500000UL);
  54. EXPECT_EQ(spi.clock(), 500000UL);
  55. EXPECT_EQ(spi.tx_data(b), 0xFF);
  56. EXPECT_EQ(spi.tx_data(bb, bbb, sizeof(bb)), sizeof (bb));
  57. EXPECT_EQ(spi.rx_data(), 0xFF);
  58. spi.rx_data(bbb, sizeof bb);
  59. for (unsigned int i=0 ; i<sizeof bb ; ++i) {
  60. EXPECT_EQ (bbb[i], 0xFF);
  61. }
  62. }
  63. }