Skip to content

Commit

Permalink
Adding tests to make sure custom device types are being loaded from c…
Browse files Browse the repository at this point in the history
…ustom xml

JIRA: ZAPP-1450
  • Loading branch information
brdandu committed Jul 22, 2024
1 parent 1335b3c commit 2a25d2b
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/gen-zigbee-7.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const genEngine = require('../src-electron/generator/generation-engine')
const env = require('../src-electron/util/env')
const dbApi = require('../src-electron/db/db-api')
const queryPackage = require('../src-electron/db/query-package')
const queryDeviceType = require('../src-electron/db/query-device-type')
const zclLoader = require('../src-electron/zcl/zcl-loader')
const importJs = require('../src-electron/importexport/import')
const testUtil = require('./test-util')
Expand Down Expand Up @@ -119,6 +120,35 @@ test(
expect(pv4).toContain(
'result = emberAfMfglibClusterClusterServerCommandParse(cmd);'
)

// Load a custom xml with device types
result = await zclLoader.loadIndividualFile(
db,
testUtil.testCustomXmlDeviceType,
sessionId
)
if (!result.succeeded) {
console.log(result)
}
expect(result.succeeded).toBeTruthy()

// Check if device type is loaded into the database
let customDeviceType = await queryDeviceType.selectDeviceTypeByCodeAndName(
db,
result.packageId,
0x0002,
'DUT-Server'
)
expect(customDeviceType).not.toBeNull()
expect(customDeviceType.name).toBe('DUT-Server')

// Check device type clusters for device type
let deviceTypeClusters =
await queryDeviceType.selectDeviceTypeClustersByDeviceTypeRef(
db,
customDeviceType.id
)
expect(deviceTypeClusters.length).toBe(2) // 2 device type clusters associated with this device type.
},
testUtil.timeout.long()
)
27 changes: 27 additions & 0 deletions test/resource/custom-cluster/custom-device-type.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0"?>
<configurator>
<deviceType>
<name>DUT-Client</name>
<domain>CUSTOM_DUT</domain>
<typeName>D.U.T. Client</typeName>
<zigbeeType>Coordinator</zigbeeType>
<profileId editable="false">0xC001</profileId>
<deviceId editable="false">0x0001</deviceId>
<clusters lockOthers="true">
<include client="true" server="false" clientLocked="true" serverLocked="true" >Test Cluster</include>
<include cluster="Basic" client="true" server="false" clientLocked="true" serverLocked="true"></include>
</clusters>
</deviceType>
<deviceType>
<name>DUT-Server</name>
<domain>CUSTOM_DUT</domain>
<typeName>D.U.T. Server</typeName>
<zigbeeType>End Device</zigbeeType>
<profileId editable="false">0xC001</profileId>
<deviceId editable="false">0x0002</deviceId>
<clusters lockOthers="true">
<include client="false" server="true" clientLocked="true" serverLocked="true" >Test Cluster</include>
<include cluster="Basic" client="false" server="true" clientLocked="true" serverLocked="true"></include>
</clusters>
</deviceType>
</configurator>
2 changes: 2 additions & 0 deletions test/test-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ exports.testServer = testServer

exports.testCustomXml = './test/resource/custom-cluster/test-custom.xml'
exports.testCustomXml2 = './test/resource/custom-cluster/custom-dut.xml'
exports.testCustomXmlDeviceType =
'./test/resource/custom-cluster/custom-device-type.xml'
exports.customClusterXml =
'./test/resource/custom-cluster/custom-bead-cluster.xml'
exports.badTestCustomXml = './test/resource/custom-cluster/bad-test-custom.xml'
Expand Down

0 comments on commit 2a25d2b

Please sign in to comment.