mirror of
https://github.com/cocos/cocos-engine.git
synced 2026-09-07 00:02:53 +08:00
* add unit test * add more unit test * refine * add test * add more unit test * add more unit test * more change * add commit * add unit test * commit package-lock.json * revert some * refine code * add more test * fix bugs * fix bugs
68 lines
2.6 KiB
JavaScript
68 lines
2.6 KiB
JavaScript
(function () {
|
|
|
|
module('Texture');
|
|
|
|
if (TestEditorExtends) {
|
|
|
|
function serializedAs (obj, expect, info) {
|
|
deepEqual(JSON.parse(Editor.serialize(obj)), expect, info);
|
|
}
|
|
|
|
test('nativeUrl', function () {
|
|
var tex = new cc.Texture2D();
|
|
tex._uuid = '555AC';
|
|
tex._setRawAsset('.png');
|
|
ok(tex.nativeUrl.endsWith('.png'), 'nativeUrl should contains extname');
|
|
});
|
|
|
|
test('(de)serialize empty texture', function () {
|
|
var tex = new cc.Texture2D();
|
|
var append = "," + tex._minFilter + "," + tex._magFilter + "," +
|
|
tex._wrapS + "," + tex._wrapT + "," +
|
|
(tex._premultiplyAlpha ? 1 : 0) + "," +
|
|
(tex._genMipmaps ? 1 : 0) + "," +
|
|
(tex._packable ? 1 : 0);
|
|
var expected = {
|
|
__type__: 'cc.Texture2D',
|
|
content: '' + append
|
|
};
|
|
serializedAs(tex, expected, 'should be serialized');
|
|
|
|
var deserialized = cc.deserialize(expected);
|
|
strictEqual(deserialized.nativeUrl, '', 'nativeUrl should be empty string by default');
|
|
strictEqual(deserialized.url, '', 'url should be empty string by default');
|
|
});
|
|
|
|
function testSerializationOfUrl (extname) {
|
|
test('(de)serialize ' + extname + ' texture asset', function () {
|
|
var tex = new cc.Texture2D();
|
|
|
|
tex._uuid = '555AC';
|
|
tex._setRawAsset('.png');
|
|
tex.url = tex.nativeUrl;
|
|
ok(tex.url.endsWith('.png'), 'url should contains extname');
|
|
|
|
var append = "," + tex._minFilter + "," + tex._magFilter + "," +
|
|
tex._wrapS + "," + tex._wrapT + "," +
|
|
(tex._premultiplyAlpha ? 1 : 0) + "," +
|
|
(tex._genMipmaps ? 1 : 0) + "," +
|
|
(tex._packable ? 1 : 0);
|
|
|
|
var expected = {
|
|
__type__: 'cc.Texture2D',
|
|
content: '0' + append
|
|
};
|
|
serializedAs(tex, expected, 'should be serialized');
|
|
|
|
var deserialized = cc.deserialize(expected, null, {
|
|
customEnv: { uuid: tex._uuid }
|
|
});
|
|
deserialized._uuid = tex._uuid;
|
|
strictEqual(deserialized.nativeUrl, tex.nativeUrl, 'nativeUrl should be deserialized');
|
|
});
|
|
}
|
|
testSerializationOfUrl('.png');
|
|
testSerializationOfUrl('.jareguo');
|
|
}
|
|
|
|
})(); |