Simplify FileObject for test.

This commit is contained in:
kovacsv 2021-12-07 12:58:21 +01:00
parent d7a33d27e2
commit 282d4ba604
5 changed files with 45 additions and 34 deletions

View File

@ -39,7 +39,7 @@ describe ('Importer Test', function () {
it ('Not existing file', function (done) { it ('Not existing file', function (done) {
let files = [ let files = [
new FileObject ('obj', 'missing.obj') new FileObject ('', 'obj/missing.obj')
]; ];
ImportFiles (files, { ImportFiles (files, {
success : function (importer, importResult) { success : function (importer, importResult) {
@ -69,7 +69,7 @@ describe ('Importer Test', function () {
it ('Wrong file', function (done) { it ('Wrong file', function (done) {
let files = [ let files = [
new FileObject ('3ds', 'wrong.3ds') new FileObject ('', '3ds/wrong.3ds')
]; ];
ImportFiles (files, { ImportFiles (files, {
success : function (importer, importResult) { success : function (importer, importResult) {
@ -84,7 +84,7 @@ describe ('Importer Test', function () {
it ('Single file', function (done) { it ('Single file', function (done) {
let files = [ let files = [
new FileObject ('obj', 'single_triangle.obj') new FileObject ('', 'obj/single_triangle.obj')
]; ];
ImportFiles (files, { ImportFiles (files, {
success : function (importer, importResult) { success : function (importer, importResult) {
@ -101,9 +101,9 @@ describe ('Importer Test', function () {
it ('Multiple files', function (done) { it ('Multiple files', function (done) {
let files = [ let files = [
new FileObject ('obj', 'cube_with_materials.obj'), new FileObject ('', 'obj/cube_with_materials.obj'),
new FileObject ('obj', 'cube_with_materials.mtl'), new FileObject ('', 'obj/cube_with_materials.mtl'),
new FileObject ('obj', 'cube_texture.png') new FileObject ('', 'obj/cube_texture.png')
] ]
let theImporter = new OV.Importer (); let theImporter = new OV.Importer ();
@ -122,19 +122,19 @@ describe ('Importer Test', function () {
it ('Missing files', function (done) { it ('Missing files', function (done) {
let files = []; let files = [];
files.push (new FileObject ('obj', 'cube_with_materials.obj')); files.push (new FileObject ('', 'obj/cube_with_materials.obj'));
ImportFiles (files, { ImportFiles (files, {
success : function (importer, importResult) { success : function (importer, importResult) {
assert (!OV.IsModelEmpty (importResult.model)); assert (!OV.IsModelEmpty (importResult.model));
assert.deepStrictEqual (importResult.usedFiles, ['cube_with_materials.obj']); assert.deepStrictEqual (importResult.usedFiles, ['cube_with_materials.obj']);
assert.deepStrictEqual (importResult.missingFiles, ['cube_with_materials.mtl']); assert.deepStrictEqual (importResult.missingFiles, ['cube_with_materials.mtl']);
files.push (new FileObject ('obj', 'cube_with_materials.mtl')); files.push (new FileObject ('', 'obj/cube_with_materials.mtl'));
ImportFiles (files, { ImportFiles (files, {
success : function (importer, importResult) { success : function (importer, importResult) {
assert (!OV.IsModelEmpty (importResult.model)); assert (!OV.IsModelEmpty (importResult.model));
assert.deepStrictEqual (importResult.usedFiles, ['cube_with_materials.obj', 'cube_with_materials.mtl']); assert.deepStrictEqual (importResult.usedFiles, ['cube_with_materials.obj', 'cube_with_materials.mtl']);
assert.deepStrictEqual (importResult.missingFiles, ['cube_texture.png']); assert.deepStrictEqual (importResult.missingFiles, ['cube_texture.png']);
files.push (new FileObject ('obj', 'cube_texture.png')); files.push (new FileObject ('', 'obj/cube_texture.png'));
ImportFiles (files, { ImportFiles (files, {
success : function (importer, importResult) { success : function (importer, importResult) {
assert (!OV.IsModelEmpty (importResult.model)); assert (!OV.IsModelEmpty (importResult.model));
@ -161,8 +161,8 @@ describe ('Importer Test', function () {
it ('Missing texture multiple times', function (done) { it ('Missing texture multiple times', function (done) {
let files = [ let files = [
new FileObject ('obj', 'two_materials_same_texture.obj'), new FileObject ('', 'obj/two_materials_same_texture.obj'),
new FileObject ('obj', 'two_materials_same_texture.mtl'), new FileObject ('', 'obj/two_materials_same_texture.mtl'),
]; ];
ImportFiles (files, { ImportFiles (files, {
success : function (importer, importResult) { success : function (importer, importResult) {
@ -179,17 +179,17 @@ describe ('Importer Test', function () {
it ('Append Missing files', function (done) { it ('Append Missing files', function (done) {
let theImporter = new OV.Importer (); let theImporter = new OV.Importer ();
ImportFilesWithImporter (theImporter, [new FileObject ('obj', 'cube_with_materials.obj')], { ImportFilesWithImporter (theImporter, [new FileObject ('', 'obj/cube_with_materials.obj')], {
success : function (importer, importResult) { success : function (importer, importResult) {
assert (!OV.IsModelEmpty (importResult.model)); assert (!OV.IsModelEmpty (importResult.model));
assert.deepStrictEqual (importResult.usedFiles, ['cube_with_materials.obj']); assert.deepStrictEqual (importResult.usedFiles, ['cube_with_materials.obj']);
assert.deepStrictEqual (importResult.missingFiles, ['cube_with_materials.mtl']); assert.deepStrictEqual (importResult.missingFiles, ['cube_with_materials.mtl']);
ImportFilesWithImporter (theImporter, [new FileObject ('obj', 'cube_with_materials.mtl')], { ImportFilesWithImporter (theImporter, [new FileObject ('', 'obj/cube_with_materials.mtl')], {
success : function (importer, importResult) { success : function (importer, importResult) {
assert (!OV.IsModelEmpty (importResult.model)); assert (!OV.IsModelEmpty (importResult.model));
assert.deepStrictEqual (importResult.usedFiles, ['cube_with_materials.obj', 'cube_with_materials.mtl']); assert.deepStrictEqual (importResult.usedFiles, ['cube_with_materials.obj', 'cube_with_materials.mtl']);
assert.deepStrictEqual (importResult.missingFiles, ['cube_texture.png']); assert.deepStrictEqual (importResult.missingFiles, ['cube_texture.png']);
ImportFilesWithImporter (theImporter, [new FileObject ('obj', 'cube_texture.png')], { ImportFilesWithImporter (theImporter, [new FileObject ('', 'obj/cube_texture.png')], {
success : function (importer, importResult) { success : function (importer, importResult) {
assert (!OV.IsModelEmpty (importResult.model)); assert (!OV.IsModelEmpty (importResult.model));
assert.deepStrictEqual (importResult.usedFiles, ['cube_with_materials.obj', 'cube_with_materials.mtl', 'cube_texture.png']); assert.deepStrictEqual (importResult.usedFiles, ['cube_with_materials.obj', 'cube_with_materials.mtl', 'cube_texture.png']);
@ -214,12 +214,12 @@ describe ('Importer Test', function () {
it ('Reuse importer', function (done) { it ('Reuse importer', function (done) {
let files1 = [ let files1 = [
new FileObject ('obj', 'cube_with_materials.obj'), new FileObject ('', 'obj/cube_with_materials.obj'),
new FileObject ('obj', 'cube_with_materials.mtl'), new FileObject ('', 'obj/cube_with_materials.mtl'),
new FileObject ('obj', 'cube_texture.png') new FileObject ('', 'obj/cube_texture.png')
] ]
let files2 = [ let files2 = [
new FileObject ('obj', 'single_triangle.obj') new FileObject ('', 'obj/single_triangle.obj')
]; ];
let theImporter = new OV.Importer (); let theImporter = new OV.Importer ();
@ -249,7 +249,7 @@ describe ('Importer Test', function () {
it ('Default color', function (done) { it ('Default color', function (done) {
let files = [ let files = [
new FileObject ('stl', 'single_triangle.stl') new FileObject ('', 'stl/single_triangle.stl')
]; ];
let theImporter = new OV.Importer (); let theImporter = new OV.Importer ();
let settings = new OV.ImportSettings (); let settings = new OV.ImportSettings ();
@ -274,7 +274,7 @@ describe ('Importer Test', function () {
it ('Zip file', function (done) { it ('Zip file', function (done) {
let files = [ let files = [
new FileObject ('zip', 'cube_four_instances.zip') new FileObject ('', 'zip/cube_four_instances.zip')
]; ];
ImportFiles (files, { ImportFiles (files, {
success : function (importer, importResult) { success : function (importer, importResult) {
@ -291,7 +291,7 @@ describe ('Importer Test', function () {
it ('Zip file with Folders', function (done) { it ('Zip file with Folders', function (done) {
let files = [ let files = [
new FileObject ('zip', 'cube_four_instances_folders.zip') new FileObject ('', 'zip/cube_four_instances_folders.zip')
]; ];
ImportFiles (files, { ImportFiles (files, {
success : function (importer, importResult) { success : function (importer, importResult) {
@ -308,8 +308,8 @@ describe ('Importer Test', function () {
it ('Multiple Zip Files', function (done) { it ('Multiple Zip Files', function (done) {
let files = [ let files = [
new FileObject ('zip', 'cube_with_materials_notexture.zip'), new FileObject ('', 'zip/cube_with_materials_notexture.zip'),
new FileObject ('zip', 'textures.zip') new FileObject ('', 'zip/textures.zip')
]; ];
ImportFiles (files, { ImportFiles (files, {
success : function (importer, importResult) { success : function (importer, importResult) {

View File

@ -3,7 +3,7 @@ var testUtils = require ('../utils/testutils.js');
describe ('IO Test', function () { describe ('IO Test', function () {
it ('Binary Reader', function () { it ('Binary Reader', function () {
let buffer = testUtils.GetArrayBufferFileContent ('bin', 'binary_content.bin'); let buffer = testUtils.GetArrayBufferFileContent ('bin/binary_content.bin');
let reader = new OV.BinaryReader (buffer, true); let reader = new OV.BinaryReader (buffer, true);
assert.strictEqual (reader.GetByteLength (), 166); assert.strictEqual (reader.GetByteLength (), 166);

View File

@ -37,7 +37,17 @@ global.FileReader = class
readAsText (fileObject) readAsText (fileObject)
{ {
let content = testUtils.GetTextFileContent (fileObject.folderName, fileObject.fileName); if (fileObject.fileContent !== null) {
this.onloadend ({
target : {
readyState : FileReader.DONE,
result : fileObject.fileContent
}
});
return;
}
let content = testUtils.GetTextFileContent (fileObject.fileName);
if (content !== null) { if (content !== null) {
this.onloadend ({ this.onloadend ({
target : { target : {
@ -62,7 +72,7 @@ global.FileReader = class
return; return;
} }
let content = testUtils.GetArrayBufferFileContent (fileObject.folderName, fileObject.fileName); let content = testUtils.GetArrayBufferFileContent (fileObject.fileName);
if (content !== null) { if (content !== null) {
this.onloadend ({ this.onloadend ({
target : { target : {

View File

@ -1,4 +1,5 @@
var testUtils = require ('./testutils.js'); var testUtils = require ('./testutils.js');
var path = require ('path');
module.exports = module.exports =
{ {
@ -46,10 +47,10 @@ module.exports =
ImportFile : function (importer, folder, fileName, onReady) ImportFile : function (importer, folder, fileName, onReady)
{ {
let content = testUtils.GetArrayBufferFileContent (folder, fileName); let content = testUtils.GetArrayBufferFileContent (path.join (folder, fileName));
var extension = OV.GetFileExtension (fileName); var extension = OV.GetFileExtension (fileName);
let fileAccessor = new OV.ImporterFileAccessor (function (filePath) { let fileAccessor = new OV.ImporterFileAccessor (function (filePath) {
let fileContent = testUtils.GetArrayBufferFileContent (folder, filePath); let fileContent = testUtils.GetArrayBufferFileContent (path.join (folder, filePath));
return fileContent; return fileContent;
}); });
importer.Import (fileName, extension, content, { importer.Import (fileName, extension, content, {

View File

@ -3,18 +3,18 @@ var path = require ('path');
module.exports = module.exports =
{ {
GetTextFileContent : function (folder, fileName) GetTextFileContent : function (fileName)
{ {
var testFilePath = path.join ('testfiles', folder, fileName); var testFilePath = path.join ('testfiles', fileName);
if (!fs.existsSync (testFilePath)) { if (!fs.existsSync (testFilePath)) {
return null; return null;
} }
return fs.readFileSync (testFilePath).toString (); return fs.readFileSync (testFilePath).toString ();
}, },
GetArrayBufferFileContent : function (folder, fileName) GetArrayBufferFileContent : function (fileName)
{ {
var testFilePath = path.join ('testfiles', folder, fileName); var testFilePath = path.join ('testfiles', fileName);
var buffer = fs.readFileSync (testFilePath); var buffer = fs.readFileSync (testFilePath);
var arrayBuffer = new ArrayBuffer (buffer.length); var arrayBuffer = new ArrayBuffer (buffer.length);
var uint8Array = new Uint8Array (arrayBuffer); var uint8Array = new Uint8Array (arrayBuffer);