Skip to content

Commit

Permalink
Update unitest
Browse files Browse the repository at this point in the history
  • Loading branch information
dumganhar committed Oct 13, 2024
1 parent 93f7839 commit fec9da3
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 45 deletions.
24 changes: 12 additions & 12 deletions tests/asset-manager/finalizer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('releaseManager', () => {
assetManager.assets.add('AAA', tex);
expect(isValid(tex, true)).toBeTruthy();
// @ts-ignore
releaseManager._free(tex, false);
releaseManager._free$(tex, false);
expect(assetManager.assets.count).toBe(1);
expect(isValid(tex, true)).toBeTruthy();
assetManager.releaseAsset(tex);
Expand All @@ -46,7 +46,7 @@ describe('releaseManager', () => {
assetManager.assets.add('BBB', texB);
assetManager.dependUtil._depends.add('AAA', {deps: ['BBB']});
// @ts-ignore
releaseManager._free(texA);
releaseManager._free$(texA);
expect(assetManager.assets.count).toBe(0);
});

Expand All @@ -73,7 +73,7 @@ describe('releaseManager', () => {
assetManager.dependUtil._depends.add('CCC', {deps: ['AAA', 'DDD']});
assetManager.dependUtil._depends.add('DDD', {deps: ['BBB']});
// @ts-ignore
releaseManager._free(texA);
releaseManager._free$(texA);
expect(assetManager.assets.count).toBe(0);
});

Expand Down Expand Up @@ -101,7 +101,7 @@ describe('releaseManager', () => {
assetManager.dependUtil._depends.add('CCC', {deps: ['AAA', 'DDD']});
assetManager.dependUtil._depends.add('DDD', {deps: ['BBB']});
// @ts-ignore
releaseManager._free(texA);
releaseManager._free$(texA);
expect(assetManager.assets.count).toBe(4);
assetManager.releaseAll();
});
Expand All @@ -128,7 +128,7 @@ describe('releaseManager', () => {
assetManager.dependUtil._depends.add('CCC', {deps: ['AAA', 'BBB']});
assetManager.dependUtil._depends.add('DDD', {deps: ['AAA']});
// @ts-ignore
releaseManager._free(texA);
releaseManager._free$(texA);
expect(assetManager.assets.count).toBe(0);
});

Expand All @@ -154,7 +154,7 @@ describe('releaseManager', () => {
assetManager.dependUtil._depends.add('CCC', {deps: ['AAA', 'BBB']});
assetManager.dependUtil._depends.add('DDD', {deps: ['AAA']});
// @ts-ignore
releaseManager._free(texA);
releaseManager._free$(texA);
expect(assetManager.assets.count).toBe(4);
assetManager.releaseAll();
});
Expand All @@ -181,7 +181,7 @@ describe('releaseManager', () => {
assetManager.dependUtil._depends.add('CCC', {deps: ['DDD']});
assetManager.dependUtil._depends.add('DDD', {deps: ['AAA']});
// @ts-ignore
releaseManager._free(texA);
releaseManager._free$(texA);

expect(assetManager.assets.count).toBe(0);
assetManager.releaseAll();
Expand Down Expand Up @@ -215,7 +215,7 @@ describe('releaseManager', () => {
assetManager.dependUtil._depends.add('scene 2', {deps: ['BBB', 'CCC']});
releaseManager._autoRelease(scene1, scene2, {});
// @ts-expect-error set private property
releaseManager._freeAssets();
releaseManager._freeAssets$();
expect(assetManager.assets.count).toBe(2);
expect(texB.refCount).toBe(1);
expect(texC.refCount).toBe(1);
Expand All @@ -236,7 +236,7 @@ describe('releaseManager', () => {
expect(assetManager.assets.count).toBe(1);
releaseManager._autoRelease(scene1, scene2, {});
// @ts-expect-error set private property
releaseManager._freeAssets();
releaseManager._freeAssets$();
expect(assetManager.assets.count).toBe(0);
});

Expand Down Expand Up @@ -266,15 +266,15 @@ describe('releaseManager', () => {
assetManager.dependUtil._depends.add('scene 2', {deps: []});
releaseManager._autoRelease(scene1, scene2, persistNodes);
// @ts-expect-error set private property
releaseManager._freeAssets();
releaseManager._freeAssets$();
expect(assetManager.assets.count).toBe(1);
expect(assetManager.assets.get('AAA')).toBe(sp);
expect(sp.refCount).toBe(2);
releaseManager._removePersistNodeRef(persistNode);
expect(sp.refCount).toBe(1);
releaseManager._autoRelease(scene2, scene3, {});
// @ts-expect-error set private property
releaseManager._freeAssets();
releaseManager._freeAssets$();
expect(assetManager.assets.count).toBe(0);
});

Expand All @@ -285,7 +285,7 @@ describe('releaseManager', () => {
assetManager.assets.add('TestDontDestroy', tex);
expect(isValid(tex, true)).toBeTruthy();
// @ts-ignore
releaseManager._free(tex, false);
releaseManager._free$(tex, false);
expect(assetManager.assets.count).toBe(1);
expect(isValid(tex, true)).toBeTruthy();
assetManager.releaseAsset(tex);
Expand Down
20 changes: 10 additions & 10 deletions tests/core/memop/container-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,55 +9,55 @@ class TestContainer extends ScalableContainer {

test('container', () => {
// @ts-expect-error
scalableContainerManager._pools.length = 0;
scalableContainerManager._pools$.length = 0;

const testContainer = new TestContainer();
// @ts-expect-error
expect(scalableContainerManager._pools.length).toBe(1);
expect(scalableContainerManager._pools$.length).toBe(1);
expect(testContainer._poolHandle).toBe(0);

scalableContainerManager.addContainer(testContainer);
// @ts-expect-error
expect(scalableContainerManager._pools.length).toBe(1);
expect(scalableContainerManager._pools$.length).toBe(1);
expect(testContainer._poolHandle).toBe(0);

const testContainer1 = new TestContainer();
// @ts-expect-error
expect(scalableContainerManager._pools.length).toBe(2);
expect(scalableContainerManager._pools$.length).toBe(2);
expect(testContainer1._poolHandle).toBe(1);

testContainer.destroy();
// @ts-expect-error
expect(scalableContainerManager._pools.length).toBe(1);
expect(scalableContainerManager._pools$.length).toBe(1);
expect(testContainer._poolHandle).toBe(-1);
expect(testContainer1._poolHandle).toBe(0);

const testContainer2 = new TestContainer();
// @ts-expect-error
expect(scalableContainerManager._pools.length).toBe(2);
expect(scalableContainerManager._pools$.length).toBe(2);
expect(testContainer2._poolHandle).toBe(1);

testContainer2.destroy();
// @ts-expect-error
expect(scalableContainerManager._pools.length).toBe(1);
expect(scalableContainerManager._pools$.length).toBe(1);
expect(testContainer2._poolHandle).toBe(-1);
expect(testContainer1._poolHandle).toBe(0);

testContainer1.destroy();
// @ts-expect-error
expect(scalableContainerManager._pools.length).toBe(0);
expect(scalableContainerManager._pools$.length).toBe(0);
expect(testContainer2._poolHandle).toBe(-1);
expect(testContainer1._poolHandle).toBe(-1);
expect(testContainer._poolHandle).toBe(-1);

scalableContainerManager.removeContainer(testContainer1);
// @ts-expect-error
expect(scalableContainerManager._pools.length).toBe(0);
expect(scalableContainerManager._pools$.length).toBe(0);
});

test('shrink', () => {
// @ts-expect-error
scalableContainerManager._pools.length = 0;
scalableContainerManager._pools$.length = 0;
const testContainer = new TestContainer();
expect(testContainer.calledTimes).toBe(0);

Expand Down
16 changes: 8 additions & 8 deletions tests/core/memop/pool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ test('shrink', () => {
// Pool available size is 10, less than 30, so will not free any object.
pool.tryShrink();
// @ts-expect-error
expect(pool._nextAvail).toEqual(9);
expect(pool._nextAvail$).toEqual(9);
calledTimes = 0;


Expand All @@ -69,7 +69,7 @@ test('shrink', () => {
pool.freeArray(test);
pool.tryShrink();
// @ts-expect-error
expect(pool._nextAvail).toEqual(29);
expect(pool._nextAvail$).toEqual(29);
calledTimes = 30;

// Pool available size is 50, but its length is 60, so it will shrink 10 elements.
Expand All @@ -83,29 +83,29 @@ test('shrink', () => {
pool.tryShrink();
calledTimes = 10;
// @ts-expect-error
expect(pool._nextAvail).toEqual(39);
expect(pool._nextAvail$).toEqual(39);

// No matter shrink how many times, pool size will not less then shrinkThreshold.
pool.tryShrink();
pool.tryShrink();
pool.tryShrink();
pool.tryShrink();
// @ts-expect-error
expect(pool._nextAvail).toEqual(29);
expect(pool._nextAvail$).toEqual(29);
});

test('destroy', () => {
calledTimes = 0;
// @ts-expect-error
const beforeDestroy = pool._nextAvail;
const beforeDestroy = pool._nextAvail$;
// @ts-expect-error
expect(pool._nextAvail).toBeGreaterThan(0);
expect(pool._nextAvail$).toBeGreaterThan(0);

pool.destroy();

expect(calledTimes).toBe(beforeDestroy + 1);
// @ts-expect-error
expect(pool._nextAvail).toBe(-1);
expect(pool._nextAvail$).toBe(-1);
// @ts-expect-error
expect(pool._freePool.length).toBe(0);
expect(pool._freePool$.length).toBe(0);
});
2 changes: 1 addition & 1 deletion tests/core/settings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('Settings', () => {
test('base', () => {
const settings = new Settings();
// @ts-expect-error access private property
settings._settings = {
settings._settings$ = {
assets: {
preloadBundles: [{ bundle: 'asddda' }, { bundle: 'internal' }],
preloadAssets: ['sdd1ssq', 'hjiepoqd'],
Expand Down
6 changes: 3 additions & 3 deletions tests/particle/renderer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ test('recycle pool release', () => {
scene.addChild(node);
game.step();
// @ts-expect-error access private property
const beforeLength = scalableContainerManager._pools.length;
const beforeLength = scalableContainerManager._pools$.length;
const comp = node.addComponent(ParticleSystem);
game.step();
// @ts-expect-error access private property
const currentLength = scalableContainerManager._pools.length;
const currentLength = scalableContainerManager._pools$.length;
expect(currentLength).toBeGreaterThan(beforeLength);
comp.destroy();
game.step();

// @ts-expect-error
expect(scalableContainerManager._pools.length).toBeLessThan(currentLength);
expect(scalableContainerManager._pools$.length).toBeLessThan(currentLength);
});
4 changes: 2 additions & 2 deletions tests/physics2d/scene-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function (parent: Node, _steps = 0) {
nodeCollider2.worldPosition = initPos2;
const body2 = nodeCollider2.addComponent(physics2d.RigidBody2D) as physics2d.RigidBody2D;
const collider2 = nodeCollider2.addComponent(physics2d.BoxCollider2D) as physics2d.Collider2D;
collider2.group = physics2d.PhysicsGroup.DEFAULT;
collider2.group = physics2d.PhysicsGroup2D.DEFAULT;

//test raycast cloest
{
Expand Down Expand Up @@ -65,7 +65,7 @@ export default function (parent: Node, _steps = 0) {
const p0 = new Vec2(0, 0);
const p1 = new Vec2(20, 0);
const type = physics2d.ERaycast2DType.All;
const mask = physics2d.PhysicsGroup.DEFAULT;
const mask = physics2d.PhysicsGroup2D.DEFAULT;
let result = physics2d.PhysicsSystem2D.instance.raycast(p0, p1, type, mask);
expect(result.length).toBe(1);
expect(result[0].collider.uuid).toBe(collider2.uuid);
Expand Down
16 changes: 8 additions & 8 deletions tests/tween/tween.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ test('to/by ITweenOption no type', function () {

test('different targets in parallel', function () {
// @ts-expect-error
director.root!._batcher = new Batcher2D(director.root!);
director.root!._batcher$ = new Batcher2D(director.root!);

const sys = new TweenSystem();
(TweenSystem.instance as any) = sys;
Expand Down Expand Up @@ -145,7 +145,7 @@ test('different targets in parallel', function () {

test('Test different target in sequence', function() {
// @ts-expect-error
director.root!._batcher = new Batcher2D(director.root!);
director.root!._batcher$ = new Batcher2D(director.root!);

const sys = new TweenSystem();
(TweenSystem.instance as any) = sys;
Expand Down Expand Up @@ -241,7 +241,7 @@ test('Test different target in sequence', function() {

test('Test different target in then', function() {
// @ts-expect-error
director.root!._batcher = new Batcher2D(director.root!);
director.root!._batcher$ = new Batcher2D(director.root!);

const sys = new TweenSystem();
(TweenSystem.instance as any) = sys;
Expand Down Expand Up @@ -331,7 +331,7 @@ test('Test different target in then', function() {

test('Test different target in clone/then', function() {
// @ts-expect-error
director.root!._batcher = new Batcher2D(director.root!);
director.root!._batcher$ = new Batcher2D(director.root!);

const sys = new TweenSystem();
(TweenSystem.instance as any) = sys;
Expand Down Expand Up @@ -457,7 +457,7 @@ test('Test different target in clone/then', function() {

test('Test different target in clone2', function() {
// @ts-expect-error
director.root!._batcher = new Batcher2D(director.root!);
director.root!._batcher$ = new Batcher2D(director.root!);

const sys = new TweenSystem();
(TweenSystem.instance as any) = sys;
Expand Down Expand Up @@ -523,7 +523,7 @@ test('Test different target in clone2', function() {

test('Test different target in re-target', function() {
// @ts-expect-error
director.root!._batcher = new Batcher2D(director.root!);
director.root!._batcher$ = new Batcher2D(director.root!);

const sys = new TweenSystem();
(TweenSystem.instance as any) = sys;
Expand Down Expand Up @@ -583,7 +583,7 @@ test('Test different target in re-target', function() {

test('Test different target in nest sequence 1', function() {
// @ts-expect-error
director.root!._batcher = new Batcher2D(director.root!);
director.root!._batcher$ = new Batcher2D(director.root!);

const sys = new TweenSystem();
(TweenSystem.instance as any) = sys;
Expand Down Expand Up @@ -813,7 +813,7 @@ test('Test different target, union, repeat with embed tween', function() {

test('Test different target in nest sequence 2', function() {
// @ts-expect-error
director.root!._batcher = new Batcher2D(director.root!);
director.root!._batcher$ = new Batcher2D(director.root!);

const sys = new TweenSystem();
(TweenSystem.instance as any) = sys;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/sprite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Batcher2D } from "../../cocos/2d/renderer/batcher-2d";
test('sprite.updateWorldMatrix', () => {

// @ts-expect-error
director.root!._batcher = new Batcher2D(director.root!);
director.root!._batcher$ = new Batcher2D(director.root!);

const scene = new Scene('test');
director.runSceneImmediate(scene);
Expand Down

0 comments on commit fec9da3

Please sign in to comment.