更新
更旧
/**
*
* Copyright (c) 2020 Silicon Labs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*
* @jest-environment node
*/
const genEngine = require('../src-electron/generator/generation-engine.js')
const dbApi = require('../src-electron/db/db-api.js')
const queryPackage = require('../src-electron/db/query-package.js')
const querySession = require('../src-electron/db/query-session.js')
const utilJs = require('../src-electron/util/util.js')
const zclLoader = require('../src-electron/zcl/zcl-loader.js')
const helperZap = require('../src-electron/generator/helper-zap.js')
const importJs = require('../src-electron/importexport/import.js')

Timotej Ecimovic
已提交
const testUtil = require('./test-util.js')

Timotej Ecimovic
已提交
const testFile = path.join(__dirname, 'resource/generation-test-file-1.zap')

Timotej Ecimovic
已提交
const testFile2 = path.join(__dirname, 'resource/three-endpoint-device.zap')
const testFile3 = path.join(__dirname, 'resource/zll-on-off-switch-test.zap')
const testFile4 = path.join(
__dirname,
'resource/mfg-specific-clusters-commands.zap'
)
const testFile5 = path.join(__dirname, 'resource/gp-combo-basic-test.zap')
const testFile6 = path.join(__dirname, 'resource/mfgSpecificConfig.zap')
let file = env.sqliteTestFile('genengine')
db = await dbApi.initDatabaseAndLoadSchema(
file,
env.schemaFile(),
env.zapVersion()
)
return zclLoader.loadZcl(db, env.builtinSilabsZclMetafile())
}, testUtil.timeout.medium())
afterAll(() => dbApi.closeDatabase(db), testUtil.timeout.short())
let templateContext
test(
'Basic gen template parsing and generation',
async () => {
let context = await genEngine.loadTemplates(
db,
testUtil.testTemplate.zigbee
)
expect(context.crc).not.toBeNull()
expect(context.templateData).not.toBeNull()
expect(context.templateData.name).toEqual('Test templates')
expect(context.templateData.version).toEqual('test-v1')
expect(context.templateData.templates.length).toEqual(templateCount)
expect(context.packageId).not.toBeNull()
templateContext = context
},
testUtil.timeout.medium()
test(
'Validate package loading',
async () => {
templateContext.packages = await queryPackage.getPackageByParent(
templateContext.db,
templateContext.packageId
)
expect(templateContext.packages.length).toBe(templateCount - 1 + 2) // -1 for ignored one, one for helper and one for overridable
},
testUtil.timeout.short()
)
test(
'Create session',
async () => {
let sessionId = await querySession.createBlankSession(db)
expect(sessionId).not.toBeNull()
templateContext.sessionId = sessionId
},
testUtil.timeout.short()
)
test(
'Initialize session packages',
async () => {
let packages = await utilJs.initializeSessionPackage(
templateContext.db,
templateContext.sessionId,
{
expect(packages.length).toBe(2)
},
testUtil.timeout.short()
)
test(
'Validate basic generation',
async () => {
let genResult = await genEngine.generate(
templateContext.db,
templateContext.sessionId,
templateContext.packageId,
{},
{ disableDeprecationWarnings: true }
)
expect(genResult).not.toBeNull()
expect(genResult.partial).toBeFalsy()
expect(genResult.content).not.toBeNull()
let simpleTest = genResult.content['simple-test.out']
expect(simpleTest.startsWith('Test template file.')).toBeTruthy()
expect(simpleTest).toContain('Strange type: bacnet_type_t')
},
testUtil.timeout.long()
test(
'Validate more complex generation',
async () => {
let genResult = await genEngine.generate(
templateContext.db,
templateContext.sessionId,
templateContext.packageId,
{},
{ disableDeprecationWarnings: true }
)
expect(genResult).not.toBeNull()
expect(genResult.partial).toBeFalsy()
expect(genResult.content).not.toBeNull()
let simpleTest = genResult.content['simple-test.out']
expect(simpleTest.startsWith('Test template file.')).toBeTruthy()
expect(simpleTest).toContain(helperZap.zap_header())
expect(simpleTest).toContain(`SessionId: ${genResult.sessionId}`)
expect(simpleTest).toContain('Addon: This is example of test addon helper')
let zclId = genResult.content['zcl-test.out']
//expect(zclId).toEqual('random placeholder')
expect(zclId).toContain(
`// ${testUtil.totalNonAtomicEnumCount - 1}/${
testUtil.totalNonAtomicEnumCount
}: label=>ZllStatus caption=>Enum of size 1 byte`
expect(zclId).toContain(`Label count: ${testUtil.totalNonAtomicEnumCount}`)
expect(zclId).toContain(
`// 129/${testUtil.totalNonAtomicEnumCount}: label=>MeteringBlockEnumerations caption=>Enum of size 1 byte`
)
expect(zclId).toContain(
'// struct: ReadReportingConfigurationAttributeRecord'
)
expect(zclId).toContain('cluster: 0x0700 Price')
expect(zclId).toContain('cmd: 0x0A GetUserStatusResponse')
expect(zclId).toContain('att: 0x0002 gps communication mode')
expect(zclId).toContain('First item\n// struct: BlockThreshold')
expect(zclId).toContain('// struct: WwahClusterStatusToUseTC\nLast item')
expect(zclId).toContain('// event: 0x0001 HelloEvent')
expect(zclId).toContain('-> field: 0x0002 arg2 INT32U')
let accumulator = genResult.content['accumulator.out']
expect(accumulator).toContain('Iteration: 19 out of 20')
expect(accumulator).toContain('Cumulative size: 16 / 206')
expect(accumulator).toContain('Cumulative size: 8 / 109')
expect(accumulator).toContain('Cumulative size: 0 / 206')
let atomics = genResult.content['atomics.out']
expect(atomics).toContain('C type: bacnet_type_t')
// Now check for the override
//expect(atomics).toContain('C type: security_key_type_override')
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
let zapCommand = genResult.content['zap-command.h']
expect(zapCommand).not.toBeNull()
expect(zapCommand).toContain(
'#define emberAfFillCommandGlobalReadAttributesResponse(clusterId,'
)
let zapPrint = genResult.content['zap-print.h']
expect(zapPrint).toContain(
'#define SILABS_PRINTCLUSTER_POWER_CONFIG_CLUSTER {ZCL_POWER_CONFIG_CLUSTER_ID, 0x0000, "Power Configuration" },'
)
let sdkExtension = genResult.content['sdk-extension.out']
expect(sdkExtension).toContain(
"// cluster: 0x0000 Basic, text extension: 'Extension to basic cluster'"
)
expect(sdkExtension).toContain(
"// cluster: 0x0002 Device Temperature Configuration, text extension: 'Extension to temperature config cluster'"
)
expect(sdkExtension).toContain(
"// server cluster: 0x0001 Power Configuration, text extension: 'Extension to power cluster'"
)
expect(sdkExtension).toContain(
"// client cluster: 0x0001 Power Configuration, text extension: ''"
)
expect(sdkExtension).toContain(
"// attribute: 0x0000 / 0x0000 => ZCL version, extensions: '42', '99'"
)
expect(sdkExtension).toContain(
"attribute: 0x0015 / 0x0015 => network key sequence number, extensions: '0', '1', [int8u:666]"
)
expect(sdkExtension).toContain(
"// cluster: 0x0003 Identify, text extension: ''"
)
expect(sdkExtension).toContain(
"// command: 0x0000 / 0x00 => ResetToFactoryDefaults, test extension: '1'"
)
expect(sdkExtension).toContain(
"// device type: HA / 0x0006 => HA-remote // extension: 'path/to/remote.c'"
)
expect(sdkExtension).toContain(
'IMPLEMENTED_COMMANDS>ResetToFactoryDefaults,IdentifyQueryResponse,IdentifyQuery,EZModeInvoke,UpdateCommissionState,<END'
)
// Testing {{#if_is_struct}} helper
expect(zclId).toContain(`attributeIds is not struct`)
// Testing {{#if_command_discovery_enabled}} helper
expect(zclId).toContain(`#define EMBER_AF_SUPPORT_COMMAND_DISCOVERY`)
// Testing {{#zcl_struct_items_by_struct_name}} helper
expect(zclId).toContain(`configureReportingRecords::direction struct item`)
expect(zclId).toContain(`readAttributeStatusRecords is struct`)
},
testUtil.timeout.long()

Timotej Ecimovic
已提交
'Validate test file 1 generation',
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
async () => {
let genResult = await genEngine.generate(
templateContext.db,
templateContext.sessionId,
templateContext.packageId,
{},
{ disableDeprecationWarnings: true }
)
expect(genResult).not.toBeNull()
expect(genResult.partial).toBeFalsy()
expect(genResult.content).not.toBeNull()
let zapId = genResult.content['zap-id.h']
//expect(zapId).toEqual('random placeholder')
expect(zapId).toContain('// Definitions for cluster: Basic')
expect(zapId).toContain(
'#define ZCL_GET_PROFILE_RESPONSE_COMMAND_ID (0x00)'
)
// Testing {{#zcl_commands_source_client}} helper
expect(zapId).toContain(
'#define ZCL_IDENTIFY_C_TO_S_IDENTIFY_QUERY_COMMAND_ID (0x01)'
)
// Testing {{#zcl_commands_source_server}} helper
expect(zapId).toContain(
'#define ZCL_IDENTIFY_S_TO_C_IDENTIFY_QUERY_RESPONSE_COMMAND_ID (0x00)'
)
expect(zapId).toContain(
'// Client attributes for cluster: Fluoride Concentration Measurement'
)
expect(zapId).toContain(
'#define ZCL_NUMBER_OF_RESETS_ATTRIBUTE_ID (0x0000)'
)
let zapTypes = genResult.content['zap-type.h']
expect(zapTypes).toContain(
'ZCL_INT16U_ATTRIBUTE_TYPE = 0x21, // Unsigned 16-bit integer'
)
expect(zapTypes).toContain('uint32_t snapshotCause')
expect(zapTypes).toContain('typedef uint8_t EphemeralData;')
let zapCommandParser = genResult.content['zap-command-parser.c']
expect(zapCommandParser).not.toBeNull()
expect(zapCommandParser).toContain(
'EmberAfStatus emberAfClusterSpecificCommandParse(EmberAfClusterCommand * cmd)'
)
},
testUtil.timeout.long()
test(
'Test file 1 generation',
async () => {
let sid = await querySession.createBlankSession(db)
await importJs.importDataFromFile(db, testFile, { sessionId: sid })
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
let genResult = await genEngine.generate(
db,
sid,
templateContext.packageId,
{},
{
disableDeprecationWarnings: true,
}
)
expect(genResult).not.toBeNull()
expect(genResult.partial).toBeFalsy()
expect(genResult.content).not.toBeNull()
let cfgVer2 = genResult.content['zap-config-version-2.h']
// Test GENERATED_DEFAULTS
expect(cfgVer2).toContain(
'0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, /* 0,DEFAULT value for cluster: Over the Air Bootloading, attribute: OTA Upgrade Server ID, side: client*/'
)
// Test GENERATED_ATTRIBUTE_COUNT
expect(cfgVer2).toContain('#define GENERATED_ATTRIBUTE_COUNT 81')
// Test GENERATED_ATTRIBUTES
expect(cfgVer2).toContain(
'{ 0x000F, ZCL_BITMAP8_ATTRIBUTE_TYPE, 1, (ATTRIBUTE_MASK_WRITABLE), { (uint8_t*)0x00 } }, /* 46 Cluster: Color Control, Attribute: color control options, Side: server*/'
)
// Test is_number_greater_than within GENERATED_ATTRIBUTES
expect(cfgVer2).toContain(
'{ 0x0000, ZCL_IEEE_ADDRESS_ATTRIBUTE_TYPE, 8, (ATTRIBUTE_MASK_CLIENT), { (uint8_t*)&(generatedDefaults[0]) } }, /* 35 Cluster: Over the Air Bootloading, Attribute: OTA Upgrade Server ID, Side: client*/'
)
// Test GENERATED_CLUSTER_COUNT
expect(cfgVer2).toContain('#define GENERATED_CLUSTER_COUNT 18')
// Test GENERATED_CLUSTERS
expect(cfgVer2).toContain(
'0x0019, (EmberAfAttributeMetadata*)&(generatedAttributes[35]), 4, 15, CLUSTER_MASK_CLIENT, NULL }, /* 15, Endpoint Id: 2, Cluster: Over the Air Bootloading, Side: client*/'
)
// Test GENERATED_ENDPOINT_TYPE_COUNT
expect(cfgVer2).toContain('#define GENERATED_ENDPOINT_TYPE_COUNT (2)')
// Test GENERATED_ENDPOINT_TYPES
expect(cfgVer2).toContain(
'{ ((EmberAfCluster*)&(generatedClusters[0])), 9, 50 },'
)
// Test ATTRIBUTE_LARGEST
expect(cfgVer2).toContain('#define ATTRIBUTE_LARGEST (65)')
// Test ATTRIBUTE_SINGLETONS_SIZE
expect(cfgVer2).toContain('#define ATTRIBUTE_SINGLETONS_SIZE (191)')
// Test ATTRIBUTE_MAX_SIZE
expect(cfgVer2).toContain('#define ATTRIBUTE_MAX_SIZE (164)')
// Test FIXED_ENDPOINT_COUNT
expect(cfgVer2).toContain('#define FIXED_ENDPOINT_COUNT (2)')
// Test EMBER_AF_GENERATED_COMMAND_COUNT
expect(cfgVer2).toContain('#define EMBER_AF_GENERATED_COMMAND_COUNT (88)')
// Test GENERATED_COMMANDS
expect(cfgVer2).toContain(
'{ 0x0004, 0x01, COMMAND_MASK_OUTGOING_SERVER }, /* 7, Cluster: Groups, Command: ViewGroupResponse*/'
)
testUtil.timeout.long()
'Test generated defaults and cli',
async () => {
let sid = await querySession.createBlankSession(db)
await importJs.importDataFromFile(db, testFile5, { sessionId: sid })
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
let genResult = await genEngine.generate(
db,
sid,
templateContext.packageId,
{},
{
disableDeprecationWarnings: true,
}
)
expect(genResult).not.toBeNull()
expect(genResult.partial).toBeFalsy()
expect(genResult.content).not.toBeNull()
let cfgVer2 = genResult.content['zap-config-version-2.h']
// Test GENERATED_DEFAULTS big endian
expect(cfgVer2).toContain(
'0x0F, 0xAE, 0x2F, /* 0,DEFAULT value for cluster: Green Power, attribute: gps functionality, side: server */'
)
// Test GENERATED_DEFAULTS little endian
expect(cfgVer2).toContain(
'0x2F, 0xAE, 0x0F, /* 0,DEFAULT value for cluster: Green Power, attribute: gps functionality, side: server*/'
)
// Test GENERATED_DEFAULTS big endian for attribute of size > 8
expect(cfgVer2).toContain(
'0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0F, 0x0G, 0x0H, /* 6,DEFAULT value for cluster: Green Power, attribute: gp link key, side: server */'
)
// Test GENERATED_DEFAULTS for same attribute name but different side of cluster, compare it to above test
expect(cfgVer2).toContain(
'0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0F, 0x0G, 0x0H, /* 28,DEFAULT value for cluster: Green Power, attribute: gp link key, side: client */'
)
// Test GENERATED_DEFAULTS little endian for attribute of size > 8 is same as big endian. Bytes are not inverted
expect(cfgVer2).not.toContain(
`0x0H, 0x0G, 0x0F, 0x0D, 0x0C, 0x0B, 0x0A, 0x09, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, /* 12,DEFAULT value for cluster: Green Power, attribute: gp link key, side: client*/`
)
// Testing GENERATED ATTRIBUTES to see that they are refering to the correct generation defaults
expect(cfgVer2).toContain(
`0x0022, ZCL_SECURITY_KEY_ATTRIBUTE_TYPE, 16, (ATTRIBUTE_MASK_WRITABLE| ATTRIBUTE_MASK_CLIENT), { (uint8_t*)&(generatedDefaults[28]) } }, /* 25 Cluster: Green Power, Attribute: gp link key, Side: client*/`
)
expect(cfgVer2).toContain(
`0x0022, ZCL_SECURITY_KEY_ATTRIBUTE_TYPE, 16, (ATTRIBUTE_MASK_WRITABLE), { (uint8_t*)&(generatedDefaults[6]) } }, /* 37 Cluster: Green Power, Attribute: gp link key, Side: server*/`
)
// Test EMBER_AF_GENERATED_REPORTING_CONFIG_DEFAULTS to see that it generates reporting for singleton attributes correctly
// This test makes sure the reporting default generates only once for a singleton attribute and not per endpoint.
// In this case: Basic Server Cluster, ZCL version is enabled on enpoint 2 and 242
expect(cfgVer2).toContain(`EMBER_AF_GENERATED_REPORTING_CONFIG_DEFAULTS`)
expect(cfgVer2).toContain(
`{ EMBER_ZCL_REPORTING_DIRECTION_REPORTED, 0x0002, 0x0000, 0x0000, CLUSTER_MASK_SERVER, 0x0000, 0, 65534, 0 }, /* Endpoint Id: 2, Cluster: Basic, Attribute: ZCL version */`
)
expect(cfgVer2).not.toContain(
`{ EMBER_ZCL_REPORTING_DIRECTION_REPORTED, 0x0001, 0x0000, 0x0000, CLUSTER_MASK_SERVER, 0x0000, 0, 65534, 0 }, /* Endpoint Id: 1, Cluster: Basic, Attribute: ZCL version */`
)
expect(cfgVer2).not.toContain(
`{ EMBER_ZCL_REPORTING_DIRECTION_REPORTED, 0x00F2, 0x0000, 0x0000, CLUSTER_MASK_SERVER, 0x0000, 0, 65534, 0 }, /* Endpoint Id: 242, Cluster: Basic, Attribute: ZCL version */`
)
// Testing zap cli helpers
expect(genResult.content['zap-cli.c']).toContain(
'static const sl_cli_command_entry_t zcl_identify_cluster_command_table[]'
)
expect(genResult.content['zap-cli.c']).toContain(
'static const sl_cli_command_info_t cli_cmd_identify_group'
)
expect(genResult.content['zap-cli.c']).toContain(
'SL_CLI_COMMAND_GROUP(zcl_identify_cluster_command_table, "ZCL identify cluster commands");'
)
expect(genResult.content['zap-cli.c']).toContain(
'{ "identify", &cli_cmd_identify_group, false },'
)
},
testUtil.timeout.long()
)
test(
'Test zap config for mfg specific content',
async () => {
let sid = await querySession.createBlankSession(db)
await importJs.importDataFromFile(db, testFile6, { sessionId: sid })
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
let genResult = await genEngine.generate(
db,
sid,
templateContext.packageId,
{},
{
disableDeprecationWarnings: true,
}
)
expect(genResult).not.toBeNull()
expect(genResult.partial).toBeFalsy()
expect(genResult.content).not.toBeNull()
let cfgVer3 = genResult.content['zap-config-version-3.h']
// Test GENERATED_ATTRIBUTES for the same attribute name but different attribute code
expect(cfgVer3).toContain(
'{ 0x0000, ZCL_INT16U_ATTRIBUTE_TYPE, 2, (ATTRIBUTE_MASK_WRITABLE), { (uint8_t*)0x0000 } }, /* 51 Cluster: Sample Mfg Specific Cluster 2, Attribute: ember sample attribute 2, Side: server*/'
)
expect(cfgVer3).toContain(
'{ 0x0001, ZCL_INT16U_ATTRIBUTE_TYPE, 2, (ATTRIBUTE_MASK_WRITABLE), { (uint8_t*)0x0000 } }, /* 52 Cluster: Sample Mfg Specific Cluster 2, Attribute: ember sample attribute 2, Side: server*/'
)
// Test GENERATED_CLUSTERS for attribute index and size on endpoint 1 and endpoint 2
expect(cfgVer3).toContain(
'{ 0xFC00, (EmberAfAttributeMetadata*)&(generatedAttributes[43]), 2, 3, CLUSTER_MASK_CLIENT, NULL }, /* 9, Endpoint Id: 1, Cluster: Sample Mfg Specific Cluster, Side: client*/'
)
expect(cfgVer3).toContain(
'{ 0xFC00, (EmberAfAttributeMetadata*)&(generatedAttributes[45]), 4, 5, CLUSTER_MASK_SERVER, NULL }, /* 10, Endpoint Id: 1, Cluster: Sample Mfg Specific Cluster, Side: server*/'
)
expect(cfgVer3).toContain(
'{ 0xFC00, (EmberAfAttributeMetadata*)&(generatedAttributes[43]), 2, 3, CLUSTER_MASK_CLIENT, NULL }, /* 15, Endpoint Id: 2, Cluster: Sample Mfg Specific Cluster, Side: client*/'
)
expect(cfgVer3).toContain(
'{ 0xFC00, (EmberAfAttributeMetadata*)&(generatedAttributes[49]), 2, 3, CLUSTER_MASK_CLIENT, NULL }, /* 16, Endpoint Id: 2, Cluster: Sample Mfg Specific Cluster 2, Side: client*/'
)
expect(cfgVer3).toContain(
'{ 0xFC00, (EmberAfAttributeMetadata*)&(generatedAttributes[45]), 4, 5, CLUSTER_MASK_SERVER, NULL }, /* 17, Endpoint Id: 2, Cluster: Sample Mfg Specific Cluster, Side: server*/'
)
expect(cfgVer3).toContain(
'{ 0xFC00, (EmberAfAttributeMetadata*)&(generatedAttributes[51]), 3, 5, CLUSTER_MASK_SERVER, NULL } /* 18, Endpoint Id: 2, Cluster: Sample Mfg Specific Cluster 2, Side: server*/'
)
// Test GENERATED_COMMANDS and its mask
expect(cfgVer3).toContain(
'{ 0xFC00, 0x00, COMMAND_MASK_INCOMING_SERVER | COMMAND_MASK_OUTGOING_CLIENT | COMMAND_MASK_MANUFACTURER_SPECIFIC }, /* 69, Cluster: Sample Mfg Specific Cluster, Command: CommandOne*/'
)
expect(cfgVer3).toContain(
'{ 0xFC00, 0x00, COMMAND_MASK_INCOMING_SERVER | COMMAND_MASK_OUTGOING_CLIENT | COMMAND_MASK_MANUFACTURER_SPECIFIC }, /* 70, Cluster: Sample Mfg Specific Cluster 2, Command: CommandTwo*/'
)
// Test GENERATED_COMMAND_MANUFACTURER_CODES
expect(cfgVer3).toContain('{ 69, 0x1002 },')
expect(cfgVer3).toContain('{ 70, 0x1049 },')
// Test GENERATED_CLUSTER_MANUFACTURER_CODES
expect(cfgVer3).toContain('{ 9, 0x1002 },')
expect(cfgVer3).toContain('{ 10, 0x1002 },')
expect(cfgVer3).toContain('{ 15, 0x1002 },')
expect(cfgVer3).toContain('{ 16, 0x1049 },')
expect(cfgVer3).toContain('{ 17, 0x1002 },')
expect(cfgVer3).toContain('{ 18, 0x1049 },')
// Test GENERATED_ATTRIBUTE_MANUFACTURER_CODES, global attributes do not show up here
expect(cfgVer3).toContain('{ 45, 0x1002 },')
expect(cfgVer3).toContain('{ 46, 0x1002 },')
expect(cfgVer3).toContain('{ 51, 0x1049 },')
expect(cfgVer3).toContain('{ 52, 0x1049 },')
},
testUtil.timeout.long()
)
test(
'Testing zap command parser generation',
async () => {
let sid = await querySession.createBlankSession(db)
await importJs.importDataFromFile(db, testFile3, { sessionId: sid })
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
let genResult = await genEngine.generate(
db,
sid,
templateContext.packageId,
{},
{
disableDeprecationWarnings: true,
}
)
let pv3 = genResult.content['zap-command-parser-ver-3.c']
// Test Cluster command parsers that should be defined
expect(pv3).toContain(
'EmberAfStatus emberAfGroupsClusterClientCommandParse(EmberAfClusterCommand * cmd);'
)
expect(pv3).toContain(
'EmberAfStatus emberAfGroupsClusterServerCommandParse(EmberAfClusterCommand * cmd);'
)
expect(pv3).toContain(
'EmberAfStatus emberAfIdentifyClusterClientCommandParse(EmberAfClusterCommand * cmd);'
)
expect(pv3).toContain(
'EmberAfStatus emberAfIdentifyClusterServerCommandParse(EmberAfClusterCommand * cmd);'
)
expect(pv3).toContain(
'EmberAfStatus emberAfLevelControlClusterServerCommandParse(EmberAfClusterCommand * cmd);'
)
expect(pv3).toContain(
'EmberAfStatus emberAfOnOffClusterServerCommandParse(EmberAfClusterCommand * cmd);'
)
expect(pv3).toContain(
'EmberAfStatus emberAfScenesClusterServerCommandParse(EmberAfClusterCommand * cmd);'
)
expect(pv3).toContain(
'EmberAfStatus emberAfZllCommissioningClusterClientCommandParse(EmberAfClusterCommand * cmd);'
)
// Test Command callback
expect(pv3).toContain(
'wasHandled = emberAfIdentifyClusterIdentifyCallback(identifyTime);'
)
expect(pv3).toContain(
'wasHandled = emberAfLevelControlClusterMoveToLevelWithOnOffCallback(level, transitionTime);'
)
// Test command argument declarations for data types greater than 4
// bytes and make sure they are declared as pointers
expect(pv3).toContain('case ZCL_GP_PROXY_TABLE_REQUEST_COMMAND_ID:')
expect(pv3).not.toContain('uint64_t gpdIeee;')
expect(pv3).toContain('uint8_t * gpdIeee;')
//********* Test the new helpers for the same content as above******************
// Test Cluster command parsers that should be defined
let pv5 = genResult.content['zap-command-parser-ver-5.c']
expect(pv5).toContain(
'EmberAfStatus emberAfGroupsClusterClientCommandParse(EmberAfClusterCommand * cmd);'
)
expect(pv5).toContain(
'EmberAfStatus emberAfGroupsClusterServerCommandParse(EmberAfClusterCommand * cmd);'
)
expect(pv5).toContain(
'EmberAfStatus emberAfIdentifyClusterClientCommandParse(EmberAfClusterCommand * cmd);'
)
expect(pv5).toContain(
'EmberAfStatus emberAfIdentifyClusterServerCommandParse(EmberAfClusterCommand * cmd);'
)
expect(pv5).toContain(
'EmberAfStatus emberAfLevelControlClusterServerCommandParse(EmberAfClusterCommand * cmd);'
)
expect(pv5).toContain(
'EmberAfStatus emberAfOnOffClusterServerCommandParse(EmberAfClusterCommand * cmd);'
)
expect(pv5).toContain(
'EmberAfStatus emberAfScenesClusterServerCommandParse(EmberAfClusterCommand * cmd);'
)
expect(pv5).toContain(
'EmberAfStatus emberAfZllCommissioningClusterClientCommandParse(EmberAfClusterCommand * cmd);'
)
// Test Command callback
expect(pv5).toContain(
'wasHandled = emberAfIdentifyClusterIdentifyCallback(identifyTime);'
)
expect(pv5).toContain(
'wasHandled = emberAfLevelControlClusterMoveToLevelWithOnOffCallback(level, transitionTime);'
)
// Test command argument declarations for data types greater than 4
// bytes and make sure they are declared as pointers
expect(pv5).toContain('case ZCL_GP_PROXY_TABLE_REQUEST_COMMAND_ID:')
expect(pv5).not.toContain('uint64_t gpdIeee;')
expect(pv5).toContain('uint8_t * gpdIeee;')
//********* Test the helpers related to outgoing commands******************
// Test Cluster outgoing commands that should be generated
let zapOutgoingCommands = genResult.content['zap-outgoing-command.out']
expect(zapOutgoingCommands).not.toBeNull()
expect(zapOutgoingCommands).toContain(
'Groups client Cluster Outgoing commands\nOutgoing Command: AddGroup\nOutgoing Command: ViewGroup\nOutgoing Command: GetGroupMembership\nOutgoing Command: RemoveGroup\nOutgoing Command: RemoveAllGroups\nOutgoing Command: AddGroupIfIdentifying\nGroups server Cluster Outgoing commands\nOutgoing Command: AddGroupResponse\nOutgoing Command: ViewGroupResponse\nOutgoing Command: GetGroupMembershipResponse\nOutgoing Command: RemoveGroupResponse\nIdentify client Cluster Outgoing commands\nOutgoing Command: Identify\nOutgoing Command: IdentifyQuery\nIdentify server Cluster Outgoing commands\nOutgoing Command: IdentifyQueryResponse\nLevel Control client Cluster Outgoing commands\nOutgoing Command: MoveToLevel\nOutgoing Command: Move\nOutgoing Command: Step\nOutgoing Command: Stop\nOutgoing Command: MoveToLevelWithOnOff\nOutgoing Command: MoveWithOnOff\nOutgoing Command: StepWithOnOff\nOutgoing Command: StopWithOnOff\nOn/off client Cluster Outgoing commands\nOutgoing Command: Off\nOutgoing Command: On\nOutgoing Command: Toggle\nScenes server Cluster Outgoing commands\nOutgoing Command: AddSceneResponse\nOutgoing Command: ViewSceneResponse\nOutgoing Command: RemoveSceneResponse\nOutgoing Command: RemoveAllScenesResponse\nOutgoing Command: StoreSceneResponse\nOutgoing Command: GetSceneMembershipResponse\nZLL Commissioning client Cluster Outgoing commands\nOutgoing Command: ScanRequest\nOutgoing Command: DeviceInformationRequest\nOutgoing Command: IdentifyRequest\nOutgoing Command: ResetToFactoryNewRequest\nOutgoing Command: NetworkStartRequest\nOutgoing Command: NetworkJoinRouterRequest\nOutgoing Command: NetworkJoinEndDeviceRequest\nOutgoing Command: NetworkUpdateRequest\nZLL Commissioning server Cluster Outgoing commands\nOutgoing Command: ScanResponse\nOutgoing Command: DeviceInformationResponse\nOutgoing Command: NetworkStartResponse\nOutgoing Command: NetworkJoinRouterResponse\nOutgoing Command: NetworkJoinEndDeviceResponse\nOutgoing Command: EndpointInformation\nOutgoing Command: GetGroupIdentifiersResponse\nOutgoing Command: GetEndpointListResponse'
test(
'Testing zap command parser generation for manufacturing specific clusters',
async () => {
let sid = await querySession.createBlankSession(db)
await importJs.importDataFromFile(db, testFile4, { sessionId: sid })
let genResult = await genEngine.generate(
db,
sid,
templateContext.packageId,
{},
{
disableDeprecationWarnings: true,
}
)
let pv4 = genResult.content['zap-command-parser-ver-4.c']
// Test Cluster command parsers for manufacturing specific clusters
expect(pv4).toContain('case 0xFC57: //Manufacturing Specific cluster')
expect(pv4).toContain('case 0x1217: // Cluster: SL Works With All Hubs')
expect(pv4).toContain(
'result = emberAfSlWorksWithAllHubsClusterClientCommandParse(cmd);'
)
expect(pv4).toContain('case 0xFC02: //Manufacturing Specific cluster')
expect(pv4).toContain('case 0x1002: // Cluster: MFGLIB Cluster')
expect(pv4).toContain(
'result = emberAfMfglibClusterClusterServerCommandParse(cmd);'
)
},
testUtil.timeout.long()
)
test(
'Test file 2 generation',
async () => {
let { sessionId, errors, warnings } = await importJs.importDataFromFile(
db,
testFile2
)
await utilJs.initializeSessionPackage(db, sessionId, {
expect(errors.length).toBe(0)
expect(warnings.length).toBe(0)
let genResult = await genEngine.generate(
db,
sessionId,
templateContext.packageId,
{},
{
disableDeprecationWarnings: true,
}
)
expect(genResult.hasErrors).toBeFalsy()
expect(genResult).not.toBeNull()
expect(genResult.partial).toBeFalsy()
expect(genResult.content).not.toBeNull()
let sdkExtension = genResult.content['sdk-extension.out']
expect(sdkExtension).not.toBeNull()
expect(
sdkExtension.includes(
'IMPLEMENTED_COMMANDS2>IdentifyQueryResponse,IdentifyQuery,<END2'
).toBeTruthy()
testUtil.timeout.long()
)
test.skip(
'Test file import and command parser generation, version 2',
async () => {
let sid = await querySession.createBlankSession(db)
await importJs.importDataFromFile(db, testFile, { sessionId: sid })
let genResult = await genEngine.generate(db, sid, templateContext.packageId)
if (genResult.hasErrors) {
// Ok, there is the error with this file.
} else {
expect(genResult).not.toBeNull()
expect(genResult.partial).toBeFalsy()
expect(genResult.content).not.toBeNull()
let zapCommandParser = genResult.content['zap-command-parser-2.c']
expect(zapCommandParser).toContain('#include "zap-command-parser.h"')
expect(zapCommandParser).toContain(
'EmberAfStatus emberAfIdentifyClusterServerCommandParse(EmberAfClusterCommand * cmd);'
)
expect(zapCommandParser).toContain('case ZCL_IDENTIFY_CLUSTER_ID:')
expect(zapCommandParser).toContain(
'wasHandled = emberAfIdentifyClusterIdentifyCallback(identifyTime);'
)
}
testUtil.timeout.long()
test(
'Test content indexer - simple',
async () => {
let preview = await genEngine.contentIndexer('Short example')
expect(preview['1']).toBe('Short example\n')
},
testUtil.timeout.short()
)
test(
'Test content indexer - line by line',
async () => {
let preview = await genEngine.contentIndexer(
'Short example\nwith three\nlines of text',
1
)
expect(preview['1']).toBe('Short example\n')
expect(preview['2']).toBe('with three\n')
expect(preview['3']).toBe('lines of text\n')
},
testUtil.timeout.short()
)
test(
'Test content indexer - blocks',
let content = ''
let i = 0
for (i = 0; i < 1000; i++) {
content = content.concat(`line ${i}\n`)
}
let preview = await genEngine.contentIndexer(content, 50)
expect(preview['1'].startsWith('line 0')).toBeTruthy()
expect(preview['2'].startsWith('line 50')).toBeTruthy()
expect(preview['3'].startsWith('line 100')).toBeTruthy()
expect(preview['20'].startsWith('line 950')).toBeTruthy()
},
testUtil.timeout.short()
)