71 lines
2.2 KiB
C++
71 lines
2.2 KiB
C++
/*!
|
|
* \file test_1w_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 <http://www.gnu.org/licenses/>.
|
|
*
|
|
*/
|
|
#include <gtest/gtest.h>
|
|
#include <utl/com/_1wire_uart.h>
|
|
|
|
/*!
|
|
* \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_1w {
|
|
using namespace utl;
|
|
|
|
// implementer class stub
|
|
class OW : public _1wire_uart_i<OW> {
|
|
friend _1wire_uart_i<OW>;
|
|
byte_t UART_RW (byte_t byte) {
|
|
// return the given. This also mean no-device
|
|
return byte;
|
|
}
|
|
void UART_BR (uint32_t br) { (void)br; } // imaginary baud-rate implementation
|
|
};
|
|
|
|
// fixture
|
|
class Test_1w_impl : public ::testing::Test {
|
|
protected:
|
|
//void SetUp() override { }
|
|
//void TearDown() override { }
|
|
OW ow;
|
|
};
|
|
|
|
TEST_F(Test_1w_impl, TestConcept) {
|
|
// EXPECT_EQ(_1Wire_i<OW>, true);
|
|
}
|
|
|
|
TEST_F(Test_1w_impl, TestConstruction) {
|
|
EXPECT_GT(sizeof(ow), 0UL);
|
|
}
|
|
|
|
TEST_F (Test_1w_impl, TestFunctionality) {
|
|
byte_t b {42};
|
|
|
|
_1wire_id_t id = ow.first(OW::Speed::STD);
|
|
EXPECT_EQ (id != _1wire_id_t::nullDev(), false); // as long as there is no slave Mock
|
|
|
|
EXPECT_EQ (ow.reset(OW::Speed::STD), false); // as long as there is no slave Mock
|
|
//ow.match(id, OW::Speed::STD);
|
|
EXPECT_EQ(ow.rx_data(OW::Speed::STD), 0xFF);
|
|
EXPECT_EQ(ow.tx_data(b, OW::Speed::STD), 42);
|
|
|
|
}
|
|
}
|