Skip to content

Commit 95fd259

Browse files
authored
Merge pull request #226 from TcMenu/main-unity-fixes
#221 move unit tests to unity.
2 parents 36346c3 + 88e68fb commit 95fd259

20 files changed

+270
-444
lines changed

platformio-test.ini

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ platform = espressif32
33
framework = arduino
44
board = esp32dev
55
extra_scripts = post:merge-bin.py
6-
test_build_src = yes
6+
test_build_src = true
77

88
lib_deps =
9-
tcMenu
109
IoAbstraction
1110
TaskManagerIO
1211
tcUnicodeHelper

test/baseRemoteTests.h

Lines changed: 0 additions & 178 deletions
This file was deleted.

test/CoreMenuItemTests.cpp renamed to test/test_core_items/CoreMenuItemTests.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <RuntimeMenuItem.h>
44
#include <RemoteMenuItem.h>
55
#include <RemoteAuthentication.h>
6-
#include "fixtures_extern.h"
6+
#include "../tutils/fixtures_extern.h"
77
#include <tcUtil.h>
88

99
RENDERING_CALLBACK_NAME_INVOKE(ipMenuItemTestCb, ipAddressRenderFn, "HelloWorld", 102, NULL)
@@ -79,7 +79,7 @@ void testFloatType() {
7979
menuFloatItem.clearSendRemoteNeededAll();
8080
menuFloatItem.setChanged(false);
8181
menuFloatItem.setFloatValue(1.001);
82-
TEST_ASSERT_FLOAT_WITHIN(1.001, menuFloatItem.getFloatValue(), 0.0001);
82+
TEST_ASSERT_FLOAT_WITHIN(0.0001, 1.001, menuFloatItem.getFloatValue());
8383
TEST_ASSERT_TRUE(menuFloatItem.isChanged());
8484
TEST_ASSERT_TRUE(menuFloatItem.isSendRemoteNeeded(0));
8585
TEST_ASSERT_EQUAL(4, menuFloatItem.getDecimalPlaces());
@@ -91,23 +91,23 @@ void testFloatType() {
9191
//
9292

9393
copyMenuItemNameAndValue(&menuFloatItem, sz, sizeof(sz));
94-
TEST_ASSERT_EQUAL("FloatItem: 1.0010", sz);
94+
TEST_ASSERT_EQUAL_STRING("FloatItem: 1.0010", sz);
9595

9696
menuFloatItem.setFloatValue(234.456722);
9797
copyMenuItemValue(&menuFloatItem, sz, sizeof(sz));
98-
TEST_ASSERT_EQUAL("234.4567", sz);
98+
TEST_ASSERT_EQUAL_STRING("234.4567", sz);
9999

100100
menuFloatItem.setFloatValue(-938.4567);
101101
copyMenuItemValue(&menuFloatItem, sz, sizeof(sz));
102-
TEST_ASSERT_EQUAL("-938.4567", sz);
102+
TEST_ASSERT_EQUAL_STRING("-938.4567", sz);
103103

104104
menuFloatItem.setFloatValue(-0.001);
105105
copyMenuItemValue(&menuFloatItem, sz, sizeof(sz));
106-
TEST_ASSERT_EQUAL("-0.0010", sz);
106+
TEST_ASSERT_EQUAL_STRING("-0.0010", sz);
107107

108108
menuFloatItem.setFloatValue(-0.0);
109109
copyMenuItemValue(&menuFloatItem, sz, sizeof(sz));
110-
TEST_ASSERT_EQUAL("0.0000", sz);
110+
TEST_ASSERT_EQUAL_STRING("0.0000", sz);
111111

112112
TEST_ASSERT_FALSE(isMenuRuntime(&menuFloatItem));
113113
TEST_ASSERT_FALSE(isMenuBasedOnValueItem(&menuFloatItem));

test/DateTimeItemTestCases.cpp renamed to test/test_core_items/DateTimeItemTestCases.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11

22
#include <unity.h>
33
#include <RuntimeMenuItem.h>
4-
#include "fixtures_extern.h"
4+
#include "../tutils/fixtures_extern.h"
55
#include <tcUtil.h>
66

7-
void printMenuItem(MenuItem* menuItem);
8-
9-
107
RENDERING_CALLBACK_NAME_INVOKE(timeMenuItemTestCb, timeItemRenderFn, "Time", 103, NULL)
118
RENDERING_CALLBACK_NAME_INVOKE(dateFormattedTestCb, dateItemRenderFn, "Date", 999, NULL)
129

test/LargeNumberItemTests.cpp renamed to test/test_core_items/LargeNumberItemTests.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <unity.h>
55
#include <RuntimeMenuItem.h>
66
#include <EditableLargeNumberMenuItem.h>
7-
#include "fixtures_extern.h"
7+
#include "../tutils/fixtures_extern.h"
88
#include <tcMenu.h>
99

1010
void dumpBuffer(LargeFixedNumber* buffer) {
@@ -69,7 +69,7 @@ void testLargeNumberGetAndSet() {
6969
TEST_ASSERT_EQUAL(largeNumber.getWhole(), (uint32_t)1234);
7070
TEST_ASSERT_EQUAL(largeNumber.getFraction(), (uint32_t)5678);
7171
TEST_ASSERT_FALSE(largeNumber.isNegative());
72-
TEST_ASSERT_FLOAT_WITHIN(largeNumber.getAsFloat(), 1234.5678f, 0.0001f);
72+
TEST_ASSERT_FLOAT_WITHIN(0.0001f, largeNumber.getAsFloat(), 1234.5678f);
7373

7474
// now set a negative value and read it back
7575
largeNumber.setValue(123UL, 56UL, true);
@@ -78,7 +78,7 @@ void testLargeNumberGetAndSet() {
7878
TEST_ASSERT_EQUAL(largeNumber.getWhole(), (uint32_t)123);
7979
TEST_ASSERT_EQUAL(largeNumber.getFraction(), (uint32_t)56);
8080
TEST_ASSERT_TRUE(largeNumber.isNegative());
81-
TEST_ASSERT_FLOAT_WITHIN(largeNumber.getAsFloat(), -123.0056f, 0.0001f);
81+
TEST_ASSERT_FLOAT_WITHIN(0.0001f, largeNumber.getAsFloat(), -123.0056f);
8282

8383
// now set a really large value and try to read back
8484
largeNumber.setPrecision(5);
@@ -201,7 +201,7 @@ void testPersistLargeInteger() {
201201
MockEepromAbstraction mockRom;
202202
menuMgr.getNavigationStore().clearNavigationListeners();
203203
menuMgr.setRootMenu(&editable);
204-
menuMgr.save(mockRom);
204+
saveMenuItem(&mockRom, &editable);
205205
dumpBuffer(editable.getLargeNumber());
206206
TEST_ASSERT_EQUAL(mockRom.read8(4), (uint8_t)0);
207207
TEST_ASSERT_EQUAL(mockRom.read8(5), (uint8_t)0x02);
@@ -249,7 +249,7 @@ void testLargeNumWithNegativeNotAllowed() {
249249
editable.setLargeNumberFromString("15234");
250250
TEST_ASSERT_EQUAL(editable.getLargeNumber()->getWhole(), (uint32_t)15234);
251251
TEST_ASSERT_EQUAL(editable.getLargeNumber()->getFraction(), (uint32_t)0);
252-
TEST_ASSERT_FLOAT_WITHIN(editable.getLargeNumber()->getAsFloat(), 15234.0F, 0.00001);
252+
TEST_ASSERT_FLOAT_WITHIN(0.00001F, editable.getLargeNumber()->getAsFloat(), 15234.0F);
253253
TEST_ASSERT_FALSE(editable.getLargeNumber()->isNegative());
254254

255255
char sz[32];

test/RuntimeItemTestCases.cpp renamed to test/test_core_items/RuntimeItemTestCases.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <RuntimeMenuItem.h>
44
#include <RemoteMenuItem.h>
55
#include <RemoteAuthentication.h>
6-
#include "fixtures_extern.h"
6+
#include "../tutils/fixtures_extern.h"
77
#include <tcUtil.h>
88

99
bool renderActivateCalled = false;

test/ScrollChoiceMenuItemTests.cpp renamed to test/test_core_items/ScrollChoiceMenuItemTests.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <unity.h>
33
#include <RuntimeMenuItem.h>
44
#include <ScrollChoiceMenuItem.h>
5-
#include "fixtures_extern.h"
5+
#include "../tutils/fixtures_extern.h"
66
#include <tcMenu.h>
77
#include <IoLogging.h>
88

@@ -139,38 +139,38 @@ void testColorMenuItemNoAlpha() {
139139
TEST_ASSERT_EQUAL((uint16_t)202, colorItemNoAlpha.getId());
140140
TEST_ASSERT_EQUAL((uint16_t)233, colorItemNoAlpha.getEepromPosition());
141141
colorItemNoAlpha.copyNameToBuffer(sz, sizeof(sz));
142-
TEST_ASSERT_EQUAL("RGB NoAlpha", sz);
142+
TEST_ASSERT_EQUAL_STRING("RGB NoAlpha", sz);
143143

144144
colorItemNoAlpha.setColorData(RgbColor32(100, 50, 200));
145145

146146
colorItemNoAlpha.copyValue(sz, sizeof sz);
147-
TEST_ASSERT_EQUAL("R100 G50 B200", sz);
147+
TEST_ASSERT_EQUAL_STRING("R100 G50 B200", sz);
148148

149149
TEST_ASSERT_EQUAL(3, colorItemNoAlpha.beginMultiEdit());
150150
TEST_ASSERT_EQUAL(255, colorItemNoAlpha.nextPart());
151151
colorItemNoAlpha.copyValue(sz, sizeof sz);
152-
TEST_ASSERT_EQUAL("R100 G50 B200", sz);
152+
TEST_ASSERT_EQUAL_STRING("R100 G50 B200", sz);
153153
TEST_ASSERT_TRUE(checkEditorHints(1, 4, CurrentEditorRenderingHints::EDITOR_RUNTIME_TEXT));
154154
colorItemNoAlpha.valueChanged(145);
155155
TEST_ASSERT_EQUAL(originalChangeCount + 2, colorCbCount);
156156

157157
TEST_ASSERT_EQUAL(255, colorItemNoAlpha.nextPart());
158158
colorItemNoAlpha.copyValue(sz, sizeof sz);
159-
TEST_ASSERT_EQUAL("R145 G50 B200", sz);
159+
TEST_ASSERT_EQUAL_STRING("R145 G50 B200", sz);
160160
TEST_ASSERT_TRUE(checkEditorHints(6, 8, CurrentEditorRenderingHints::EDITOR_RUNTIME_TEXT));
161161
colorItemNoAlpha.valueChanged(222);
162162
TEST_ASSERT_EQUAL(originalChangeCount + 3, colorCbCount);
163163

164164
TEST_ASSERT_EQUAL(255, colorItemNoAlpha.nextPart());
165165
colorItemNoAlpha.copyValue(sz, sizeof sz);
166-
TEST_ASSERT_EQUAL("R145 G222 B200", sz);
166+
TEST_ASSERT_EQUAL_STRING("R145 G222 B200", sz);
167167
TEST_ASSERT_TRUE(checkEditorHints(11, 14, CurrentEditorRenderingHints::EDITOR_RUNTIME_TEXT));
168168
colorItemNoAlpha.valueChanged(1);
169169
TEST_ASSERT_EQUAL(originalChangeCount + 4, colorCbCount);
170170

171171
TEST_ASSERT_EQUAL(0, colorItemNoAlpha.nextPart());
172172
colorItemNoAlpha.copyValue(sz, sizeof sz);
173-
TEST_ASSERT_EQUAL("R145 G222 B1", sz);
173+
TEST_ASSERT_EQUAL_STRING("R145 G222 B1", sz);
174174
}
175175

176176
RENDERING_CALLBACK_NAME_INVOKE(colorItemWithAlphaFn, rgbAlphaItemRenderFn, "RGB Alpha", 333, myCountingCallback);
@@ -182,27 +182,27 @@ void testColorMenuItemWithAlphaAndFn() {
182182
char sz[25];
183183
TEST_ASSERT_EQUAL((uint16_t)202, colorItemWithAlpha.getId());
184184
colorItemWithAlpha.copyNameToBuffer(sz, sizeof(sz));
185-
TEST_ASSERT_EQUAL("RGB Alpha", sz);
185+
TEST_ASSERT_EQUAL_STRING("RGB Alpha", sz);
186186

187187
colorItemWithAlpha.setColorData(RgbColor32(100, 50, 200, 150));
188188

189189
colorItemWithAlpha.copyValue(sz, sizeof sz);
190-
TEST_ASSERT_EQUAL("R100 G50 B200 A150", sz);
190+
TEST_ASSERT_EQUAL_STRING("R100 G50 B200 A150", sz);
191191

192192
TEST_ASSERT_EQUAL(4, colorItemWithAlpha.beginMultiEdit());
193193
TEST_ASSERT_EQUAL(255, colorItemWithAlpha.nextPart());
194194
TEST_ASSERT_EQUAL(255, colorItemWithAlpha.nextPart());
195195
TEST_ASSERT_EQUAL(255, colorItemWithAlpha.nextPart());
196196
TEST_ASSERT_EQUAL(255, colorItemWithAlpha.nextPart());
197197
colorItemWithAlpha.copyValue(sz, sizeof sz);
198-
TEST_ASSERT_EQUAL("R100 G50 B200 A150", sz);
198+
TEST_ASSERT_EQUAL_STRING("R100 G50 B200 A150", sz);
199199
TEST_ASSERT_TRUE(checkEditorHints(15, 18, CurrentEditorRenderingHints::EDITOR_RUNTIME_TEXT));
200200
colorItemWithAlpha.valueChanged(225);
201201
TEST_ASSERT_EQUAL(originalChangeCount + 2, colorCbCount);
202202

203203
TEST_ASSERT_EQUAL(0, colorItemWithAlpha.nextPart());
204204
colorItemWithAlpha.copyValue(sz, sizeof sz);
205-
TEST_ASSERT_EQUAL("R100 G50 B200 A225", sz);
205+
TEST_ASSERT_EQUAL_STRING("R100 G50 B200 A225", sz);
206206
}
207207

208208

0 commit comments

Comments
 (0)