Some more testing files
This commit is contained in:
@@ -1,30 +0,0 @@
|
||||
/*!
|
||||
* \file test/main.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 <iostream>
|
||||
|
||||
GTEST_API_ int main(int argc, char **argv) {
|
||||
std::cout << "Running tests from main.cpp\n";
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
/*!
|
||||
* \file test_spi_bb.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/spi_bb.h>
|
||||
|
||||
namespace test_spi {
|
||||
using namespace utl;
|
||||
|
||||
// derived 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
|
||||
bool MISO () { return true; } // All reads become 0xFF
|
||||
void SCLK (bool st) { } // Imaginary pin functionality
|
||||
void delay (uint32_t nsec) { }// Imaginary delay functionality
|
||||
|
||||
public:
|
||||
SPI (uint32_t clk =100000) noexcept : // expect 100000 default constructed clock
|
||||
spi_bb_i<SPI, spi::cpol::LOW, spi::cpha::LOW>(clk) {
|
||||
}
|
||||
};
|
||||
|
||||
// fixture
|
||||
class Test_spi_bb : public ::testing::Test {
|
||||
protected:
|
||||
//void SetUp() override { }
|
||||
//void TearDown() override { }
|
||||
SPI spi {};
|
||||
};
|
||||
|
||||
TEST_F(Test_spi_bb, TestConcept) {
|
||||
EXPECT_EQ(Spi_i<SPI>, true);
|
||||
}
|
||||
|
||||
TEST_F(Test_spi_bb, TestConstruction) {
|
||||
EXPECT_EQ(spi.clock(), 100000UL);
|
||||
}
|
||||
|
||||
TEST_F (Test_spi_bb, TestFunctionality) {
|
||||
uint8_t b = 42;
|
||||
uint8_t bb[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
|
||||
uint8_t bbb[sizeof bb];
|
||||
|
||||
spi.clock(500000UL);
|
||||
EXPECT_EQ(spi.clock(), 500000UL);
|
||||
|
||||
EXPECT_EQ(spi.tx_data(b), 0xFF);
|
||||
EXPECT_EQ(spi.tx_data(bb, bbb, sizeof(bb)), sizeof (bb));
|
||||
EXPECT_EQ(spi.rx_data(), 0xFF);
|
||||
|
||||
spi.rx_data(bbb, sizeof bb);
|
||||
for (unsigned int i=0 ; i<sizeof bb ; ++i) {
|
||||
EXPECT_EQ (bbb[i], 0xFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user