| | 1 | | using DCL; |
| | 2 | | using NUnit.Framework; |
| | 3 | | using System.Collections; |
| | 4 | | using System.Collections.Generic; |
| | 5 | | using System.IO; |
| | 6 | | using System.Text; |
| | 7 | | using System.Text.RegularExpressions; |
| | 8 | | using DCL.Helpers; |
| | 9 | | using UnityEditor; |
| | 10 | | using UnityEngine; |
| | 11 | | using UnityEngine.Events; |
| | 12 | | using UnityEngine.TestTools; |
| | 13 | | using UnityEngine.UI; |
| | 14 | | using UnityGLTF.Cache; |
| | 15 | |
|
| | 16 | | namespace DCL.ABConverter.Tests |
| | 17 | | { |
| | 18 | | public class ABConverterShould |
| | 19 | | { |
| | 20 | | [UnityTest] |
| | 21 | | public IEnumerator DumpAreaCorrectly() |
| | 22 | | { |
| | 23 | | //TODO(Brian): Implement later |
| | 24 | | yield break; |
| | 25 | | } |
| | 26 | |
|
| | 27 | | [UnityTest] |
| | 28 | | public IEnumerator DumpSceneCorrectly() |
| | 29 | | { |
| | 30 | | //TODO(Brian): Implement later |
| | 31 | | yield break; |
| | 32 | | } |
| | 33 | | } |
| | 34 | |
|
| | 35 | | public class ABConverterCoreShould |
| | 36 | | { |
| | 37 | | private ABConverter.Core core; |
| | 38 | | private ABConverter.Environment env; |
| | 39 | |
|
| 0 | 40 | | string basePath = @"C:\test-path\"; |
| 0 | 41 | | string hash1 = "QmHash1", hash2 = "QmHash2", hash3 = "QmHash3", hash4 = "QmHash4"; |
| 0 | 42 | | string baseUrl = @"https://peer.decentraland.org/lambdas/contentv2/contents/"; |
| 0 | 43 | | private string contentData1 = "TestContent1 - guid: 14e357df3f3b75940b5d59e1035255b1\n"; |
| 0 | 44 | | private string contentData2 = "TestContent2 - guid: 14e357df3f3b75940b5d59e1035255b2\n"; |
| 0 | 45 | | private string contentData3 = "TestContent3 - guid: 14e357df3f3b75940b5d59e1035255b3\n"; |
| | 46 | |
|
| | 47 | | [SetUp] |
| | 48 | | public void SetUp() |
| | 49 | | { |
| 0 | 50 | | ResetCacheAndWorkingFolders(); |
| | 51 | |
|
| 0 | 52 | | var settings = new ABConverter.Client.Settings(ContentServerUtils.ApiTLD.ZONE); |
| 0 | 53 | | settings.deleteDownloadPathAfterFinished = false; |
| | 54 | |
|
| 0 | 55 | | env = ABConverter.Environment.CreateWithMockImplementations(); |
| 0 | 56 | | core = new ABConverter.Core(env, settings); |
| | 57 | |
|
| 0 | 58 | | if (env.webRequest is Mocked.WebRequest mockedReq) |
| | 59 | | { |
| 0 | 60 | | mockedReq.mockedContent.Add($"{baseUrl}{hash1}", contentData1); |
| 0 | 61 | | mockedReq.mockedContent.Add($"{baseUrl}{hash2}", contentData2); |
| 0 | 62 | | mockedReq.mockedContent.Add($"{baseUrl}{hash3}", contentData3); |
| | 63 | | } |
| 0 | 64 | | } |
| | 65 | |
|
| | 66 | | [TearDown] |
| 0 | 67 | | public void TearDown() { ResetCacheAndWorkingFolders(); } |
| | 68 | |
|
| | 69 | | [Test] |
| | 70 | | public void PopulateLowercaseMappingsCorrectly() |
| | 71 | | { |
| 0 | 72 | | var pairs = new List<ContentServerUtils.MappingPair>(); |
| | 73 | |
|
| 0 | 74 | | pairs.Add(new ContentServerUtils.MappingPair() { file = "foo", hash = "tEsT1" }); |
| 0 | 75 | | pairs.Add(new ContentServerUtils.MappingPair() { file = "foo", hash = "Test2" }); |
| 0 | 76 | | pairs.Add(new ContentServerUtils.MappingPair() { file = "foo", hash = "tesT3" }); |
| 0 | 77 | | pairs.Add(new ContentServerUtils.MappingPair() { file = "foo", hash = "teSt4" }); |
| | 78 | |
|
| 0 | 79 | | core.PopulateLowercaseMappings(pairs.ToArray()); |
| | 80 | |
|
| 0 | 81 | | Assert.IsTrue(core.hashLowercaseToHashProper.ContainsKey("test1")); |
| 0 | 82 | | Assert.IsTrue(core.hashLowercaseToHashProper.ContainsKey("test2")); |
| 0 | 83 | | Assert.IsTrue(core.hashLowercaseToHashProper.ContainsKey("test3")); |
| 0 | 84 | | Assert.IsTrue(core.hashLowercaseToHashProper.ContainsKey("test4")); |
| | 85 | |
|
| 0 | 86 | | Assert.AreEqual("tEsT1", core.hashLowercaseToHashProper["test1"]); |
| 0 | 87 | | Assert.AreEqual("Test2", core.hashLowercaseToHashProper["test2"]); |
| 0 | 88 | | Assert.AreEqual("tesT3", core.hashLowercaseToHashProper["test3"]); |
| 0 | 89 | | Assert.AreEqual("teSt4", core.hashLowercaseToHashProper["test4"]); |
| 0 | 90 | | } |
| | 91 | |
|
| | 92 | | [Test] |
| | 93 | | public void InitializeDirectoryPathsCorrectly() |
| | 94 | | { |
| 0 | 95 | | var settings = new ABConverter.Client.Settings(ContentServerUtils.ApiTLD.ZONE); |
| 0 | 96 | | settings.deleteDownloadPathAfterFinished = false; |
| | 97 | |
|
| 0 | 98 | | env = ABConverter.Environment.CreateWithDefaultImplementations(); |
| 0 | 99 | | core = new ABConverter.Core(env, settings); |
| | 100 | |
|
| 0 | 101 | | core.InitializeDirectoryPaths(false); |
| | 102 | |
|
| 0 | 103 | | Assert.IsFalse(string.IsNullOrEmpty(core.settings.finalAssetBundlePath)); |
| 0 | 104 | | Assert.IsFalse(string.IsNullOrEmpty(core.finalDownloadedPath)); |
| | 105 | |
|
| 0 | 106 | | Assert.IsTrue(env.directory.Exists(core.settings.finalAssetBundlePath)); |
| 0 | 107 | | Assert.IsTrue(env.directory.Exists(core.finalDownloadedPath)); |
| | 108 | |
|
| 0 | 109 | | string file1 = core.settings.finalAssetBundlePath + "test.txt"; |
| 0 | 110 | | string file2 = core.finalDownloadedPath + "test.txt"; |
| | 111 | |
|
| 0 | 112 | | env.file.WriteAllText(file1, "test"); |
| 0 | 113 | | env.file.WriteAllText(file2, "test"); |
| | 114 | |
|
| 0 | 115 | | core.InitializeDirectoryPaths(true); |
| | 116 | |
|
| 0 | 117 | | Assert.IsFalse(env.file.Exists(file1)); |
| 0 | 118 | | Assert.IsFalse(env.file.Exists(file2)); |
| 0 | 119 | | } |
| | 120 | |
|
| | 121 | | [Test] |
| | 122 | | public void InjectTexturesCorrectly() |
| | 123 | | { |
| 0 | 124 | | AssetPath gltfPath = new AssetPath(core.finalDownloadedPath, "MyHash", "model/myModel.gltf"); |
| 0 | 125 | | AssetPath texturePath = new AssetPath(core.finalDownloadedPath, "MyHash2", "model/texture.png"); |
| 0 | 126 | | AssetPath texturePath2 = new AssetPath(core.finalDownloadedPath, "MyHash3", "model/invalid-texture.png"); |
| | 127 | |
|
| 0 | 128 | | PersistentAssetCache.ImageCacheByUri.Clear(); |
| 0 | 129 | | PersistentAssetCache.StreamCacheByUri.Clear(); |
| | 130 | |
|
| 0 | 131 | | core.RetrieveAndInjectTexture(gltfPath, texturePath); |
| | 132 | |
|
| 0 | 133 | | string content1 = "Test"; |
| 0 | 134 | | env.file.WriteAllText(texturePath.finalPath, content1); |
| | 135 | |
|
| 0 | 136 | | core.RetrieveAndInjectTexture(gltfPath, texturePath); |
| 0 | 137 | | core.RetrieveAndInjectTexture(gltfPath, texturePath2); |
| | 138 | |
|
| 0 | 139 | | string id1 = $"texture.png@{gltfPath.finalPath}"; |
| 0 | 140 | | string id2 = $"invalid-texture.png@{gltfPath.finalPath}"; |
| | 141 | |
|
| | 142 | | //NOTE(Brian): Check if streams exists and are added correctly |
| 0 | 143 | | Assert.IsTrue(PersistentAssetCache.HasImage(id1), $"id1:{id1} doesn't exist?"); |
| 0 | 144 | | Assert.IsFalse(PersistentAssetCache.HasImage(id2), $"Second file with {id2} shouldn't be injected because it |
| | 145 | |
|
| 0 | 146 | | Assert.IsNotNull(PersistentAssetCache.GetImage(id1), "First image don't exist!"); |
| | 147 | |
|
| | 148 | | //NOTE(Brian): Read image and validate content |
| 0 | 149 | | var image1 = PersistentAssetCache.GetImage(id1); |
| 0 | 150 | | } |
| | 151 | |
|
| | 152 | | [Test] |
| | 153 | | public void InjectBuffersCorrectly() |
| | 154 | | { |
| 0 | 155 | | AssetPath gltfPath = new AssetPath(core.finalDownloadedPath, "MyHash", "models/myModel.gltf"); |
| 0 | 156 | | AssetPath bufferPath = new AssetPath(core.finalDownloadedPath, "MyHash2", "models/anims/anim1.bin"); |
| 0 | 157 | | AssetPath bufferPath2 = new AssetPath(core.finalDownloadedPath, "MyHash3", "models/misc.bin"); |
| 0 | 158 | | AssetPath bufferPath3 = new AssetPath(core.finalDownloadedPath, "MyHash4", "missing-file.bin"); |
| | 159 | |
|
| 0 | 160 | | PersistentAssetCache.ImageCacheByUri.Clear(); |
| 0 | 161 | | PersistentAssetCache.StreamCacheByUri.Clear(); |
| | 162 | |
|
| 0 | 163 | | string content1 = "Test"; |
| 0 | 164 | | string content2 = "Test2"; |
| | 165 | |
|
| 0 | 166 | | env.file.WriteAllText(bufferPath.finalPath, content1); |
| 0 | 167 | | env.file.WriteAllText(bufferPath2.finalPath, content2); |
| | 168 | |
|
| 0 | 169 | | core.RetrieveAndInjectBuffer(gltfPath, bufferPath); |
| 0 | 170 | | core.RetrieveAndInjectBuffer(gltfPath, bufferPath2); |
| 0 | 171 | | core.RetrieveAndInjectBuffer(gltfPath, bufferPath3); |
| | 172 | |
|
| 0 | 173 | | char ds = Path.DirectorySeparatorChar; |
| | 174 | |
|
| 0 | 175 | | string id1 = $"anims{ds}anim1.bin@{gltfPath.finalPath}"; |
| 0 | 176 | | string id2 = $"misc.bin@{gltfPath.finalPath}"; |
| 0 | 177 | | string id3 = $"..{ds}missing-file.bin@{gltfPath.finalPath}"; |
| | 178 | |
|
| | 179 | | //NOTE(Brian): Check if streams exists and are added correctly |
| 0 | 180 | | Assert.IsTrue(PersistentAssetCache.HasBuffer(id1)); |
| 0 | 181 | | Assert.IsTrue(PersistentAssetCache.HasBuffer(id2)); |
| 0 | 182 | | Assert.IsFalse(PersistentAssetCache.HasBuffer(id3), "Third file shouldn't be injected because it doesn't exi |
| | 183 | |
|
| 0 | 184 | | Assert.IsNotNull(PersistentAssetCache.GetBuffer(id1), "First stream don't exist!"); |
| 0 | 185 | | Assert.IsNotNull(PersistentAssetCache.GetBuffer(id2), "Second stream don't exist!"); |
| | 186 | |
|
| | 187 | | //NOTE(Brian): Read stream and validate content |
| 0 | 188 | | var buffer1 = PersistentAssetCache.GetBuffer(id1); |
| 0 | 189 | | var buffer2 = PersistentAssetCache.GetBuffer(id2); |
| | 190 | |
|
| 0 | 191 | | byte[] chars = new byte[100]; |
| 0 | 192 | | buffer1.stream.Read(chars, 0, 100); |
| 0 | 193 | | string bufferText = UTF8Encoding.UTF8.GetString(chars).TrimEnd('\0'); |
| 0 | 194 | | Assert.AreEqual(content1, bufferText, "First stream has invalid content!"); |
| | 195 | |
|
| 0 | 196 | | buffer2.stream.Read(chars, 0, 100); |
| 0 | 197 | | bufferText = UTF8Encoding.UTF8.GetString(chars).TrimEnd('\0'); |
| 0 | 198 | | Assert.AreEqual(content2, bufferText, "Second stream has invalid content!"); |
| | 199 | |
|
| 0 | 200 | | buffer1.stream.Dispose(); |
| 0 | 201 | | buffer2.stream.Dispose(); |
| 0 | 202 | | } |
| | 203 | |
|
| | 204 | | [Test] |
| | 205 | | public void DumpGLTFSucceedsCorrectly() |
| | 206 | | { |
| 0 | 207 | | List<AssetPath> texturePaths = new List<AssetPath>(); |
| 0 | 208 | | List<AssetPath> bufferPaths = new List<AssetPath>(); |
| | 209 | |
|
| 0 | 210 | | AssetPath gltfPath = new AssetPath(basePath, hash1, "test.gltf"); |
| | 211 | |
|
| 0 | 212 | | var output = core.DumpGltf(gltfPath, texturePaths, bufferPaths); |
| | 213 | |
|
| 0 | 214 | | Assert.IsNotNull(output); |
| 0 | 215 | | } |
| | 216 | |
|
| | 217 | | [Test] |
| | 218 | | public void DumpGLTFFailsCorrectly() |
| | 219 | | { |
| 0 | 220 | | List<AssetPath> texturePaths = new List<AssetPath>(); |
| 0 | 221 | | List<AssetPath> bufferPaths = new List<AssetPath>(); |
| | 222 | |
|
| 0 | 223 | | AssetPath gltfPath = new AssetPath(basePath, "QmNonExistentHash", "test.gltf"); |
| | 224 | |
|
| 0 | 225 | | var output = core.DumpGltf(gltfPath, texturePaths, bufferPaths); |
| | 226 | |
|
| 0 | 227 | | LogAssert.Expect(LogType.Error, new Regex("^.*?Download failed!")); |
| 0 | 228 | | Assert.IsNull(output); |
| 0 | 229 | | } |
| | 230 | |
|
| | 231 | | [Test] |
| | 232 | | public void DumpImportableAssetsCorrectly() |
| | 233 | | { |
| 0 | 234 | | List<AssetPath> paths = new List<AssetPath>(); |
| | 235 | |
|
| 0 | 236 | | string[] files = { "file1.png", "file2.png", "file3.png", "file4.png" }; |
| | 237 | |
|
| 0 | 238 | | paths.Add(new AssetPath(basePath, hash1, files[0])); |
| 0 | 239 | | paths.Add(new AssetPath(basePath, hash2, files[1])); |
| 0 | 240 | | paths.Add(new AssetPath(basePath, hash3, files[2])); |
| 0 | 241 | | paths.Add(new AssetPath(basePath, hash4, files[3])); |
| | 242 | |
|
| 0 | 243 | | string targetGuid1 = ABConverter.Utils.CidToGuid(hash1); |
| 0 | 244 | | string targetGuid2 = ABConverter.Utils.CidToGuid(hash2); |
| 0 | 245 | | string targetGuid3 = ABConverter.Utils.CidToGuid(hash3); |
| | 246 | |
|
| 0 | 247 | | var textures = core.DumpImportableAssets(paths); |
| | 248 | |
|
| 0 | 249 | | LogAssert.Expect(LogType.Error, new Regex(@"^.*?Download failed")); |
| 0 | 250 | | LogAssert.Expect(LogType.Error, new Regex(@"^.*?QmHash4")); |
| | 251 | |
|
| 0 | 252 | | Assert.AreEqual(3, textures.Count); |
| | 253 | |
|
| | 254 | | //NOTE(Brian): textures exist? |
| 0 | 255 | | Assert.IsTrue(env.file.Exists(paths[0].finalPath)); |
| 0 | 256 | | Assert.IsTrue(env.file.Exists(paths[1].finalPath)); |
| 0 | 257 | | Assert.IsTrue(env.file.Exists(paths[2].finalPath)); |
| 0 | 258 | | Assert.IsFalse(env.file.Exists(paths[3].finalPath)); |
| | 259 | |
|
| | 260 | | //NOTE(Brian): textures .meta exist? |
| 0 | 261 | | Assert.IsTrue(env.file.Exists(paths[0].finalMetaPath)); |
| 0 | 262 | | Assert.IsTrue(env.file.Exists(paths[1].finalMetaPath)); |
| 0 | 263 | | Assert.IsTrue(env.file.Exists(paths[2].finalMetaPath)); |
| 0 | 264 | | Assert.IsFalse(env.file.Exists(paths[3].finalMetaPath)); |
| | 265 | |
|
| | 266 | | //NOTE(Brian): textures .meta guid is changed? |
| 0 | 267 | | Assert.IsTrue(env.file.ReadAllText(paths[0].finalMetaPath).Contains(targetGuid1)); |
| 0 | 268 | | Assert.IsTrue(env.file.ReadAllText(paths[1].finalMetaPath).Contains(targetGuid2)); |
| 0 | 269 | | Assert.IsTrue(env.file.ReadAllText(paths[2].finalMetaPath).Contains(targetGuid3)); |
| 0 | 270 | | } |
| | 271 | |
|
| | 272 | | [Test] |
| | 273 | | public void DumpRawAssetsCorrectly() |
| | 274 | | { |
| 0 | 275 | | List<AssetPath> paths = new List<AssetPath>(); |
| | 276 | |
|
| 0 | 277 | | string[] files = { "file1.bin", "file2.bin", "file3.bin", "file4.bin" }; |
| | 278 | |
|
| 0 | 279 | | paths.Add(new AssetPath(basePath, hash1, files[0])); |
| 0 | 280 | | paths.Add(new AssetPath(basePath, hash2, files[1])); |
| 0 | 281 | | paths.Add(new AssetPath(basePath, hash3, files[2])); |
| 0 | 282 | | paths.Add(new AssetPath(basePath, hash4, files[3])); |
| | 283 | |
|
| 0 | 284 | | var buffers = core.DumpRawAssets(paths); |
| | 285 | |
|
| 0 | 286 | | LogAssert.Expect(LogType.Error, new Regex(@"^.*?Download failed")); |
| 0 | 287 | | LogAssert.Expect(LogType.Error, new Regex(@"^.*?QmHash4")); |
| | 288 | |
|
| 0 | 289 | | Assert.AreEqual(3, buffers.Count); |
| | 290 | |
|
| | 291 | | //NOTE(Brian): textures exist? |
| 0 | 292 | | Assert.IsTrue(env.file.Exists(paths[0].finalPath)); |
| 0 | 293 | | Assert.IsTrue(env.file.Exists(paths[1].finalPath)); |
| 0 | 294 | | Assert.IsTrue(env.file.Exists(paths[2].finalPath)); |
| 0 | 295 | | Assert.IsFalse(env.file.Exists(paths[3].finalPath)); |
| | 296 | |
|
| | 297 | | //NOTE(Brian): textures .meta exist? |
| 0 | 298 | | Assert.IsTrue(env.file.Exists(paths[0].finalMetaPath)); |
| 0 | 299 | | Assert.IsTrue(env.file.Exists(paths[1].finalMetaPath)); |
| 0 | 300 | | Assert.IsTrue(env.file.Exists(paths[2].finalMetaPath)); |
| 0 | 301 | | Assert.IsFalse(env.file.Exists(paths[3].finalMetaPath)); |
| 0 | 302 | | } |
| | 303 | |
|
| | 304 | | [Test] |
| | 305 | | public void DownloadAssetCorrectly() |
| | 306 | | { |
| 0 | 307 | | AssetPath path = new AssetPath( |
| | 308 | | basePath: basePath, |
| | 309 | | hash: hash1, |
| | 310 | | file: "texture.png" |
| | 311 | | ); |
| | 312 | |
|
| 0 | 313 | | string output = core.DownloadAsset(path); |
| | 314 | |
|
| 0 | 315 | | UnityEngine.Assertions.Assert.IsTrue(env.file.Exists(path.finalPath)); |
| 0 | 316 | | UnityEngine.Assertions.Assert.IsTrue(env.file.Exists(path.finalMetaPath)); |
| 0 | 317 | | UnityEngine.Assertions.Assert.AreEqual(contentData1, env.file.ReadAllText(output)); |
| 0 | 318 | | } |
| | 319 | |
|
| | 320 | | [UnityTest] |
| | 321 | | public IEnumerator ConvertAssetsWithExternalTextures() |
| | 322 | | { |
| 0 | 323 | | ContentServerUtils.MappingPair[] input = |
| | 324 | | { |
| | 325 | | new ContentServerUtils.MappingPair { file = "SimpleCubeWithSharedNormal.gltf", hash = "SimpleCubeWithSha |
| | 326 | | new ContentServerUtils.MappingPair { file = "SimpleCubeWithSharedNormal.bin", hash = "SimpleCubeWithShar |
| | 327 | | new ContentServerUtils.MappingPair { file = "Textures/Test.png", hash = "Test.png" } |
| | 328 | | }; |
| | 329 | |
|
| 0 | 330 | | core.settings.baseUrl = TestAssetsUtils.GetPath() + "/GLTF/SimpleCube/"; |
| | 331 | |
|
| 0 | 332 | | env = ABConverter.Environment.CreateWithDefaultImplementations(); |
| 0 | 333 | | core = new ABConverter.Core(env, core.settings); |
| | 334 | |
|
| 0 | 335 | | core.Convert(input); |
| | 336 | |
|
| 0 | 337 | | yield return new WaitUntil(() => core.state.step == ABConverter.Core.State.Step.FINISHED); |
| | 338 | |
|
| 0 | 339 | | Assert.IsTrue(core.state.lastErrorCode == ABConverter.Core.ErrorCodes.SUCCESS); |
| | 340 | |
|
| 0 | 341 | | AssetBundle abDependency = AssetBundle.LoadFromFile(ABConverter.Config.ASSET_BUNDLES_PATH_ROOT + "/Test.png" |
| 0 | 342 | | abDependency.LoadAllAssets(); |
| | 343 | |
|
| 0 | 344 | | AssetBundle abMain = AssetBundle.LoadFromFile(ABConverter.Config.ASSET_BUNDLES_PATH_ROOT + "/SimpleCubeWithS |
| 0 | 345 | | Material[] mats = abMain.LoadAllAssets<Material>(); |
| | 346 | |
|
| 0 | 347 | | bool hasMap = false; |
| | 348 | |
|
| 0 | 349 | | foreach (var mat in mats) |
| | 350 | | { |
| 0 | 351 | | hasMap = mat.GetTexture("_BaseMap") != null; |
| | 352 | | } |
| | 353 | |
|
| 0 | 354 | | abMain.Unload(true); |
| 0 | 355 | | abDependency.Unload(true); |
| | 356 | |
|
| 0 | 357 | | Assert.IsTrue(hasMap, "Dependency has NOT been generated correctly!"); |
| 0 | 358 | | } |
| | 359 | |
|
| | 360 | | [UnityTest] |
| | 361 | | public IEnumerator NotGenerateColorMapsWithDXTnm() |
| | 362 | | { |
| 0 | 363 | | ContentServerUtils.MappingPair[] input = |
| | 364 | | { |
| | 365 | | new ContentServerUtils.MappingPair { file = "SimpleCubeWithSharedNormal.gltf", hash = "SimpleCubeWithSha |
| | 366 | | new ContentServerUtils.MappingPair { file = "SimpleCubeWithSharedNormal.bin", hash = "SimpleCubeWithShar |
| | 367 | | new ContentServerUtils.MappingPair { file = "Textures/Test.png", hash = "Test.png" } |
| | 368 | | }; |
| | 369 | |
|
| 0 | 370 | | core.settings.baseUrl = TestAssetsUtils.GetPath() + "/GLTF/SimpleCube/"; |
| 0 | 371 | | core.settings.verbose = true; |
| 0 | 372 | | core.settings.dumpOnly = true; |
| 0 | 373 | | core.settings.deleteDownloadPathAfterFinished = false; |
| | 374 | |
|
| 0 | 375 | | env = ABConverter.Environment.CreateWithDefaultImplementations(); |
| 0 | 376 | | core = new ABConverter.Core(env, core.settings); |
| | 377 | |
|
| 0 | 378 | | core.Convert(input); |
| | 379 | |
|
| 0 | 380 | | yield return new WaitUntil(() => core.state.step == ABConverter.Core.State.Step.FINISHED); |
| | 381 | |
|
| 0 | 382 | | Assert.IsTrue(core.state.lastErrorCode == ABConverter.Core.ErrorCodes.SUCCESS); |
| | 383 | |
|
| 0 | 384 | | string importerPath = $"{core.finalDownloadedPath}Test.png{ABConverter.Config.DASH}Test.png.png"; |
| 0 | 385 | | TextureImporter importer = env.assetDatabase.GetImporterAtPath(importerPath) as TextureImporter; |
| | 386 | |
|
| 0 | 387 | | Assert.IsTrue(importer != null, "Texture importer is null!"); |
| 0 | 388 | | Assert.IsTrue(TextureImporterType.NormalMap != importer.textureType, "Texture is used for color! It shouldn' |
| 0 | 389 | | } |
| | 390 | |
|
| | 391 | | [UnityTest] |
| | 392 | | public IEnumerator NotFailIfExternalTexturesAreMissing() |
| | 393 | | { |
| 0 | 394 | | ContentServerUtils.MappingPair[] input = |
| | 395 | | { |
| | 396 | | new ContentServerUtils.MappingPair { file = "SimpleCubeWithSharedNormal.gltf", hash = "SimpleCubeWithSha |
| | 397 | | new ContentServerUtils.MappingPair { file = "SimpleCubeWithSharedNormal.bin", hash = "SimpleCubeWithShar |
| | 398 | | }; |
| | 399 | |
|
| 0 | 400 | | core.settings.baseUrl = TestAssetsUtils.GetPath() + "/GLTF/SimpleCube/"; |
| | 401 | |
|
| 0 | 402 | | env = ABConverter.Environment.CreateWithDefaultImplementations(); |
| 0 | 403 | | core = new ABConverter.Core(env, core.settings); |
| | 404 | |
|
| 0 | 405 | | core.Convert(input); |
| | 406 | |
|
| 0 | 407 | | yield return new WaitUntil(() => core.state.step == ABConverter.Core.State.Step.FINISHED); |
| | 408 | |
|
| 0 | 409 | | Assert.IsTrue(core.state.lastErrorCode == ABConverter.Core.ErrorCodes.SUCCESS); |
| 0 | 410 | | LogAssert.Expect(LogType.Error, new Regex(@"^.*?Buffer file not found")); |
| 0 | 411 | | LogAssert.Expect(LogType.Error, new Regex(@"^.*?Buffer file not found")); |
| 0 | 412 | | } |
| | 413 | |
|
| | 414 | | void ResetCacheAndWorkingFolders() |
| | 415 | | { |
| 0 | 416 | | Caching.ClearCache(); |
| | 417 | |
|
| 0 | 418 | | if (Directory.Exists(ABConverter.Config.ASSET_BUNDLES_PATH_ROOT)) |
| 0 | 419 | | Directory.Delete(ABConverter.Config.ASSET_BUNDLES_PATH_ROOT, true); |
| | 420 | |
|
| 0 | 421 | | if (Directory.Exists(ABConverter.Config.DOWNLOADED_PATH_ROOT)) |
| 0 | 422 | | Directory.Delete(ABConverter.Config.DOWNLOADED_PATH_ROOT, true); |
| | 423 | |
|
| 0 | 424 | | if (File.Exists(ABConverter.Config.DOWNLOADED_PATH_ROOT + ".meta")) |
| 0 | 425 | | File.Delete(ABConverter.Config.DOWNLOADED_PATH_ROOT + ".meta"); |
| | 426 | |
|
| 0 | 427 | | UnityEditor.AssetDatabase.Refresh(); |
| 0 | 428 | | } |
| | 429 | | } |
| | 430 | | } |