Skip to content

Commit

Permalink
Merge pull request #306 from pandamicro/master
Browse files Browse the repository at this point in the history
Issue #3806: Test case for SAXParser added
  • Loading branch information
dingpinglv committed Jan 23, 2014
2 parents a4f44bd + df6235e commit daab7f0
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 39 deletions.
149 changes: 117 additions & 32 deletions tests/FileUtils/FileUtilsTest.js → tests/FileTest/FileTest.js
Expand Up @@ -23,14 +23,14 @@
THE SOFTWARE.
****************************************************************************/

var fileUtilsTestSceneIdx = -1;
var FileTestSceneIdx = -1;

//------------------------------------------------------------------
//
// FileUtilsBase
// FileTestBase
//
//------------------------------------------------------------------
var FileUtilsBase = BaseTestLayer.extend({
var FileTestBase = BaseTestLayer.extend({
_title:"",
_subtitle:"",

Expand All @@ -39,27 +39,27 @@ var FileUtilsBase = BaseTestLayer.extend({
},

onRestartCallback:function (sender) {
var s = new FileUtilsTestScene();
s.addChild(restartFileUtilsTest());
var s = new FileTestScene();
s.addChild(restartFileTest());
director.replaceScene(s);
},
onNextCallback:function (sender) {
var s = new FileUtilsTestScene();
s.addChild(nextFileUtilsTest());
var s = new FileTestScene();
s.addChild(nextFileTest());
director.replaceScene(s);
},
onBackCallback:function (sender) {
var s = new FileUtilsTestScene();
s.addChild(previousFileUtilsTest());
var s = new FileTestScene();
s.addChild(previousFileTest());
director.replaceScene(s);
},

// automation
numberOfPendingTests:function() {
return ( (arrayOfFileUtilsTest.length-1) - fileUtilsTestSceneIdx );
return ( (arrayOfFileTest.length-1) - FileTestSceneIdx );
},
getTestNumber:function() {
return fileUtilsTestSceneIdx;
return FileTestSceneIdx;
}
});

Expand All @@ -68,7 +68,7 @@ var FileUtilsBase = BaseTestLayer.extend({
// FilenameLookupTest
//
//------------------------------------------------------------------
var FilenameLookupTest = FileUtilsBase.extend({
var FilenameLookupTest = FileTestBase.extend({
_title:"Testing FilenameLookup ",
_subtitle:"You should see a grossini on the screen",

Expand All @@ -77,11 +77,11 @@ var FilenameLookupTest = FileUtilsBase.extend({

var t = sys.platform;
if( t == 'mobile') {
cc.FileUtils.getInstance().loadFilenameLookup('FileUtils/lookup-mobile.plist');
cc.FileUtils.getInstance().loadFilenameLookup('FileTest/lookup-mobile.plist');
} else if( t == 'desktop' ) {
cc.FileUtils.getInstance().loadFilenameLookup('FileUtils/lookup-desktop.plist');
cc.FileUtils.getInstance().loadFilenameLookup('FileTest/lookup-desktop.plist');
} else {
cc.FileUtils.getInstance().loadFilenameLookup('FileUtils/lookup-html5.plist');
cc.FileUtils.getInstance().loadFilenameLookup('FileTest/lookup-html5.plist');
}

var sprite = cc.Sprite.create("grossini.bmp");
Expand Down Expand Up @@ -116,39 +116,124 @@ var FilenameLookupTest = FileUtilsBase.extend({
}
});

var FileUtilsTestScene = TestScene.extend({
var FileTestScene = TestScene.extend({
runThisTest:function () {
fileUtilsTestSceneIdx = -1;
var layer = nextFileUtilsTest();
FileTestSceneIdx = -1;
var layer = nextFileTest();
this.addChild(layer);

director.replaceScene(this);
}
});


//------------------------------------------------------------------
//
// Flow control
// SAXParser Test
//
//------------------------------------------------------------------
var SAXParserTest = FileTestBase.extend({
_title:"Testing SAXParser",
_expectResult: {
texture: {
width: 256,
height: 128
},
frames: {
"grossini.png": {
x: 103,
y: 1,
width: 51,
height: 109,
offsetX: 0,
offsetY: -1,
originalWidth: 85,
originalHeight: 121
},
"grossinis_sister1.png": {
x: 55,
y: 1,
width: 47,
height: 112,
offsetX: -0.5,
offsetY: -11.5,
originalWidth: 52,
originalHeight: 139
},
"grossinis_sister2.png": {
x: 1,
y: 1,
width: 53,
height: 126,
offsetX: -0.5,
offsetY: -2,
originalWidth: 56,
originalHeight: 138
}
}
},
_label: null,

ctor:function () {
this._super();

var parser = cc.SAXParser.getInstance();
var result = parser.parse(s_grossini_familyPlist);

var ok = JSON.stringify(this._expectResult) == JSON.stringify(result);
this._label = cc.LabelTTF.create(ok ? "SUCCESS" : "FAIL");
var winsize = cc.Director.getInstance().getWinSize();
this._label.setPosition(winsize.width/2, winsize.height/2);
this.addChild(this._label);
},

//
// only for automation
//
getExpectedResult:function() {
return JSON.stringify(this._expectResult);
},
getCurrentResult:function() {
var parser = cc.SAXParser.getInstance();
var result = parser.parse(s_grossini_familyPlist);
return JSON.stringify(result);
}
});

var FileTestScene = TestScene.extend({
runThisTest:function () {
fileTestSceneIdx = -1;
var layer = nextFileTest();
this.addChild(layer);

var arrayOfFileUtilsTest = [
director.replaceScene(this);
}
});


//
// Flow control
//

FilenameLookupTest
var arrayOfFileTest = [
FilenameLookupTest,
SAXParserTest
];

var nextFileUtilsTest = function () {
fileUtilsTestSceneIdx++;
fileUtilsTestSceneIdx = fileUtilsTestSceneIdx % arrayOfFileUtilsTest.length;
var nextFileTest = function () {
fileTestSceneIdx++;
fileTestSceneIdx = fileTestSceneIdx % arrayOfFileTest.length;

return new arrayOfFileUtilsTest[fileUtilsTestSceneIdx]();
return new arrayOfFileTest[fileTestSceneIdx]();
};
var previousFileUtilsTest = function () {
fileUtilsTestSceneIdx--;
if (fileUtilsTestSceneIdx < 0)
fileUtilsTestSceneIdx += arrayOfFileUtilsTest.length;
var previousFileTest = function () {
fileTestSceneIdx--;
if (fileTestSceneIdx < 0)
fileTestSceneIdx += arrayOfFileTest.length;

return new arrayOfFileUtilsTest[fileUtilsTestSceneIdx]();
return new arrayOfFileTest[fileTestSceneIdx]();
};
var restartFileUtilsTest = function () {
return new arrayOfFileUtilsTest[fileUtilsTestSceneIdx]();
var restartFileTest = function () {
return new arrayOfFileTest[fileTestSceneIdx]();
};

File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions tests/build.xml
Expand Up @@ -57,7 +57,7 @@
<file name="EventTest/EventTest.js"/>
<file name="EffectsTest/EffectsTest.js"/>
<file name="EffectsAdvancedTest/EffectsAdvancedTest.js"/>
<file name="FileUtils/FileUtilsTest.js"/>
<file name="FileTest/FileTest.js"/>
<file name="MotionStreakTest/MotionStreakTest.js"/>
<file name="RenderTextureTest/RenderTextureTest.js"/>
<file name="UnitTest/UnitTest.js"/>
Expand Down Expand Up @@ -383,7 +383,7 @@
<file name="EventTest/EventTest.js"/>
<file name="EffectsTest/EffectsTest.js"/>
<file name="EffectsAdvancedTest/EffectsAdvancedTest.js"/>
<file name="FileUtils/FileUtilsTest.js"/>
<file name="FileTest/FileTest.js"/>
<file name="MotionStreakTest/MotionStreakTest.js"/>
<file name="RenderTextureTest/RenderTextureTest.js"/>
<file name="UnitTest/UnitTest.js"/>
Expand Down
2 changes: 1 addition & 1 deletion tests/tests-boot-html5.js
Expand Up @@ -87,7 +87,7 @@
'EventTest/EventTest.js',
'UnitTest/UnitTest.js',
'SysTest/SysTest.js',
'FileUtils/FileUtilsTest.js',
'FileTest/FileTest.js',
'EffectsTest/EffectsTest.js',
'EffectsAdvancedTest/EffectsAdvancedTest.js',
'MotionStreakTest/MotionStreakTest.js',
Expand Down
2 changes: 1 addition & 1 deletion tests/tests-boot-jsb.js
Expand Up @@ -27,7 +27,7 @@ var tests_files = [
'EffectsAdvancedTest/EffectsAdvancedTest.js',
'MotionStreakTest/MotionStreakTest.js',
'EventTest/EventTest.js',
'FileUtils/FileUtilsTest.js',
'FileTest/FileTest.js',
'FontTest/FontTest.js',
'IntervalTest/IntervalTest.js',
'LabelTest/LabelTest.js',
Expand Down
4 changes: 2 additions & 2 deletions tests/tests-main.js
Expand Up @@ -314,11 +314,11 @@ var testNames = [
},
//"ExtensionsTest",
{
title:"FileUtils Test",
title:"File Tests",
resource:g_fileUtils,
platforms: PLATFORM_ALL,
testScene:function () {
return new FileUtilsTestScene();
return new FileTestScene();
}
},
{
Expand Down
3 changes: 2 additions & 1 deletion tests/tests_resources-html5.js
Expand Up @@ -298,7 +298,8 @@ var g_touches = [
];

var g_fileUtils = [
{src:"FileUtils/lookup-html5.plist"}
{src:"FileTest/lookup-html5.plist"},
{src:s_grossini_familyPlist}
];

var g_s9s_blocks = [
Expand Down

0 comments on commit daab7f0

Please sign in to comment.