-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(asset-bundle): script api add releaseLoadedSAB,releaseLoadedRAB,…
…releaseAssembleRABData add related tests
- Loading branch information
Showing
5 changed files
with
194 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
test/unit/asset_bundle/OperateRABAssetBundleMainService_test.re
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters