From 9b6f2133df34d4998babc67e2e859ba890acec30 Mon Sep 17 00:00:00 2001 From: Ian Katz Date: Thu, 3 Jan 2019 09:21:52 -0500 Subject: [PATCH] Use arduino_ci for unit testing --- .arduino-ci.yaml | 7 +++++ .gitignore | 9 +++++- .travis.yml | 10 +++---- Gemfile | 2 ++ test/libtst.cpp | 71 ++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 93 insertions(+), 6 deletions(-) create mode 100644 .arduino-ci.yaml create mode 100644 Gemfile create mode 100644 test/libtst.cpp diff --git a/.arduino-ci.yaml b/.arduino-ci.yaml new file mode 100644 index 0000000..9064797 --- /dev/null +++ b/.arduino-ci.yaml @@ -0,0 +1,7 @@ +compile: + platforms: + - uno + +unittest: + platforms: + - uno diff --git a/.gitignore b/.gitignore index 9cb1bff..a015892 100755 --- a/.gitignore +++ b/.gitignore @@ -30,4 +30,11 @@ #Doxygen doxygen_sqlite3.db -html \ No newline at end of file +html + +# arduino_ci unit test files +*.bin +*.bin.dSYM + +# arduino_ci ruby bundle lockfile +Gemfile.lock diff --git a/.travis.yml b/.travis.yml index 8f8e413..bc627f6 100755 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ -language: c +sudo: false +language: ruby addons: apt: @@ -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) diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..7e57322 --- /dev/null +++ b/Gemfile @@ -0,0 +1,2 @@ +source 'https://rubygems.org' +gem 'arduino_ci', '~> 0.1.14' diff --git a/test/libtst.cpp b/test/libtst.cpp new file mode 100644 index 0000000..ab4a659 --- /dev/null +++ b/test/libtst.cpp @@ -0,0 +1,71 @@ +#include +#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()