Skip to content

Commit

Permalink
feat(asset-bundle): script api add releaseLoadedSAB,releaseLoadedRAB,…
Browse files Browse the repository at this point in the history
…releaseAssembleRABData

add related tests
  • Loading branch information
yyc-git committed Apr 27, 2019
1 parent 8394da3 commit a874898
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 21 deletions.
18 changes: 18 additions & 0 deletions src/service/state/main/api/script/RecordScriptAPIMainService.re
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,22 @@ let create = () => {
name,
state,
),
"releaseLoadedSAB":
(. sabRelativePath, state) =>
OperateSABAssetBundleMainService.releaseLoadedSAB(
sabRelativePath,
state,
),
"releaseLoadedRAB":
(. rabRelativePath, state) =>
OperateRABAssetBundleMainService.releaseLoadedRAB(
rabRelativePath,
state,
),
"releaseAssembleRABData":
(. rabRelativePath, state) =>
OperateRABAssetBundleMainService.releaseAssembleRABData(
rabRelativePath,
state,
),
};
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ let releaseLoadedRAB = (rabRelativePath, {assetBundleRecord} as state) =>
},
},
}
/* TODO test */
|> markNotLoaded(rabRelativePath);

let releaseAssembleRABData = (rabRelativePath, {assetBundleRecord} as state) => {
Expand Down Expand Up @@ -155,7 +154,6 @@ let releaseAssembleRABData = (rabRelativePath, {assetBundleRecord} as state) =>
},
},
}
/* TODO test */
|> markNotAssembled(rabRelativePath);
};

Expand All @@ -175,16 +173,6 @@ let setAssembleRABData =
) => {
let {assembleRABData} = assetBundleRecord;

/* let {
imageMap,
textureMap,
basicMaterialMap,
lightMaterialMap,
geometryMap,
scriptEventFunctionDataMap,
scriptAttributeMap,
} = assembleRABData; */

{
...state,
assetBundleRecord: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,7 @@ let isLoaded = (sabRelativePath, {assetBundleRecord} as state) =>
};

let canAssemble =
(
sabRelativePath,
wabRelativePath,
{assetBundleRecord} as state,
) =>
(sabRelativePath, wabRelativePath, {assetBundleRecord} as state) =>
isLoaded(sabRelativePath, state)
&& (
switch (
Expand Down Expand Up @@ -131,5 +127,4 @@ let releaseLoadedSAB = (sabRelativePath, {assetBundleRecord} as state) =>
},
},
}
/* TODO test */
|> markNotLoaded(sabRelativePath);
134 changes: 134 additions & 0 deletions test/unit/asset_bundle/OperateRABAssetBundleMainService_test.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
open Wonder_jest;

let _ =
describe("OperateRABAssetBundleMainService", () => {
open Expect;
open Expect.Operators;
open Sinon;

let sandbox = getSandboxDefaultVal();
let state = ref(CreateStateMainService.createState());

beforeEach(() => {
sandbox := createSandbox();
state := TestTool.init(~sandbox, ());
});
afterEach(() => restoreSandbox(refJsObjToSandbox(sandbox^)));

describe("releaseLoadedRAB", () => {
let _prepare = state => {
let rabRelativePath = "rab1.rab";
let rab = Obj.magic(100);
let state =
state
|> OperateRABAssetBundleMainService.setLoadedRAB(
rabRelativePath,
rab,
)
|> OperateRABAssetBundleMainService.markLoaded(rabRelativePath);

(state, rabRelativePath, rab);
};

test("delete loaded rab", () => {
let (state, rabRelativePath, rab) = _prepare(state^);

let state =
OperateRABAssetBundleMainService.releaseLoadedRAB(
rabRelativePath,
state,
);

OperateRABAssetBundleMainService.getLoadedRAB(rabRelativePath, state)
|> expect == None;
});
test("mark not loaded", () => {
let (state, rabRelativePath, rab) = _prepare(state^);

let state =
OperateRABAssetBundleMainService.releaseLoadedRAB(
rabRelativePath,
state,
);

OperateRABAssetBundleMainService.isLoaded(rabRelativePath, state)
|> expect == false;
});
});

describe("releaseAssembleRABData", () => {
let _prepare =
(
~state,
~rabRelativePath="rab1.rab",
~imageMapByName=WonderCommonlib.ImmutableHashMapService.createEmpty(),
~textureMapByName=WonderCommonlib.ImmutableHashMapService.createEmpty(),
~basicMaterialMap=WonderCommonlib.ImmutableHashMapService.createEmpty(),
~lightMaterialMap=WonderCommonlib.ImmutableHashMapService.createEmpty(),
~geometryMap=WonderCommonlib.ImmutableHashMapService.createEmpty(),
~scriptEventFunctionDataMap=WonderCommonlib.ImmutableHashMapService.createEmpty(),
~scriptAttributeMap=WonderCommonlib.ImmutableHashMapService.createEmpty(),
(),
) => {
let state =
state
|> OperateRABAssetBundleMainService.markAssembled(rabRelativePath)
|> OperateRABAssetBundleMainService.setAssembleRABData(
rabRelativePath,
(
imageMapByName,
textureMapByName,
basicMaterialMap,
lightMaterialMap,
geometryMap,
scriptEventFunctionDataMap,
scriptAttributeMap,
),
);

(state, rabRelativePath);
};

test("delete assembled image", () => {
let rabRelativePath = "rab1.rab";
let imageName = "a";
let (state, rabRelativePath) =
_prepare(
~state=state^,
~rabRelativePath,
~imageMapByName=
WonderCommonlib.ImmutableHashMapService.createEmpty()
|> WonderCommonlib.ImmutableHashMapService.set(
imageName,
Obj.magic(10),
),
(),
);

let state =
OperateRABAssetBundleMainService.releaseAssembleRABData(
rabRelativePath,
state,
);

OperateRABAssetBundleMainService.findImageByName(
rabRelativePath,
imageName,
state,
)
|> expect == None;
});
test("mark not assembled", () => {
let (state, rabRelativePath) = _prepare(~state=state^, ());

let state =
OperateRABAssetBundleMainService.releaseAssembleRABData(
rabRelativePath,
state,
);

OperateRABAssetBundleMainService.isAssembled(rabRelativePath, state)
|> expect == false;
});
});
});
44 changes: 41 additions & 3 deletions test/unit/asset_bundle/OperateSABAssetBundleMainService_test.re
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ let _ =
~state,
~wabRelativePath=_getWABRelativePath(),
~sabRelativePath=ImportABTool.SAB.getSABRelativePath(),
/* ~wholeDependencyRelationMap=ImportABTool.RAB.buildWholeDependencyRelationMap(
ImportABTool.SAB.getABRelativePaths(),
), */
(),
) =>
OperateSABAssetBundleMainService.canAssemble(
Expand Down Expand Up @@ -103,4 +100,45 @@ let _ =
});
});
});

describe("releaseLoadedSAB", () => {
let _prepare = state => {
let sabRelativePath = "sab1.sab";
let sab = Obj.magic(100);
let state =
state
|> OperateSABAssetBundleMainService.setLoadedSAB(
sabRelativePath,
sab,
)
|> OperateSABAssetBundleMainService.markLoaded(sabRelativePath);

(state, sabRelativePath, sab);
};

test("delete loaded sab", () => {
let (state, sabRelativePath, sab) = _prepare(state^);

let state =
OperateSABAssetBundleMainService.releaseLoadedSAB(
sabRelativePath,
state,
);

OperateSABAssetBundleMainService.getLoadedSAB(sabRelativePath, state)
|> expect == None;
});
test("mark not loaded", () => {
let (state, sabRelativePath, sab) = _prepare(state^);

let state =
OperateSABAssetBundleMainService.releaseLoadedSAB(
sabRelativePath,
state,
);

OperateSABAssetBundleMainService.isLoaded(sabRelativePath, state)
|> expect == false;
});
});
});

0 comments on commit a874898

Please sign in to comment.