Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .arduino-ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
compile:
platforms:
- uno

unittest:
platforms:
- uno
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,11 @@

#Doxygen
doxygen_sqlite3.db
html
html

# arduino_ci unit test files
*.bin
*.bin.dSYM

# arduino_ci ruby bundle lockfile
Gemfile.lock
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: c
sudo: false
language: ruby

addons:
apt:
Expand All @@ -17,13 +18,12 @@ env:
- GH_REPO_REF: github.com/SMFSW/Queue.git
- DOXYFILE: $TRAVIS_BUILD_DIR/Doxyfile.auto

before_install:
- source <(curl -SLs https://raw.githubusercontent.com/SMFSW/travis-ci-arduino/master/install.sh)

script:
- build_main_platforms
- bundle install
- bundle exec arduino_ci_remote.rb

# Generate and deploy documentation
after_success:
- source <(curl -SLs https://raw.githubusercontent.com/SMFSW/travis-ci-arduino/master/install.sh)
- source <(curl -SLs https://raw.githubusercontent.com/SMFSW/travis-ci-arduino/master/library_check.sh)
- source <(curl -SLs https://raw.githubusercontent.com/SMFSW/travis-ci-arduino/master/doxy_gen_and_deploy.sh)
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
source 'https://rubygems.org'
gem 'arduino_ci', '~> 0.1.14'
71 changes: 71 additions & 0 deletions test/libtst.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include <ArduinoUnitTests.h>
#include "../src/cppQueue.h"

#define IMPLEMENTATION FIFO
#define OVERWRITE true

#define NB_PUSH 14
#define NB_PULL 11
#define Q_SIZE 10

typedef struct strRec {
uint16_t entry1;
uint16_t entry2;
} Rec;

unittest(LibTst)
{
Rec tab[6] = {
{ 0x1234, 0x3456 },
{ 0x5678, 0x7890 },
{ 0x90AB, 0xABCD },
{ 0xCDEF, 0xEFDC },
{ 0xDCBA, 0xBA09 },
{ 0x0987, 0x8765 }
};

Queue q(sizeof(Rec), Q_SIZE, IMPLEMENTATION, OVERWRITE); // Instantiate queue
assertEqual(40, q.sizeOf());
assertEqual(0, q.getCount());

int i;
for (i = 0 ; i < NB_PUSH ; i++)
{
Rec rec = tab[i % (sizeof(tab)/sizeof(Rec))];
q.push(&rec);
assertEqual(min(Q_SIZE, i + 1), q.getCount());
assertEqual(max(0, (Q_SIZE - 1) - i), q.getRemainingCount());
assertEqual((i + 1) >= Q_SIZE, q.isFull());
}

assertFalse(q.isEmpty());
assertEqual(10, q.getCount());

for (i = 0 ; i < NB_PULL+1 ; i++)
{
// account for the behavior of the test in the example,
// where at an odd spot we peek instead of pop.
bool canPop = i <= Q_SIZE; // note allowance for the peek -- 'i' can be 10
bool didPeek = i <= NB_PULL / 2; // matches logic of conditional
int offset = didPeek ? 4 : 3; // adjust offset in tab
int idx = (i + offset) % (sizeof(tab)/sizeof(Rec)); // index of tab
Rec rec = {0xffff,0xffff};
if (i != NB_PULL / 2)
{
assertEqual(canPop, q.pop(&rec));
}
else
{
assertTrue(q.peek(&rec));
}

assertEqual(canPop ? tab[idx].entry1 : 0xffff, rec.entry1);
assertEqual(canPop ? tab[idx].entry2 : 0xffff, rec.entry2);
}

assertTrue(q.isEmpty());
assertEqual(0, q.getCount());
}


unittest_main()