Home > functions > internal > unit-test > dsUnitTest_autogenDirs_all.m

dsUnitTest_autogenDirs_all

PURPOSE ^

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 classdef dsUnitTest_autogenDirs_all < matlab.unittest.TestCase
0002   properties
0003     unitTestDataPath = dsGetConfig('ds_unitTestData_path');
0004   end
0005   
0006   properties (TestParameter)
0007     dataDirName = dsUnitGetAutogenDirs();
0008   end
0009   
0010   methods (Test,  TestTags = {'autogen'})
0011     function testCellIn(testCase, dataDirName)
0012       dataDirPath = fullfile(testCase.unitTestDataPath, 'autogenDirs', dataDirName);
0013       
0014       % Make Temp Folder
0015       import matlab.unittest.fixtures.WorkingFolderFixture
0016       tempDirFixture = testCase.applyFixture(WorkingFolderFixture('WithSuffix', ['_' dataDirName]));
0017       tempDirPath = tempDirFixture.Folder;
0018 %       tempOutputDir = fullfile(tempDirPath, 'output');
0019 %       mkdirSilent(tempOutputDir);
0020       
0021       args = load(fullfile(dataDirPath, 'args.mat'));
0022       expectedOut = args.argout;
0023       
0024       fnName = strsplit(dataDirName,'_autogen_');
0025       fh = str2func(fnName{1});
0026       
0027       [testOut{1:length(expectedOut)}] = feval(fh, args.argin{:});
0028       
0029       % testOut fig handles
0030       % TODO: generalize fig handle checking
0031       if all(isValidFigHandle(testOut{1}))
0032         handles = testOut{1};
0033         
0034         dsUnitSave_figHandles( handles, tempDirPath )
0035         
0036         close all
0037       end
0038       
0039       % test output args
0040       for ind = 1:length(expectedOut)
0041         testCase.verifyEqual(testOut{ind}, expectedOut{ind});
0042       end
0043       
0044       % test output files
0045       expectedOutputDir = fullfile(dataDirPath, 'output');
0046       if exist(expectedOutputDir, 'dir')
0047         expectedOutputFiles = rls(expectedOutputDir);
0048         expectedOutputFiles(1) = []; % remove 'output' reference
0049         testOutputFiles = rls(tempDirPath);
0050         testOutputFiles(1) = []; % remove parent folder reference
0051         
0052         % test same num files
0053         testCase.assertLength(testOutputFiles, length(expectedOutputFiles));
0054         
0055         % test each file
0056         for iFile = 1:length(expectedOutputFiles)
0057 %           thisExpectedOutputFilePath = fullfile(expectedOutputDir, expectedOutputFiles{iFile});
0058           thisExpectedOutputFilePath = expectedOutputFiles{iFile};
0059           
0060 %           thistestOutputFilePath = fullfile(tempDirPath, testOutputFiles{iFile});
0061           thistestOutputFilePath = testOutputFiles{iFile};
0062           
0063           [~,~,ext] = fileparts2(thistestOutputFilePath);
0064           switch ext
0065             case '' % dir
0066               continue
0067             case '.fig'
0068               % compareFigFiles
0069               testCase.verifyEmpty( compareFigFiles2(thistestOutputFilePath, thisExpectedOutputFilePath, true) );
0070             case '.mat'
0071               % compare loaded structs
0072               thistest = load(thistestOutputFilePath);
0073               thisExpected = load(thisExpectedOutputFilePath);
0074               testCase.verifyEqual(thistest, thisExpected);
0075             case '.mex4unittest'
0076               continue % skip testing of mex files
0077             otherwise
0078               % do diff
0079               testCase.verifyFalse( logical(system(sprintf('diff -qr %s %s', thistestOutputFilePath, thisExpectedOutputFilePath))) );
0080           end
0081         end
0082       end
0083       
0084     end
0085   end
0086   
0087 end

Generated on Tue 12-Dec-2017 11:32:10 by m2html © 2005