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.
 
 
 
 

71 lignes
2.2 KiB

  1. /*!
  2. * \file test_1w_impl.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/gtest.h>
  21. #include <utl/com/_1wire_uart.h>
  22. /*!
  23. * \warning
  24. * This is not right way of testing communication interfaces. We have to
  25. * implement a Mock object to simulate the slave's behavior. Until then
  26. * we have the following.
  27. */
  28. namespace test_1w {
  29. using namespace utl;
  30. // implementer class stub
  31. class OW : public _1wire_uart_i<OW> {
  32. friend _1wire_uart_i<OW>;
  33. byte_t UART_RW (byte_t byte) {
  34. // return the given. This also mean no-device
  35. return byte;
  36. }
  37. void UART_BR (uint32_t br) { (void)br; } // imaginary baud-rate implementation
  38. };
  39. // fixture
  40. class Test_1w_impl : public ::testing::Test {
  41. protected:
  42. //void SetUp() override { }
  43. //void TearDown() override { }
  44. OW ow;
  45. };
  46. TEST_F(Test_1w_impl, TestConcept) {
  47. // EXPECT_EQ(_1Wire_i<OW>, true);
  48. }
  49. TEST_F(Test_1w_impl, TestConstruction) {
  50. EXPECT_GT(sizeof(ow), 0UL);
  51. }
  52. TEST_F (Test_1w_impl, TestFunctionality) {
  53. byte_t b {42};
  54. _1wire_id_t id = ow.first(OW::Speed::STD);
  55. EXPECT_EQ (id != _1wire_id_t::nullDev(), false); // as long as there is no slave Mock
  56. EXPECT_EQ (ow.reset(OW::Speed::STD), false); // as long as there is no slave Mock
  57. //ow.match(id, OW::Speed::STD);
  58. EXPECT_EQ(ow.rx_data(OW::Speed::STD), 0xFF);
  59. EXPECT_EQ(ow.tx_data(b, OW::Speed::STD), 42);
  60. }
  61. }