Skip to content

Commit ba873d3

Browse files
authored
Merge pull request #49 from cujomalainey/develop
Release initial tests
2 parents ead105a + e9ab696 commit ba873d3

File tree

9 files changed

+244
-2
lines changed

9 files changed

+244
-2
lines changed

.circleci/config.yml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Python CircleCI 2.0 configuration file
2+
#
3+
# Check https://circleci.com/docs/2.0/language-python/ for more details
4+
#
5+
version: 2
6+
jobs:
7+
build:
8+
docker:
9+
# specify the version you desire here
10+
# use `-browsers` prefix for selenium tests, e.g. `3.6.1-browsers`
11+
- image: circleci/python:2.7
12+
13+
# Specify service dependencies here if necessary
14+
# CircleCI maintains a library of pre-built images
15+
# documented at https://circleci.com/docs/2.0/circleci-images/
16+
# - image: circleci/postgres:9.4
17+
18+
working_directory: ~/repo
19+
20+
steps:
21+
- checkout
22+
23+
- run:
24+
name: install dependencies
25+
command: |
26+
sudo pip install -U platformio
27+
28+
# other common Python testing frameworks include pytest and nose
29+
# https://pytest.org
30+
# https://nose.readthedocs.io
31+
- run:
32+
name: run tests
33+
command: |
34+
pio test -e native
35+
36+
- store_artifacts:
37+
path: test-reports
38+
destination: test-reports
39+

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Arduino library for communicating with ANT radios, with support for nrf51 device
55
## Status
66

77
[![Build Status](https://travis-ci.org/cujomalainey/ant-arduino.svg?branch=master)](https://travis-ci.org/cujomalainey/ant-arduino)
8+
[![Test Status](https://img.shields.io/circleci/project/github/cujomalainey/ant-arduino/master.svg)](https://circleci.com/gh/cujomalainey/ant-arduino)
89

910
## News
1011

platformio.ini

+6-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,9 @@ board = teensy31
2626
platform = nordicnrf52
2727
framework = arduino
2828
board = nrf52_dk
29-
build_flags = -DNRF52_S132
29+
build_flags = -DNRF52_S132
30+
31+
[env:native]
32+
platform = native
33+
build_flags = -Wno-c++11-extensions -std=c++11
34+

src/BaseClasses/ANT_BaseAnt.h

+5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66

77
#include <ANT_defines.h>
88

9+
#ifdef UNIT_TEST
10+
// Includes a mock stream object for unit testing
11+
#include "Util/Testing.h"
12+
#else
913
#include "Arduino.h"
14+
#endif
1015

1116
class BaseAnt {
1217
public:

src/TX/Config/ANT_SetNetworkKey.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
#include <ANT_private_defines.h>
44

5-
#include <Arduino.h>
5+
#ifdef UNIT_TEST
6+
#include "Util/Testing.h"
7+
#else
8+
#include "Arduino.h"
9+
#endif
610

711
SetNetworkKey::SetNetworkKey() : AntRequest(SET_NETWORK_KEY) {
812
memset(_key, 0, NETWORK_KEY_SIZE);

src/Util/Testing.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#ifdef UNIT_TEST
2+
3+
#include "Util/Testing.h"
4+
#include <sys/time.h>
5+
#include "unity.h"
6+
7+
Stream Serial = Stream(NULL, NULL);
8+
9+
unsigned long millis() {
10+
struct timeval time;
11+
gettimeofday(&time, NULL);
12+
return time.tv_usec/1000;
13+
}
14+
15+
Stream::Stream(const uint8_t* inBuffer, const uint8_t* outBuffer) {
16+
_inBuffer = inBuffer;
17+
_outBuffer = outBuffer;
18+
}
19+
20+
uint8_t Stream::available() {
21+
return sizeof(_inBuffer) - _read;
22+
}
23+
24+
uint8_t Stream::read() {
25+
return _inBuffer[_read++];
26+
}
27+
28+
void Stream::write(uint8_t data) {
29+
if (_wrote < sizeof(_outBuffer)) {
30+
TEST_ASSERT_EQUAL(data, _outBuffer[_wrote++]);
31+
}
32+
}
33+
34+
35+
#endif // UNIT_TEST

src/Util/Testing.h

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#ifdef UNIT_TEST
2+
#ifndef ANT_TESTING_h
3+
#define ANT_TESTING_h
4+
#include <string.h>
5+
#include <inttypes.h>
6+
7+
unsigned long millis();
8+
9+
class Stream {
10+
public:
11+
Stream(const uint8_t* inBuffer, const uint8_t* outBuffer);
12+
uint8_t available();
13+
uint8_t read();
14+
void write(uint8_t data);
15+
private:
16+
const uint8_t* _inBuffer;
17+
const uint8_t* _outBuffer;
18+
uint8_t _read = 0;
19+
uint8_t _wrote = 0;
20+
};
21+
22+
extern Stream Serial;
23+
#endif // ANT_TESTING_h
24+
#endif // UNIT_TEST
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#include "unity.h"
2+
#include "ANT.h"
3+
#include "Util/Testing.h"
4+
5+
#ifdef UNIT_TEST
6+
7+
const uint8_t expectedOut[] = {0xA4, 6, 0x59, 2, 0x44, 0x33, 120, 34, 2, 214};
8+
Stream mock_stream = Stream(NULL, expectedOut);
9+
AntWithCallbacks ant = AntWithCallbacks();
10+
AddChannelIdToList msg;
11+
12+
void test_constructors(void) {
13+
msg = AddChannelIdToList(2, 3344, 120, 34, 2);
14+
TEST_ASSERT_EQUAL_UINT8(2, msg.getChannel());
15+
TEST_ASSERT_EQUAL_UINT16(3344, msg.getDeviceNumber());
16+
TEST_ASSERT_EQUAL_UINT8(120, msg.getDeviceType());
17+
TEST_ASSERT_EQUAL_UINT8(34, msg.getTransmissionType());
18+
TEST_ASSERT_EQUAL_UINT8(2, msg.getListIndex());
19+
}
20+
21+
void test_setChannel(void) {
22+
msg.setChannel(3);
23+
TEST_ASSERT_EQUAL_UINT8(3, msg.getChannel());
24+
}
25+
26+
void test_setDeviceNumber(void) {
27+
msg.setDeviceNumber(0x4455);
28+
TEST_ASSERT_EQUAL_UINT16(0x4455, msg.getDeviceNumber());
29+
}
30+
31+
void test_setDeviceType(void) {
32+
msg.setDeviceType(100);
33+
TEST_ASSERT_EQUAL_UINT8(100, msg.getDeviceType());
34+
}
35+
36+
void test_setTransmisionType(void) {
37+
msg.setTransmissionType(12);
38+
TEST_ASSERT_EQUAL_UINT8(12, msg.getTransmissionType());
39+
}
40+
41+
void test_setListIndex(void) {
42+
msg.setListIndex(4);
43+
TEST_ASSERT_EQUAL_UINT8(4, msg.getListIndex());
44+
}
45+
46+
void test_getDataLength(void) {
47+
TEST_ASSERT_EQUAL_UINT8(6, msg.getDataLength());
48+
}
49+
50+
void test_serialize(void) {
51+
// Asserts are in mock stream
52+
ant.begin(mock_stream);
53+
msg = AddChannelIdToList(2, 0x3344, 120, 34, 2);
54+
ant.send(msg);
55+
}
56+
57+
int main(int argc, char **argv) {
58+
UNITY_BEGIN();
59+
RUN_TEST(test_constructors);
60+
RUN_TEST(test_setChannel);
61+
RUN_TEST(test_setDeviceNumber);
62+
RUN_TEST(test_setDeviceType);
63+
RUN_TEST(test_setTransmisionType);
64+
RUN_TEST(test_setListIndex);
65+
RUN_TEST(test_getDataLength);
66+
RUN_TEST(test_serialize);
67+
UNITY_END();
68+
69+
return 0;
70+
}
71+
72+
#endif // UNIT_TEST
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#include "unity.h"
2+
#include "ANT.h"
3+
#include "Util/Testing.h"
4+
5+
#ifdef UNIT_TEST
6+
7+
const uint8_t expectedOut[] = {0xA4, 6, 0x59, 1, 0x78, 0x56, 0x34, 0x12, 3, 241};
8+
Stream mock_stream = Stream(NULL, expectedOut);
9+
AntWithCallbacks ant = AntWithCallbacks();
10+
AddEncryptionIdToList msg;
11+
12+
void test_constructors(void) {
13+
msg = AddEncryptionIdToList(1, 0x12345678, 3);
14+
TEST_ASSERT_EQUAL_UINT8(1, msg.getChannel());
15+
TEST_ASSERT_EQUAL_UINT32(0x12345678, msg.getEncryptionId());
16+
TEST_ASSERT_EQUAL_UINT8(3, msg.getListIndex());
17+
}
18+
19+
void test_setChannel(void) {
20+
msg.setChannel(3);
21+
TEST_ASSERT_EQUAL_UINT8(3, msg.getChannel());
22+
}
23+
24+
void test_setEncryptionId(void) {
25+
msg.setEncryptionId(0x11223344);
26+
TEST_ASSERT_EQUAL_UINT16(0x11223344, msg.getEncryptionId());
27+
}
28+
29+
void test_setListIndex(void) {
30+
msg.setListIndex(3);
31+
TEST_ASSERT_EQUAL_UINT8(3, msg.getListIndex());
32+
}
33+
34+
void test_getDataLength(void) {
35+
TEST_ASSERT_EQUAL_UINT8(6, msg.getDataLength());
36+
}
37+
38+
void test_serialize(void) {
39+
// Asserts are in mock stream
40+
ant.begin(mock_stream);
41+
msg = AddEncryptionIdToList(1, 0x12345678, 3);
42+
ant.send(msg);
43+
}
44+
45+
int main(int argc, char **argv) {
46+
UNITY_BEGIN();
47+
RUN_TEST(test_constructors);
48+
RUN_TEST(test_setEncryptionId);
49+
RUN_TEST(test_setListIndex);
50+
RUN_TEST(test_getDataLength);
51+
RUN_TEST(test_serialize);
52+
UNITY_END();
53+
54+
return 0;
55+
}
56+
57+
#endif // UNIT_TEST

0 commit comments

Comments
 (0)