Skip to content

Commit 91691ad

Browse files
committed
restructure animation tests
1 parent f8cbf26 commit 91691ad

File tree

7 files changed

+361
-444
lines changed

7 files changed

+361
-444
lines changed

test/animation/helper.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include <Arduino.h>
2+
3+
#define FPS 60
4+
#define FRAMES 5
5+
#define FRAME_MICROS 16667
6+
7+
byte modeChangeCount = 0;
8+
9+
struct positionLog {
10+
int index;
11+
int positions[20];
12+
};
13+
14+
positionLog lastPositions[16];
15+
16+
void setUpHelper(void) {
17+
for (int id = 0; id < 16; id++) {
18+
lastPositions[id].index = 0;
19+
20+
for (int i = 0; i < 20; i++) {
21+
lastPositions[id].positions[i] = 0;
22+
}
23+
}
24+
25+
modeChangeCount = 0;
26+
}
27+
28+
void onModeChange(byte prevMode, byte newMode) {
29+
modeChangeCount++;
30+
}
31+
32+
void move(byte servoID, int position) {
33+
int index = lastPositions[servoID].index;
34+
lastPositions[servoID].positions[index] = position;
35+
lastPositions[servoID].index++;
36+
}

test/animation/test_live/test_live.cpp

Lines changed: 54 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,17 @@
11
#include "../../SerialMock.h"
2+
#include "../helper.h"
23
#include "BlenderServoAnimation.h"
34
#include <unity.h>
45

56
using namespace BlenderServoAnimation;
67

7-
#define FPS 60
8-
#define FRAMES 5
9-
10-
struct positionLog {
11-
int index;
12-
int positions[20];
13-
};
14-
15-
positionLog lastPositions[16];
16-
178
void setUp(void) {
18-
for (int id = 0; id < 16; id++) {
19-
lastPositions[id].index = 0;
20-
21-
for (int i = 0; i < 20; i++) {
22-
lastPositions[id].positions[i] = 0;
23-
}
24-
}
25-
}
26-
27-
void move(byte servoID, int position) {
28-
int index = lastPositions[servoID].index;
29-
lastPositions[servoID].positions[index] = position;
30-
lastPositions[servoID].index++;
9+
setUpHelper();
3110
}
3211

3312
const int positions[5] PROGMEM = {350, 340, 330, 340, 330};
3413

35-
void test_multiple_servos(void) {
14+
void test_live(void) {
3615
Animation animation;
3716
SerialMock mock;
3817
Servo servos[] = {
@@ -65,7 +44,7 @@ void test_multiple_servos(void) {
6544
TEST_ASSERT_EQUAL(355, lastPositions[1].positions[1]);
6645
}
6746

68-
void test_skip(void) {
47+
void test_skip_incomplete_command(void) {
6948
Animation animation;
7049
SerialMock mock;
7150
Servo servo(0, move);
@@ -85,9 +64,57 @@ void test_skip(void) {
8564
TEST_ASSERT_EQUAL(360, lastPositions[0].positions[1]);
8665
}
8766

67+
void test_call_twice(void) {
68+
Serial_ mock;
69+
Animation animation(FPS, FRAMES);
70+
animation.onModeChange(onModeChange);
71+
72+
TEST_ASSERT_EQUAL(Animation::MODE_DEFAULT, animation.getMode());
73+
animation.live(mock);
74+
TEST_ASSERT_EQUAL(Animation::MODE_LIVE, animation.getMode());
75+
animation.live(mock);
76+
TEST_ASSERT_EQUAL(Animation::MODE_LIVE, animation.getMode());
77+
78+
TEST_ASSERT_EQUAL(1, modeChangeCount);
79+
}
80+
81+
void test_prevented(void) {
82+
Serial_ mock;
83+
Animation animation(FPS, FRAMES);
84+
85+
animation.play(0);
86+
TEST_ASSERT_EQUAL(Animation::MODE_PLAY, animation.getMode());
87+
animation.live(mock);
88+
TEST_ASSERT_EQUAL(Animation::MODE_PLAY, animation.getMode());
89+
animation.pause();
90+
TEST_ASSERT_EQUAL(Animation::MODE_PAUSE, animation.getMode());
91+
animation.live(mock);
92+
TEST_ASSERT_EQUAL(Animation::MODE_PAUSE, animation.getMode());
93+
animation.loop(0);
94+
TEST_ASSERT_EQUAL(Animation::MODE_LOOP, animation.getMode());
95+
animation.live(mock);
96+
TEST_ASSERT_EQUAL(Animation::MODE_LOOP, animation.getMode());
97+
animation.stop();
98+
TEST_ASSERT_EQUAL(Animation::MODE_STOP, animation.getMode());
99+
animation.live(mock);
100+
TEST_ASSERT_EQUAL(Animation::MODE_STOP, animation.getMode());
101+
}
102+
103+
void test_allowed(void) {
104+
Serial_ mock;
105+
Animation animation(FPS, FRAMES);
106+
107+
TEST_ASSERT_EQUAL(Animation::MODE_DEFAULT, animation.getMode());
108+
animation.live(mock);
109+
TEST_ASSERT_EQUAL(Animation::MODE_LIVE, animation.getMode());
110+
}
111+
88112
int main(int argc, char **argv) {
89113
UNITY_BEGIN();
90-
RUN_TEST(test_multiple_servos);
91-
RUN_TEST(test_skip);
114+
RUN_TEST(test_live);
115+
RUN_TEST(test_skip_incomplete_command);
116+
RUN_TEST(test_call_twice);
117+
RUN_TEST(test_prevented);
118+
RUN_TEST(test_allowed);
92119
UNITY_END();
93120
}

test/animation/test_mode_restrictions/test_mode_restrictions.cpp

Lines changed: 0 additions & 181 deletions
This file was deleted.

0 commit comments

Comments
 (0)