Skip to content

Commit

Permalink
add a couple more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcello Romani committed Mar 28, 2017
1 parent 6fd8abd commit a71c054
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
42 changes: 42 additions & 0 deletions SimpleTimer/tests/TestEnableDisable/TestEnableDisable.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <ArduinoUnit.h>
#include <SimpleTimer.h>

// if when calling disable(), the timer callback doesn't get executed.

// the timer object
SimpleTimer timer;

bool all_done = false;

int counter = 0;

void callMeOnce() {
Serial.print("callMeOnce: counter=");
counter++;
Serial.println(counter);
}

void setup() {
Serial.begin(9600);

for (int i = 0; i < timer.MAX_TIMERS; i++) {
int id = timer.setTimer(10, callMeOnce, 1);
assertNotEqual(id, -1);
}

int id = timer.setTimer(10, callMeOnce, 1);
assertEqual(id, -1);

timer.disable(4);

assertEqual(timer.getNumTimers(), timer.MAX_TIMERS);
}

void loop() {
timer.run();

if (counter == (timer.MAX_TIMERS - 1)) {
Serial.println("Tests finished.");
while (true);
}
}
37 changes: 37 additions & 0 deletions SimpleTimer/tests/TestFillTimerTable/TestFillTimerTable.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <ArduinoUnit.h>
#include <SimpleTimer.h>

// the timer object
SimpleTimer timer;

bool all_done = false;

int counter = 0;

void callMeOnce() {
Serial.print("callMeOnce: counter=");
counter++;
Serial.println(counter);
}

void setup() {
Serial.begin(9600);

for (int i = 0; i < timer.MAX_TIMERS; i++) {
int id = timer.setTimer(10, callMeOnce, 1);
assertNotEqual(id, -1);
}

int id = timer.setTimer(10, callMeOnce, 1);
assertEqual(id, -1);
assertEqual(timer.getNumTimers(), timer.MAX_TIMERS);
}

void loop() {
timer.run();

if (counter == timer.MAX_TIMERS) {
Serial.println("Tests finished.");
while (true);
}
}

0 comments on commit a71c054

Please sign in to comment.