Skip to content

Commit 9b5cd4c

Browse files
authored
Merge pull request Arduino-CI#177 from Lizj96/tdd
Add tests for EEPROM
2 parents a0677ff + f923a7f commit 9b5cd4c

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

SampleProjects/TestSomething/test/eeprom.cpp

+63
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,74 @@
55
#if defined(EEPROM_SIZE) || (defined(E2END) && E2END)
66
#include <EEPROM.h>
77

8+
GodmodeState* state = GODMODE();
9+
unittest_setup()
10+
{
11+
state->reset();
12+
}
13+
814
unittest(length)
915
{
1016
assertEqual(EEPROM_SIZE, EEPROM.length());
1117
}
1218

19+
unittest(firstRead)
20+
{
21+
uint8_t a = EEPROM.read(0);
22+
assertEqual(255, a);
23+
}
24+
25+
unittest(writeRead)
26+
{
27+
EEPROM.write(0, 24);
28+
uint8_t a = EEPROM.read(0);
29+
assertEqual(24, a);
30+
31+
EEPROM.write(0, 128);
32+
a = EEPROM.read(0);
33+
assertEqual(128, a);
34+
35+
EEPROM.write(0, 256);
36+
a = EEPROM.read(0);
37+
assertEqual(0, a);
38+
39+
int addr = EEPROM_SIZE / 2;
40+
EEPROM.write(addr, 63);
41+
a = EEPROM.read(addr);
42+
assertEqual(63, a);
43+
44+
addr = EEPROM_SIZE - 1;
45+
EEPROM.write(addr, 188);
46+
a = EEPROM.read(addr);
47+
assertEqual(188, a);
48+
}
49+
50+
unittest(updateWrite)
51+
{
52+
EEPROM.write(1, 14);
53+
EEPROM.update(1, 22);
54+
uint8_t a = EEPROM.read(1);
55+
assertEqual(22, a);
56+
}
57+
58+
unittest(putGet)
59+
{
60+
const float f1 = 0.025f;
61+
float f2 = 0.0f;
62+
EEPROM.put(5, f1);
63+
assertEqual(0.0f, f2);
64+
EEPROM.get(5, f2);
65+
assertEqual(0.025f, f2);
66+
}
67+
68+
unittest(array)
69+
{
70+
int val = 10;
71+
EEPROM[2] = val;
72+
uint8_t a = EEPROM[2];
73+
assertEqual(10, a);
74+
}
75+
1376
#endif
1477

1578
unittest_main()

cpp/arduino/Godmode.h

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <avr/io.h>
44
#include "WString.h"
55
#include "PinHistory.h"
6+
#include "EEPROM.h"
67

78
// random
89
void randomSeed(unsigned long seed);
@@ -87,12 +88,19 @@ class GodmodeState {
8788
spi.readDelayMicros = 0;
8889
}
8990

91+
void resetEEPROM() {
92+
for(int i = 0; i < EEPROM.length(); ++i){
93+
EEPROM.update(i, 255);
94+
}
95+
}
96+
9097
void reset() {
9198
resetClock();
9299
resetPins();
93100
resetInterrupts();
94101
resetPorts();
95102
resetSPI();
103+
resetEEPROM();
96104
seed = 1;
97105
}
98106

0 commit comments

Comments
 (0)