1-phase PV router
Loading...
Searching...
No Matches
test_main.cpp
Go to the documentation of this file.
1
11
12#include <Arduino.h>
13#include <U8g2lib.h>
14
15#include <unity.h>
16
17#include "utils_pins.h"
18
22void setUp(void)
23{
24 // set stuff up here
25}
26
30void tearDown(void)
31{
32 // clean stuff up here
33}
34
38void test_setPinON(void)
39{
40 setPinON(LED_BUILTIN);
41 delay(100);
42 TEST_ASSERT_EQUAL(HIGH, digitalRead(LED_BUILTIN));
43}
44
49{
50 setPinOFF(LED_BUILTIN);
51 delay(100);
52 TEST_ASSERT_EQUAL(LOW, digitalRead(LED_BUILTIN));
53}
54
59{
60 digitalWrite(LED_BUILTIN, HIGH);
61 delay(100);
62 togglePin(LED_BUILTIN);
63 delay(100);
64 TEST_ASSERT_EQUAL(LOW, digitalRead(LED_BUILTIN));
65
66 togglePin(LED_BUILTIN);
67 delay(100);
68 TEST_ASSERT_EQUAL(HIGH, digitalRead(LED_BUILTIN));
69}
70
75{
76 setPinState(LED_BUILTIN, true);
77 delay(100);
78 TEST_ASSERT_EQUAL(HIGH, digitalRead(LED_BUILTIN));
79 setPinState(LED_BUILTIN, false);
80 delay(100);
81 TEST_ASSERT_EQUAL(LOW, digitalRead(LED_BUILTIN));
82}
83
88{
89 const uint16_t pinsToSet{ 0b11111111111100 };
90
91 setPinsON(pinsToSet);
92 delay(100);
93
94 for (uint8_t pin = 2; pin < 14; ++pin)
95 {
96 TEST_ASSERT_EQUAL(HIGH, digitalRead(pin));
97 }
98}
99
104{
105 const uint16_t pinsToSet{ 0b11111111111100 };
106
107 setPinsOFF(pinsToSet);
108 delay(100);
109
110 for (uint8_t pin = 2; pin < 14; ++pin)
111 {
112 TEST_ASSERT_EQUAL(LOW, digitalRead(pin));
113 }
114}
115
119void setup()
120{
121 delay(1000);
122
123 for (uint8_t pin = 2; pin < 14; ++pin)
124 {
125 pinMode(pin, OUTPUT);
126 }
127
128 UNITY_BEGIN(); // IMPORTANT LINE!
129}
130
131uint8_t i = 0;
132uint8_t max_blinks = 2;
133
137void loop()
138{
139 if (i < max_blinks)
140 {
141 RUN_TEST(test_setPinON);
142 delay(100);
143 RUN_TEST(test_setPinOFF);
144 delay(100);
145 RUN_TEST(test_togglePin);
146 delay(100);
147 RUN_TEST(test_setPinState);
148 delay(100);
149 RUN_TEST(test_setPinsON);
150 delay(100);
151 RUN_TEST(test_setPinsOFF);
152 delay(100);
153 ++i;
154 }
155 else if (i == max_blinks)
156 {
157 UNITY_END(); // stop unit testing
158 }
159}
void setup()
uint8_t max_blinks
void setUp(void)
Definition test_main.cpp:6
void tearDown(void)
Definition test_main.cpp:11
uint8_t i
void loop()
void test_setPinON(void)
Definition test_main.cpp:38
void test_togglePin(void)
Definition test_main.cpp:58
void test_setPinsON(void)
Definition test_main.cpp:87
void test_setPinsOFF(void)
void test_setPinState(void)
Definition test_main.cpp:74
void test_setPinOFF(void)
Definition test_main.cpp:48
Some utility functions for pins manipulation.
void setPinsOFF(uint16_t pins)
Set the Pins state to OFF.
Definition utils_pins.h:181
constexpr void setPinState(const uint8_t pin, const bool bState)
Set the Pin state for the specified pin.
Definition utils_pins.h:111
constexpr void togglePin(uint8_t pin)
Toggle the specified pin.
Definition utils_pins.h:89
constexpr void setPinON(uint8_t pin)
Set the Pin state to ON for the specified pin.
Definition utils_pins.h:128
constexpr void setPinOFF(uint8_t pin)
Set the Pin state to OFF for the specified pin.
Definition utils_pins.h:160
void setPinsON(uint16_t pins)
Set the Pins state to ON.
Definition utils_pins.h:149