< Summary

Class:Tests.VideoTests
Assembly:VideoTests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/Video/Tests/VideoTests.cs
Covered lines:151
Uncovered lines:0
Coverable lines:151
Total lines:335
Line coverage:100% (151 of 151)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SetUp()0%330100%
TearDown()0%110100%
VideoTextureIsCreatedCorrectly()0%330100%
VideoTextureReplaceOtherTextureCorrectly()0%660100%
VideoTextureIsAttachedAndDetachedCorrectly()0%550100%
VideoTextureVisibleStateIsSetCorrectlyWhenAddedToAMaterialNotAttachedToShape()0%440100%
VideoTextureVisibleStateIsSetCorrectly()0%880100%
VideoTextureVisibleStateIsSetCorrectlyWhenAddedToAlreadyAttachedMaterial()0%990100%
VideoTextureVisibleStateIsSetCorrectlyWhenEntityIsRemoved()0%770100%
VolumeWhenVideoCreatedWithNoUserInScene()0%660100%
VolumeWhenVideoCreatedWithUserInScene()0%660100%
VolumeIsMutedWhenUserLeavesScene()0%880100%
VolumeIsUnmutedWhenUserEntersScene()0%770100%
CreateDCLVideoClip(...)0%110100%
CreateDCLVideoTexture(...)0%110100%
CreateDCLVideoTexture(...)0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/Video/Tests/VideoTests.cs

#LineLine coverage
 1using DCL;
 2using DCL.Helpers;
 3using DCL.Components;
 4using DCL.Models;
 5using NUnit.Framework;
 6using System.Collections;
 7using DCL.Components.Video.Plugin;
 8using UnityEngine;
 9using UnityEngine.TestTools;
 10using DCL.Controllers;
 11using Newtonsoft.Json;
 12
 13namespace Tests
 14{
 15    public class VideoTests : IntegrationTestSuite_Legacy
 16    {
 17        protected override IEnumerator SetUp()
 18        {
 1119            yield return base.SetUp();
 1120            DCLVideoTexture.isTest = true;
 1121        }
 22
 23        protected override IEnumerator TearDown()
 24        {
 1125            sceneController.enabled = true;
 1126            return base.TearDown();
 27        }
 28
 29        [UnityTest]
 30        public IEnumerator VideoTextureIsCreatedCorrectly()
 31        {
 132            DCLVideoTexture videoTexture = CreateDCLVideoTexture(scene, "it-wont-load-during-test");
 133            yield return videoTexture.routine;
 134            Assert.IsTrue(videoTexture.attachedMaterials.Count == 0, "DCLVideoTexture started with attachedMaterials != 
 135        }
 36
 37        [UnityTest]
 38        public IEnumerator VideoTextureReplaceOtherTextureCorrectly()
 39        {
 140            DCLVideoTexture videoTexture = CreateDCLVideoTexture(scene, "it-wont-load-during-test");
 141            yield return videoTexture.routine;
 142            Assert.IsTrue(videoTexture.attachedMaterials.Count == 0, "DCLVideoTexture started with attachedMaterials != 
 43
 144            DCLTexture dclTexture = TestHelpers.CreateDCLTexture(
 45                scene,
 46                TestAssetsUtils.GetPath() + "/Images/atlas.png",
 47                DCLTexture.BabylonWrapMode.CLAMP,
 48                FilterMode.Bilinear);
 49
 150            yield return dclTexture.routine;
 51
 152            BasicMaterial mat = TestHelpers.SharedComponentCreate<BasicMaterial, BasicMaterial.Model>
 53            (scene, CLASS_ID.BASIC_MATERIAL,
 54                new BasicMaterial.Model
 55                {
 56                    texture = dclTexture.id
 57                });
 58
 159            yield return mat.routine;
 60
 161            yield return TestHelpers.SharedComponentUpdate<BasicMaterial, BasicMaterial.Model>(mat, new BasicMaterial.Mo
 62
 163            Assert.IsTrue(videoTexture.attachedMaterials.Count == 1, $"did DCLVideoTexture attach to material? {videoTex
 164        }
 65
 66        [UnityTest]
 67        public IEnumerator VideoTextureIsAttachedAndDetachedCorrectly()
 68        {
 169            DCLVideoTexture videoTexture = CreateDCLVideoTexture(scene, "it-wont-load-during-test");
 170            yield return videoTexture.routine;
 171            Assert.IsTrue(videoTexture.attachedMaterials.Count == 0, "DCLVideoTexture started with attachedMaterials != 
 72
 173            BasicMaterial mat2 = TestHelpers.SharedComponentCreate<BasicMaterial, BasicMaterial.Model>
 74            (scene, CLASS_ID.BASIC_MATERIAL,
 75                new BasicMaterial.Model
 76                {
 77                    texture = videoTexture.id
 78                });
 79
 180            yield return mat2.routine;
 81
 182            Assert.IsTrue(videoTexture.attachedMaterials.Count == 1, $"did DCLVideoTexture attach to material? {videoTex
 83
 84            // TEST: DCLVideoTexture detach on material disposed
 185            mat2.Dispose();
 186            Assert.IsTrue(videoTexture.attachedMaterials.Count == 0, $"did DCLVideoTexture detach from material? {videoT
 87
 188            videoTexture.Dispose();
 89
 190            yield return null;
 191            Assert.IsTrue(videoTexture.texture == null, "DCLVideoTexture didn't dispose correctly?");
 192        }
 93
 94        [UnityTest]
 95        public IEnumerator VideoTextureVisibleStateIsSetCorrectlyWhenAddedToAMaterialNotAttachedToShape()
 96        {
 197            DCLVideoTexture videoTexture = CreateDCLVideoTexture(scene, "it-wont-load-during-test");
 198            yield return videoTexture.routine;
 99
 1100            var ent1 = TestHelpers.CreateSceneEntity(scene);
 1101            BasicMaterial ent1Mat = TestHelpers.SharedComponentCreate<BasicMaterial, BasicMaterial.Model>(scene, CLASS_I
 1102            TestHelpers.SharedComponentAttach(ent1Mat, ent1);
 1103            yield return ent1Mat.routine;
 104
 1105            Assert.IsTrue(!videoTexture.isVisible, "DCLVideoTexture should not be visible without a shape");
 1106        }
 107
 108        [UnityTest]
 109        public IEnumerator VideoTextureVisibleStateIsSetCorrectly()
 110        {
 1111            DCLVideoTexture videoTexture = CreateDCLVideoTexture(scene, "it-wont-load-during-test");
 1112            yield return videoTexture.routine;
 113
 1114            var ent1 = TestHelpers.CreateSceneEntity(scene);
 1115            BasicMaterial ent1Mat = TestHelpers.SharedComponentCreate<BasicMaterial, BasicMaterial.Model>(scene, CLASS_I
 1116            TestHelpers.SharedComponentAttach(ent1Mat, ent1);
 1117            yield return ent1Mat.routine;
 118
 1119            BoxShape ent1Shape = TestHelpers.SharedComponentCreate<BoxShape, BoxShape.Model>(scene, CLASS_ID.BOX_SHAPE, 
 1120            yield return ent1Shape.routine;
 121
 1122            TestHelpers.SharedComponentAttach(ent1Shape, ent1);
 1123            yield return new WaitForAllMessagesProcessed();
 1124            Assert.IsTrue(videoTexture.isVisible, "DCLVideoTexture should be visible");
 125
 1126            yield return TestHelpers.SharedComponentUpdate<BoxShape, BoxShape.Model>(ent1Shape, new BoxShape.Model() { v
 1127            yield return new WaitForAllMessagesProcessed();
 128
 1129            Assert.IsTrue(!videoTexture.isVisible, "DCLVideoTexture should not be visible ");
 1130        }
 131
 132        [UnityTest]
 133        public IEnumerator VideoTextureVisibleStateIsSetCorrectlyWhenAddedToAlreadyAttachedMaterial()
 134        {
 1135            DCLVideoTexture videoTexture = CreateDCLVideoTexture(scene, "it-wont-load-during-test");
 1136            yield return videoTexture.routine;
 137
 1138            var ent1 = TestHelpers.CreateSceneEntity(scene);
 1139            BasicMaterial ent1Mat = TestHelpers.SharedComponentCreate<BasicMaterial, BasicMaterial.Model>(scene, CLASS_I
 1140            TestHelpers.SharedComponentAttach(ent1Mat, ent1);
 1141            yield return ent1Mat.routine;
 142
 1143            BoxShape ent1Shape = TestHelpers.SharedComponentCreate<BoxShape, BoxShape.Model>(scene, CLASS_ID.BOX_SHAPE, 
 1144            yield return ent1Shape.routine;
 145
 1146            TestHelpers.SharedComponentAttach(ent1Shape, ent1);
 147
 1148            yield return TestHelpers.SharedComponentUpdate<BasicMaterial, BasicMaterial.Model>(ent1Mat, new BasicMateria
 1149            yield return new WaitForAllMessagesProcessed();
 1150            Assert.IsTrue(videoTexture.isVisible, "DCLVideoTexture should be visible");
 151
 1152            yield return TestHelpers.SharedComponentUpdate<BoxShape, BoxShape.Model>(ent1Shape, new BoxShape.Model() { v
 1153            yield return new WaitForAllMessagesProcessed();
 154
 1155            Assert.IsTrue(!videoTexture.isVisible, "DCLVideoTexture should not be visible ");
 1156        }
 157
 158        [UnityTest]
 159        public IEnumerator VideoTextureVisibleStateIsSetCorrectlyWhenEntityIsRemoved()
 160        {
 1161            DCLVideoTexture videoTexture = CreateDCLVideoTexture(scene, "it-wont-load-during-test");
 1162            yield return videoTexture.routine;
 163
 1164            var ent1 = TestHelpers.CreateSceneEntity(scene);
 1165            BasicMaterial ent1Mat = TestHelpers.SharedComponentCreate<BasicMaterial, BasicMaterial.Model>(scene, CLASS_I
 1166            TestHelpers.SharedComponentAttach(ent1Mat, ent1);
 1167            yield return ent1Mat.routine;
 168
 1169            BoxShape ent1Shape = TestHelpers.SharedComponentCreate<BoxShape, BoxShape.Model>(scene, CLASS_ID.BOX_SHAPE, 
 1170            yield return ent1Shape.routine;
 171
 1172            TestHelpers.SharedComponentAttach(ent1Shape, ent1);
 1173            yield return new WaitForAllMessagesProcessed();
 1174            Assert.IsTrue(videoTexture.isVisible, "DCLVideoTexture should be visible");
 175
 1176            scene.RemoveEntity(ent1.entityId, true);
 1177            yield return new WaitForAllMessagesProcessed();
 178
 1179            Assert.IsTrue(!videoTexture.isVisible, "DCLVideoTexture should not be visible ");
 1180        }
 181
 182        [UnityTest]
 183        public IEnumerator VolumeWhenVideoCreatedWithNoUserInScene()
 184        {
 185            // We disable SceneController monobehaviour to avoid its current scene id update
 1186            sceneController.enabled = false;
 187
 188            // Set current scene as a different one
 1189            CommonScriptableObjects.sceneID.Set("unexistent-scene");
 190
 1191            DCLVideoTexture videoTexture = CreateDCLVideoTexture(scene, "it-wont-load-during-test");
 1192            yield return videoTexture.routine;
 193
 1194            var ent1 = TestHelpers.CreateSceneEntity(scene);
 1195            BasicMaterial ent1Mat = TestHelpers.SharedComponentCreate<BasicMaterial, BasicMaterial.Model>(scene, CLASS_I
 1196            TestHelpers.SharedComponentAttach(ent1Mat, ent1);
 1197            yield return ent1Mat.routine;
 198
 1199            BoxShape ent1Shape = TestHelpers.SharedComponentCreate<BoxShape, BoxShape.Model>(scene, CLASS_ID.BOX_SHAPE, 
 1200            yield return ent1Shape.routine;
 201
 1202            TestHelpers.SharedComponentAttach(ent1Shape, ent1);
 1203            yield return new WaitForAllMessagesProcessed();
 204
 205            // Check the volume
 1206            Assert.AreEqual(0f, videoTexture.texturePlayer.volume);
 1207        }
 208
 209        [UnityTest]
 210        public IEnumerator VolumeWhenVideoCreatedWithUserInScene()
 211        {
 212            // We disable SceneController monobehaviour to avoid its current scene id update
 1213            sceneController.enabled = false;
 214
 215            // Set current scene with this scene's id
 1216            CommonScriptableObjects.sceneID.Set(scene.sceneData.id);
 217
 1218            DCLVideoTexture videoTexture = CreateDCLVideoTexture(scene, "it-wont-load-during-test");
 1219            yield return videoTexture.routine;
 220
 1221            var ent1 = TestHelpers.CreateSceneEntity(scene);
 1222            BasicMaterial ent1Mat = TestHelpers.SharedComponentCreate<BasicMaterial, BasicMaterial.Model>(scene, CLASS_I
 1223            TestHelpers.SharedComponentAttach(ent1Mat, ent1);
 1224            yield return ent1Mat.routine;
 225
 1226            BoxShape ent1Shape = TestHelpers.SharedComponentCreate<BoxShape, BoxShape.Model>(scene, CLASS_ID.BOX_SHAPE, 
 1227            yield return ent1Shape.routine;
 228
 1229            TestHelpers.SharedComponentAttach(ent1Shape, ent1);
 1230            yield return new WaitForAllMessagesProcessed();
 231
 232            // Check the volume
 1233            Assert.AreEqual(videoTexture.GetVolume(), videoTexture.texturePlayer.volume);
 1234        }
 235
 236        [UnityTest]
 237        public IEnumerator VolumeIsMutedWhenUserLeavesScene()
 238        {
 239            // We disable SceneController monobehaviour to avoid its current scene id update
 1240            sceneController.enabled = false;
 241
 242            // Set current scene with this scene's id
 1243            CommonScriptableObjects.sceneID.Set(scene.sceneData.id);
 1244            yield return null;
 245
 1246            DCLVideoTexture videoTexture = CreateDCLVideoTexture(scene, "it-wont-load-during-test");
 1247            yield return videoTexture.routine;
 248
 1249            var ent1 = TestHelpers.CreateSceneEntity(scene);
 1250            BasicMaterial ent1Mat = TestHelpers.SharedComponentCreate<BasicMaterial, BasicMaterial.Model>(scene, CLASS_I
 1251            TestHelpers.SharedComponentAttach(ent1Mat, ent1);
 1252            yield return ent1Mat.routine;
 253
 1254            BoxShape ent1Shape = TestHelpers.SharedComponentCreate<BoxShape, BoxShape.Model>(scene, CLASS_ID.BOX_SHAPE, 
 1255            yield return ent1Shape.routine;
 256
 1257            TestHelpers.SharedComponentAttach(ent1Shape, ent1);
 1258            yield return new WaitForAllMessagesProcessed();
 259
 260            // Set current scene as a different one
 1261            CommonScriptableObjects.sceneID.Set("unexistent-scene");
 262
 263            // to force the video player to update its volume
 1264            CommonScriptableObjects.playerCoords.Set(new Vector2Int(666, 666));
 265
 1266            yield return null;
 267
 268            // Check the volume
 1269            Assert.AreEqual(0f, videoTexture.texturePlayer.volume);
 1270        }
 271
 272        [UnityTest]
 273        public IEnumerator VolumeIsUnmutedWhenUserEntersScene()
 274        {
 275            // We disable SceneController monobehaviour to avoid its current scene id update
 1276            sceneController.enabled = false;
 277
 278            // Set current scene as a different one
 1279            CommonScriptableObjects.sceneID.Set("unexistent-scene");
 280
 1281            DCLVideoTexture videoTexture = CreateDCLVideoTexture(scene, "it-wont-load-during-test");
 1282            yield return videoTexture.routine;
 283
 1284            var ent1 = TestHelpers.CreateSceneEntity(scene);
 1285            BasicMaterial ent1Mat = TestHelpers.SharedComponentCreate<BasicMaterial, BasicMaterial.Model>(scene, CLASS_I
 1286            TestHelpers.SharedComponentAttach(ent1Mat, ent1);
 1287            yield return ent1Mat.routine;
 288
 1289            BoxShape ent1Shape = TestHelpers.SharedComponentCreate<BoxShape, BoxShape.Model>(scene, CLASS_ID.BOX_SHAPE, 
 1290            yield return ent1Shape.routine;
 291
 1292            TestHelpers.SharedComponentAttach(ent1Shape, ent1);
 1293            yield return new WaitForAllMessagesProcessed();
 294
 295            // Set current scene with this scene's id
 1296            CommonScriptableObjects.sceneID.Set(scene.sceneData.id);
 297
 298            // to force the video player to update its volume
 1299            CommonScriptableObjects.playerCoords.Set(new Vector2Int(666, 666));
 300
 1301            yield return null;
 302
 303            // Check the volume
 1304            Assert.AreEqual(videoTexture.GetVolume(), videoTexture.texturePlayer.volume);
 1305        }
 306
 307        static DCLVideoClip CreateDCLVideoClip(ParcelScene scn, string url)
 308        {
 11309            return TestHelpers.SharedComponentCreate<DCLVideoClip, DCLVideoClip.Model>
 310            (
 311                scn,
 312                DCL.Models.CLASS_ID.VIDEO_CLIP,
 313                new DCLVideoClip.Model
 314                {
 315                    url = url
 316                }
 317            );
 318        }
 319
 320        static DCLVideoTexture CreateDCLVideoTexture(ParcelScene scn, DCLVideoClip clip)
 321        {
 11322            return TestHelpers.SharedComponentCreate<DCLVideoTexture, DCLVideoTexture.Model>
 323            (
 324                scn,
 325                DCL.Models.CLASS_ID.VIDEO_TEXTURE,
 326                new DCLVideoTexture.Model
 327                {
 328                    videoClipId = clip.id
 329                }
 330            );
 331        }
 332
 11333        static DCLVideoTexture CreateDCLVideoTexture(ParcelScene scn, string url) { return CreateDCLVideoTexture(scn, Cr
 334    }
 335}