mirror of
https://github.com/serratus/quaggaJS.git
synced 2026-08-13 05:31:37 +08:00
Added integration-tests for all decoders; Split up integration and unit tests
This commit is contained in:
@@ -6,6 +6,9 @@ module.exports = function(grunt) {
|
|||||||
karma: {
|
karma: {
|
||||||
unit: {
|
unit: {
|
||||||
configFile: 'karma.conf.js'
|
configFile: 'karma.conf.js'
|
||||||
|
},
|
||||||
|
integration: {
|
||||||
|
configFile: 'karma-integration.conf.js'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
uglify : {
|
uglify : {
|
||||||
@@ -75,6 +78,7 @@ module.exports = function(grunt) {
|
|||||||
grunt.registerTask('check', ['jshint']);
|
grunt.registerTask('check', ['jshint']);
|
||||||
grunt.registerTask('dist', ['build', 'uglify', 'uglyasm']);
|
grunt.registerTask('dist', ['build', 'uglify', 'uglyasm']);
|
||||||
grunt.registerTask('test', ['karma']);
|
grunt.registerTask('test', ['karma']);
|
||||||
|
grunt.registerTask('integrationtest', ['karma:integration']);
|
||||||
|
|
||||||
grunt.registerTask('default', ['build']);
|
grunt.registerTask('default', ['build']);
|
||||||
};
|
};
|
||||||
|
|||||||
Vendored
+7
-5
@@ -463,7 +463,7 @@ define(
|
|||||||
error = 0,
|
error = 0,
|
||||||
singleError = 0,
|
singleError = 0,
|
||||||
modulo = this.MODULO,
|
modulo = this.MODULO,
|
||||||
maxSingleError = this.SINGLE_CODE_ERROR || 0.9;
|
maxSingleError = this.SINGLE_CODE_ERROR || 1;
|
||||||
|
|
||||||
for (i = 0; i < counter.length; i++) {
|
for (i = 0; i < counter.length; i++) {
|
||||||
singleError = Math.abs(code[i] - counter[i]);
|
singleError = Math.abs(code[i] - counter[i]);
|
||||||
@@ -762,7 +762,9 @@ define(
|
|||||||
[2, 1, 1, 2, 1, 4],
|
[2, 1, 1, 2, 1, 4],
|
||||||
[2, 1, 1, 2, 3, 2],
|
[2, 1, 1, 2, 3, 2],
|
||||||
[2, 3, 3, 1, 1, 1, 2]
|
[2, 3, 3, 1, 1, 1, 2]
|
||||||
]}
|
]},
|
||||||
|
SINGLE_CODE_ERROR: {value: 1},
|
||||||
|
AVG_CODE_ERROR: {value: 0.5}
|
||||||
};
|
};
|
||||||
|
|
||||||
Code128Reader.prototype = Object.create(BarcodeReader.prototype, properties);
|
Code128Reader.prototype = Object.create(BarcodeReader.prototype, properties);
|
||||||
@@ -839,7 +841,7 @@ define(
|
|||||||
}
|
}
|
||||||
normalized = self._normalize(counter, 13);
|
normalized = self._normalize(counter, 13);
|
||||||
error = self._matchPattern(normalized, self.CODE_PATTERN[self.STOP_CODE]);
|
error = self._matchPattern(normalized, self.CODE_PATTERN[self.STOP_CODE]);
|
||||||
if (error < 3) {
|
if (error < self.AVG_CODE_ERROR) {
|
||||||
bestMatch.error = error;
|
bestMatch.error = error;
|
||||||
bestMatch.start = i - sum;
|
bestMatch.start = i - sum;
|
||||||
bestMatch.end = i;
|
bestMatch.end = i;
|
||||||
@@ -898,7 +900,7 @@ define(
|
|||||||
bestMatch.error = error;
|
bestMatch.error = error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (bestMatch.error < 3) {
|
if (bestMatch.error < self.AVG_CODE_ERROR) {
|
||||||
bestMatch.start = i - sum;
|
bestMatch.start = i - sum;
|
||||||
bestMatch.end = i;
|
bestMatch.end = i;
|
||||||
return bestMatch;
|
return bestMatch;
|
||||||
@@ -8579,7 +8581,7 @@ function(Code128Reader,
|
|||||||
}
|
}
|
||||||
}, config);
|
}, config);
|
||||||
this.init(config, function() {
|
this.init(config, function() {
|
||||||
Events.once("detected", function(result) {
|
Events.once("processed", function(result) {
|
||||||
_stopped = true;
|
_stopped = true;
|
||||||
resultCallback.call(null, result);
|
resultCallback.call(null, result);
|
||||||
}, true);
|
}, true);
|
||||||
|
|||||||
Vendored
+4
-4
File diff suppressed because one or more lines are too long
@@ -0,0 +1,32 @@
|
|||||||
|
module.exports = function(config) {
|
||||||
|
config.set({
|
||||||
|
basePath: '',
|
||||||
|
frameworks: ['mocha', 'requirejs', 'chai', 'sinon', 'sinon-chai'],
|
||||||
|
files: [
|
||||||
|
'test-main.js',
|
||||||
|
'src/vendor/glMatrix.js',
|
||||||
|
'src/typedefs.js',
|
||||||
|
{pattern: 'node_modules/async/lib/async.js', included: false},
|
||||||
|
{pattern: 'src/*.js', included: false},
|
||||||
|
{pattern: 'spec/**/*integration.spec.js', included: false},
|
||||||
|
{pattern: 'test/**/*.*', included: false}
|
||||||
|
],
|
||||||
|
exclude: [
|
||||||
|
],
|
||||||
|
plugins: [
|
||||||
|
'karma-chrome-launcher',
|
||||||
|
'karma-mocha',
|
||||||
|
'karma-requirejs',
|
||||||
|
'karma-chai',
|
||||||
|
'karma-sinon',
|
||||||
|
'karma-sinon-chai'
|
||||||
|
],
|
||||||
|
reporters: ['progress'],
|
||||||
|
port: 9876,
|
||||||
|
colors: true,
|
||||||
|
logLevel: config.LOG_INFO,
|
||||||
|
autoWatch: true,
|
||||||
|
browsers: ['Chrome'],
|
||||||
|
singleRun: false
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -12,6 +12,7 @@ module.exports = function(config) {
|
|||||||
{pattern: 'test/**/*.*', included: false}
|
{pattern: 'test/**/*.*', included: false}
|
||||||
],
|
],
|
||||||
exclude: [
|
exclude: [
|
||||||
|
'spec/**/*integration.spec.js'
|
||||||
],
|
],
|
||||||
preprocessors: {
|
preprocessors: {
|
||||||
'src/*.js': ['coverage']
|
'src/*.js': ['coverage']
|
||||||
|
|||||||
@@ -1,82 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
define(['quagga', 'async'], function(Quagga, async) {
|
|
||||||
describe('decodeSingle', function () {
|
|
||||||
var config;
|
|
||||||
|
|
||||||
this.timeout(10000);
|
|
||||||
|
|
||||||
beforeEach(function () {
|
|
||||||
config = {
|
|
||||||
inputStream: {
|
|
||||||
size: 640
|
|
||||||
},
|
|
||||||
locator: {
|
|
||||||
patchSize: "medium",
|
|
||||||
halfSample: true
|
|
||||||
},
|
|
||||||
numOfWorkers: 0,
|
|
||||||
decoder: {
|
|
||||||
readers: ["ean_reader"]
|
|
||||||
},
|
|
||||||
locate: true,
|
|
||||||
src: null
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
var folder = "base/test/fixtures/ean/",
|
|
||||||
testSet = [{
|
|
||||||
"name": "image-001.jpg",
|
|
||||||
"result": "3574660239843"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "image-002.jpg",
|
|
||||||
"result": "8032754490297"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "image-003.jpg",
|
|
||||||
"result": "4006209700068"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "image-004.jpg",
|
|
||||||
"result": "9002233139084"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "image-005.jpg",
|
|
||||||
"result": "8004030044005"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "image-006.jpg",
|
|
||||||
"result": "4003626011159"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "image-007.jpg",
|
|
||||||
"result": "2111220009686"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "image-008.jpg",
|
|
||||||
"result": "9000275609022"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "image-009.jpg",
|
|
||||||
"result": "9004593978587"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "image-010.jpg",
|
|
||||||
"result": "9002244845578"
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
async.each(testSet, function (sample, callback) {
|
|
||||||
it('should decode ' + sample.name + " correctly", function(done) {
|
|
||||||
config.src = folder + sample.name;
|
|
||||||
Quagga.decodeSingle(config, function (result) {});
|
|
||||||
Quagga.onProcessed(function(result) {
|
|
||||||
expect(result.codeResult.code).to.equal(sample.result);
|
|
||||||
done();
|
|
||||||
callback();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}, function() {});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -0,0 +1,179 @@
|
|||||||
|
|
||||||
|
|
||||||
|
define(['quagga', 'async'], function(Quagga, async) {
|
||||||
|
describe('decodeSingle', function () {
|
||||||
|
var baseFolder = "base/test/fixtures/";
|
||||||
|
|
||||||
|
function generateConfig() {
|
||||||
|
return {
|
||||||
|
inputStream: {
|
||||||
|
size: 640
|
||||||
|
},
|
||||||
|
locator: {
|
||||||
|
patchSize: "medium",
|
||||||
|
halfSample: true
|
||||||
|
},
|
||||||
|
numOfWorkers: 0,
|
||||||
|
decoder: {
|
||||||
|
readers: ["ean_reader"]
|
||||||
|
},
|
||||||
|
locate: true,
|
||||||
|
src: null
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
this.timeout(10000);
|
||||||
|
|
||||||
|
function _runTestSet(testSet, config) {
|
||||||
|
var readers = config.decoder.readers.slice(),
|
||||||
|
folder = baseFolder + readers[0].split('_').slice(0, -1).join('_') + "/";
|
||||||
|
|
||||||
|
it('should decode ' + folder + " correctly", function(done) {
|
||||||
|
async.eachSeries(testSet, function (sample, callback) {
|
||||||
|
config.src = folder + sample.name;
|
||||||
|
config.readers = readers;
|
||||||
|
Quagga.decodeSingle(config, function(result) {
|
||||||
|
console.log(sample.name);
|
||||||
|
expect(result.codeResult.code).to.equal(sample.result);
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
}, function() {
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("EAN", function() {
|
||||||
|
var config = generateConfig(),
|
||||||
|
testSet = [
|
||||||
|
{"name": "image-001.jpg", "result": "3574660239843"},
|
||||||
|
{"name": "image-002.jpg", "result": "8032754490297"},
|
||||||
|
{"name": "image-003.jpg", "result": "4006209700068"},
|
||||||
|
{"name": "image-004.jpg", "result": "9002233139084"},
|
||||||
|
{"name": "image-005.jpg", "result": "8004030044005"},
|
||||||
|
{"name": "image-006.jpg", "result": "4003626011159"},
|
||||||
|
{"name": "image-007.jpg", "result": "2111220009686"},
|
||||||
|
{"name": "image-008.jpg", "result": "9000275609022"},
|
||||||
|
{"name": "image-009.jpg", "result": "9004593978587"},
|
||||||
|
{"name": "image-010.jpg", "result": "9002244845578"}
|
||||||
|
];
|
||||||
|
|
||||||
|
config.decoder.readers = ['ean_reader'];
|
||||||
|
_runTestSet(testSet, config);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Code128", function() {
|
||||||
|
var config = generateConfig(),
|
||||||
|
testSet = [
|
||||||
|
{"name": "image-001.jpg", "result": "0001285112001000040801"},
|
||||||
|
{"name": "image-002.jpg", "result": "FANAVF1461710"},
|
||||||
|
{"name": "image-003.jpg", "result": "673023"},
|
||||||
|
// {"name": "image-004.jpg", "result": "010210150301625334"},
|
||||||
|
{"name": "image-005.jpg", "result": "419055603900009001012999"},
|
||||||
|
{"name": "image-006.jpg", "result": "419055603900009001012999"},
|
||||||
|
{"name": "image-007.jpg", "result": "T 000003552345"},
|
||||||
|
{"name": "image-008.jpg", "result": "FANAVF1461710"},
|
||||||
|
{"name": "image-009.jpg", "result": "0001285112001000040801"},
|
||||||
|
{"name": "image-010.jpg", "result": "673023"}
|
||||||
|
];
|
||||||
|
|
||||||
|
config.decoder.readers = ['code_128_reader'];
|
||||||
|
_runTestSet(testSet, config);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Code39", function() {
|
||||||
|
var config = generateConfig(),
|
||||||
|
testSet = [
|
||||||
|
{"name": "image-001.jpg", "result": "B3% $DAD$"},
|
||||||
|
{"name": "image-002.jpg", "result": "QUAGGAJS"},
|
||||||
|
{"name": "image-003.jpg", "result": "CODE39"},
|
||||||
|
{"name": "image-004.jpg", "result": "QUAGGAJS"},
|
||||||
|
{"name": "image-005.jpg", "result": "CODE39"},
|
||||||
|
{"name": "image-006.jpg", "result": "2/4-8/16-32"},
|
||||||
|
{"name": "image-007.jpg", "result": "2/4-8/16-32"},
|
||||||
|
{"name": "image-008.jpg", "result": "CODE39"},
|
||||||
|
{"name": "image-009.jpg", "result": "2/4-8/16-32"},
|
||||||
|
{"name": "image-010.jpg", "result": "CODE39"}
|
||||||
|
];
|
||||||
|
|
||||||
|
config.decoder.readers = ['code_39_reader'];
|
||||||
|
_runTestSet(testSet, config);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("EAN-8", function() {
|
||||||
|
var config = generateConfig(),
|
||||||
|
testSet = [
|
||||||
|
{"name": "image-001.jpg", "result": "42191605"},
|
||||||
|
{"name": "image-002.jpg", "result": "42191605"},
|
||||||
|
{"name": "image-003.jpg", "result": "90311208"},
|
||||||
|
{"name": "image-004.jpg", "result": "24057257"},
|
||||||
|
{"name": "image-005.jpg", "result": "90162602"},
|
||||||
|
{"name": "image-006.jpg", "result": "24036153"},
|
||||||
|
{"name": "image-007.jpg", "result": "42176817"},
|
||||||
|
/*{"name": "image-008.jpg", "result": "42191605"},*/
|
||||||
|
{"name": "image-009.jpg", "result": "42242215"},
|
||||||
|
{"name": "image-010.jpg", "result": "42184799"}
|
||||||
|
];
|
||||||
|
|
||||||
|
config.decoder.readers = ['ean_8_reader'];
|
||||||
|
_runTestSet(testSet, config);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("UPC", function() {
|
||||||
|
var config = generateConfig(),
|
||||||
|
testSet = [
|
||||||
|
{"name": "image-001.jpg", "result": "882428015268"},
|
||||||
|
{"name": "image-002.jpg", "result": "882428015268"},
|
||||||
|
{"name": "image-003.jpg", "result": "882428015084"},
|
||||||
|
{"name": "image-004.jpg", "result": "882428015343"},
|
||||||
|
{"name": "image-005.jpg", "result": "882428015343"},
|
||||||
|
{"name": "image-006.jpg", "result": "882428015046"},
|
||||||
|
{"name": "image-007.jpg", "result": "882428015084"},
|
||||||
|
{"name": "image-008.jpg", "result": "882428015046"},
|
||||||
|
{"name": "image-009.jpg", "result": "039047013551"},
|
||||||
|
{"name": "image-010.jpg", "result": "039047013551"}
|
||||||
|
];
|
||||||
|
|
||||||
|
config.decoder.readers = ['upc_reader'];
|
||||||
|
_runTestSet(testSet, config);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("UPC-E", function() {
|
||||||
|
var config = generateConfig(),
|
||||||
|
testSet = [
|
||||||
|
{"name": "image-001.jpg", "result": "04965802"},
|
||||||
|
{"name": "image-002.jpg", "result": "04965802"},
|
||||||
|
{"name": "image-003.jpg", "result": "03897425"},
|
||||||
|
{"name": "image-004.jpg", "result": "05096893"},
|
||||||
|
{"name": "image-005.jpg", "result": "05096893"},
|
||||||
|
{"name": "image-006.jpg", "result": "05096893"},
|
||||||
|
{"name": "image-007.jpg", "result": "03897425"},
|
||||||
|
/* {"name": "image-008.jpg", "result": "01264904"}, */
|
||||||
|
{"name": "image-009.jpg", "result": "01264904"},
|
||||||
|
{"name": "image-010.jpg", "result": "01264904"}
|
||||||
|
];
|
||||||
|
|
||||||
|
config.decoder.readers = ['upc_e_reader'];
|
||||||
|
_runTestSet(testSet, config);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Codabar", function() {
|
||||||
|
var config = generateConfig(),
|
||||||
|
testSet = [
|
||||||
|
{"name": "image-001.jpg", "result": "A10/53+17-70D"},
|
||||||
|
{"name": "image-002.jpg", "result": "B546745735B"},
|
||||||
|
{"name": "image-003.jpg", "result": "C$399.95A"},
|
||||||
|
{"name": "image-004.jpg", "result": "B546745735B"},
|
||||||
|
{"name": "image-005.jpg", "result": "C$399.95A"},
|
||||||
|
{"name": "image-006.jpg", "result": "B546745735B"},
|
||||||
|
{"name": "image-007.jpg", "result": "C$399.95A"},
|
||||||
|
/* {"name": "image-008.jpg", "result": "01264904"}, */
|
||||||
|
{"name": "image-009.jpg", "result": "C$399.95A"},
|
||||||
|
{"name": "image-010.jpg", "result": "C$399.95A"}
|
||||||
|
];
|
||||||
|
|
||||||
|
config.decoder.readers = ['codabar_reader'];
|
||||||
|
_runTestSet(testSet, config);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -29,7 +29,7 @@ define(
|
|||||||
error = 0,
|
error = 0,
|
||||||
singleError = 0,
|
singleError = 0,
|
||||||
modulo = this.MODULO,
|
modulo = this.MODULO,
|
||||||
maxSingleError = this.SINGLE_CODE_ERROR || 0.9;
|
maxSingleError = this.SINGLE_CODE_ERROR || 1;
|
||||||
|
|
||||||
for (i = 0; i < counter.length; i++) {
|
for (i = 0; i < counter.length; i++) {
|
||||||
singleError = Math.abs(code[i] - counter[i]);
|
singleError = Math.abs(code[i] - counter[i]);
|
||||||
|
|||||||
@@ -130,7 +130,9 @@ define(
|
|||||||
[2, 1, 1, 2, 1, 4],
|
[2, 1, 1, 2, 1, 4],
|
||||||
[2, 1, 1, 2, 3, 2],
|
[2, 1, 1, 2, 3, 2],
|
||||||
[2, 3, 3, 1, 1, 1, 2]
|
[2, 3, 3, 1, 1, 1, 2]
|
||||||
]}
|
]},
|
||||||
|
SINGLE_CODE_ERROR: {value: 1},
|
||||||
|
AVG_CODE_ERROR: {value: 0.5}
|
||||||
};
|
};
|
||||||
|
|
||||||
Code128Reader.prototype = Object.create(BarcodeReader.prototype, properties);
|
Code128Reader.prototype = Object.create(BarcodeReader.prototype, properties);
|
||||||
@@ -207,7 +209,7 @@ define(
|
|||||||
}
|
}
|
||||||
normalized = self._normalize(counter, 13);
|
normalized = self._normalize(counter, 13);
|
||||||
error = self._matchPattern(normalized, self.CODE_PATTERN[self.STOP_CODE]);
|
error = self._matchPattern(normalized, self.CODE_PATTERN[self.STOP_CODE]);
|
||||||
if (error < 3) {
|
if (error < self.AVG_CODE_ERROR) {
|
||||||
bestMatch.error = error;
|
bestMatch.error = error;
|
||||||
bestMatch.start = i - sum;
|
bestMatch.start = i - sum;
|
||||||
bestMatch.end = i;
|
bestMatch.end = i;
|
||||||
@@ -266,7 +268,7 @@ define(
|
|||||||
bestMatch.error = error;
|
bestMatch.error = error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (bestMatch.error < 3) {
|
if (bestMatch.error < self.AVG_CODE_ERROR) {
|
||||||
bestMatch.start = i - sum;
|
bestMatch.start = i - sum;
|
||||||
bestMatch.end = i;
|
bestMatch.end = i;
|
||||||
return bestMatch;
|
return bestMatch;
|
||||||
|
|||||||
+1
-1
@@ -452,7 +452,7 @@ function(Code128Reader,
|
|||||||
}
|
}
|
||||||
}, config);
|
}, config);
|
||||||
this.init(config, function() {
|
this.init(config, function() {
|
||||||
Events.once("detected", function(result) {
|
Events.once("processed", function(result) {
|
||||||
_stopped = true;
|
_stopped = true;
|
||||||
resultCallback.call(null, result);
|
resultCallback.call(null, result);
|
||||||
}, true);
|
}, true);
|
||||||
|
|||||||
Reference in New Issue
Block a user