-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
10 changed files
with
898 additions
and
7 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/** | ||
* These should all fail and throw errors | ||
*/ | ||
|
||
const {Profile, Transform, eIntent, color, eColourType} = require('../src/main'); | ||
|
||
function incorrectLabInput() { | ||
let rgb2lab = new Transform(); | ||
rgb2lab.create('*lab', '*srgb', eIntent.absolute); | ||
let input = color.RGB(200,150,50); | ||
rgb2lab.transform(input); | ||
} | ||
|
||
test('incorrect Lab Input', () => { | ||
expect(incorrectLabInput).toThrow('stage_cmsLab_to_LabD50: input is not of type Lab'); | ||
}); | ||
|
||
function inputProfileNotLoaded() { | ||
let inputProfile = new Profile(); | ||
let testTransform = new Transform(); | ||
testTransform.create( inputProfile,'*lab', eIntent.absolute); | ||
} | ||
|
||
|
||
|
||
|
||
test('input Profile Not Loaded', () => { | ||
expect(inputProfileNotLoaded).toThrow('Profile 1 in chain is not loaded'); | ||
}); | ||
|
||
|
||
function outputProfileNotLoaded() { | ||
let outputProfile = new Profile(); | ||
let testTransform = new Transform(); | ||
testTransform.create('*lab', outputProfile, eIntent.absolute); | ||
} | ||
|
||
test('output Profile Not Loaded', () => { | ||
expect(outputProfileNotLoaded).toThrow('Profile 2 in chain is not loaded'); | ||
}); | ||
|
||
|
||
function outputProfileNotAProfile() { | ||
let outputProfile = {}; | ||
let testTransform = new Transform(); | ||
testTransform.create('*lab', outputProfile, eIntent.absolute); | ||
} | ||
|
||
test('output Profile is not a profile', () => { | ||
expect(outputProfileNotAProfile).toThrow('Profile 2 in chain is not a Profile'); | ||
}); | ||
|
||
|
||
function inputProfileNotAProfile() { | ||
let inputProfile = {}; | ||
let testTransform = new Transform(); | ||
testTransform.create( inputProfile, '*lab', eIntent.absolute); | ||
} | ||
|
||
test('input Profile is not a profile', () => { | ||
expect(inputProfileNotAProfile).toThrow('Profile 1 in chain is not a Profile'); | ||
}); | ||
|
||
|
||
function incorrectVirtualProfileString() { | ||
let testTransform = new Transform(); | ||
testTransform.create( 'lab', '*lab', eIntent.absolute); | ||
} | ||
|
||
test('incorrect Virtual Profile String', () => { | ||
expect(incorrectVirtualProfileString).toThrow('Profile 1 is a string. Virtual profiles must be prefixed with "*"'); | ||
}); | ||
|
||
function multiStageNotArray() { | ||
let testTransform = new Transform(); | ||
testTransform.createMultiStage('*lab', eIntent.absolute); | ||
} | ||
test('multiStage Not Array', () => { | ||
expect(multiStageNotArray).toThrow('Invalid profileChain, must be an array'); | ||
}); | ||
|
||
|
||
function multiStageNoOutputProfile() { | ||
let testTransform = new Transform(); | ||
testTransform.createMultiStage(['*lab', eIntent.absolute]); | ||
} | ||
|
||
test('multiStage No Output Profile', () => { | ||
expect(multiStageNoOutputProfile).toThrow('Invalid profileChain, must have at least 3 items [profile, intent, profile]'); | ||
}); | ||
|
||
function multiStageMissingLastItem() { | ||
let testTransform = new Transform(); | ||
testTransform.createMultiStage(['*lab', eIntent.absolute, '*srgb', eIntent.absolute]); | ||
} | ||
|
||
test('multiStage Missing Last Item', () => { | ||
expect(multiStageMissingLastItem).toThrow('Last step in chain is not a Profile'); | ||
}); | ||
|
||
function intentIsAString() { | ||
let testTransform = new Transform(); | ||
testTransform.create('*lab', '*srgb', 'absolute'); | ||
} | ||
|
||
test('Intent is a string', () => { | ||
expect(intentIsAString).toThrow('Intent 1 in chain is not a number'); | ||
}); | ||
|
||
function invalidIntent() { | ||
let testTransform = new Transform(); | ||
testTransform.create('*lab', '*srgb', 9); | ||
} | ||
|
||
test('Intent is invalid number', () => { | ||
expect(invalidIntent).toThrow('Intent 1 in chain is not a valid intent'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
/** | ||
* Test Loading of ICC profiles | ||
*/ | ||
|
||
let Profile = require('../src/Profile'); | ||
const http = require('http'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const url = require('url'); | ||
const testServerPort = 3000; | ||
|
||
let realProfile = path.join(__dirname, './GRACoL2006_Coated1v2.icc'); | ||
let realProfileName = 'GRACoL2006_Coated1v2.icc'; | ||
let nonExistingProfile = path.join(__dirname, '../IDoNotExist.icc'); | ||
let profileURL = 'http://localhost:' + testServerPort + '/giveMeTheFile'; | ||
let invalidProfileURL = 'http://localhost:' + testServerPort + '/hereBeDragons'; | ||
|
||
// Function to create a simple server | ||
function createServer(port) { | ||
const server = http.createServer((req, res) => { | ||
|
||
const parsedUrl = url.parse(req.url, true); | ||
if (parsedUrl.pathname === '/giveMeTheFile') { | ||
fs.readFile(realProfile, (err, data) => { | ||
if (err) { | ||
res.writeHead(500); | ||
res.end('Server Error'); | ||
return; | ||
} | ||
res.writeHead(200); | ||
res.end(data); | ||
}); | ||
} else { | ||
res.writeHead(404, { 'Content-Type': 'text/plain' }); | ||
res.end('Not Found'); | ||
} | ||
}); | ||
|
||
server.listen(port); | ||
//console.log('Server running at http://localhost:' + port +'/'); | ||
return server; | ||
} | ||
|
||
// Jest global setup and teardown | ||
let server; | ||
beforeAll(() => { | ||
// Start server before all tests | ||
server = createServer(testServerPort); | ||
}); | ||
|
||
afterAll(() => { | ||
// Close server after all tests | ||
server.close(); | ||
//console.log('Server stopped'); | ||
}); | ||
|
||
|
||
test('Loading profile from buffer', done => { | ||
let profile = new Profile(); | ||
let buffer = fs.readFileSync(realProfile); | ||
|
||
profile.loadBinary(buffer, function (profile) { | ||
try { | ||
expect(profile.loaded).toBe(true); | ||
expect(profile.name).toBe(realProfileName); | ||
done(); | ||
} catch (error) { | ||
done(error); | ||
} | ||
}); | ||
}); | ||
|
||
|
||
test('Loading profile from buffer via generic loader', done => { | ||
let profile = new Profile(); | ||
let buffer = fs.readFileSync(realProfile); | ||
|
||
profile.load(buffer, function (profile) { | ||
try { | ||
expect(profile.loaded).toBe(true); | ||
expect(profile.name).toBe(realProfileName); | ||
done(); | ||
} catch (error) { | ||
done(error); | ||
} | ||
}); | ||
}); | ||
|
||
test('Loading profile from base64', done => { | ||
let profile = new Profile(); | ||
let buffer = fs.readFileSync(realProfile); | ||
const base64String = buffer.toString('base64'); | ||
profile.loadBase64(base64String, function (profile) { | ||
try { | ||
expect(profile.loaded).toBe(true); | ||
expect(profile.name).toBe(realProfileName); | ||
done(); | ||
} catch (error) { | ||
done(error); | ||
} | ||
}); | ||
}); | ||
|
||
test('Loading profile from base64 via generic loader', done => { | ||
let profile = new Profile(); | ||
let buffer = fs.readFileSync(realProfile); | ||
const base64String = buffer.toString('base64'); | ||
profile.load('data:' + base64String, function (profile) { | ||
try { | ||
expect(profile.loaded).toBe(true); | ||
expect(profile.name).toBe(realProfileName); | ||
done(); | ||
} catch (error) { | ||
done(error); | ||
} | ||
}); | ||
}); | ||
|
||
test('Loading profile from file', done => { | ||
let profile = new Profile(); | ||
profile.loadFile(realProfile, function (profile) { | ||
try { | ||
expect(profile.loaded).toBe(true); | ||
expect(profile.name).toBe(realProfileName); | ||
done(); | ||
} catch (error) { | ||
done(error); | ||
} | ||
}); | ||
}); | ||
|
||
test('Loading profile from file via generic loader', done => { | ||
let profile = new Profile(); | ||
profile.load('file:' + realProfile, function (profile) { | ||
try { | ||
expect(profile.loaded).toBe(true); | ||
expect(profile.name).toBe(realProfileName); | ||
done(); | ||
} catch (error) { | ||
done(error); | ||
} | ||
}); | ||
}); | ||
test('Loading profile from file - but not found', done => { | ||
let profile = new Profile(); | ||
profile.loadFile(nonExistingProfile, function (profile) { | ||
try { | ||
expect(profile.loaded).toBe(false); | ||
done(); | ||
} catch (error) { | ||
done(error); | ||
} | ||
}); | ||
}); | ||
test('Loading profile from url', done => { | ||
let profile = new Profile(); | ||
profile.loadURL(profileURL, function (profile) { | ||
try { | ||
expect(profile.loaded).toBe(true); | ||
expect(profile.name).toBe(realProfileName); | ||
done(); | ||
} catch (error) { | ||
done(error); | ||
} | ||
}); | ||
}); | ||
|
||
test('Loading profile from url - but returns 404', done => { | ||
let profile = new Profile(); | ||
profile.loadURL(invalidProfileURL, function (profile) { | ||
try { | ||
expect(profile.loadError).toBe(true); | ||
expect(profile.lastError.text).toBe('Response status was 404'); | ||
done(); | ||
} catch (error) { | ||
done(error); | ||
} | ||
}); | ||
}); | ||
|
||
|
||
test('Loading profile from url (ASYNC)', async () => { | ||
let profile = new Profile(); | ||
await profile.loadPromise(profileURL) | ||
|
||
expect(profile.loaded).toBe(true); | ||
expect(profile.name).toBe(realProfileName); | ||
}); |
Oops, something went wrong.