API
 
Loading...
Searching...
No Matches
siglentSDG_test.cpp
Go to the documentation of this file.
1/** \file siglentSDG_test.cpp
2 * \brief Catch2 tests for the siglentSDG app.
3 * \author Jared R. Males (jaredmales@gmail.com)
4 *
5 * \ingroup siglentSDG_files
6 */
7
8#include "../../../tests/testXWC.hpp"
9#include "../../../tests/testMacrosINDI.hpp"
10
11#include "../siglentSDG.hpp"
12
13using namespace MagAOX::app;
14
15namespace libXWCTest
16{
17
18/** \defgroup siglentSDG_unit_test siglentSDG Unit Tests
19 * \brief Unit tests for the siglentSDG application.
20 *
21 * \ingroup application_unit_test
22 */
23
24/// Namespace for `siglentSDG` unit tests.
25/** \ingroup siglentSDG_unit_test
26 */
27namespace siglentSDGTest
28{
29
30/// \cond DOXYGEN_SUPPRESS_TEST_HARNESS
31class siglentSDG_test : public siglentSDG
32{
33
34 public:
35 siglentSDG_test( const std::string device )
36 {
37 m_configName = device;
38
47
56 }
57};
58/// \endcond
59
60/// Verify siglentSDG callback validation and parser helpers behave as expected.
61/**
62 * \ingroup siglentSDG_unit_test
63 */
64SCENARIO( "INDI Callbacks", "[siglentSDG]" )
65{
66 // clang-format off
67 #ifdef SIGLENTSDG_TEST_DOXYGEN_REF
68 siglentSDG::newCallBack_m_indiP_C1outp( pcf::IndiProperty() );
69 siglentSDG::newCallBack_m_indiP_C2sync( pcf::IndiProperty() );
70 parseOUTP( *(int *)nullptr, *(int *)nullptr, "" );
71 #endif
72 // clang-format on
73
90}
91
92SCENARIO( "Parsing the OUTP? response", "[siglentSDG]" )
93{
94 GIVEN( "A valid response to OUTP from the SDG" )
95 {
96 int rv;
97
98 WHEN( "Valid OUTP passed, off" )
99 {
100 int channel = -10;
101 int outp = -10;
102
103 rv = parseOUTP( channel, outp, "C1:OUTP OFF,LOAD,HZ,PLRT,NOR" );
104
105 REQUIRE( rv == 0 );
106 REQUIRE( channel == 1 );
107 REQUIRE( outp == 0 );
108 }
109
110 WHEN( "Valid OUTP passed, on" )
111 {
112 int channel = -10;
113 int outp = -10;
114
115 rv = parseOUTP( channel, outp, "C2:OUTP ON,LOAD,HZ,PLRT,NOR" );
116
117 REQUIRE( rv == 0 );
118 REQUIRE( channel == 2 );
119 REQUIRE( outp == 1 );
120 }
121
122 WHEN( "Valid OUTP passed, two-digit channel on" )
123 {
124 int channel = -10;
125 int outp = -10;
126
127 rv = parseOUTP( channel, outp, "C35:OUTP ON,LOAD,HZ,PLRT,NOR" );
128
129 REQUIRE( rv == 0 );
130 REQUIRE( channel == 35 );
131 REQUIRE( outp == 1 );
132 }
133 }
134 GIVEN( "An invalid response to OUTP from the SDG" )
135 {
136 int rv;
137
138 WHEN( "Invalid OUTP passed, no sp" )
139 {
140 int channel = -10;
141 int outp = -10;
142
143 rv = parseOUTP( channel, outp, "C2:OUTPON,LOAD,HZ,PLRT,NOR" );
144
145 REQUIRE( rv == -2 );
146 }
147
148 WHEN( "Invalid OUTP passed, end before N in ON" )
149 {
150 int channel = -10;
151 int outp = -10;
152
153 rv = parseOUTP( channel, outp, "C2:OUTP O" );
154
155 REQUIRE( rv == -6 );
156 }
157
158 WHEN( "Invalid OUTP passed, end before :" )
159 {
160 int channel = -10;
161 int outp = -10;
162
163 rv = parseOUTP( channel, outp, "C2" );
164
165 REQUIRE( rv == -1 );
166 }
167
168 WHEN( "Wrong Command Reply" )
169 {
170 int channel = -10;
171 int outp = -10;
172
173 rv = parseOUTP(
174 channel,
175 outp,
176 "C1:BSWV WVTP,SINE,FRQ,10HZ,PERI,0.1S,AMP,2V,AMPVRMS,0.707Vrms,OFST,0V,HLEV,1V,LLEV,-1V,PHSE,0" );
177
178 REQUIRE( rv == -2 );
179 }
180 }
181}
182
183/// Verify automatic pulse width calculation across the requested frequency regimes.
184/**
185 * \ingroup siglentSDG_unit_test
186 */
187TEST_CASE( "auto pulse width from frequency", "[siglentSDG]" )
188{
189 SECTION( "below 2 kHz uses 250 us target" )
190 {
191 REQUIRE( autoPulseWidthFromFrequency( 1000.0 ) == Approx( 0.00075 ) );
192 }
193
194 SECTION( "at 2 kHz equals 250 us" )
195 {
196 REQUIRE( autoPulseWidthFromFrequency( 2000.0 ) == Approx( 0.00025 ) );
197 }
198
199 SECTION( "above 2 kHz uses 50 percent duty limit" )
200 {
201 REQUIRE( autoPulseWidthFromFrequency( 4000.0 ) == Approx( 0.000125 ) );
202 }
203
204 SECTION( "zero frequency yields zero width" )
205 {
206 REQUIRE( autoPulseWidthFromFrequency( 0.0 ) == Approx( 0.0 ) );
207 }
208}
209
210} // namespace siglentSDGTest
211
212} // namespace libXWCTest
213
214SCENARIO( "Parsing the BSWV? response", "[siglentSDG]" )
215{
216 GIVEN( "A valid response to BSWV from the SDG" )
217 {
218 int rv;
219
220 WHEN( "Valid BSWV passed" )
221 {
222 int channel = -10;
223 std::string wvtp;
224 double freq;
225 double peri;
226 double amp;
227 double ampvrms;
228 double ofst;
229 double hlev;
230 double llev;
231 double phse;
232 double wdth;
233 std::string resp = "C1:BSWV "
234 "WVTP,SINE,FRQ,10.123HZ,PERI,0.8345S,AMP,2.567V,AMPVRMS,0.707Vrms,OFST,0.34V,HLEV,1.3V,"
235 "LLEV,-2.567V,PHSE,4.3567";
236 rv = parseBSWV( channel, wvtp, freq, peri, amp, ampvrms, ofst, hlev, llev, phse, wdth, resp );
237
238 REQUIRE( rv == 0 );
239 REQUIRE( channel == 1 );
240 REQUIRE( wvtp == "SINE" );
241 REQUIRE( freq == 10.123 );
242 REQUIRE( peri == 0.8345 );
243 REQUIRE( amp == 2.567 );
244 REQUIRE( ampvrms == 0.707 );
245 REQUIRE( ofst == 0.34 );
246 REQUIRE( hlev == 1.3 );
247 REQUIRE( llev == -2.567 );
248 REQUIRE( phse == 4.3567 );
249 }
250 }
251
252 GIVEN( "An invalid response to BSWV from the SDG" )
253 {
254 int rv;
255
256 WHEN( "An invalid BSWV passed - not enough args" )
257 {
258 int channel = -10;
259 std::string wvtp;
260 double freq;
261 double peri;
262 double amp;
263 double ampvrms;
264 double ofst;
265 double hlev;
266 double llev;
267 double phse;
268 double wdth;
269 std::string resp = "C1:BSWV WVTP";
270 rv = parseBSWV( channel, wvtp, freq, peri, amp, ampvrms, ofst, hlev, llev, phse, wdth, resp );
271
272 REQUIRE( rv == -1 );
273 }
274
275 WHEN( "An invalid BSWV passed - wrong response" )
276 {
277 int channel = -10;
278 std::string wvtp;
279 double freq;
280 double peri;
281 double amp;
282 double ampvrms;
283 double ofst;
284 double hlev;
285 double llev;
286 double phse;
287 double wdth;
288 std::string resp = "C1:MDWV "
289 "WVTP,SINE,FRQ,10.123HZ,PERI,0.8345S,AMP,2.567V,AMPVRMS,0.707Vrms,OFST,0.34V,HLEV,1.3V,"
290 "LLEV,-2.567V,PHSE,4.3567";
291 rv = parseBSWV( channel, wvtp, freq, peri, amp, ampvrms, ofst, hlev, llev, phse, wdth, resp );
292
293 REQUIRE( rv == -2 );
294 }
295
296 WHEN( "An invalid BSWV passed - bad channel spec, no C" )
297 {
298 int channel = -10;
299 std::string wvtp;
300 double freq;
301 double peri;
302 double amp;
303 double ampvrms;
304 double ofst;
305 double hlev;
306 double llev;
307 double phse;
308 double wdth;
309 std::string resp = "X1:BSWV "
310 "WVTP,SINE,FRQ,10.123HZ,PERI,0.8345S,AMP,2.567V,AMPVRMS,0.707Vrms,OFST,0.34V,HLEV,1.3V,"
311 "LLEV,-2.567V,PHSE,4.3567";
312 rv = parseBSWV( channel, wvtp, freq, peri, amp, ampvrms, ofst, hlev, llev, phse, wdth, resp );
313
314 REQUIRE( rv == -3 );
315 }
316
317 WHEN( "An invalid BSWV passed - bad channel spec, too short " )
318 {
319 int channel = -10;
320 std::string wvtp;
321 double freq;
322 double peri;
323 double amp;
324 double ampvrms;
325 double ofst;
326 double hlev;
327 double llev;
328 double phse;
329 double wdth;
330 std::string resp = "C:BSWV "
331 "WVTP,SINE,FRQ,10.123HZ,PERI,0.8345S,AMP,2.567V,AMPVRMS,0.707Vrms,OFST,0.34V,HLEV,1.3V,"
332 "LLEV,-2.567V,PHSE,4.3567";
333 rv = parseBSWV( channel, wvtp, freq, peri, amp, ampvrms, ofst, hlev, llev, phse, wdth, resp );
334
335 REQUIRE( rv == -4 );
336 }
337
338 WHEN( "An invalid BSWV passed - bad WVTP indicator" )
339 {
340 int channel = -10;
341 std::string wvtp;
342 double freq;
343 double peri;
344 double amp;
345 double ampvrms;
346 double ofst;
347 double hlev;
348 double llev;
349 double phse;
350 double wdth;
351 std::string resp = "C1:BSWV "
352 "WVTQ,SINE,FRQ,10.123HZ,PERI,0.8345S,AMP,2.567V,AMPVRMS,0.707Vrms,OFST,0.34V,HLEV,1.3V,"
353 "LLEV,-2.567V,PHSE,4.3567";
354 rv = parseBSWV( channel, wvtp, freq, peri, amp, ampvrms, ofst, hlev, llev, phse, wdth, resp );
355
356 REQUIRE( rv == -5 );
357 }
358
359 WHEN( "An invalid BSWV passed - wvtp not SINE" )
360 {
361 int channel = -10;
362 std::string wvtp;
363 double freq;
364 double peri;
365 double amp;
366 double ampvrms;
367 double ofst;
368 double hlev;
369 double llev;
370 double phse;
371 double wdth;
372 std::string resp = "C1:BSWV "
373 "WVTP,UPIY,FRQ,10.123HZ,PERI,0.8345S,AMP,2.567V,AMPVRMS,0.707Vrms,OFST,0.34V,HLEV,1.3V,"
374 "LLEV,-2.567V,PHSE,4.3567";
375 rv = parseBSWV( channel, wvtp, freq, peri, amp, ampvrms, ofst, hlev, llev, phse, wdth, resp );
376
377 REQUIRE( rv == -6 );
378 }
379
380 WHEN( "An invalid BSWV passed - bad FRQ indicator" )
381 {
382 int channel = -10;
383 std::string wvtp;
384 double freq;
385 double peri;
386 double amp;
387 double ampvrms;
388 double ofst;
389 double hlev;
390 double llev;
391 double phse;
392 double wdth;
393 std::string resp = "C1:BSWV "
394 "WVTP,SINE,FRZ,10.123HZ,PERI,0.8345S,AMP,2.567V,AMPVRMS,0.707Vrms,OFST,0.34V,HLEV,1.3V,"
395 "LLEV,-2.567V,PHSE,4.3567";
396 rv = parseBSWV( channel, wvtp, freq, peri, amp, ampvrms, ofst, hlev, llev, phse, wdth, resp );
397
398 REQUIRE( rv == -10 );
399 }
400
401 WHEN( "An invalid BSWV passed - bad PERI indicator" )
402 {
403 int channel = -10;
404 std::string wvtp;
405 double freq;
406 double peri;
407 double amp;
408 double ampvrms;
409 double ofst;
410 double hlev;
411 double llev;
412 double phse;
413 double wdth;
414 std::string resp = "C1:BSWV "
415 "WVTP,SINE,FRQ,10.123HZ,PERZ,0.8345S,AMP,2.567V,AMPVRMS,0.707Vrms,OFST,0.34V,HLEV,1.3V,"
416 "LLEV,-2.567V,PHSE,4.3567";
417 rv = parseBSWV( channel, wvtp, freq, peri, amp, ampvrms, ofst, hlev, llev, phse, wdth, resp );
418
419 REQUIRE( rv == -11 );
420 }
421
422 WHEN( "An invalid BSWV passed - bad AMP indicator" )
423 {
424 int channel = -10;
425 std::string wvtp;
426 double freq;
427 double peri;
428 double amp;
429 double ampvrms;
430 double ofst;
431 double hlev;
432 double llev;
433 double phse;
434 double wdth;
435 std::string resp = "C1:BSWV "
436 "WVTP,SINE,FRQ,10.123HZ,PERI,0.8345S,A/"
437 "P,2.567V,AMPVRMS,0.707Vrms,OFST,0.34V,HLEV,1.3V,LLEV,-2.567V,PHSE,4.3567";
438 rv = parseBSWV( channel, wvtp, freq, peri, amp, ampvrms, ofst, hlev, llev, phse, wdth, resp );
439
440 REQUIRE( rv == -12 );
441 }
442
443 WHEN( "An invalid BSWV passed - bad AMPVRMS indicator" )
444 {
445 int channel = -10;
446 std::string wvtp;
447 double freq;
448 double peri;
449 double amp;
450 double ampvrms;
451 double ofst;
452 double hlev;
453 double llev;
454 double phse;
455 double wdth;
456 std::string resp = "C1:BSWV "
457 "WVTP,SINE,FRQ,10.123HZ,PERI,0.8345S,AMP,2.567V,APVRMS,0.707Vrms,OFST,0.34V,HLEV,1.3V,"
458 "LLEV,-2.567V,PHSE,4.3567";
459 rv = parseBSWV( channel, wvtp, freq, peri, amp, ampvrms, ofst, hlev, llev, phse, wdth, resp );
460
461 REQUIRE( rv == -13 );
462 }
463
464 WHEN( "An invalid BSWV passed - bad OFST indicator" )
465 {
466 int channel = -10;
467 std::string wvtp;
468 double freq;
469 double peri;
470 double amp;
471 double ampvrms;
472 double ofst;
473 double hlev;
474 double llev;
475 double phse;
476 double wdth;
477 std::string resp = "C1:BSWV "
478 "WVTP,SINE,FRQ,10.123HZ,PERI,0.8345S,AMP,2.567V,AMPVRMS,0.707Vrms,O,0.34V,HLEV,1.3V,"
479 "LLEV,-2.567V,PHSE,4.3567";
480 rv = parseBSWV( channel, wvtp, freq, peri, amp, ampvrms, ofst, hlev, llev, phse, wdth, resp );
481
482 REQUIRE( rv == -14 );
483 }
484
485 WHEN( "An invalid BSWV passed - bad HLEV indicator" )
486 {
487 int channel = -10;
488 std::string wvtp;
489 double freq;
490 double peri;
491 double amp;
492 double ampvrms;
493 double ofst;
494 double hlev;
495 double llev;
496 double phse;
497 double wdth;
498 std::string resp = "C1:BSWV "
499 "WVTP,SINE,FRQ,10.123HZ,PERI,0.8345S,AMP,2.567V,AMPVRMS,0.707Vrms,OFST,0.34V,HLV,1.3V,"
500 "LLEV,-2.567V,PHSE,4.3567";
501 rv = parseBSWV( channel, wvtp, freq, peri, amp, ampvrms, ofst, hlev, llev, phse, wdth, resp );
502
503 REQUIRE( rv == -15 );
504 }
505
506 WHEN( "An invalid BSWV passed - bad LLEV indicator" )
507 {
508 int channel = -10;
509 std::string wvtp;
510 double freq;
511 double peri;
512 double amp;
513 double ampvrms;
514 double ofst;
515 double hlev;
516 double llev;
517 double phse;
518 double wdth;
519 std::string resp = "C1:BSWV "
520 "WVTP,SINE,FRQ,10.123HZ,PERI,0.8345S,AMP,2.567V,AMPVRMS,0.707Vrms,OFST,0.34V,HLEV,1.3V,"
521 "QLEV,-2.567V,PHSE,4.3567";
522 rv = parseBSWV( channel, wvtp, freq, peri, amp, ampvrms, ofst, hlev, llev, phse, wdth, resp );
523
524 REQUIRE( rv == -16 );
525 }
526
527 WHEN( "An invalid BSWV passed - bad PHSE indicator" )
528 {
529 int channel = -10;
530 std::string wvtp;
531 double freq;
532 double peri;
533 double amp;
534 double ampvrms;
535 double ofst;
536 double hlev;
537 double llev;
538 double phse;
539 double wdth;
540 std::string resp = "C1:BSWV "
541 "WVTP,SINE,FRQ,10.123HZ,PERI,0.8345S,AMP,2.567V,AMPVRMS,0.707Vrms,OFST,0.34V,HLEV,1.3V,"
542 "LLEV,-2.567V,XXXXX,4.3567";
543 rv = parseBSWV( channel, wvtp, freq, peri, amp, ampvrms, ofst, hlev, llev, phse, wdth, resp );
544
545 REQUIRE( rv == -17 );
546 }
547 }
548}
549
550SCENARIO( "Parsing the MDWV? response", "[siglentSDG]" )
551{
552 GIVEN( "A valid response to MDWV from the SDG" )
553 {
554 int rv;
555
556 WHEN( "Valid MDWV passed, with state off" )
557 {
558 int channel = -10;
559 std::string state;
560 std::string resp = "C1:MDWV STATE,OFF";
561 rv = parseMDWV( channel, state, resp );
562
563 REQUIRE( rv == 0 );
564 REQUIRE( channel == 1 );
565 REQUIRE( state == "OFF" );
566 }
567
568 WHEN( "Valid MDWV passed, with state on" )
569 {
570 // We ignore the rest of the string
571 int channel = -10;
572 std::string state;
573 std::string resp = "C1:MDWV "
574 "STATE,ON,AM,MDSP,SINE,SRC,INT,FRQ,100HZ,DEPTH,100,CARR,WVTP,SINE,FRQ,1000HZ,AMP,4V,"
575 "AMPVRMS,1.414Vrms,OFST,0V,PHSE,0";
576 rv = parseMDWV( channel, state, resp );
577
578 REQUIRE( rv == 0 );
579 REQUIRE( channel == 1 );
580 REQUIRE( state == "ON" );
581 }
582 }
583
584 GIVEN( "An invalid response to MDWV from the SDG" )
585 {
586 int rv;
587
588 WHEN( "invalid MDWV passed - too short" )
589 {
590 int channel = -10;
591 std::string state;
592 std::string resp = "C1:MDWV S";
593 rv = parseMDWV( channel, state, resp );
594
595 REQUIRE( rv == -1 );
596 }
597
598 WHEN( "invalid MDWV passed - wrong command" )
599 {
600 int channel = -10;
601 std::string state;
602 std::string resp = "C1:MDWQ STATE,OFF";
603 rv = parseMDWV( channel, state, resp );
604
605 REQUIRE( rv == -2 );
606 }
607
608 WHEN( "invalid MDWV passed - no C" )
609 {
610 int channel = -10;
611 std::string state;
612 std::string resp = "X1:MDWV STATE,OFF";
613 rv = parseMDWV( channel, state, resp );
614
615 REQUIRE( rv == -3 );
616 }
617
618 WHEN( "invalid MDWV passed - no channel" )
619 {
620 int channel = -10;
621 std::string state;
622 std::string resp = "C:MDWV STATE,OFF";
623 rv = parseMDWV( channel, state, resp );
624
625 REQUIRE( rv == 0 );
626 REQUIRE( channel == 0 );
627 }
628
629 WHEN( "invalid MDWV passed - no STATE" )
630 {
631 int channel = -10;
632 std::string state;
633 std::string resp = "C1:MDWV STAT,OFF";
634 rv = parseMDWV( channel, state, resp );
635
636 REQUIRE( rv == -4 );
637 }
638 }
639}
640
641SCENARIO( "Parsing the SWWV? response", "[siglentSDG]" )
642{
643 GIVEN( "A valid response to SWWV from the SDG" )
644 {
645 int rv;
646
647 WHEN( "Valid SWWV passed, with state off" )
648 {
649 int channel = -10;
650 std::string state;
651 std::string resp = "C1:SWWV STATE,OFF";
652 rv = parseSWWV( channel, state, resp );
653
654 REQUIRE( rv == 0 );
655 REQUIRE( channel == 1 );
656 REQUIRE( state == "OFF" );
657 }
658
659 WHEN( "Valid SWWV passed, with state on" )
660 {
661 // We ignore the rest of the string
662 int channel = -10;
663 std::string state;
664 std::string resp = "C1:SWWV "
665 "STATE,ON,TIME,1S,STOP,1500HZ,START,500HZ,TRSR,INT,TRMD,OFF,SWMD,LINE,DIR,UP,SYM,0."
666 "000000,CARR,WVTP,SINE,FRQ,1000HZ,AMP,4V,AMPVRMS,1.414Vrms,OFST,0V,PHSE,0";
667 rv = parseSWWV( channel, state, resp );
668
669 REQUIRE( rv == 0 );
670 REQUIRE( channel == 1 );
671 REQUIRE( state == "ON" );
672 }
673 }
674
675 GIVEN( "An invalid response to SWWV from the SDG" )
676 {
677 int rv;
678
679 WHEN( "invalid SWWV passed - too short" )
680 {
681 int channel = -10;
682 std::string state;
683 std::string resp = "C1:SWWV S";
684 rv = parseSWWV( channel, state, resp );
685
686 REQUIRE( rv == -1 );
687 }
688
689 WHEN( "invalid SWWV passed - wrong command" )
690 {
691 int channel = -10;
692 std::string state;
693 std::string resp = "C1:SWWQ STATE,OFF";
694 rv = parseSWWV( channel, state, resp );
695
696 REQUIRE( rv == -2 );
697 }
698
699 WHEN( "invalid SWWV passed - no C" )
700 {
701 int channel = -10;
702 std::string state;
703 std::string resp = "X1:SWWV STATE,OFF";
704 rv = parseSWWV( channel, state, resp );
705
706 REQUIRE( rv == -3 );
707 }
708
709 WHEN( "invalid SWWV passed - no channel" )
710 {
711 int channel = -10;
712 std::string state;
713 std::string resp = "C:SWWV STATE,OFF";
714 rv = parseSWWV( channel, state, resp );
715
716 REQUIRE( rv == 0 );
717 REQUIRE( channel == 0 );
718 }
719
720 WHEN( "invalid SWWV passed - no STATE" )
721 {
722 int channel = -10;
723 std::string state;
724 std::string resp = "C1:SWWV STAT,OFF";
725 rv = parseSWWV( channel, state, resp );
726
727 REQUIRE( rv == -4 );
728 }
729 }
730}
731
732SCENARIO( "Parsing the BTWV? response", "[siglentSDG]" )
733{
734 GIVEN( "A valid response to BTWV from the SDG" )
735 {
736 int rv;
737
738 WHEN( "Valid BTWV passed, with state off" )
739 {
740 int channel = -10;
741 std::string state;
742 std::string resp = "C1:BTWV STATE,OFF";
743 rv = parseBTWV( channel, state, resp );
744
745 REQUIRE( rv == 0 );
746 REQUIRE( channel == 1 );
747 REQUIRE( state == "OFF" );
748 }
749
750 WHEN( "Valid BTWV passed, with state on" )
751 {
752 // We ignore the rest of the string
753 int channel = -10;
754 std::string state;
755 std::string resp = "C1:BTWV "
756 "STATE,ON,PRD,0.01S,STPS,0,TRSR,INT,TRMD,OFF,TIME,1,DLAY,5.21035e-07S,GATE_NCYC,NCYC,"
757 "CARR,WVTP,SINE,FRQ,1000HZ,AMP,4V,AMPVRMS,1.414Vrms,OFST,0V,PHSE,0";
758 rv = parseBTWV( channel, state, resp );
759
760 REQUIRE( rv == 0 );
761 REQUIRE( channel == 1 );
762 REQUIRE( state == "ON" );
763 }
764 }
765
766 GIVEN( "An invalid response to BTWV from the SDG" )
767 {
768 int rv;
769
770 WHEN( "invalid BTWV passed - too short" )
771 {
772 int channel = -10;
773 std::string state;
774 std::string resp = "C1:BTWV S";
775 rv = parseBTWV( channel, state, resp );
776
777 REQUIRE( rv == -1 );
778 }
779
780 WHEN( "invalid BTWV passed - wrong command" )
781 {
782 int channel = -10;
783 std::string state;
784 std::string resp = "C1:BTWQ STATE,OFF";
785 rv = parseBTWV( channel, state, resp );
786
787 REQUIRE( rv == -2 );
788 }
789
790 WHEN( "invalid BTWV passed - no C" )
791 {
792 int channel = -10;
793 std::string state;
794 std::string resp = "X1:BTWV STATE,OFF";
795 rv = parseBTWV( channel, state, resp );
796
797 REQUIRE( rv == -3 );
798 }
799
800 WHEN( "invalid BTWV passed - no channel" )
801 {
802 int channel = -10;
803 std::string state;
804 std::string resp = "C:BTWV STATE,OFF";
805 rv = parseBTWV( channel, state, resp );
806
807 REQUIRE( rv == 0 );
808 REQUIRE( channel == 0 );
809 }
810
811 WHEN( "invalid BTWV passed - no STATE" )
812 {
813 int channel = -10;
814 std::string state;
815 std::string resp = "C1:BTWV STAT,OFF";
816 rv = parseBTWV( channel, state, resp );
817
818 REQUIRE( rv == -4 );
819 }
820 }
821}
822
823SCENARIO( "Parsing the ARWV? response", "[siglentSDG]" )
824{
825 GIVEN( "A valid response to ARWV from the SDG" )
826 {
827 int rv;
828
829 WHEN( "Valid ARWV passed, with index 0" )
830 {
831 int channel = -10;
832 int index = -10;
833 ;
834 std::string resp = "C1:ARWV INDEX,0,NAME,";
835 rv = parseARWV( channel, index, resp );
836
837 REQUIRE( rv == 0 );
838 REQUIRE( channel == 1 );
839 REQUIRE( index == 0 );
840 }
841
842 WHEN( "Valid ARWV passed, with index 1" )
843 {
844 // We ignore the rest of the string
845 int channel = -10;
846 int index = -10;
847 std::string resp = "C2:ARWV INDEX,1,NAME,";
848 rv = parseARWV( channel, index, resp );
849
850 REQUIRE( rv == 0 );
851 REQUIRE( channel == 2 );
852 REQUIRE( index == 1 );
853 }
854 }
855
856 GIVEN( "An invalid response to ARWV from the SDG" )
857 {
858 int rv;
859
860 WHEN( "invalid ARWV passed - too short" )
861 {
862 int channel = -10;
863 int index = -10;
864 std::string resp = "C1:ARWV I";
865 rv = parseARWV( channel, index, resp );
866
867 REQUIRE( rv == -1 );
868 }
869
870 WHEN( "invalid ARWV passed - wrong command" )
871 {
872 int channel = -10;
873 int index = -10;
874 std::string resp = "C1:ARWQ INDEX,0";
875 rv = parseARWV( channel, index, resp );
876
877 REQUIRE( rv == -2 );
878 }
879
880 WHEN( "invalid ARWV passed - no C" )
881 {
882 int channel = -10;
883 int index = -10;
884 std::string resp = "X1:ARWV INDEX,0";
885 rv = parseARWV( channel, index, resp );
886
887 REQUIRE( rv == -3 );
888 }
889
890 WHEN( "invalid ARWV passed - no channel" )
891 {
892 int channel = -10;
893 int index = -10;
894 std::string resp = "C:ARWV INDEX,0";
895 rv = parseARWV( channel, index, resp );
896
897 REQUIRE( rv == 0 );
898 REQUIRE( channel == 0 );
899 }
900
901 WHEN( "invalid ARWV passed - no INDEX" )
902 {
903 int channel = -10;
904 int index = -10;
905 std::string resp = "C1:ARWV INDX,0";
906 rv = parseARWV( channel, index, resp );
907
908 REQUIRE( rv == -4 );
909 }
910 }
911}
912
913} // namespace siglentSDG_test
SCENARIO("INDI Callbacks", "[siglentSDG]")
Verify siglentSDG callback validation and parser helpers behave as expected.
TEST_CASE("siglentSDG parser placeholder harness compiles", "[siglentSDG]")
Verify the placeholder siglentSDG parser test harness instantiates the helper paths cleanly.
#define XWCTEST_INDI_NEW_CALLBACK(testclass, propname)
Catch-2 tests for whether a NEW callback properly validates the input property properly.
int parseOUTP(int &channel, int &output, const std::string &strRead)
Parse the SDG response to the OUTP query.
int parseSWWV(int &channel, std::string &state, const std::string &strRead)
Parse the SDG response to the SWWV query.
int parseMDWV(int &channel, std::string &state, const std::string &strRead)
Parse the SDG response to the MDWV query.
int parseBSWV(int &channel, std::string &wvtp, double &freq, double &peri, double &amp, double &ampvrms, double &ofst, double &hlev, double &llev, double &phse, double &wdth, const std::string &strRead)
Parse the SDG response to the BSWV query.
int parseBTWV(int &channel, std::string &state, const std::string &strRead)
Parse the SDG response to the BTWV query.
int parseARWV(int &channel, int &index, const std::string &strRead)
Parse the SDG response to the ARWV query.
double autoPulseWidthFromFrequency(const double freqHz)
Calculate the auto pulse width for a requested pulse frequency.
Namespace for all libXWC tests.
SCENARIO("Parsing the BSWV? response", "[siglentSDG]")
#define XWCTEST_SETUP_INDI_NEW_PROP(propname)