| | 1 | | using Cinemachine; |
| | 2 | | using DCL.SettingsCommon; |
| | 3 | | using DCL.SettingsController; |
| | 4 | | using DCL.SettingsControls; |
| | 5 | | using NUnit.Framework; |
| | 6 | | using System.Collections; |
| | 7 | | using System.Reflection; |
| | 8 | | using UnityEditor.SceneManagement; |
| | 9 | | using UnityEngine; |
| | 10 | | using UnityEngine.Rendering; |
| | 11 | | using UnityEngine.Rendering.Universal; |
| | 12 | | using UnityEngine.SceneManagement; |
| | 13 | | using UnityEngine.TestTools; |
| | 14 | |
|
| | 15 | | namespace Tests |
| | 16 | | { |
| | 17 | | public class SettingsControlsShould |
| | 18 | | { |
| | 19 | | private const string TEST_SCENE_PATH = "Assets/Scripts/MainScripts/DCL/Controllers/Settings/SettingsControllers/ |
| | 20 | | private const string TEST_SCENE_NAME = "SettingsTestScene"; |
| | 21 | |
|
| | 22 | | private SettingsControlController settingController; |
| | 23 | |
|
| | 24 | | private CinemachineFreeLook freeLookCamera; |
| | 25 | | private CinemachineVirtualCamera firstPersonCamera; |
| | 26 | | private CinemachinePOV povCamera; |
| | 27 | | private Light environmentLight; |
| | 28 | | private Volume postProcessVolume; |
| | 29 | | private UniversalRenderPipelineAsset urpAsset; |
| | 30 | | private FieldInfo lwrpaShadowField = null; |
| | 31 | | private FieldInfo lwrpaShadowResolutionField = null; |
| | 32 | | private FieldInfo lwrpaSoftShadowField = null; |
| | 33 | |
|
| | 34 | | [UnitySetUp] |
| | 35 | | public IEnumerator SetUp() |
| | 36 | | { |
| 17 | 37 | | yield return EditorSceneManager.LoadSceneAsyncInPlayMode($"{TEST_SCENE_PATH}/{TEST_SCENE_NAME}.unity", new L |
| | 38 | |
|
| 17 | 39 | | SetupReferences(); |
| 17 | 40 | | } |
| | 41 | |
|
| | 42 | | [UnityTearDown] |
| | 43 | | public IEnumerator TearDown() |
| | 44 | | { |
| 17 | 45 | | ScriptableObject.Destroy(settingController); |
| | 46 | |
|
| 17 | 47 | | yield return EditorSceneManager.UnloadSceneAsync(TEST_SCENE_NAME); |
| 17 | 48 | | } |
| | 49 | |
|
| | 50 | | private void SetupReferences() |
| | 51 | | { |
| 17 | 52 | | urpAsset = GraphicsSettings.renderPipelineAsset as UniversalRenderPipelineAsset; |
| 17 | 53 | | Assert.IsNotNull(urpAsset, "urpAsset is null!"); |
| | 54 | |
|
| 17 | 55 | | lwrpaShadowField = urpAsset.GetType().GetField("m_MainLightShadowsSupported", BindingFlags.NonPublic | Bindi |
| 17 | 56 | | Assert.IsNotNull(lwrpaShadowField, "lwrpaShadowField is null!"); |
| | 57 | |
|
| 17 | 58 | | lwrpaShadowResolutionField = urpAsset.GetType().GetField("m_MainLightShadowmapResolution", BindingFlags.NonP |
| 17 | 59 | | Assert.IsNotNull(lwrpaShadowResolutionField, "lwrpaShadowResolutionField is null!"); |
| | 60 | |
|
| 17 | 61 | | lwrpaSoftShadowField = urpAsset.GetType().GetField("m_SoftShadowsSupported", BindingFlags.NonPublic | Bindin |
| 17 | 62 | | Assert.IsNotNull(lwrpaSoftShadowField, "lwrpaSoftShadowField is null!"); |
| | 63 | |
|
| 17 | 64 | | GeneralSettingsReferences generalSettingsReferences = GameObject.FindObjectOfType<GeneralSettingsReferences> |
| 17 | 65 | | QualitySettingsReferences qualitySettingsReferences = GameObject.FindObjectOfType<QualitySettingsReferences> |
| | 66 | |
|
| 17 | 67 | | Assert.IsNotNull(generalSettingsReferences, "GeneralSettingsReferences not found in scene"); |
| 17 | 68 | | Assert.IsNotNull(qualitySettingsReferences, "QualitySettingsReferences not found in scene"); |
| | 69 | |
|
| 17 | 70 | | freeLookCamera = generalSettingsReferences.thirdPersonCamera; |
| 17 | 71 | | Assert.IsNotNull(freeLookCamera, "GeneralSettingsController: thirdPersonCamera reference missing"); |
| | 72 | |
|
| 17 | 73 | | CinemachineVirtualCamera virtualCamera = generalSettingsReferences.firstPersonCamera; |
| 17 | 74 | | Assert.IsNotNull(virtualCamera, "GeneralSettingsController: firstPersonCamera reference missing"); |
| 17 | 75 | | povCamera = virtualCamera.GetCinemachineComponent<CinemachinePOV>(); |
| 17 | 76 | | Assert.IsNotNull(povCamera, "GeneralSettingsController: firstPersonCamera doesn't have CinemachinePOV compon |
| | 77 | |
|
| 17 | 78 | | environmentLight = qualitySettingsReferences.environmentLight; |
| 17 | 79 | | Assert.IsNotNull(environmentLight, "QualitySettingsController: environmentLight reference missing"); |
| | 80 | |
|
| 17 | 81 | | postProcessVolume = qualitySettingsReferences.postProcessVolume; |
| 17 | 82 | | Assert.IsNotNull(postProcessVolume, "QualitySettingsController: postProcessVolume reference missing"); |
| | 83 | |
|
| 17 | 84 | | firstPersonCamera = qualitySettingsReferences.firstPersonCamera; |
| 17 | 85 | | Assert.IsNotNull(firstPersonCamera, "QualitySettingsController: firstPersonCamera reference missing"); |
| 17 | 86 | | Assert.IsNotNull(qualitySettingsReferences.thirdPersonCamera, "QualitySettingsController: thirdPersonCamera |
| 17 | 87 | | } |
| | 88 | |
|
| | 89 | | [Test] |
| | 90 | | public void ChangeAllowVoiceChatCorrectly() |
| | 91 | | { |
| | 92 | | // Arrange |
| 1 | 93 | | settingController = ScriptableObject.CreateInstance<AllowVoiceChatControlController>(); |
| 1 | 94 | | settingController.Initialize(); |
| | 95 | |
|
| | 96 | | // Act |
| 1 | 97 | | int newValue = (int)DCL.SettingsData.GeneralSettings.VoiceChatAllow.FRIENDS_ONLY; |
| 1 | 98 | | settingController.UpdateSetting(newValue); |
| | 99 | |
|
| | 100 | | // Assert |
| 1 | 101 | | Assert.AreEqual(newValue, settingController.GetStoredValue(), "voiceChatAllow stored value mismatch"); |
| 1 | 102 | | } |
| | 103 | |
|
| | 104 | | [Test] |
| | 105 | | public void ChangeAntialiasingChatCorrectly() |
| | 106 | | { |
| | 107 | | // Arrange |
| 1 | 108 | | settingController = ScriptableObject.CreateInstance<AntiAliasingControlController>(); |
| 1 | 109 | | settingController.Initialize(); |
| | 110 | |
|
| | 111 | | // Act |
| 1 | 112 | | float newValue = (float)MsaaQuality._8x; |
| 1 | 113 | | settingController.UpdateSetting(newValue); |
| | 114 | |
|
| | 115 | | // Assert |
| 1 | 116 | | int antiAliasingValue = 1 << (int)newValue; |
| 1 | 117 | | Assert.AreEqual((antiAliasingValue >> 2) + 1, settingController.GetStoredValue(), "antiAliasing stored value |
| 1 | 118 | | Assert.AreEqual(antiAliasingValue, urpAsset.msaaSampleCount, "antiAliasing mismatch"); |
| 1 | 119 | | } |
| | 120 | |
|
| | 121 | | [Test] |
| | 122 | | public void ChangeBaseResolutionCorrectly() |
| | 123 | | { |
| | 124 | | // Arrange |
| 1 | 125 | | settingController = ScriptableObject.CreateInstance<BaseResolutionControlController>(); |
| 1 | 126 | | settingController.Initialize(); |
| | 127 | |
|
| | 128 | | // Act |
| 1 | 129 | | DCL.SettingsData.QualitySettings.BaseResolution newValue = DCL.SettingsData.QualitySettings.BaseResolution.B |
| 1 | 130 | | settingController.UpdateSetting(newValue); |
| | 131 | |
|
| | 132 | | // Assert |
| 1 | 133 | | Assert.AreEqual((int)newValue, settingController.GetStoredValue(), "baseResolution stored value mismatch"); |
| 1 | 134 | | } |
| | 135 | |
|
| | 136 | | [Test] |
| | 137 | | public void ChangeBloomCorrectly() |
| | 138 | | { |
| | 139 | | // Arrange |
| 1 | 140 | | settingController = ScriptableObject.CreateInstance<BloomControlController>(); |
| 1 | 141 | | settingController.Initialize(); |
| | 142 | |
|
| | 143 | | // Act |
| 1 | 144 | | bool newValue = true; |
| 1 | 145 | | settingController.UpdateSetting(newValue); |
| | 146 | |
|
| | 147 | | // Assert |
| 1 | 148 | | Assert.AreEqual(newValue, settingController.GetStoredValue(), "bloom stored value mismatch"); |
| 1 | 149 | | if (postProcessVolume.profile.TryGet<Bloom>(out Bloom bloom)) |
| | 150 | | { |
| 1 | 151 | | Assert.AreEqual(newValue, bloom.active, "bloom mismatch"); |
| | 152 | | } |
| 1 | 153 | | } |
| | 154 | |
|
| | 155 | | [Test] |
| | 156 | | public void ChangeColorGradingCorrectly() |
| | 157 | | { |
| | 158 | | // Arrange |
| 1 | 159 | | settingController = ScriptableObject.CreateInstance<ColorGradingControlController>(); |
| 1 | 160 | | settingController.Initialize(); |
| | 161 | |
|
| | 162 | | // Act |
| 1 | 163 | | bool newValue = true; |
| 1 | 164 | | settingController.UpdateSetting(newValue); |
| | 165 | |
|
| | 166 | | // Assert |
| 1 | 167 | | Assert.AreEqual(newValue, settingController.GetStoredValue(), "colorGrading stored value mismatch"); |
| | 168 | | Tonemapping toneMapping; |
| 1 | 169 | | if (QualitySettingsReferences.i.postProcessVolume.profile.TryGet<Tonemapping>(out toneMapping)) |
| | 170 | | { |
| 1 | 171 | | Assert.AreEqual(newValue, toneMapping.active, "bloom mismatch"); |
| | 172 | | } |
| 1 | 173 | | } |
| | 174 | |
|
| | 175 | | [Test] |
| | 176 | | public void ChangeDetailObjectCullingCorrectly() |
| | 177 | | { |
| | 178 | | // Arrange |
| 1 | 179 | | settingController = ScriptableObject.CreateInstance<DetailObjectCullingControlController>(); |
| 1 | 180 | | settingController.Initialize(); |
| | 181 | |
|
| | 182 | | // Act |
| 1 | 183 | | bool newValue = true; |
| 1 | 184 | | settingController.UpdateSetting(newValue); |
| | 185 | |
|
| | 186 | | // Assert |
| 1 | 187 | | Assert.AreEqual(newValue, settingController.GetStoredValue(), "enableDetailObjectCulling stored value mismat |
| 1 | 188 | | Assert.AreNotEqual(newValue, CommonSettingsScriptableObjects.detailObjectCullingDisabled.Get()); |
| 1 | 189 | | } |
| | 190 | |
|
| | 191 | | [Test] |
| | 192 | | public void ChangeDetailObjectCullingSizeCorrectly() |
| | 193 | | { |
| | 194 | | // Arrange |
| 1 | 195 | | settingController = ScriptableObject.CreateInstance<DetailObjectCullingSizeControlController>(); |
| 1 | 196 | | settingController.Initialize(); |
| | 197 | |
|
| | 198 | | // Act |
| 1 | 199 | | float newValue = 20f; |
| 1 | 200 | | settingController.UpdateSetting(newValue); |
| | 201 | |
|
| | 202 | | // Assert |
| 1 | 203 | | Assert.AreEqual(newValue, settingController.GetStoredValue(), "detailObjectCullingThreshold stored value mis |
| 1 | 204 | | } |
| | 205 | |
|
| | 206 | | [Test] |
| | 207 | | public void ChangeDrawDistanceCorrectly() |
| | 208 | | { |
| | 209 | | // Arrange |
| 1 | 210 | | settingController = ScriptableObject.CreateInstance<DrawDistanceControlController>(); |
| 1 | 211 | | settingController.Initialize(); |
| | 212 | |
|
| | 213 | | // Act |
| 1 | 214 | | float newValue = 50f; |
| 1 | 215 | | settingController.UpdateSetting(newValue); |
| | 216 | |
|
| | 217 | | // Assert |
| 1 | 218 | | Assert.AreEqual(newValue, settingController.GetStoredValue(), "cameraDrawDistance stored value mismatch"); |
| 1 | 219 | | Assert.AreEqual(freeLookCamera.m_Lens.FarClipPlane, newValue, "3rd person camera FarClipPlane value mismatch |
| 1 | 220 | | Assert.AreEqual(firstPersonCamera.m_Lens.FarClipPlane, newValue, "1st person camera FarClipPlane value misma |
| 1 | 221 | | Assert.AreEqual(RenderSettings.fogEndDistance, newValue, "fogEndDistance value mismatch"); |
| 1 | 222 | | Assert.AreEqual(RenderSettings.fogStartDistance, newValue * 0.8f, "fogStartDistance value mismatch"); |
| 1 | 223 | | } |
| | 224 | |
|
| | 225 | | [Test] |
| | 226 | | public void ChangeFPSLimitCorrectly() |
| | 227 | | { |
| | 228 | | // Arrange |
| 1 | 229 | | settingController = ScriptableObject.CreateInstance<FPSLimitControlController>(); |
| 1 | 230 | | settingController.Initialize(); |
| | 231 | |
|
| | 232 | | // Act |
| 1 | 233 | | bool newValue = true; |
| 1 | 234 | | settingController.UpdateSetting(newValue); |
| | 235 | |
|
| | 236 | | // Assert |
| 1 | 237 | | Assert.AreEqual(newValue, settingController.GetStoredValue(), "fpsCap stored value mismatch"); |
| 1 | 238 | | } |
| | 239 | |
|
| | 240 | | [Test] |
| | 241 | | public void ChangeMouseSensivityCorrectly() |
| | 242 | | { |
| | 243 | | // Arrange |
| 1 | 244 | | settingController = ScriptableObject.CreateInstance<MouseSensivityControlController>(); |
| 1 | 245 | | settingController.Initialize(); |
| | 246 | |
|
| | 247 | | // Act |
| 1 | 248 | | float newValue = 80f; |
| 1 | 249 | | settingController.UpdateSetting(newValue); |
| | 250 | |
|
| | 251 | | // Assert |
| 1 | 252 | | Assert.AreEqual(newValue, settingController.GetStoredValue(), "mouseSensitivity stored value mismatch"); |
| 1 | 253 | | var povSpeed = Mathf.Lerp(MouseSensivityControlController.FIRST_PERSON_MIN_SPEED, MouseSensivityControlContr |
| 1 | 254 | | UnityEngine.Assertions.Assert.AreApproximatelyEqual(povSpeed, povCamera.m_HorizontalAxis.m_MaxSpeed, "povCam |
| 1 | 255 | | UnityEngine.Assertions.Assert.AreApproximatelyEqual(povSpeed, povCamera.m_VerticalAxis.m_MaxSpeed, "povCamer |
| 1 | 256 | | UnityEngine.Assertions.Assert.AreApproximatelyEqual( |
| | 257 | | Mathf.Lerp(MouseSensivityControlController.THIRD_PERSON_X_MIN_SPEED, MouseSensivityControlController.THI |
| | 258 | | freeLookCamera.m_XAxis.m_MaxSpeed, |
| | 259 | | "freeLookCamera.m_XAxis.m_MaxSpeed value mismatch"); |
| 1 | 260 | | UnityEngine.Assertions.Assert.AreApproximatelyEqual( |
| | 261 | | Mathf.Lerp(MouseSensivityControlController.THIRD_PERSON_Y_MIN_SPEED, MouseSensivityControlController.THI |
| | 262 | | freeLookCamera.m_YAxis.m_MaxSpeed, |
| | 263 | | "freeLookCamera.m_YAxis.m_MaxSpeed value mismatch"); |
| 1 | 264 | | } |
| | 265 | |
|
| | 266 | | [Test] |
| | 267 | | public void ChangeMuteSoundCorrectly() |
| | 268 | | { |
| | 269 | | // Arrange |
| 1 | 270 | | settingController = ScriptableObject.CreateInstance<MuteSoundControlController>(); |
| 1 | 271 | | settingController.Initialize(); |
| | 272 | |
|
| | 273 | | // Act |
| 1 | 274 | | bool newValue = true; |
| 1 | 275 | | settingController.UpdateSetting(newValue); |
| | 276 | |
|
| | 277 | | // Assert |
| 1 | 278 | | Assert.AreEqual(newValue, settingController.GetStoredValue(), "muteSound stored value mismatch"); |
| 1 | 279 | | Assert.AreEqual(newValue ? 1f : 0f, AudioListener.volume, "sfxVolume value mismatch"); |
| 1 | 280 | | } |
| | 281 | |
|
| | 282 | | [Test] |
| | 283 | | public void ChangeRenderingScaleCorrectly() |
| | 284 | | { |
| | 285 | | // Arrange |
| 1 | 286 | | settingController = ScriptableObject.CreateInstance<RenderingScaleControlController>(); |
| 1 | 287 | | settingController.Initialize(); |
| | 288 | |
|
| | 289 | | // Act |
| 1 | 290 | | float newValue = 0.5f; |
| 1 | 291 | | settingController.UpdateSetting(newValue); |
| | 292 | |
|
| | 293 | | // Assert |
| 1 | 294 | | Assert.AreEqual(newValue, settingController.GetStoredValue(), "renderScale stored value mismatch"); |
| 1 | 295 | | Assert.AreEqual(newValue, urpAsset.renderScale, "renderScale value mismatch"); |
| 1 | 296 | | } |
| | 297 | |
|
| | 298 | | [Test] |
| | 299 | | public void ChangeShadowsCorrectly() |
| | 300 | | { |
| | 301 | | // Arrange |
| 1 | 302 | | settingController = ScriptableObject.CreateInstance<ShadowControlController>(); |
| 1 | 303 | | settingController.Initialize(); |
| | 304 | |
|
| | 305 | | // Act |
| 1 | 306 | | bool newValue = true; |
| 1 | 307 | | settingController.UpdateSetting(newValue); |
| | 308 | |
|
| | 309 | | // Assert |
| 1 | 310 | | Assert.AreEqual(newValue, settingController.GetStoredValue(), "shadows stored value mismatch"); |
| 1 | 311 | | Assert.AreEqual(newValue, lwrpaShadowField.GetValue(urpAsset), "lwrpaShadowField value mismatch"); |
| 1 | 312 | | Assert.AreNotEqual(newValue, CommonSettingsScriptableObjects.shadowsDisabled.Get()); |
| 1 | 313 | | } |
| | 314 | |
|
| | 315 | | [Test] |
| | 316 | | public void ChangeShadowDistanceCorrectly() |
| | 317 | | { |
| | 318 | | // Arrange |
| 1 | 319 | | settingController = ScriptableObject.CreateInstance<ShadowDistanceControlController>(); |
| 1 | 320 | | settingController.Initialize(); |
| | 321 | |
|
| | 322 | | // Act |
| 1 | 323 | | float newValue = 50f; |
| 1 | 324 | | settingController.UpdateSetting(newValue); |
| | 325 | |
|
| | 326 | | // Assert |
| 1 | 327 | | Assert.AreEqual(newValue, settingController.GetStoredValue(), "shadowDistance stored value mismatch"); |
| 1 | 328 | | Assert.AreEqual(newValue, urpAsset.shadowDistance, "shadowDistance value mismatch"); |
| 1 | 329 | | } |
| | 330 | |
|
| | 331 | | [Test] |
| | 332 | | public void ChangeShadowresolutionCorrectly() |
| | 333 | | { |
| | 334 | | // Arrange |
| 1 | 335 | | settingController = ScriptableObject.CreateInstance<ShadowResolutionControlController>(); |
| 1 | 336 | | settingController.Initialize(); |
| | 337 | |
|
| | 338 | | // Act |
| 1 | 339 | | int newValue = 4; |
| 1 | 340 | | settingController.UpdateSetting(newValue); |
| | 341 | |
|
| | 342 | | // Assert |
| 1 | 343 | | UnityEngine.Rendering.Universal.ShadowResolution newValueFormatted = (UnityEngine.Rendering.Universal.Shadow |
| 1 | 344 | | Assert.AreEqual( |
| | 345 | | (int)Mathf.Log((int)newValueFormatted, 2) - 8, |
| | 346 | | settingController.GetStoredValue(), |
| | 347 | | "shadowResolution stored value mismatch"); |
| 1 | 348 | | Assert.AreEqual(newValueFormatted, lwrpaShadowResolutionField.GetValue(urpAsset), "lwrpaShadowResolutionFiel |
| 1 | 349 | | } |
| | 350 | |
|
| | 351 | | [Test] |
| | 352 | | public void ChangeSoftShadowsCorrectly() |
| | 353 | | { |
| | 354 | | // Arrange |
| 1 | 355 | | settingController = ScriptableObject.CreateInstance<SoftShadowsControlController>(); |
| 1 | 356 | | settingController.Initialize(); |
| | 357 | |
|
| | 358 | | // Act |
| 1 | 359 | | bool newValue = true; |
| 1 | 360 | | settingController.UpdateSetting(newValue); |
| | 361 | |
|
| | 362 | | // Assert |
| 1 | 363 | | Assert.AreEqual(newValue, settingController.GetStoredValue(), "softShadows stored value mismatch"); |
| 1 | 364 | | Assert.AreEqual(newValue, lwrpaSoftShadowField.GetValue(urpAsset), "lwrpaShadowResolutionField value mismatc |
| 1 | 365 | | } |
| | 366 | |
|
| | 367 | | [Test] |
| | 368 | | public void ChangeVoiceChatVolumeCorrectly() |
| | 369 | | { |
| | 370 | | // Arrange |
| 1 | 371 | | settingController = ScriptableObject.CreateInstance<VoiceChatVolumeControlController>(); |
| 1 | 372 | | settingController.Initialize(); |
| | 373 | |
|
| | 374 | | // Act |
| 1 | 375 | | float newValue = 90f; |
| 1 | 376 | | settingController.UpdateSetting(newValue); |
| | 377 | |
|
| | 378 | | // Assert |
| 1 | 379 | | Assert.AreEqual(newValue, settingController.GetStoredValue(), "voiceChatVolume stored value mismatch"); |
| 1 | 380 | | } |
| | 381 | | } |
| | 382 | | } |