-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsolution-outline-hardware-item.test.ts
More file actions
112 lines (94 loc) · 4.27 KB
/
solution-outline-hardware-item.test.ts
File metadata and controls
112 lines (94 loc) · 4.27 KB
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
/**
* Copyright 2025-2026 Arm Limited
*
* 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
*
* https://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.
*/
import { CTreeItem } from '../../../generic/tree-item';
import { ETextFileResult } from '../../../generic/text-file';
import { parseYamlToCTreeItem } from '../../../generic/tree-item-yaml-parser';
import { CSolution } from '../../../solutions/csolution';
import { HardwareItemBuilder } from './solution-outline-hardware-item';
import { TestDataHandler } from '../../../__test__/test-data';
import path from 'node:path';
describe('HardwareItemBuilder', () => {
let cSolFile: string;
let tmpSolutionDir: string;
const testDataHandler = new TestDataHandler();
beforeAll(async () => {
tmpSolutionDir = testDataHandler.copyTestDataToTmp('solutions');
cSolFile = path.join(tmpSolutionDir, 'USBD', 'USB_Device.csolution.yml');
});
afterAll(async () => {
testDataHandler.dispose();
});
it('create dbgconf file node', async () => {
const cbuildContent = `
build:
dbgconf:
- file: .cmsis/Hello+CS300.dbgconf
version: 0.0.0`;
const root = parseYamlToCTreeItem(cbuildContent);
const topChild = root?.getChild();
root!.rootFileName = cSolFile;
const csolution = new CSolution();
const loadResult = await csolution.load(cSolFile);
expect(loadResult).toEqual(ETextFileResult.Success);
const want = 'Hello+CS300.dbgconf';
const hwItemBuilder = new HardwareItemBuilder(csolution);
const hwNodes = hwItemBuilder.createHardwareNodes(csolution, topChild as CTreeItem);
const node = hwNodes.get('STM32U585AIIx');
let got: string = '';
const children = node?.getChildren();
if (children) {
const device = children[0];
got = device.getAttribute('label') ?? '';
}
expect(got).toEqual(want);
});
it('sets merge attributes on dbgconf node using addMergeFeature', async () => {
const cbuildContent = `
build:
dbgconf:
- file: .cmsis/Hello+CS300.dbgconf
update: .cmsis/Hello+CS300.dbgconf.update@1.0.0
base: .cmsis/Hello+CS300.dbgconf.base@0.0.1
status: update suggested
version: 0.0.1`;
const root = parseYamlToCTreeItem(cbuildContent);
const topChild = root?.getChild();
root!.rootFileName = cSolFile;
const csolution = new CSolution();
const loadResult = await csolution.load(cSolFile);
expect(loadResult).toEqual(ETextFileResult.Success);
const hwItemBuilder = new HardwareItemBuilder(csolution);
const hwNodes = hwItemBuilder.createHardwareNodes(csolution, topChild as CTreeItem);
const node = hwNodes.get('STM32U585AIIx');
// find dbgConfFile child node
const children = node?.getChildren();
expect(children).toBeDefined();
const device = children?.[0];
// check merge attributes set by addMergeFeature
const local = device?.getAttribute('local');
const gotLocal = local ? path.basename(local) : '';
const wantLocal = 'Hello+CS300.dbgconf';
expect(gotLocal).toEqual(wantLocal);
const update = device?.getAttribute('update');
const gotUpdate = update ? path.basename(update) : '';
const wantUpdate = 'Hello+CS300.dbgconf.update@1.0.0';
expect(gotUpdate).toEqual(wantUpdate);
const base = device?.getAttribute('base');
const gotBase = base ? path.basename(base) : '';
const wantBase = 'Hello+CS300.dbgconf.base@0.0.1';
expect(gotBase).toEqual(wantBase);
});
});