Added a framework for CxxTest based unit tests
This commit is contained in:
parent
bf34454a82
commit
f7081f3917
@ -1,4 +1,8 @@
|
||||
#include "Arduino.h"
|
||||
#include "SPI.h"
|
||||
|
||||
#include "SegmentDisplay.h"
|
||||
#include "SegmentDisplayChars.h"
|
||||
|
||||
|
||||
void SegmentDisplay::begin()
|
||||
|
@ -2,9 +2,6 @@
|
||||
#define SegmentDisplay_h
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "SPI.h"
|
||||
|
||||
#include "SegmentDisplayChars.h"
|
||||
|
||||
/**
|
||||
* Drives up to 8 digits using two 8-bit shift registers.
|
||||
@ -19,7 +16,7 @@
|
||||
**/
|
||||
|
||||
// Comment to use shiftOut. Set clockPin and dataPin instead.
|
||||
#define SDSupportSPI
|
||||
//#define SDSupportSPI
|
||||
|
||||
|
||||
class SegmentDisplay
|
||||
@ -51,8 +48,8 @@ class SegmentDisplay
|
||||
#endif
|
||||
|
||||
protected:
|
||||
void writeDigit(byte value, byte digitMask);
|
||||
void writeDisplay(byte characterMask, byte digitMask);
|
||||
inline void writeDigit(unsigned char value, unsigned char digitMask);
|
||||
inline void writeDisplay(unsigned char characterMask, unsigned char digitMask);
|
||||
|
||||
private:
|
||||
int digits = 6;
|
||||
|
@ -13,7 +13,7 @@
|
||||
#define SegmentG 64 // Middle
|
||||
|
||||
|
||||
const byte SDNumberSegments[10] PROGMEM =
|
||||
const unsigned char SDNumberSegments[10] PROGMEM =
|
||||
{
|
||||
/**
|
||||
* _
|
||||
@ -98,7 +98,7 @@ const byte SDNumberSegments[10] PROGMEM =
|
||||
|
||||
|
||||
|
||||
const byte SDCharacterSegments[26] PROGMEM =
|
||||
const unsigned char SDCharacterSegments[26] PROGMEM =
|
||||
{
|
||||
/**
|
||||
* _
|
||||
@ -170,7 +170,7 @@ const byte SDCharacterSegments[26] PROGMEM =
|
||||
* |
|
||||
*
|
||||
**/
|
||||
SegmentE | SegmentF,
|
||||
SegmentB | SegmentC,
|
||||
|
||||
/**
|
||||
*
|
||||
@ -182,11 +182,11 @@ const byte SDCharacterSegments[26] PROGMEM =
|
||||
|
||||
/**
|
||||
*
|
||||
* |_|
|
||||
* |_
|
||||
* |
|
||||
*
|
||||
**/
|
||||
SegmentE | SegmentF | SegmentG,
|
||||
SegmentB | SegmentD | SegmentE | SegmentF | SegmentG,
|
||||
|
||||
/**
|
||||
*
|
||||
@ -196,14 +196,6 @@ const byte SDCharacterSegments[26] PROGMEM =
|
||||
**/
|
||||
SegmentD | SegmentE | SegmentF,
|
||||
|
||||
/**
|
||||
* _
|
||||
*
|
||||
* | |
|
||||
*
|
||||
**/
|
||||
SegmentA | SegmentC | SegmentE,
|
||||
|
||||
/**
|
||||
*
|
||||
* _
|
||||
@ -212,6 +204,14 @@ const byte SDCharacterSegments[26] PROGMEM =
|
||||
**/
|
||||
SegmentC | SegmentE | SegmentG,
|
||||
|
||||
/**
|
||||
* _
|
||||
* | |
|
||||
* | |
|
||||
*
|
||||
**/
|
||||
SegmentA | SegmentB | SegmentC | SegmentE | SegmentF,
|
||||
|
||||
/**
|
||||
* _
|
||||
* | |
|
||||
@ -268,6 +268,14 @@ const byte SDCharacterSegments[26] PROGMEM =
|
||||
**/
|
||||
SegmentB | SegmentC | SegmentD | SegmentE | SegmentF,
|
||||
|
||||
/**
|
||||
*
|
||||
* | |
|
||||
* |_|
|
||||
*
|
||||
**/
|
||||
SegmentB | SegmentC | SegmentD | SegmentE | SegmentF,
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
@ -278,19 +286,11 @@ const byte SDCharacterSegments[26] PROGMEM =
|
||||
|
||||
/**
|
||||
*
|
||||
* |_|
|
||||
* | |
|
||||
* _
|
||||
*
|
||||
**/
|
||||
SegmentB | SegmentD | SegmentF,
|
||||
|
||||
/**
|
||||
*
|
||||
* _|
|
||||
* |
|
||||
*
|
||||
**/
|
||||
SegmentB | SegmentC | SegmentG,
|
||||
SegmentB | SegmentC | SegmentE | SegmentF | SegmentG,
|
||||
|
||||
/**
|
||||
*
|
||||
|
2
test/.gitignore
vendored
Normal file
2
test/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
runner
|
||||
runner.cpp
|
49
test/SegmentDisplayTestSuite.h
Normal file
49
test/SegmentDisplayTestSuite.h
Normal file
@ -0,0 +1,49 @@
|
||||
#include <cxxtest/TestSuite.h>
|
||||
#include "lib/SegmentDisplay.h"
|
||||
|
||||
class SegmentDisplayTestSuite : public CxxTest::TestSuite
|
||||
{
|
||||
public:
|
||||
void testBeginEnd(void)
|
||||
{
|
||||
SegmentDisplay* display = new SegmentDisplay();
|
||||
display->begin();
|
||||
display->end();
|
||||
}
|
||||
|
||||
void testWriteNumberFull(void)
|
||||
{
|
||||
// TODO test writing the full 8-digit numbers
|
||||
TS_WARN("Not implemented");
|
||||
}
|
||||
|
||||
void testWriteTextFull(void)
|
||||
{
|
||||
// TODO test writing full length text
|
||||
TS_WARN("Not implemented");
|
||||
}
|
||||
|
||||
void testWriteNumberPartial(void)
|
||||
{
|
||||
// TODO test writing a partial 5-digit numbers
|
||||
TS_WARN("Not implemented");
|
||||
}
|
||||
|
||||
void testWriteTextPartial(void)
|
||||
{
|
||||
// TODO test writing partial text
|
||||
TS_WARN("Not implemented");
|
||||
}
|
||||
|
||||
void testWriteNumberOverflow(void)
|
||||
{
|
||||
// TODO test writing a number larger than 8 digits
|
||||
TS_WARN("Not implemented");
|
||||
}
|
||||
|
||||
void testWriteTextOverflow(void)
|
||||
{
|
||||
// TODO test writing text which is too long
|
||||
TS_WARN("Not implemented");
|
||||
}
|
||||
};
|
31
test/mock/Arduino.h
Normal file
31
test/mock/Arduino.h
Normal file
@ -0,0 +1,31 @@
|
||||
// Contains the bare minimum to get the test suite up and running
|
||||
#ifndef ArduinoMock_h
|
||||
#define ArduinoMock_h
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define HIGH 0x1
|
||||
#define LOW 0x0
|
||||
|
||||
#define INPUT 0x0
|
||||
#define OUTPUT 0x1
|
||||
|
||||
#define LSBFIRST 0
|
||||
#define MSBFIRST 1
|
||||
|
||||
#define PIN_SPI_SS (17)
|
||||
#define PIN_SPI_MOSI (16)
|
||||
#define PIN_SPI_MISO (14)
|
||||
#define PIN_SPI_SCK (15)
|
||||
|
||||
static const uint8_t SS = PIN_SPI_SS;
|
||||
static const uint8_t MOSI = PIN_SPI_MOSI;
|
||||
static const uint8_t MISO = PIN_SPI_MISO;
|
||||
static const uint8_t SCK = PIN_SPI_SCK;
|
||||
|
||||
|
||||
void digitalWrite( uint32_t dwPin, uint32_t dwVal );
|
||||
void pinMode( uint32_t dwPin, uint32_t dwMode );
|
||||
void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
|
||||
|
||||
#endif
|
19
test/mock/Mock.cpp
Normal file
19
test/mock/Mock.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
// Provides hookable implementations for the mock headers
|
||||
#include "Arduino.h"
|
||||
|
||||
void digitalWrite( uint32_t dwPin, uint32_t dwVal )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void pinMode( uint32_t dwPin, uint32_t dwMode )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val)
|
||||
{
|
||||
|
||||
}
|
1
test/mock/SPI.h
Normal file
1
test/mock/SPI.h
Normal file
@ -0,0 +1 @@
|
||||
// Contains the bare minimum to get the test suite up and running
|
7
test/mock/avr/pgmspace.h
Normal file
7
test/mock/avr/pgmspace.h
Normal file
@ -0,0 +1,7 @@
|
||||
// Contains the bare minimum to get the test suite up and running
|
||||
#ifndef pgmspacemock_h
|
||||
#define pgmspacemock_h
|
||||
|
||||
#define PROGMEM __attribute__(())
|
||||
|
||||
#endif
|
22
test/runner.sh
Normal file
22
test/runner.sh
Normal file
@ -0,0 +1,22 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Note:
|
||||
# This works perfectly on Windows 10 Anniversary Edition using Ubuntu on Windows,
|
||||
# just apt-get install g++!
|
||||
|
||||
CXXTest="../../CxxTest"
|
||||
CXXTestGen="$CXXTest/bin/cxxtestgen"
|
||||
|
||||
$CXXTestGen --error-printer -o runner.cpp SegmentDisplayTestSuite.h
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Generating unit test runner failed, aborting"
|
||||
exit $?
|
||||
fi
|
||||
|
||||
g++ -o runner -I$CXXTest -I ../ -Imock -std=c++11 mock/Mock.cpp ../lib/*.cpp runner.cpp
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Compiling unit test runner failed, aborting"
|
||||
exit $?
|
||||
fi
|
||||
|
||||
./runner
|
Loading…
Reference in New Issue
Block a user