Skip to content
This repository was archived by the owner on Mar 25, 2021. It is now read-only.

Commit c2c9e58

Browse files
author
Wesley Duerksen
committed
Testing
1 parent ce7fca5 commit c2c9e58

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/Devices/Ethernet_TC.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,6 @@ void Ethernet_TC::renewDHCPLease() {
2828
Ethernet.maintain();
2929
previous_lease = current_millis;
3030
}
31+
32+
numAttemptedDHCPReleases++;
3133
}

src/Devices/Ethernet_TC.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ class Ethernet_TC {
1313
IPAddress getIP() {
1414
return IP;
1515
};
16+
int getNumAttemptedDHCPReleases() {
17+
return numAttemptedDHCPReleases;
18+
};
1619
void renewDHCPLease();
1720

1821
protected:
@@ -26,4 +29,7 @@ class Ethernet_TC {
2629
IPAddress IP;
2730
unsigned long previous_lease;
2831
const unsigned long LEASE_INTERVAL = 345600000; // 4 days in milliseconds
32+
33+
// testing
34+
int numAttemptedDHCPReleases = 0;
2935
};

test/Ethernet.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,21 @@
44
#include "Ethernet_TC.h"
55

66
unittest(test) {
7-
assertTrue(true);
7+
// Test singleton
8+
Ethernet_TC singleton1;
9+
singleton1 = singleton1->getInstance();
10+
Ethernet_TC singleton2;
11+
singleton2 = singleton2->getInstance();
12+
assertEqual(singleton1, singleton2);
13+
14+
// Test that the default Ip was used as a fall back
15+
assertEqual(singleton->getIP(), "19216812");
16+
17+
// Test DHCP is being maintained
18+
singleton1->renewDHCPLease();
19+
singleton1->renewDHCPLease();
20+
singleton1->renewDHCPLease();
21+
assertEqual(singleton1->getNumAttemptedDHCPReleases(), 3);
822
}
923

1024
unittest_main()

0 commit comments

Comments
 (0)