forked from project-chip/zap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zcl-properties-loader.test.js
127 lines (124 loc) · 4.33 KB
/
zcl-properties-loader.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/**
*
* 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 dbApi = require('../src-electron/db/db-api.js')
const dbEnum = require('../src-shared/db-enum.js')
const queryZcl = require('../src-electron/db/query-zcl.js')
const queryPackage = require('../src-electron/db/query-package.js')
const queryGeneric = require('../src-electron/db/query-generic.js')
const zclLoader = require('../src-electron/zcl/zcl-loader.js')
const env = require('../src-electron/util/env.js')
const path = require('path')
const zclPropertiesFile = path.join(
__dirname,
'../zcl-builtin/silabs/zcl-test.properties'
)
test('test Silabs zcl data loading in memory', () => {
let db
let packageId
return dbApi
.initRamDatabase()
.then((db) => dbApi.loadSchema(db, env.schemaFile(), env.zapVersion()))
.then((d) => {
db = d
return db
})
.then((db) => zclLoader.loadZcl(db, zclPropertiesFile))
.then((ctx) => {
packageId = ctx.packageId
return queryPackage.getPackageByPackageId(ctx.db, ctx.packageId)
})
.then((p) => expect(p.version).toEqual('ZCL Test Data'))
.then(() =>
queryPackage.getPackagesByType(db, dbEnum.packageType.zclProperties)
)
.then((rows) => expect(rows.length).toEqual(1))
.then(() => queryZcl.selectAllClusters(db, packageId))
.then((x) => expect(x.length).toEqual(104))
.then(() => queryZcl.selectAllDomains(db, packageId))
.then((x) => expect(x.length).toEqual(19))
.then(() => queryZcl.selectAllEnums(db, packageId))
.then((x) => expect(x.length).toEqual(205))
.then(() => queryZcl.selectAllStructs(db, packageId))
.then((x) => expect(x.length).toEqual(50))
.then(() => queryZcl.selectAllBitmaps(db, packageId))
.then((x) => expect(x.length).toEqual(120))
.then(() => queryZcl.selectAllDeviceTypes(db, packageId))
.then((x) => expect(x.length).toEqual(152))
.then(() => queryGeneric.selectCountFrom(db, 'COMMAND_ARG'))
.then((x) => expect(x).toEqual(1663))
.then(() => queryGeneric.selectCountFrom(db, 'COMMAND'))
.then((x) => expect(x).toEqual(553))
.then(() => queryGeneric.selectCountFrom(db, 'ENUM_ITEM'))
.then((x) => expect(x).toEqual(1534))
.then(() => queryGeneric.selectCountFrom(db, 'ATTRIBUTE'))
.then((x) => expect(x).toEqual(3408))
.then(() => queryGeneric.selectCountFrom(db, 'BITMAP_FIELD'))
.then((x) => expect(x).toEqual(721))
.then(() => queryGeneric.selectCountFrom(db, 'STRUCT_ITEM'))
.then((x) => expect(x).toEqual(154))
.then(() =>
dbApi.dbAll(
db,
'SELECT MANUFACTURER_CODE FROM CLUSTER WHERE MANUFACTURER_CODE NOT NULL',
[]
)
)
.then((x) => expect(x.length).toEqual(0))
.then(() =>
dbApi.dbAll(
db,
'SELECT MANUFACTURER_CODE FROM COMMAND WHERE MANUFACTURER_CODE NOT NULL',
[]
)
)
.then((x) => expect(x.length).toEqual(0))
.then(() =>
dbApi.dbAll(
db,
'SELECT MANUFACTURER_CODE FROM ATTRIBUTE WHERE MANUFACTURER_CODE NOT NULL',
[]
)
)
.then((x) => expect(x.length).toEqual(0))
.then(() =>
dbApi.dbMultiSelect(db, 'SELECT CLUSTER_ID FROM CLUSTER WHERE CODE = ?', [
[0],
[6],
])
)
.then((rows) => {
expect(rows.length).toBe(2)
expect(rows[0]).not.toBeUndefined()
expect(rows[1]).not.toBeUndefined()
expect(rows[0].CLUSTER_ID).not.toBeUndefined()
expect(rows[1].CLUSTER_ID).not.toBeUndefined()
})
.then(() =>
queryPackage.selectAllOptionsValues(
db,
packageId,
dbEnum.sessionOption.defaultResponsePolicy
)
)
.then((rows) => expect(rows.length).toBe(3))
.finally(() => {
dbApi.closeDatabase(db)
})
}, 5000) // Give this test 5 secs to resolve