Skip to content
This repository has been archived by the owner on Jul 15, 2019. It is now read-only.

Commit

Permalink
Add test infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelerz committed May 24, 2015
1 parent 580cc1a commit 0652a0f
Show file tree
Hide file tree
Showing 240 changed files with 201 additions and 0 deletions.
File renamed without changes
Binary file added test/png/PngSuite/basic/basn0g01.raw
Binary file not shown.
Binary file added test/png/PngSuite/basic/basn0g01_trueColor.png
Binary file added test/png/PngSuite/basic/basn0g02.raw
Binary file not shown.
Binary file added test/png/PngSuite/basic/basn0g02_trueColor.png
Binary file added test/png/PngSuite/basic/basn0g04.raw
Binary file not shown.
Binary file added test/png/PngSuite/basic/basn0g04_trueColor.png
Binary file added test/png/PngSuite/basic/basn0g08.raw
Binary file not shown.
Binary file added test/png/PngSuite/basic/basn0g08_trueColor.png
Binary file added test/png/PngSuite/basic/basn0g16.raw
Binary file not shown.
Binary file added test/png/PngSuite/basic/basn0g16_trueColor.png
Binary file added test/png/PngSuite/basic/basn2c08.raw
Binary file not shown.
Binary file added test/png/PngSuite/basic/basn2c08_trueColor.png
Binary file added test/png/PngSuite/basic/basn2c16.raw
Binary file not shown.
Binary file added test/png/PngSuite/basic/basn2c16_trueColor.png
1 change: 1 addition & 0 deletions test/png/PngSuite/basic/basn3p01.raw
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
��"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f��"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"���"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f��"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"���"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f��"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"���"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f��"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�"f��"f��"f��"f����"���"���"���"�
Binary file added test/png/PngSuite/basic/basn3p01_trueColor.png
Binary file added test/png/PngSuite/basic/basn3p02.raw
Binary file not shown.
Binary file added test/png/PngSuite/basic/basn3p02_trueColor.png
Binary file added test/png/PngSuite/basic/basn3p04.raw
Binary file not shown.
Binary file added test/png/PngSuite/basic/basn3p04_trueColor.png
Binary file added test/png/PngSuite/basic/basn3p08.raw
Binary file not shown.
Binary file added test/png/PngSuite/basic/basn3p08_trueColor.png
Binary file added test/png/PngSuite/basic/basn4a08.raw
Binary file not shown.
Binary file added test/png/PngSuite/basic/basn4a08_trueColor.png
Binary file added test/png/PngSuite/basic/basn4a16.raw
Binary file not shown.
Binary file added test/png/PngSuite/basic/basn4a16_trueColor.png
Binary file added test/png/PngSuite/basic/basn6a08.raw
Binary file not shown.
Binary file added test/png/PngSuite/basic/basn6a08_trueColor.png
Binary file added test/png/PngSuite/basic/basn6a16.raw
Binary file not shown.
Binary file added test/png/PngSuite/basic/basn6a16_trueColor.png
Binary file added test/png/PngSuite/compression/z00n2c08.raw
Binary file not shown.
Binary file added test/png/PngSuite/compression/z03n2c08.raw
Binary file not shown.
Binary file added test/png/PngSuite/compression/z06n2c08.raw
Binary file not shown.
Binary file added test/png/PngSuite/compression/z09n2c08.raw
Binary file not shown.
Binary file added test/png/PngSuite/filter/f00n0g08.raw
Binary file not shown.
Binary file added test/png/PngSuite/filter/f00n0g08_trueColor.png
Binary file added test/png/PngSuite/filter/f00n2c08.raw
Binary file not shown.
Binary file added test/png/PngSuite/filter/f00n2c08_trueColor.png
Binary file added test/png/PngSuite/filter/f01n0g08.raw
Binary file not shown.
Binary file added test/png/PngSuite/filter/f01n0g08_trueColor.png
Binary file added test/png/PngSuite/filter/f01n2c08.raw
Binary file not shown.
Binary file added test/png/PngSuite/filter/f01n2c08_trueColor.png
Binary file added test/png/PngSuite/filter/f02n0g08.raw
Binary file not shown.
Binary file added test/png/PngSuite/filter/f02n0g08_trueColor.png
Binary file added test/png/PngSuite/filter/f02n2c08.raw
Binary file not shown.
Binary file added test/png/PngSuite/filter/f02n2c08_trueColor.png
Binary file added test/png/PngSuite/filter/f03n0g08.raw
Binary file not shown.
Binary file added test/png/PngSuite/filter/f03n0g08_trueColor.png
Binary file added test/png/PngSuite/filter/f03n2c08.raw
Binary file not shown.
Binary file added test/png/PngSuite/filter/f03n2c08_trueColor.png
Binary file added test/png/PngSuite/filter/f04n0g08.raw
Binary file not shown.
Binary file added test/png/PngSuite/filter/f04n0g08_trueColor.png
Binary file added test/png/PngSuite/filter/f04n2c08.raw
Binary file not shown.
Binary file added test/png/PngSuite/filter/f04n2c08_trueColor.png
6 changes: 6 additions & 0 deletions test/png/decode/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright 2015 Yahoo! Inc.
// Copyrights licensed under the Mit License. See the accompanying LICENSE file for terms.

describe('Decode', function () {

});
6 changes: 6 additions & 0 deletions test/png/encode/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright 2015 Yahoo! Inc.
// Copyrights licensed under the Mit License. See the accompanying LICENSE file for terms.

describe('Encode', function () {

});
10 changes: 10 additions & 0 deletions test/png/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2015 Yahoo! Inc.
// Copyrights licensed under the Mit License. See the accompanying LICENSE file for terms.

describe('PNG', function () {

require('./utils');

require('./decode');
require('./encode');
});
117 changes: 117 additions & 0 deletions test/png/testGen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
var expect = require('chai').expect;

var fs = require('fs');

module.exports = {

/**
* @class tests
* @method addTests
* @param {object} options
* @param {string} options.resourceGroup
* @param {string} options.resourceFile
* @param {string[]} [options.chunkTypes]
* @param {boolean} [options.imageCheck=false]
* @param {boolean} [options.headerCheck=false]
* @param {int} [options.width=32]
* @param {int} [options.height=32]
* @param {int} [options.bitDepth=8]
* @param {int} [options.colorType=0]
* @param {int} [options.filter=0]
* @param {int} [options.compression=0]
* @param {int} [options.interlace=0]
*/
addTests: function (options) {

before(function () {
this.file = this.resource(options.resourceGroup, options.resourceFile + '.png');
});

it('should decode', function () {
this.decode(this.file);
});

it('should have mandatory chunks', function () {
expect(this.chunks).to.contain.keys('IDAT', 'IHDR', 'IEND');
});

if (options.chunkTypes) {
it('should have chunks', function () {
expect(this.chunks).to.contain.keys(options.chunkTypes);
});
}

if (options.imageCheck) {
it('should load the image buffer', function () {

var pathRaw = this.resource(options.resourceGroup, options.resourceFile + '.raw'),
pathPng = this.resource(options.resourceGroup, options.resourceFile + '_trueColor.png');

if (!fs.existsSync(pathRaw)) {

fs.writeFileSync(pathRaw, this.image);
this.encode(pathPng, this.image, options.width, options.height);

throw new Error('Compare-to image did not exist. Please check manually the image and check it in.');
}

this.compareToFile(this.image, pathRaw);
});
}

describe('Data', function () {

it('should have volatile data', function () {
if (options.headerCheck) {
expect(this.data).to.contain.key('volatile');
}
});

if (options.headerCheck) {

describe('Header', function () {

before(function () {
expect(this.data.volatile.header).to.be.not.undefined;
this.header = this.data.volatile.header;
});

it('should have the right resolution', function () {
expect(this.header.width).to.be.equal(options.width || 32);
expect(this.header.height).to.be.equal(options.height || 32);
});

if (options.bitDepth !== undefined) {
it('should have the correct bit-depth', function () {
expect(this.header.bitDepth).to.be.equal(options.bitDepth);
});
}

if (options.colorType !== undefined) {
it('should have the correct color-type', function () {
expect(this.header.colorType).to.be.equal(options.colorType);
});
}

if (options.filter !== undefined) {
it('should have the correct filter method', function () {
expect(this.header.filter).to.be.equal(options.filter);
});
}

if (options.compression !== undefined) {
it('should have the correct compression method', function () {
expect(this.header.compression).to.be.equal(options.compression);
});
}

if (options.interlace !== undefined) {
it('should have the correct interlace method', function () {
expect(this.header.interlace).to.be.equal(options.interlace);
});
}
});
}
});
}
};
61 changes: 61 additions & 0 deletions test/png/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright 2015 Yahoo! Inc.
// Copyrights licensed under the Mit License. See the accompanying LICENSE file for terms.

var fs = require('fs');
var path = require('path');

var Decoder = require('../../index').Decoder;
var Encoder = require('../../index').Encoder;

before(function () {

this.resource = function (groups, file) {

groups = [].concat(groups);

var completePath = path.join(__dirname, 'PngSuite');

groups.forEach(function (group) {
completePath = path.join(completePath, group);
});

completePath = path.join(completePath, file);

return completePath;
};

this.decode = function (path) {

this.blob = fs.readFileSync(path);

this.decoder = new Decoder();

this.image = this.decoder.decode(this.blob, { strict: true });
this.data = this.decoder.getChunkData();
this.chunks = this.decoder.getChunks();
};

this.encode = function (path, buffer, width, height) {

this.encoder = new Encoder();

this.encodedBlob = this.encoder.encode(buffer, width, height);

fs.writeFileSync(path, this.encodedBlob);
};

this.compareToFile = function (buffer, path) {

var compareToBuffer = fs.readFileSync(path);

if (compareToBuffer.length != buffer.length) {
throw new Error('Buffer have different sizes.');
}

for(var i = 0; i < buffer.length; i++) {
if (buffer[i] != compareToBuffer[i]) {
throw new Error('Buffers are different.');
}
}
}
});

0 comments on commit 0652a0f

Please sign in to comment.