Skip to content

Commit 52419a0

Browse files
committed
ZTEST unit testing facility
1 parent 229bef1 commit 52419a0

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed

EXRAIL2MacroBase.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,3 +875,12 @@
875875
///brief Resumes locos saved speed
876876
///param cab loco id
877877
///see XRESTORE_SPEED
878+
879+
#define ZTEST(command,testcode...)
880+
///brief Developer Unit testing. Do not use.
881+
882+
#define ZTEST2(command,reply)
883+
///brief Developer Unit testing. Do not use.
884+
885+
#define ZTEST3(command,reply,testcode...)
886+
///brief Developer Unit testing. Do not use.

EXRAIL2MacroReset.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@
230230
#undef XFWD
231231
#undef XSAVE_SPEED
232232
#undef XRESTORE_SPEED
233+
#undef ZTEST
234+
#undef ZTEST2
235+
#undef ZTEST3
233236

234237
#ifndef RMFT2_UNDEF_ONLY
235238
#include "EXRAIL2MacroBase.h"

EXRAILMacros.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,20 @@ case (__COUNTER__ - StringMacroTracker1) : {\
323323
#define STEALTH(code...) case (__COUNTER__ - StringMacroTracker1) : {code} return;
324324
#undef WITHROTTLE
325325
#define WITHROTTLE(msg) THRUNGE(msg,thrunge_withrottle)
326+
#undef ZTEST
327+
#define ZTEST(command,code...) case (__COUNTER__ - StringMacroTracker1) : \
328+
Ztest::parse(F(command),nullptr,[]() -> bool { return (code);}); \
329+
return;
330+
#undef ZTEST2
331+
#define ZTEST2(command,response) case (__COUNTER__ - StringMacroTracker1) : \
332+
Ztest::parse(F(command),F(response),nullptr); \
333+
return;
334+
#undef ZTEST3
335+
#define ZTEST3(command,response,code...) case (__COUNTER__ - StringMacroTracker1) : \
336+
Ztest::parse(F(command),F(response),[]() -> bool { return (code);}); \
337+
return;
338+
339+
#include "Ztest.h"
326340

327341
void RMFT2::printMessage(uint16_t id) {
328342
thrunger tmode;
@@ -701,6 +715,9 @@ int RMFT2::onLCCLookup[RMFT2::countLCCLookup];
701715
#define XPOM(cab,cv,value) OPCODE_XPOM,V(cab),OPCODE_PAD,V(cv),OPCODE_PAD,V(value),
702716
#define XSAVE_SPEED(cab) OPCODE_XSAVE_SPEED,V(cab),
703717
#define XRESTORE_SPEED(cab) OPCODE_XRESTORE_SPEED,V(cab),
718+
#define ZTEST(command,code...) PRINT(dummy)
719+
#define ZTEST2(command,response) PRINT(dummy)
720+
#define ZTEST3(command,response,code...) PRINT(dummy)
704721

705722
// Build RouteCode
706723
const int StringMacroTracker2=__COUNTER__;

EXRAILTest.h

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,37 @@ SEQUENCE(7500)
135135
RESET(870)
136136
AT(870)
137137
PRINT("870 set")
138-
DONE
138+
DONE
139+
140+
ROUTE(7800, "ZTESTS")
141+
PRINT("ZTESTS starting")
142+
ZTEST("<t 3 5 1>",DCC::getLocoSpeedByte(3)==(128+6))
143+
ZTEST("<t 3 5 0>",DCC::getLocoSpeedByte(3)==(6))
144+
ZTEST("<-3>",DCC::getLocoSpeedByte(3)==(128))
145+
ZTEST2("<$>","<X>\n")
146+
DONE
147+
148+
ROUTE(7900,"7900 Test IFSTASHED_HERE")
149+
SETLOCO(4) // set loco 4
150+
STASH(200) // stash loco 4 in stash 2
151+
152+
// loco is 4
153+
IFSTASHED_HERE(100) // should be false
154+
PRINT("FAIL Loco 4 in stash 100")
155+
ELSE
156+
PRINT("OK: loco 4 is not in stash 100")
157+
ENDIF
158+
159+
SETLOCO(3)
160+
IFSTASHED_HERE(200) // should be false
161+
PRINT("FAIL Loco 3 in stash 200")
162+
ELSE
163+
PRINT("OK: loco 3 is not in stash 200")
164+
ENDIF
165+
166+
IFSTASHED_HERE(100) // should be true
167+
PRINT("OK: Loco 3 is in stash 100")
168+
ELSE
169+
PRINT("FAIL: loco 3 not in stash 100")
170+
ENDIF
171+
DONE

0 commit comments

Comments
 (0)