Skip to content

Commit 9b6f213

Browse files
committed
Use arduino_ci for unit testing
1 parent 91506b3 commit 9b6f213

File tree

5 files changed

+93
-6
lines changed

5 files changed

+93
-6
lines changed

.arduino-ci.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
compile:
2+
platforms:
3+
- uno
4+
5+
unittest:
6+
platforms:
7+
- uno

.gitignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,11 @@
3030

3131
#Doxygen
3232
doxygen_sqlite3.db
33-
html
33+
html
34+
35+
# arduino_ci unit test files
36+
*.bin
37+
*.bin.dSYM
38+
39+
# arduino_ci ruby bundle lockfile
40+
Gemfile.lock

.travis.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
language: c
1+
sudo: false
2+
language: ruby
23

34
addons:
45
apt:
@@ -17,13 +18,12 @@ env:
1718
- GH_REPO_REF: github.com/SMFSW/Queue.git
1819
- DOXYFILE: $TRAVIS_BUILD_DIR/Doxyfile.auto
1920

20-
before_install:
21-
- source <(curl -SLs https://raw.githubusercontent.com/SMFSW/travis-ci-arduino/master/install.sh)
22-
2321
script:
24-
- build_main_platforms
22+
- bundle install
23+
- bundle exec arduino_ci_remote.rb
2524

2625
# Generate and deploy documentation
2726
after_success:
27+
- source <(curl -SLs https://raw.githubusercontent.com/SMFSW/travis-ci-arduino/master/install.sh)
2828
- source <(curl -SLs https://raw.githubusercontent.com/SMFSW/travis-ci-arduino/master/library_check.sh)
2929
- source <(curl -SLs https://raw.githubusercontent.com/SMFSW/travis-ci-arduino/master/doxy_gen_and_deploy.sh)

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
source 'https://rubygems.org'
2+
gem 'arduino_ci', '~> 0.1.14'

test/libtst.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#include <ArduinoUnitTests.h>
2+
#include "../src/cppQueue.h"
3+
4+
#define IMPLEMENTATION FIFO
5+
#define OVERWRITE true
6+
7+
#define NB_PUSH 14
8+
#define NB_PULL 11
9+
#define Q_SIZE 10
10+
11+
typedef struct strRec {
12+
uint16_t entry1;
13+
uint16_t entry2;
14+
} Rec;
15+
16+
unittest(LibTst)
17+
{
18+
Rec tab[6] = {
19+
{ 0x1234, 0x3456 },
20+
{ 0x5678, 0x7890 },
21+
{ 0x90AB, 0xABCD },
22+
{ 0xCDEF, 0xEFDC },
23+
{ 0xDCBA, 0xBA09 },
24+
{ 0x0987, 0x8765 }
25+
};
26+
27+
Queue q(sizeof(Rec), Q_SIZE, IMPLEMENTATION, OVERWRITE); // Instantiate queue
28+
assertEqual(40, q.sizeOf());
29+
assertEqual(0, q.getCount());
30+
31+
int i;
32+
for (i = 0 ; i < NB_PUSH ; i++)
33+
{
34+
Rec rec = tab[i % (sizeof(tab)/sizeof(Rec))];
35+
q.push(&rec);
36+
assertEqual(min(Q_SIZE, i + 1), q.getCount());
37+
assertEqual(max(0, (Q_SIZE - 1) - i), q.getRemainingCount());
38+
assertEqual((i + 1) >= Q_SIZE, q.isFull());
39+
}
40+
41+
assertFalse(q.isEmpty());
42+
assertEqual(10, q.getCount());
43+
44+
for (i = 0 ; i < NB_PULL+1 ; i++)
45+
{
46+
// account for the behavior of the test in the example,
47+
// where at an odd spot we peek instead of pop.
48+
bool canPop = i <= Q_SIZE; // note allowance for the peek -- 'i' can be 10
49+
bool didPeek = i <= NB_PULL / 2; // matches logic of conditional
50+
int offset = didPeek ? 4 : 3; // adjust offset in tab
51+
int idx = (i + offset) % (sizeof(tab)/sizeof(Rec)); // index of tab
52+
Rec rec = {0xffff,0xffff};
53+
if (i != NB_PULL / 2)
54+
{
55+
assertEqual(canPop, q.pop(&rec));
56+
}
57+
else
58+
{
59+
assertTrue(q.peek(&rec));
60+
}
61+
62+
assertEqual(canPop ? tab[idx].entry1 : 0xffff, rec.entry1);
63+
assertEqual(canPop ? tab[idx].entry2 : 0xffff, rec.entry2);
64+
}
65+
66+
assertTrue(q.isEmpty());
67+
assertEqual(0, q.getCount());
68+
}
69+
70+
71+
unittest_main()

0 commit comments

Comments
 (0)