Skip to content

Commit

Permalink
Encoding test
Browse files Browse the repository at this point in the history
Signed-off-by: worksofliam <[email protected]>
  • Loading branch information
worksofliam committed Apr 10, 2024
1 parent 9b1b2ca commit 07bd1b1
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 4 deletions.
15 changes: 12 additions & 3 deletions src/api/IBMi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ const remoteApps = [ // All names MUST also be defined as key in 'remoteFeatures

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

client: node_ssh.NodeSSH;
currentHost: string = ``;
Expand Down Expand Up @@ -1289,9 +1293,13 @@ export default class IBMi {
}
}

setOverrideCcsid(ccsid: number | undefined) {
this.overrideCcsid = ccsid;
}

getEncoding() {
const fallback = ((this.runtimeCcsid < 1 || this.runtimeCcsid === 65535) && this.userDefaultCCSID > 0 ? true : false);
const ccsid = fallback ? this.userDefaultCCSID : this.runtimeCcsid;
const fallback = this.overrideCcsid !== undefined || ((this.runtimeCcsid < 1 || this.runtimeCcsid === 65535) && this.userDefaultCCSID > 0 ? true : false);
const ccsid = fallback ? (this.overrideCcsid || this.userDefaultCCSID) : this.runtimeCcsid;
return {
fallback,
ccsid,
Expand All @@ -1303,7 +1311,8 @@ export default class IBMi {
return {
origin: this.runtimeCcsidOrigin,
runtimeCcsid: this.runtimeCcsid,
userDefaultCCSID: this.userDefaultCCSID
userDefaultCCSID: this.userDefaultCCSID,
overrideCcsid: this.overrideCcsid,
};
}
}
86 changes: 86 additions & 0 deletions src/testing/encoding.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import assert from "assert";
import tmp from 'tmp';
import util, { TextDecoder } from 'util';
import { Uri, workspace } from "vscode";
import { TestSuite } from ".";
import { Tools } from "../api/Tools";
import { instance } from "../instantiate";
import { CommandResult } from "../typings";
import { getMemberUri } from "../filesystems/qsys/QSysFs";

export const EncodingSuite: TestSuite = {
name: `Encoding tests`,
after: async () => {
const connection = instance.getConnection();
connection?.setOverrideCcsid(undefined);
},

before: async () => {
const config = instance.getConfig()!;
assert.ok(config.enableSourceDates, `Source dates must be enabled for this test.`);
},

tests: [
{
name: `Encoding 37`, test: async () => {
const connection = instance.getConnection();
const config = instance.getConfig()!;

const lines = [
`Hello world`
].join(`\n`);

const tempLib = config!.tempLibrary;

connection?.setOverrideCcsid(37);

const file = `TEST37`;

await connection!.runCommand({ command: `CRTSRCPF FILE(${tempLib}/${file}) RCDLEN(112) CCSID(37)`, noLibList: true });
await connection!.runCommand({ command: `ADDPFM FILE(${tempLib}/${file}) MBR(THEMEMBER) SRCTYPE(TXT)`, noLibList: true });

const theBadOneUri = getMemberUri({library: tempLib, file, name: `THEMEMBER`, extension: `TXT`});

await workspace.fs.readFile(theBadOneUri);

await workspace.fs.writeFile(theBadOneUri, Buffer.from(lines, `utf8`));

const memberContentBuf = await workspace.fs.readFile(theBadOneUri);
const fileContent = new TextDecoder().decode(memberContentBuf)

assert.strictEqual(fileContent, lines);
},
},
// {
// name: `Encoding 273`, test: async () => {
// const connection = instance.getConnection();
// const config = instance.getConfig()!;

// const lines = [
// `Hello world`,
// `àáãÄÜö£øß`
// ].join(`\n`);

// const tempLib = config!.tempLibrary;

// connection?.setOverrideCcsid(37);

// const file = `TEST273`;

// await connection!.runCommand({ command: `CRTSRCPF FILE(${tempLib}/${file}) RCDLEN(112) CCSID(273)`, noLibList: true });
// await connection!.runCommand({ command: `ADDPFM FILE(${tempLib}/${file}) MBR(THEMEMBER) SRCTYPE(TXT)`, noLibList: true });

// const theBadOneUri = getMemberUri({library: tempLib, file, name: `THEMEMBER`, extension: `TXT`});

// await workspace.fs.readFile(theBadOneUri);

// await workspace.fs.writeFile(theBadOneUri, Buffer.from(lines, `utf8`));

// const memberContentBuf = await workspace.fs.readFile(theBadOneUri);
// const fileContent = new TextDecoder().decode(memberContentBuf)

// assert.strictEqual(fileContent, lines);
// }
// }
]
};
4 changes: 3 additions & 1 deletion src/testing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ILEErrorSuite } from "./ileErrors";
import { StorageSuite } from "./storage";
import { TestSuitesTreeProvider } from "./testCasesTree";
import { ToolsSuite } from "./tools";
import { EncodingSuite } from "./encoding";

const suites: TestSuite[] = [
ActionSuite,
Expand All @@ -19,7 +20,8 @@ const suites: TestSuite[] = [
ToolsSuite,
ILEErrorSuite,
FilterSuite,
StorageSuite
StorageSuite,
EncodingSuite
]

export type TestSuite = {
Expand Down

0 comments on commit 07bd1b1

Please sign in to comment.