@@ -17,12 +17,24 @@ void assertStringsEqual(Test& __test__, const char* expected, const String& actu
1717{
1818 size_t expectedLength = strlen (expected);
1919 assertEquals (expectedLength, actual.length ());
20- for (size_t i = 0 ; i < strlen (expected) ; i++)
20+ for (size_t i = 0 ; i < expectedLength ; i++)
2121 {
2222 assertEquals (expected[i], actual[i]);
2323 }
2424}
2525
26+ test (setFirmwareVersionDoesNotLeakMemory)
27+ {
28+ Firmata.setFirmwareVersion (1 , 0 );
29+ int initialMemory = freeMemory ();
30+
31+ Firmata.setFirmwareVersion (1 , 0 );
32+
33+ assertEquals (0 , initialMemory - freeMemory ());
34+
35+ Firmata.unsetFirmwareVersion ();
36+ }
37+
2638test (beginPrintsVersion)
2739{
2840 FakeStream stream;
@@ -59,8 +71,14 @@ void writeToDigitalPort(byte port, int value)
5971 _digitalPortValue = value;
6072}
6173
74+ void setupDigitalPort () {
75+ _digitalPort = 0 ;
76+ _digitalPortValue = 0 ;
77+ }
78+
6279test (processWriteDigital_0)
6380{
81+ setupDigitalPort ();
6482 Firmata.attach (DIGITAL_MESSAGE, writeToDigitalPort);
6583
6684 byte message[] = { DIGITAL_MESSAGE, 0 , 0 };
@@ -71,6 +89,7 @@ test(processWriteDigital_0)
7189
7290test (processWriteDigital_127)
7391{
92+ setupDigitalPort ();
7493 Firmata.attach (DIGITAL_MESSAGE, writeToDigitalPort);
7594
7695 byte message[] = { DIGITAL_MESSAGE, 127 , 0 };
@@ -79,18 +98,9 @@ test(processWriteDigital_127)
7998 assertEquals (127 , _digitalPortValue);
8099}
81100
82- test (processWriteDigitalStripsTopBit)
83- {
84- Firmata.attach (DIGITAL_MESSAGE, writeToDigitalPort);
85-
86- byte message[] = { DIGITAL_MESSAGE, B11111111, 0 };
87- processMessage (message, 3 );
88-
89- assertEquals (B01111111, _digitalPortValue);
90- }
91-
92101test (processWriteDigital_128)
93102{
103+ setupDigitalPort ();
94104 Firmata.attach (DIGITAL_MESSAGE, writeToDigitalPort);
95105
96106 byte message[] = { DIGITAL_MESSAGE, 0 , 1 };
@@ -101,6 +111,7 @@ test(processWriteDigital_128)
101111
102112test (processWriteLargestDigitalValue)
103113{
114+ setupDigitalPort ();
104115 Firmata.attach (DIGITAL_MESSAGE, writeToDigitalPort);
105116
106117 byte message[] = { DIGITAL_MESSAGE, 0x7F , 0x7F };
@@ -112,6 +123,7 @@ test(processWriteLargestDigitalValue)
112123
113124test (defaultDigitalWritePortIsZero)
114125{
126+ setupDigitalPort ();
115127 Firmata.attach (DIGITAL_MESSAGE, writeToDigitalPort);
116128
117129 byte message[] = { DIGITAL_MESSAGE, 0 , 0 };
@@ -122,6 +134,7 @@ test(defaultDigitalWritePortIsZero)
122134
123135test (specifiedDigitalWritePort)
124136{
137+ setupDigitalPort ();
125138 Firmata.attach (DIGITAL_MESSAGE, writeToDigitalPort);
126139
127140 byte message[] = { DIGITAL_MESSAGE + 1 , 0 , 0 };
@@ -130,12 +143,3 @@ test(specifiedDigitalWritePort)
130143 assertEquals (1 , _digitalPort);
131144}
132145
133- test (setFirmwareVersionDoesNotLeakMemory)
134- {
135- Firmata.setFirmwareVersion (1 , 0 );
136- int initialMemory = freeMemory ();
137-
138- Firmata.setFirmwareVersion (1 , 0 );
139-
140- assertEquals (0 , initialMemory - freeMemory ());
141- }
0 commit comments