@@ -33,96 +33,107 @@ describe('test packages based on YAML descriptors, through the dispatcher', func
3333 yamlTestFiles . forEach ( function ( filename ) {
3434 describe ( filename , function ( ) {
3535 var yamlConfig = yaml . safeLoad ( fs . readFileSync ( filename ) ) ;
36- yamlConfig . tests . map ( function ( testSpec , i ) {
37- describe ( 'test spec ' + i , function ( ) {
38- it ( 'should parse binary sbp and payload' , function ( done ) {
39- var rs = new Readable ( ) ;
40- rs . push ( new Buffer ( testSpec [ 'raw_packet' ] , 'base64' ) ) ;
41- rs . push ( null ) ;
42- let ctx = {
43- testSpec,
44- done,
45- expectedCalls : 1 ,
46- callbacks : 0 ,
47- } ;
48- dispatch ( rs , dispatchee . bind ( ctx ) ) ;
49- } ) ;
36+ if ( "tests" in yamlConfig ) {
37+ yamlConfig . tests . map ( function ( testSpec , i ) {
38+ describe ( 'test spec ' + i , function ( ) {
39+ it ( 'should parse binary sbp and payload' , function ( done ) {
40+ var rs = new Readable ( ) ;
41+ rs . push ( new Buffer ( testSpec [ 'raw_packet' ] , 'base64' ) ) ;
42+ rs . push ( null ) ;
43+ let ctx = {
44+ testSpec,
45+ done,
46+ expectedCalls : 1 ,
47+ callbacks : 0 ,
48+ } ;
49+ dispatch ( rs , dispatchee . bind ( ctx ) ) ;
50+ } ) ;
5051
51- it ( 'should parse binary sbp and payload with leading extra preamble' , function ( done ) {
52- var rs = new Readable ( ) ;
53- rs . push ( new Buffer ( [ 0x55 ] ) ) ;
54- let expectedCalls = 0
55- let bufLength = 0 ;
56- while ( bufLength < 500 ) {
57- var buf = new Buffer ( testSpec [ 'raw_packet' ] , 'base64' ) ;
58- rs . push ( buf ) ;
59- bufLength += buf . length ;
60- expectedCalls ++
61- }
62- rs . push ( null ) ;
52+ it ( 'should parse binary sbp and payload with leading extra preamble' , function ( done ) {
53+ var rs = new Readable ( ) ;
54+ rs . push ( new Buffer ( [ 0x55 ] ) ) ;
55+ let expectedCalls = 0
56+ let bufLength = 0 ;
57+ while ( bufLength < 500 ) {
58+ var buf = new Buffer ( testSpec [ 'raw_packet' ] , 'base64' ) ;
59+ rs . push ( buf ) ;
60+ bufLength += buf . length ;
61+ expectedCalls ++
62+ }
63+ rs . push ( null ) ;
6364
64- let ctx = {
65- testSpec,
66- done,
67- expectedCalls,
68- callbacks : 0 ,
69- } ;
70- dispatch ( rs , dispatchee . bind ( ctx ) ) ;
71- } ) ;
65+ let ctx = {
66+ testSpec,
67+ done,
68+ expectedCalls,
69+ callbacks : 0 ,
70+ } ;
71+ dispatch ( rs , dispatchee . bind ( ctx ) ) ;
72+ } ) ;
7273
73- // For both "corrupt preamble" tests, the corrupt "length" field could be much longer than the actual message.
74- // In a real-world case we will have a constant stream of data which will allow us to read that
75- // full length, and reframe after discovering that it's a corrupt preamble.
76- // In these cases, we just repeat the message several times to create an arbitrarily long stream.
77- it ( 'should parse binary sbp and payload with leading extra preamble (2)' , function ( done ) {
78- var rs = new Readable ( ) ;
79- var bigBuf = new Buffer ( 0 ) ;
80- let expectedCalls = 0 ;
81- while ( bigBuf . length < 500 ) {
82- bigBuf = Buffer . concat ( [ bigBuf , new Buffer ( testSpec [ 'raw_packet' ] , 'base64' ) ] ) ;
83- expectedCalls ++
84- }
85- rs . push ( Buffer . concat ( [ new Buffer ( [ 0x55 ] ) , bigBuf ] ) ) ;
86- rs . push ( null ) ;
74+ // For both "corrupt preamble" tests, the corrupt "length" field could be much longer than the actual message.
75+ // In a real-world case we will have a constant stream of data which will allow us to read that
76+ // full length, and reframe after discovering that it's a corrupt preamble.
77+ // In these cases, we just repeat the message several times to create an arbitrarily long stream.
78+ it ( 'should parse binary sbp and payload with leading extra preamble (2)' , function ( done ) {
79+ var rs = new Readable ( ) ;
80+ var bigBuf = new Buffer ( 0 ) ;
81+ let expectedCalls = 0 ;
82+ while ( bigBuf . length < 500 ) {
83+ bigBuf = Buffer . concat ( [ bigBuf , new Buffer ( testSpec [ 'raw_packet' ] , 'base64' ) ] ) ;
84+ expectedCalls ++
85+ }
86+ rs . push ( Buffer . concat ( [ new Buffer ( [ 0x55 ] ) , bigBuf ] ) ) ;
87+ rs . push ( null ) ;
8788
88- let ctx = {
89- testSpec,
90- done,
91- expectedCalls,
92- callbacks : 0 ,
93- } ;
94- dispatch ( rs , dispatchee . bind ( ctx ) ) ;
95- } ) ;
89+ let ctx = {
90+ testSpec,
91+ done,
92+ expectedCalls,
93+ callbacks : 0 ,
94+ } ;
95+ dispatch ( rs , dispatchee . bind ( ctx ) ) ;
96+ } ) ;
9697
97- it ( 'should parse binary sbp and payload with leading truncated message' , function ( done ) {
98- var rs = new Readable ( ) ;
99- var packetBuf = new Buffer ( testSpec [ 'raw_packet' ] , 'base64' ) ;
100- rs . push ( packetBuf . slice ( 0 , packetBuf . length - 5 ) ) ;
98+ if ( filename . indexOf ( 'test_MsgFlashDone.yaml' ) === - 1 &&
99+ filename . indexOf ( 'test_MsgM25FlashWriteStatus.yaml' ) === - 1 &&
100+ filename . indexOf ( 'test_MsgBootloaderJumptoApp.yaml' ) === - 1 ) {
101+ it ( 'should parse binary sbp and payload with leading truncated message' , function ( done ) {
102+ var rs = new Readable ( ) ;
103+ var packetBuf = new Buffer ( testSpec [ 'raw_packet' ] , 'base64' ) ;
104+ rs . push ( packetBuf . slice ( 0 , packetBuf . length - 5 ) ) ;
101105
102- var requiredCalls = 1 ;
106+ var requiredCalls = 1 ;
103107
104- // `length` is longer than one full buffer for these corrupted messages
105- // similar issue to the above tests
106- if ( filename . indexOf ( 'test_MsgUartState.yaml' ) !== - 1 ) {
107- requiredCalls = 10 ;
108- }
108+ // `length` is longer than one full buffer for these corrupted messages
109+ // similar issue to the above tests
110+ if ( filename . indexOf ( 'test_MsgUartState.yaml' ) !== - 1 ||
111+ filename . indexOf ( 'test_MsgSsrOrbitClockDepA.yaml' ) !== - 1 ||
112+ filename . indexOf ( 'test_MsgSettingsReadByIndexReq.yaml' ) !== - 1 ||
113+ filename . indexOf ( 'test_MsgResetFilters.yaml' ) !== - 1 ||
114+ filename . indexOf ( 'test_MsgLinuxSysState.yaml' ) !== - 1 ||
115+ filename . indexOf ( 'test_MsgStmUniqueIdResp.yaml' ) !== - 1 ) {
116+ requiredCalls = 10 ;
117+ }
109118
110- var expectedCalls ;
111- for ( expectedCalls = 0 ; expectedCalls < requiredCalls ; expectedCalls ++ ) {
112- rs . push ( packetBuf ) ;
113- }
114- rs . push ( null ) ;
119+ var expectedCalls ;
120+ for ( expectedCalls = 0 ; expectedCalls < requiredCalls ; expectedCalls ++ ) {
121+ rs . push ( packetBuf ) ;
122+ }
123+ rs . push ( null ) ;
115124
116- let ctx = {
117- testSpec,
118- done,
119- expectedCalls,
120- callbacks : 0 ,
121- } ;
122- dispatch ( rs , dispatchee . bind ( ctx ) ) ;
125+ let ctx = {
126+ testSpec,
127+ done,
128+ expectedCalls,
129+ callbacks : 0 ,
130+ } ;
131+ dispatch ( rs , dispatchee . bind ( ctx ) ) ;
132+ } ) ;
133+ }
123134 } ) ;
124135 } ) ;
125- } ) ;
136+ }
126137 } ) ;
127138 } ) ;
128139} ) ;
0 commit comments