Skip to content

Commit 07bd1b1

Browse files
committed
Encoding test
Signed-off-by: worksofliam <[email protected]>
1 parent 9b1b2ca commit 07bd1b1

File tree

3 files changed

+101
-4
lines changed

3 files changed

+101
-4
lines changed

src/api/IBMi.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,12 @@ const remoteApps = [ // All names MUST also be defined as key in 'remoteFeatures
4646

4747
export default class IBMi {
4848
private runtimeCcsidOrigin = CcsidOrigin.User;
49+
/** Runtime CCSID is either job CCSID or QCCSID */
4950
private runtimeCcsid: number = CCSID_SYSVAL;
51+
/** User default CCSID is job default CCSID */
5052
private userDefaultCCSID: number = 0;
53+
/** override allows the API to hardcode a CCSID. Usually good for testing */
54+
private overrideCcsid: number | undefined;
5155

5256
client: node_ssh.NodeSSH;
5357
currentHost: string = ``;
@@ -1289,9 +1293,13 @@ export default class IBMi {
12891293
}
12901294
}
12911295

1296+
setOverrideCcsid(ccsid: number | undefined) {
1297+
this.overrideCcsid = ccsid;
1298+
}
1299+
12921300
getEncoding() {
1293-
const fallback = ((this.runtimeCcsid < 1 || this.runtimeCcsid === 65535) && this.userDefaultCCSID > 0 ? true : false);
1294-
const ccsid = fallback ? this.userDefaultCCSID : this.runtimeCcsid;
1301+
const fallback = this.overrideCcsid !== undefined || ((this.runtimeCcsid < 1 || this.runtimeCcsid === 65535) && this.userDefaultCCSID > 0 ? true : false);
1302+
const ccsid = fallback ? (this.overrideCcsid || this.userDefaultCCSID) : this.runtimeCcsid;
12951303
return {
12961304
fallback,
12971305
ccsid,
@@ -1303,7 +1311,8 @@ export default class IBMi {
13031311
return {
13041312
origin: this.runtimeCcsidOrigin,
13051313
runtimeCcsid: this.runtimeCcsid,
1306-
userDefaultCCSID: this.userDefaultCCSID
1314+
userDefaultCCSID: this.userDefaultCCSID,
1315+
overrideCcsid: this.overrideCcsid,
13071316
};
13081317
}
13091318
}

src/testing/encoding.ts

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import assert from "assert";
2+
import tmp from 'tmp';
3+
import util, { TextDecoder } from 'util';
4+
import { Uri, workspace } from "vscode";
5+
import { TestSuite } from ".";
6+
import { Tools } from "../api/Tools";
7+
import { instance } from "../instantiate";
8+
import { CommandResult } from "../typings";
9+
import { getMemberUri } from "../filesystems/qsys/QSysFs";
10+
11+
export const EncodingSuite: TestSuite = {
12+
name: `Encoding tests`,
13+
after: async () => {
14+
const connection = instance.getConnection();
15+
connection?.setOverrideCcsid(undefined);
16+
},
17+
18+
before: async () => {
19+
const config = instance.getConfig()!;
20+
assert.ok(config.enableSourceDates, `Source dates must be enabled for this test.`);
21+
},
22+
23+
tests: [
24+
{
25+
name: `Encoding 37`, test: async () => {
26+
const connection = instance.getConnection();
27+
const config = instance.getConfig()!;
28+
29+
const lines = [
30+
`Hello world`
31+
].join(`\n`);
32+
33+
const tempLib = config!.tempLibrary;
34+
35+
connection?.setOverrideCcsid(37);
36+
37+
const file = `TEST37`;
38+
39+
await connection!.runCommand({ command: `CRTSRCPF FILE(${tempLib}/${file}) RCDLEN(112) CCSID(37)`, noLibList: true });
40+
await connection!.runCommand({ command: `ADDPFM FILE(${tempLib}/${file}) MBR(THEMEMBER) SRCTYPE(TXT)`, noLibList: true });
41+
42+
const theBadOneUri = getMemberUri({library: tempLib, file, name: `THEMEMBER`, extension: `TXT`});
43+
44+
await workspace.fs.readFile(theBadOneUri);
45+
46+
await workspace.fs.writeFile(theBadOneUri, Buffer.from(lines, `utf8`));
47+
48+
const memberContentBuf = await workspace.fs.readFile(theBadOneUri);
49+
const fileContent = new TextDecoder().decode(memberContentBuf)
50+
51+
assert.strictEqual(fileContent, lines);
52+
},
53+
},
54+
// {
55+
// name: `Encoding 273`, test: async () => {
56+
// const connection = instance.getConnection();
57+
// const config = instance.getConfig()!;
58+
59+
// const lines = [
60+
// `Hello world`,
61+
// `àáãÄÜö£øß`
62+
// ].join(`\n`);
63+
64+
// const tempLib = config!.tempLibrary;
65+
66+
// connection?.setOverrideCcsid(37);
67+
68+
// const file = `TEST273`;
69+
70+
// await connection!.runCommand({ command: `CRTSRCPF FILE(${tempLib}/${file}) RCDLEN(112) CCSID(273)`, noLibList: true });
71+
// await connection!.runCommand({ command: `ADDPFM FILE(${tempLib}/${file}) MBR(THEMEMBER) SRCTYPE(TXT)`, noLibList: true });
72+
73+
// const theBadOneUri = getMemberUri({library: tempLib, file, name: `THEMEMBER`, extension: `TXT`});
74+
75+
// await workspace.fs.readFile(theBadOneUri);
76+
77+
// await workspace.fs.writeFile(theBadOneUri, Buffer.from(lines, `utf8`));
78+
79+
// const memberContentBuf = await workspace.fs.readFile(theBadOneUri);
80+
// const fileContent = new TextDecoder().decode(memberContentBuf)
81+
82+
// assert.strictEqual(fileContent, lines);
83+
// }
84+
// }
85+
]
86+
};

src/testing/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { ILEErrorSuite } from "./ileErrors";
1010
import { StorageSuite } from "./storage";
1111
import { TestSuitesTreeProvider } from "./testCasesTree";
1212
import { ToolsSuite } from "./tools";
13+
import { EncodingSuite } from "./encoding";
1314

1415
const suites: TestSuite[] = [
1516
ActionSuite,
@@ -19,7 +20,8 @@ const suites: TestSuite[] = [
1920
ToolsSuite,
2021
ILEErrorSuite,
2122
FilterSuite,
22-
StorageSuite
23+
StorageSuite,
24+
EncodingSuite
2325
]
2426

2527
export type TestSuite = {

0 commit comments

Comments
 (0)