3-phase PV router
Loading...
Searching...
No Matches
test_main.cpp
Go to the documentation of this file.
1#include <Arduino.h>
2#include <unity.h>
3
4#include "teleinfo.h"
5#include "config_system.h"
6
7void setUp(void)
8{
9 // Setup for each test
10}
11
12void tearDown(void)
13{
14 // Clean up after each test
15}
16
18{
19 // Test lineSize function with various tag and value lengths
20 // Format: LF + tag + TAB + value + TAB + checksum + CR = 5 + tagLen + valueLen
21
22 TEST_ASSERT_EQUAL(5 + 1 + 3, lineSize(1, 3)); // 1-char tag, 3-char value
23 TEST_ASSERT_EQUAL(5 + 2 + 5, lineSize(2, 5)); // 2-char tag, 5-char value
24 TEST_ASSERT_EQUAL(5 + 4 + 2, lineSize(4, 2)); // 4-char tag, 2-char value
25}
26
28{
29 // Test that calcBufferSize is evaluated at compile time
30 constexpr size_t bufferSize = calcBufferSize();
31
32 // Basic validation - should be reasonable size
33 TEST_ASSERT_GREATER_THAN(10, bufferSize); // Should be more than just STX+ETX
34 TEST_ASSERT_LESS_THAN(1000, bufferSize); // Should be reasonable for embedded system
35}
36
38{
39 // Test that we can create TeleInfo objects without issues
40 TeleInfo teleinfo;
41
42 // This test mainly validates that the class compiles and can be instantiated
43 // The buffer size calculation and memory allocation should work
44 TEST_ASSERT_TRUE(true); // If we get here, instantiation worked
45}
46
48{
49 // Test basic operations that don't require output verification
50 TeleInfo teleinfo;
51
52 // These should not crash or cause issues
53 teleinfo.startFrame();
54 teleinfo.send("P", 1234);
55 teleinfo.send("V", 230, 1);
56 teleinfo.send("T", -15, 2);
57 teleinfo.endFrame();
58
59 // If we reach here, the basic operations completed without crashing
60 TEST_ASSERT_TRUE(true);
61}
62
64{
65 // Test edge case values
66 TeleInfo teleinfo;
67
68 teleinfo.startFrame();
69
70 // Test various edge case values
71 teleinfo.send("ZERO", 0);
72 teleinfo.send("MAX", 32767); // MAX INT16
73 teleinfo.send("MIN", -32768); // MIN INT16
74 teleinfo.send("POS", 1);
75 teleinfo.send("NEG", -1);
76
77 teleinfo.endFrame();
78
79 // If execution reaches here, edge values were handled correctly
80 TEST_ASSERT_TRUE(true);
81}
82
84{
85 // Test creating multiple frames in sequence
86 TeleInfo teleinfo;
87
88 // First frame
89 teleinfo.startFrame();
90 teleinfo.send("F1", 100);
91 teleinfo.endFrame();
92
93 // Second frame
94 teleinfo.startFrame();
95 teleinfo.send("F2", 200);
96 teleinfo.endFrame();
97
98 // Third frame
99 teleinfo.startFrame();
100 teleinfo.send("F3", 300);
101 teleinfo.endFrame();
102
103 // If we reach here, multiple frames were created successfully
104 TEST_ASSERT_TRUE(true);
105}
106
108{
109 // Test longer sequences to validate buffer management
110 TeleInfo teleinfo;
111
112 teleinfo.startFrame();
113
114 // Add many values to test buffer capacity
115 for (int i = 1; i <= 10; i++)
116 {
117 teleinfo.send("V", 230 + i, i);
118 }
119
120 teleinfo.endFrame();
121
122 // If we reach here, long sequences were handled correctly
123 TEST_ASSERT_TRUE(true);
124}
125
126void setup()
127{
128 delay(2000); // Give time for Serial to initialize
129
130 Serial.begin(9600);
131 Serial.println("Starting TeleInfo embedded tests...");
132
133 UNITY_BEGIN();
134}
135
136void loop()
137{
145
146 Serial.println("All TeleInfo tests completed!");
147
148 UNITY_END();
149}
A class for managing and sending telemetry information in a structured frame format.
Definition teleinfo.h:166
void send(const char *tag, int16_t value, uint8_t index=0)
Sends a telemetry value as an integer.
Definition teleinfo.h:240
Basic configuration values to be set by the end-user.
void setup()
void setUp(void)
Definition test_main.cpp:6
void tearDown(void)
Definition test_main.cpp:11
uint8_t i
void loop()
void test_teleinfo_edge_values(void)
Definition test_main.cpp:63
void test_lineSize_calculation(void)
Definition test_main.cpp:17
void test_teleinfo_multiple_frames(void)
Definition test_main.cpp:83
void test_teleinfo_instantiation(void)
Definition test_main.cpp:37
void test_teleinfo_long_sequences(void)
void test_calcBufferSize_compile_time(void)
Definition test_main.cpp:27
void test_teleinfo_basic_operations(void)
Definition test_main.cpp:47
static constexpr size_t calcBufferSize()
Calculates the total buffer size required for the telemetry frame.
Definition teleinfo.h:95
static constexpr size_t lineSize(size_t tagLen, size_t valueLen)
Calculates the size of a single telemetry line in the frame.
Definition teleinfo.h:49
Manages telemetry data and frame formatting.