11#include " ../../SerialMock.h"
2+ #include " ../helper.h"
23#include " BlenderServoAnimation.h"
34#include < unity.h>
45
56using 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-
178void 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
3312const 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+
88112int 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}
0 commit comments