Browse Source

Some more testing files

doc
Christos Houtouridis 5 years ago
parent
commit
510fe5ffa3
4 changed files with 159 additions and 7 deletions
  1. +3
    -1
      test/main.cpp
  2. +70
    -0
      test/tests/test_1w_impl.cpp
  3. +74
    -0
      test/tests/test_i2c_impl.cpp
  4. +12
    -6
      test/tests/test_spi_impl.cpp

test/eclipse-cygwin/src/main.cpp → test/main.cpp View File

@@ -1,5 +1,6 @@
/*!
* \file test/main.cpp
* \file main.cpp
* \brief Test project main file
*
* Copyright (C) 2018 Christos Choutouridis
*
@@ -20,6 +21,7 @@
#include <gtest.h>
#include <iostream>
GTEST_API_ int main(int argc, char **argv) {
std::cout << "Running tests from main.cpp\n";
testing::InitGoogleTest(&argc, argv);

+ 70
- 0
test/tests/test_1w_impl.cpp View File

@@ -0,0 +1,70 @@
/*!
* \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.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) {} // 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);
}
}

+ 74
- 0
test/tests/test_i2c_impl.cpp View File

@@ -0,0 +1,74 @@
/*!
* \file test_i2c_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.h>
#include <utl/com/i2c_bb.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_i2c {
using namespace utl;
// implementer class stub
class I2C : public i2c_bb_i<I2C> {
friend i2c_bb_i<I2C>;
void SCL (bool x) { } // imaginary SCL pin functionality
bool SDA (SDAMode mode, bool x) {
// always read 0 back (which means always ACK)
return 0;
}
void delay (uint32_t u) {
// Pseudo-delay
for (int i =0 ; i<10 ; ++i)
;
}
public:
I2C (uint32_t clk =100000) noexcept
: i2c_bb_i<I2C>(clk) {
start();
}
};
TEST(Test_i2c_impl, TestConcept) {
I2C i2c {};
EXPECT_EQ(I2c_i<I2C>, true);
}
TEST(Test_i2c_impl, TestConstruction) {
I2C i2c {};
EXPECT_EQ(i2c.clock(), 100000UL);
}
TEST(Test_i2c_impl, TestFunctionality) {
I2C i2c {};
uint8_t b = 42;
i2c.clock(200000UL);
EXPECT_EQ(i2c.clock(), 200000UL);
EXPECT_EQ(i2c.tx_data(b), true);
EXPECT_EQ(i2c.rx_data(true), 0x00);
EXPECT_EQ(i2c.rx_data(false), 0x00);
}
}

test/eclipse-cygwin/src/test_spi_bb.cpp → test/tests/test_spi_impl.cpp View File

@@ -1,5 +1,5 @@
/*!
* \file test_spi_bb.cpp
* \file test_spi_impl.cpp
*
* Copyright (C) 2018 Christos Choutouridis
*
@@ -20,10 +20,16 @@
#include <gtest.h>
#include <utl/com/spi_bb.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_spi {
using namespace utl;
// derived class stub
// implementer class stub
class SPI : public spi_bb_i<SPI, spi::cpol::LOW, spi::cpha::LOW> {
friend spi_bb_i<SPI, spi::cpol::LOW, spi::cpha::LOW>;
void MOSI (bool st) { } // Imaginary pin functionality
@@ -38,22 +44,22 @@ namespace test_spi {
};
// fixture
class Test_spi_bb : public ::testing::Test {
class Test_spi_impl : public ::testing::Test {
protected:
//void SetUp() override { }
//void TearDown() override { }
SPI spi {};
};
TEST_F(Test_spi_bb, TestConcept) {
TEST_F(Test_spi_impl, TestConcept) {
EXPECT_EQ(Spi_i<SPI>, true);
}
TEST_F(Test_spi_bb, TestConstruction) {
TEST_F(Test_spi_impl, TestConstruction) {
EXPECT_EQ(spi.clock(), 100000UL);
}
TEST_F (Test_spi_bb, TestFunctionality) {
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];

Loading…
Cancel
Save