diff --git a/FinalEngine.Audio.OpenAL/Factories/CASLSoundFactory.cs b/FinalEngine.Audio.OpenAL/Factories/CASLSoundFactory.cs index 3f41f89c..91c115db 100644 --- a/FinalEngine.Audio.OpenAL/Factories/CASLSoundFactory.cs +++ b/FinalEngine.Audio.OpenAL/Factories/CASLSoundFactory.cs @@ -9,7 +9,7 @@ namespace FinalEngine.Audio.OpenAL.Factories; using CASLSound = CASL.Sound; using ICASLSound = CASL.ISound; -[ExcludeFromCodeCoverage] +[ExcludeFromCodeCoverage(Justification = "Invocation")] internal sealed class CASLSoundFactory : ICASLSoundFactory { public ICASLSound CreateSound(string filePath) diff --git a/FinalEngine.Audio.OpenAL/FinalEngine.Audio.OpenAL.csproj b/FinalEngine.Audio.OpenAL/FinalEngine.Audio.OpenAL.csproj index 1caeda6f..4e249870 100644 --- a/FinalEngine.Audio.OpenAL/FinalEngine.Audio.OpenAL.csproj +++ b/FinalEngine.Audio.OpenAL/FinalEngine.Audio.OpenAL.csproj @@ -3,9 +3,9 @@ net8.0 enable - SA0001 All false + true x64 diff --git a/FinalEngine.Audio.OpenAL/Loaders/SoundResourceLoader.cs b/FinalEngine.Audio.OpenAL/Loaders/SoundResourceLoader.cs index aedf102b..18b0de40 100644 --- a/FinalEngine.Audio.OpenAL/Loaders/SoundResourceLoader.cs +++ b/FinalEngine.Audio.OpenAL/Loaders/SoundResourceLoader.cs @@ -11,13 +11,25 @@ namespace FinalEngine.Audio.OpenAL.Loaders; using FinalEngine.Audio.OpenAL.Factories; using FinalEngine.Resources; +/// +/// Provides an resource loader. +/// +/// +/// public class SoundResourceLoader : ResourceLoaderBase { private readonly ICASLSoundFactory factory; private readonly IFileSystem fileSystem; - [ExcludeFromCodeCoverage] + /// + /// Initializes a new instance of the class. + /// + /// + /// + /// The file system used to load resources. + /// + [ExcludeFromCodeCoverage(Justification = "Cannot unit test")] public SoundResourceLoader(IFileSystem fileSystem) : this(fileSystem, new CASLSoundFactory()) { @@ -29,6 +41,21 @@ internal SoundResourceLoader(IFileSystem fileSystem, ICASLSoundFactory factory) this.factory = factory ?? throw new ArgumentNullException(nameof(factory)); } + /// + /// Loads a resource from the specified . + /// + /// + /// + /// The file path of the resource to load. + /// + /// + /// + /// The loaded resource, of type . + /// + /// + /// + /// The specified parameter cannot be located on the current file system. + /// public override ISound LoadResource(string filePath) { ArgumentException.ThrowIfNullOrWhiteSpace(filePath, nameof(filePath)); diff --git a/FinalEngine.ECS/Attributes/EntitySystemProcessAttribute.cs b/FinalEngine.ECS/Attributes/EntitySystemProcessAttribute.cs index c86b5cb6..3353e617 100644 --- a/FinalEngine.ECS/Attributes/EntitySystemProcessAttribute.cs +++ b/FinalEngine.ECS/Attributes/EntitySystemProcessAttribute.cs @@ -6,8 +6,23 @@ namespace FinalEngine.ECS.Attributes; using System; +/// +/// Provides an attribute used to determine when an will execute. +/// +/// [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] public sealed class EntitySystemProcessAttribute : Attribute { + /// + /// Gets the type of the execution. + /// + /// + /// + /// The type of the execution. + /// + /// + /// + /// The determines when the associated system will be executed. + /// public GameLoopType ExecutionType { get; init; } } diff --git a/FinalEngine.ECS/Components/Core/TagComponent.cs b/FinalEngine.ECS/Components/Core/TagComponent.cs index db84af1f..ea2d5ee8 100644 --- a/FinalEngine.ECS/Components/Core/TagComponent.cs +++ b/FinalEngine.ECS/Components/Core/TagComponent.cs @@ -6,13 +6,33 @@ namespace FinalEngine.ECS.Components.Core; using System.ComponentModel; +/// +/// Represents a tag for an . +/// +/// +/// +/// An can be associated with a tag for identification. However, an also has a unique identifier - see . +/// +/// +/// +/// [Category("Core")] public sealed class TagComponent : IEntityComponent, INotifyPropertyChanged { private string? name; + /// + /// Occurs when a property value changes. + /// public event PropertyChangedEventHandler? PropertyChanged; + /// + /// Gets or sets the name (or tag). + /// + /// + /// + /// The name (or tag). + /// public string? Name { get diff --git a/FinalEngine.ECS/FinalEngine.ECS.csproj b/FinalEngine.ECS/FinalEngine.ECS.csproj index 3ff4cad7..06a21bc2 100644 --- a/FinalEngine.ECS/FinalEngine.ECS.csproj +++ b/FinalEngine.ECS/FinalEngine.ECS.csproj @@ -5,6 +5,7 @@ enable All false + true x64 SA0001 diff --git a/FinalEngine.ECS/IEntityFactory.cs b/FinalEngine.ECS/IEntityFactory.cs index 312dbb54..b9bcb7ae 100644 --- a/FinalEngine.ECS/IEntityFactory.cs +++ b/FinalEngine.ECS/IEntityFactory.cs @@ -4,7 +4,21 @@ namespace FinalEngine.ECS; +/// +/// Defines an interface that provides a method to create an . +/// +/// +/// +/// You should implement this interface in a scenario where an must be created and assigned a default collection of components and can be reused. It simply provides a means to simplify the relationship between entities and components. +/// public interface IEntityFactory { + /// + /// Creates the entity. + /// + /// + /// + /// The newly created . + /// Entity CreateEntity(); } diff --git a/FinalEngine.ECS/IEntitySystemsProcessor.cs b/FinalEngine.ECS/IEntitySystemsProcessor.cs deleted file mode 100644 index c607def1..00000000 --- a/FinalEngine.ECS/IEntitySystemsProcessor.cs +++ /dev/null @@ -1,10 +0,0 @@ -// -// Copyright (c) Software Antics. All rights reserved. -// - -namespace FinalEngine.ECS; - -public interface IEntitySystemsProcessor -{ - void ProcessAll(GameLoopType type); -} diff --git a/FinalEngine.ECS/IEntityWorld.cs b/FinalEngine.ECS/IEntityWorld.cs index a6f7d8b7..93cccc02 100644 --- a/FinalEngine.ECS/IEntityWorld.cs +++ b/FinalEngine.ECS/IEntityWorld.cs @@ -6,12 +6,14 @@ namespace FinalEngine.ECS; using System; -public interface IEntityWorld : IEntitySystemsProcessor +public interface IEntityWorld { void AddEntity(Entity entity); void AddSystem(EntitySystemBase system); + void ProcessAll(GameLoopType type); + void RemoveEntity(Entity entity); void RemoveSystem(Type type); diff --git a/FinalEngine.Maths/MathHelper.cs b/FinalEngine.Maths/MathHelper.cs index bfb2a3ff..d77bdd99 100644 --- a/FinalEngine.Maths/MathHelper.cs +++ b/FinalEngine.Maths/MathHelper.cs @@ -6,13 +6,71 @@ namespace FinalEngine.Maths; using System; +/// +/// Provides helper methods for mathematical operations. +/// public static class MathHelper { + /// + /// Converts the specified from degrees to radians. + /// + /// + /// + /// The angle in degrees. + /// + /// + /// + /// The equivalent angle in radians. + /// + /// + /// + /// This method is useful for converting angles from the more commonly used degrees + /// measurement to radians, which is often required by trigonometric functions. + /// + /// + /// + /// The example below will convert 45 degrees to radians and then print the result. + /// + /// + /// // Convert 45 degrees to radians + /// float degrees = 45f; + /// float radians = MathHelper.DegreesToRadians(degrees); + /// + /// Console.WriteLine($"45 degrees in radians is {radians}"); + /// + /// public static float DegreesToRadians(float angle) { return (float)Math.PI / 180.0f * angle; } + /// + /// Converts the specified from radians to degrees. + /// + /// + /// + /// The angle in radians. + /// + /// + /// + /// The equivalent angle in degrees. + /// + /// + /// + /// This method is useful for converting angles from radians back to degrees, + /// which can be more intuitive for human interpretation. + /// + /// + /// + /// The below example will convert π/4 from radians to degrees. + /// + /// + /// float radians = Math.PI / 4f; + /// float degrees = MathHelper.RadiansToDegrees(radians); + /// + /// Console.WriteLine($"π/4 radians in degrees is {degrees}"); + /// + /// public static float RadiansToDegrees(float angle) { return 180.0f / (float)Math.PI * angle; diff --git a/FinalEngine.Resources/Exceptions/ResourceLoaderNotRegisteredException.cs b/FinalEngine.Resources/Exceptions/ResourceLoaderNotRegisteredException.cs index fd27bd46..03e97238 100644 --- a/FinalEngine.Resources/Exceptions/ResourceLoaderNotRegisteredException.cs +++ b/FinalEngine.Resources/Exceptions/ResourceLoaderNotRegisteredException.cs @@ -6,19 +6,49 @@ namespace FinalEngine.Resources.Exceptions; using System; +/// +/// Represents an exception that is thrown when a has not been registered to an . +/// +/// +/// +/// To register a to an you should invoke the function. +/// +/// +/// [Serializable] public class ResourceLoaderNotRegisteredException : Exception { + /// + /// Initializes a new instance of the class. + /// public ResourceLoaderNotRegisteredException() : base("Resource Loader not registered.") { } + /// + /// Initializes a new instance of the class. + /// + /// + /// + /// The message that describes the error. + /// public ResourceLoaderNotRegisteredException(string? message) : base(message) { } + /// + /// Initializes a new instance of the class. + /// + /// + /// + /// The error message that explains the reason for the exception. + /// + /// + /// + /// The exception that is the cause of the current exception, or a null reference if no inner exception is specified. + /// public ResourceLoaderNotRegisteredException(string? message, Exception? innerException) : base(message, innerException) { diff --git a/FinalEngine.Resources/FinalEngine.Resources.csproj b/FinalEngine.Resources/FinalEngine.Resources.csproj index f0658a2d..c8c5ae97 100644 --- a/FinalEngine.Resources/FinalEngine.Resources.csproj +++ b/FinalEngine.Resources/FinalEngine.Resources.csproj @@ -2,7 +2,6 @@ net8.0 - SA0001 enable All false diff --git a/FinalEngine.Resources/IResource.cs b/FinalEngine.Resources/IResource.cs index 6236b6b9..03ad535d 100644 --- a/FinalEngine.Resources/IResource.cs +++ b/FinalEngine.Resources/IResource.cs @@ -6,6 +6,13 @@ namespace FinalEngine.Resources; using System.Diagnostics.CodeAnalysis; +/// +/// Defines an interface that represents a resource that can loaded via an . +/// +/// +/// +/// You should implement on an object that should be managed by an . +/// [SuppressMessage("Design", "CA1040:Avoid empty interfaces", Justification = "Required for Resource Manager.")] public interface IResource { diff --git a/FinalEngine.Resources/IResourceManager.cs b/FinalEngine.Resources/IResourceManager.cs index 7653b99b..72ca92d9 100644 --- a/FinalEngine.Resources/IResourceManager.cs +++ b/FinalEngine.Resources/IResourceManager.cs @@ -5,14 +5,64 @@ namespace FinalEngine.Resources; using System; +using FinalEngine.Resources.Exceptions; +/// +/// Defines an interface that represents a resource manager. +/// +/// +/// +/// In almost all scenarios you should never have to implement this interface; if you require management of resources you should use the standard implementation. +/// +/// +/// public interface IResourceManager : IDisposable { + /// + /// Loads a resource at the specified . + /// + /// + /// The type of resource to load. + /// + /// + /// + /// The file path of the resource to load. + /// + /// + /// + /// The typical implementation of should attempt to cache resources; this way if is called for the same file a reference the already loaded resource can be fetched. + /// + /// + /// + /// The loaded resource, of type . + /// T LoadResource(string filePath) where T : IResource; + /// + /// Registers the specified to this . + /// + /// + /// + /// The type of resource that can be loaded. + /// + /// + /// + /// The resource loader to be used when attempting to resolve a resource of type . + /// + /// + /// + /// The typical implementation of an should likely throw a if a loader of the specified type has already been registered. + /// void RegisterLoader(ResourceLoaderBase loader) where T : IResource; - void UnloadResource(IResource? resource); + /// + /// Unloads the specified from this (calling it's dispose method if is implemented and there are no references). + /// + /// + /// + /// The resource to unload. + /// + void UnloadResource(IResource resource); } diff --git a/FinalEngine.Resources/ResourceLoaderBase.cs b/FinalEngine.Resources/ResourceLoaderBase.cs index 814712f2..f547c3b3 100644 --- a/FinalEngine.Resources/ResourceLoaderBase.cs +++ b/FinalEngine.Resources/ResourceLoaderBase.cs @@ -6,9 +6,33 @@ namespace FinalEngine.Resources; using System; +/// +/// Provides an abstract class used to load resources of the specified type. +/// +/// +/// +/// The type of the resource to load. +/// +/// +/// +/// You should implement this interface if there is a resource type you wish to load via an . Please note that the implementation should (usually) be able to function without a resource manager. +/// +/// +/// public abstract class ResourceLoaderBase : IResourceLoaderInternal where TResource : IResource { + /// + /// Loads a resource from the specified . + /// + /// + /// + /// The file path of the resource to load. + /// + /// + /// + /// The loaded resource, of type . + /// public abstract TResource LoadResource(string filePath); IResource IResourceLoaderInternal.LoadResource(string filePath) diff --git a/FinalEngine.Resources/ResourceManager.cs b/FinalEngine.Resources/ResourceManager.cs index 0efef308..5a936b49 100644 --- a/FinalEngine.Resources/ResourceManager.cs +++ b/FinalEngine.Resources/ResourceManager.cs @@ -9,6 +9,11 @@ namespace FinalEngine.Resources; using System.Linq; using FinalEngine.Resources.Exceptions; +/// +/// Provides a standard implementation of an . +/// +/// +/// public class ResourceManager : IResourceManager { private static IResourceManager? instance; @@ -17,17 +22,30 @@ public class ResourceManager : IResourceManager private readonly Dictionary typeToLoaderMap; + /// + /// Initializes a new instance of the class. + /// public ResourceManager() { this.typeToLoaderMap = []; this.pathToResourceDataMap = []; } + /// + /// Finalizes an instance of the class. + /// ~ResourceManager() { this.Dispose(false); } + /// + /// Gets the instance. + /// + /// + /// + /// The instance. + /// public static IResourceManager Instance { get @@ -36,14 +54,54 @@ public static IResourceManager Instance } } + /// + /// Gets a value indicating whether this is disposed. + /// + /// + /// + /// true if this instance is disposed; otherwise, false. + /// protected bool IsDisposed { get; private set; } + /// + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + /// public void Dispose() { this.Dispose(true); GC.SuppressFinalize(this); } + /// + /// Loads a resource at the specified . + /// + /// + /// The type of resource to load. + /// + /// + /// + /// The file path of the resource to load. + /// + /// + /// + /// The typical implementation of should attempt to cache resources; this way if is called for the same file a reference the already loaded resource can be fetched. + /// + /// + /// + /// The loaded resource, of type . + /// + /// + /// + /// The specified parameter does not have an associated registered loader. You should call on the resource type you wish to load. + /// + /// + /// + /// The has been disposed. + /// + /// + /// + /// The specified parameter cannot be null, empty or consist of only whitespace characters. + /// public T LoadResource(string filePath) where T : IResource { @@ -66,6 +124,29 @@ public T LoadResource(string filePath) return (T)resourceData.Reference; } + /// + /// Registers the specified to this . + /// + /// + /// + /// The type of resource that can be loaded. + /// + /// + /// + /// The resource loader to be used when attempting to resolve a resource of type . + /// + /// + /// + /// The typical implementation of an should likely throw a if a loader of the specified type has already been registered. + /// + /// + /// + /// The has been disposed. + /// + /// + /// + /// The specified parameter cannot be null. + /// public void RegisterLoader(ResourceLoaderBase loader) where T : IResource { @@ -80,7 +161,22 @@ public void RegisterLoader(ResourceLoaderBase loader) this.typeToLoaderMap.Add(typeof(T), loader); } - public void UnloadResource(IResource? resource) + /// + /// Unloads the specified from this (calling it's dispose method if is implemented and there are no references). + /// + /// + /// + /// The resource to unload. + /// + /// + /// + /// The has been disposed. + /// + /// + /// + /// The specified parameter cannot be null. + /// + public void UnloadResource(IResource resource) { ObjectDisposedException.ThrowIf(this.IsDisposed, this); ArgumentNullException.ThrowIfNull(resource, nameof(resource)); @@ -107,6 +203,13 @@ public void UnloadResource(IResource? resource) } } + /// + /// Releases unmanaged and - optionally - managed resources. + /// + /// + /// + /// true to release both managed and unmanaged resources; false to release only unmanaged resources. + /// protected virtual void Dispose(bool disposing) { if (this.IsDisposed) diff --git a/FinalEngine.Tests/Rendering/Geometry/MeshTests.cs b/FinalEngine.Tests/Rendering/Geometry/MeshTests.cs index 355922db..17b88661 100644 --- a/FinalEngine.Tests/Rendering/Geometry/MeshTests.cs +++ b/FinalEngine.Tests/Rendering/Geometry/MeshTests.cs @@ -1,265 +1,265 @@ -// -// Copyright (c) Software Antics. All rights reserved. -// - -namespace FinalEngine.Tests.Rendering.Geometry; - -using System; -using System.Collections.Generic; -using System.Numerics; -using FinalEngine.Rendering; -using FinalEngine.Rendering.Buffers; -using FinalEngine.Rendering.Geometry; -using FinalEngine.Rendering.Primitives; -using Moq; -using NUnit.Framework; - -[TestFixture] -public sealed class MeshTests -{ - private Mock factory; - - private Mock indexBuffer; - - private int[] indices; - - private Mock inputAssembler; - - private Mock inputLayout; - - private Mesh mesh; - - private Mock renderDevice; - - private Mock vertexBuffer; - - private MeshVertex[] vertices; - - [Test] - public void BindShouldInvokeSetIndexBufferWhenInvoked() - { - // Act - this.mesh.Bind(this.inputAssembler.Object); - - // Assert - this.inputAssembler.Verify(x => x.SetIndexBuffer(this.indexBuffer.Object), Times.Once); - } - - [Test] - public void BindShouldInvokeSetInputLayoutWhenInvoked() - { - // Act - this.mesh.Bind(this.inputAssembler.Object); - - // Assert - this.inputAssembler.Verify(x => x.SetInputLayout(this.inputLayout.Object), Times.Once); - } - - [Test] - public void BindShouldInvokeSetVertexBufferWhenInvoked() - { - // Act - this.mesh.Bind(this.inputAssembler.Object); - - // Assert - this.inputAssembler.Verify(x => x.SetVertexBuffer(this.vertexBuffer.Object), Times.Once); - } - - [Test] - public void BindShouldThrowArgumentNullExceptionWhenInputAssemblerIsNull() - { - // Act and assert - Assert.Throws(() => - { - this.mesh.Bind(null); - }); - } - - [Test] - public void BindShouldThrowObjectDisposedExceptionWhenDisposed() - { - // Arrange - this.mesh.Dispose(); - - // Act and assert - Assert.Throws(() => - { - this.mesh.Bind(this.inputAssembler.Object); - }); - } - - [Test] - public void ConstructorShouldInvokeCreateIndexBufferWhenInvoked() - { - // Assert - this.factory.Verify(x => x.CreateIndexBuffer(BufferUsageType.Static, this.indices, this.indices.Length * sizeof(int)), Times.Once); - } - - [Test] - public void ConstructorShouldInvokeCreateInputLayoutWhenInvoked() - { - // Assert - this.factory.Verify(x => x.CreateInputLayout(MeshVertex.InputElements), Times.Once); - } - - [Test] - public void ConstructorShouldInvokeCreateVertexBufferWhenInvoked() - { - // Assert - this.factory.Verify(x => x.CreateVertexBuffer(BufferUsageType.Static, this.vertices, this.vertices.Length * MeshVertex.SizeInBytes, MeshVertex.SizeInBytes), Times.Once); - } - - [Test] - public void ConstructorShouldThrowArgumentNullExceptionWhenFactoryIsNull() - { - // Act and assert - Assert.Throws(() => - { - new Mesh(null, Array.Empty(), Array.Empty()); - }); - } - - [Test] - public void ConstructorShouldThrowArgumentNullExceptionWhenIndicesIsNull() - { - // Act and assert - Assert.Throws(() => - { - new Mesh(this.factory.Object, Array.Empty(), null); - }); - } - - [Test] - public void ConstructorShouldThrowArgumentNullExceptionWhenVerticesIsNull() - { - // Act and assert - Assert.Throws(() => - { - new Mesh(this.factory.Object, null, Array.Empty()); - }); - } - - [Test] - public void DisposeShouldInvokeIndexBufferDisposeWhenNotDisposed() - { - // Act - this.mesh.Dispose(); - - // Assert - this.indexBuffer.Verify(x => x.Dispose(), Times.Once); - } - - [Test] - public void DisposeShouldInvokeVertexBufferDisposeWhenNotDisposed() - { - // Act - this.mesh.Dispose(); - - // Assert - this.vertexBuffer.Verify(x => x.Dispose(), Times.Once); - } - - [Test] - public void DisposeShouldNotInvokeIndexBufferDisposeWhenAlreadyDisposed() - { - // Arrange - this.mesh.Dispose(); - - // Act - this.mesh.Dispose(); - - // Assert - this.indexBuffer.Verify(x => x.Dispose(), Times.Once); - } - - [Test] - public void DisposeShouldNotInvokeVertexBufferDisposeWhenAlreadyDisposed() - { - // Arrange - this.mesh.Dispose(); - - // Act - this.mesh.Dispose(); - - // Assert - this.vertexBuffer.Verify(x => x.Dispose(), Times.Once); - } - - [Test] - public void DrawShouldInvokeDrawIndicesWhenInvoked() - { - // Act - this.mesh.Draw(this.renderDevice.Object); - - // Assert - this.renderDevice.Verify(x => x.DrawIndices(PrimitiveTopology.Triangle, 0, this.indices.Length), Times.Once); - } - - [Test] - public void DrawShouldThrowArgumentNullExceptionWhenRenderDeviceIsNull() - { - // Act and assert - Assert.Throws(() => - { - this.mesh.Draw(null); - }); - } - - [Test] - public void DrawShouldThrowObjectDisposedExceptionWhenDisposed() - { - // Arrange - this.mesh.Dispose(); - - // Act and assert - Assert.Throws(() => - { - this.mesh.Draw(this.renderDevice.Object); - }); - } - - [SetUp] - public void Setup() - { - this.factory = new Mock(); - this.renderDevice = new Mock(); - this.inputAssembler = new Mock(); - this.vertexBuffer = new Mock(); - this.indexBuffer = new Mock(); - this.inputLayout = new Mock(); - - this.vertices = new MeshVertex[] - { - new MeshVertex() - { - Position = new Vector3(-1, -1, 0), - TextureCoordinate = new Vector2(0, 0), - }, - - new MeshVertex() - { - Position = new Vector3(1, -1, 0), - TextureCoordinate = new Vector2(1, 0), - }, - - new MeshVertex() - { - Position = new Vector3(0, 1, 0), - TextureCoordinate = new Vector2(0.5f, 1), - }, - }; - - this.indices = new int[] - { - 0, 1, 2, - }; - - this.indexBuffer.Setup(x => x.Length).Returns(this.indices.Length); - - this.factory.Setup(x => x.CreateIndexBuffer(It.IsAny(), It.IsAny>(), It.IsAny())).Returns(this.indexBuffer.Object); - this.factory.Setup(x => x.CreateVertexBuffer(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny())).Returns(this.vertexBuffer.Object); - this.factory.Setup(x => x.CreateInputLayout(It.IsAny>())).Returns(this.inputLayout.Object); - - this.mesh = new Mesh(this.factory.Object, this.vertices, this.indices); - } -} +////// +////// Copyright (c) Software Antics. All rights reserved. +////// + +////namespace FinalEngine.Tests.Rendering.Geometry; + +////using System; +////using System.Collections.Generic; +////using System.Numerics; +////using FinalEngine.Rendering; +////using FinalEngine.Rendering.Buffers; +////using FinalEngine.Rendering.Geometry; +////using FinalEngine.Rendering.Primitives; +////using Moq; +////using NUnit.Framework; + +////[TestFixture] +////public sealed class MeshTests +////{ +//// private Mock factory; + +//// private Mock indexBuffer; + +//// private int[] indices; + +//// private Mock inputAssembler; + +//// private Mock inputLayout; + +//// private Mesh mesh; + +//// private Mock renderDevice; + +//// private Mock vertexBuffer; + +//// private MeshVertex[] vertices; + +//// [Test] +//// public void BindShouldInvokeSetIndexBufferWhenInvoked() +//// { +//// // Act +//// this.mesh.Bind(this.inputAssembler.Object); + +//// // Assert +//// this.inputAssembler.Verify(x => x.SetIndexBuffer(this.indexBuffer.Object), Times.Once); +//// } + +//// [Test] +//// public void BindShouldInvokeSetInputLayoutWhenInvoked() +//// { +//// // Act +//// this.mesh.Bind(this.inputAssembler.Object); + +//// // Assert +//// this.inputAssembler.Verify(x => x.SetInputLayout(this.inputLayout.Object), Times.Once); +//// } + +//// [Test] +//// public void BindShouldInvokeSetVertexBufferWhenInvoked() +//// { +//// // Act +//// this.mesh.Bind(this.inputAssembler.Object); + +//// // Assert +//// this.inputAssembler.Verify(x => x.SetVertexBuffer(this.vertexBuffer.Object), Times.Once); +//// } + +//// [Test] +//// public void BindShouldThrowArgumentNullExceptionWhenInputAssemblerIsNull() +//// { +//// // Act and assert +//// Assert.Throws(() => +//// { +//// this.mesh.Bind(null); +//// }); +//// } + +//// [Test] +//// public void BindShouldThrowObjectDisposedExceptionWhenDisposed() +//// { +//// // Arrange +//// this.mesh.Dispose(); + +//// // Act and assert +//// Assert.Throws(() => +//// { +//// this.mesh.Bind(this.inputAssembler.Object); +//// }); +//// } + +//// [Test] +//// public void ConstructorShouldInvokeCreateIndexBufferWhenInvoked() +//// { +//// // Assert +//// this.factory.Verify(x => x.CreateIndexBuffer(BufferUsageType.Static, this.indices, this.indices.Length * sizeof(int)), Times.Once); +//// } + +//// [Test] +//// public void ConstructorShouldInvokeCreateInputLayoutWhenInvoked() +//// { +//// // Assert +//// this.factory.Verify(x => x.CreateInputLayout(MeshVertex.InputElements), Times.Once); +//// } + +//// [Test] +//// public void ConstructorShouldInvokeCreateVertexBufferWhenInvoked() +//// { +//// // Assert +//// this.factory.Verify(x => x.CreateVertexBuffer(BufferUsageType.Static, this.vertices, this.vertices.Length * MeshVertex.SizeInBytes, MeshVertex.SizeInBytes), Times.Once); +//// } + +//// [Test] +//// public void ConstructorShouldThrowArgumentNullExceptionWhenFactoryIsNull() +//// { +//// // Act and assert +//// Assert.Throws(() => +//// { +//// new Mesh(null, Array.Empty(), Array.Empty()); +//// }); +//// } + +//// [Test] +//// public void ConstructorShouldThrowArgumentNullExceptionWhenIndicesIsNull() +//// { +//// // Act and assert +//// Assert.Throws(() => +//// { +//// new Mesh(this.factory.Object, Array.Empty(), null); +//// }); +//// } + +//// [Test] +//// public void ConstructorShouldThrowArgumentNullExceptionWhenVerticesIsNull() +//// { +//// // Act and assert +//// Assert.Throws(() => +//// { +//// new Mesh(this.factory.Object, null, Array.Empty()); +//// }); +//// } + +//// [Test] +//// public void DisposeShouldInvokeIndexBufferDisposeWhenNotDisposed() +//// { +//// // Act +//// this.mesh.Dispose(); + +//// // Assert +//// this.indexBuffer.Verify(x => x.Dispose(), Times.Once); +//// } + +//// [Test] +//// public void DisposeShouldInvokeVertexBufferDisposeWhenNotDisposed() +//// { +//// // Act +//// this.mesh.Dispose(); + +//// // Assert +//// this.vertexBuffer.Verify(x => x.Dispose(), Times.Once); +//// } + +//// [Test] +//// public void DisposeShouldNotInvokeIndexBufferDisposeWhenAlreadyDisposed() +//// { +//// // Arrange +//// this.mesh.Dispose(); + +//// // Act +//// this.mesh.Dispose(); + +//// // Assert +//// this.indexBuffer.Verify(x => x.Dispose(), Times.Once); +//// } + +//// [Test] +//// public void DisposeShouldNotInvokeVertexBufferDisposeWhenAlreadyDisposed() +//// { +//// // Arrange +//// this.mesh.Dispose(); + +//// // Act +//// this.mesh.Dispose(); + +//// // Assert +//// this.vertexBuffer.Verify(x => x.Dispose(), Times.Once); +//// } + +//// [Test] +//// public void DrawShouldInvokeDrawIndicesWhenInvoked() +//// { +//// // Act +//// this.mesh.Draw(this.renderDevice.Object); + +//// // Assert +//// this.renderDevice.Verify(x => x.DrawIndices(PrimitiveTopology.Triangle, 0, this.indices.Length), Times.Once); +//// } + +//// [Test] +//// public void DrawShouldThrowArgumentNullExceptionWhenRenderDeviceIsNull() +//// { +//// // Act and assert +//// Assert.Throws(() => +//// { +//// this.mesh.Draw(null); +//// }); +//// } + +//// [Test] +//// public void DrawShouldThrowObjectDisposedExceptionWhenDisposed() +//// { +//// // Arrange +//// this.mesh.Dispose(); + +//// // Act and assert +//// Assert.Throws(() => +//// { +//// this.mesh.Draw(this.renderDevice.Object); +//// }); +//// } + +//// [SetUp] +//// public void Setup() +//// { +//// this.factory = new Mock(); +//// this.renderDevice = new Mock(); +//// this.inputAssembler = new Mock(); +//// this.vertexBuffer = new Mock(); +//// this.indexBuffer = new Mock(); +//// this.inputLayout = new Mock(); + +//// this.vertices = new MeshVertex[] +//// { +//// new MeshVertex() +//// { +//// Position = new Vector3(-1, -1, 0), +//// TextureCoordinate = new Vector2(0, 0), +//// }, + +//// new MeshVertex() +//// { +//// Position = new Vector3(1, -1, 0), +//// TextureCoordinate = new Vector2(1, 0), +//// }, + +//// new MeshVertex() +//// { +//// Position = new Vector3(0, 1, 0), +//// TextureCoordinate = new Vector2(0.5f, 1), +//// }, +//// }; + +//// this.indices = new int[] +//// { +//// 0, 1, 2, +//// }; + +//// this.indexBuffer.Setup(x => x.Length).Returns(this.indices.Length); + +//// this.factory.Setup(x => x.CreateIndexBuffer(It.IsAny(), It.IsAny>(), It.IsAny())).Returns(this.indexBuffer.Object); +//// this.factory.Setup(x => x.CreateVertexBuffer(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny())).Returns(this.vertexBuffer.Object); +//// this.factory.Setup(x => x.CreateInputLayout(It.IsAny>())).Returns(this.inputLayout.Object); + +//// this.mesh = new Mesh(this.factory.Object, this.vertices, this.indices); +//// } +////} diff --git a/FinalEngine.Tests/Rendering/OpenGL/OpenGLPipelineTests.cs b/FinalEngine.Tests/Rendering/OpenGL/OpenGLPipelineTests.cs index 161604c1..6a55433d 100644 --- a/FinalEngine.Tests/Rendering/OpenGL/OpenGLPipelineTests.cs +++ b/FinalEngine.Tests/Rendering/OpenGL/OpenGLPipelineTests.cs @@ -1,740 +1,740 @@ -// -// Copyright (c) Software Antics. All rights reserved. -// - -namespace FinalEngine.Tests.Rendering.OpenGL; - -using System; -using System.Numerics; -using FinalEngine.Rendering.OpenGL; -using FinalEngine.Rendering.OpenGL.Invocation; -using FinalEngine.Rendering.OpenGL.Pipeline; -using FinalEngine.Rendering.OpenGL.Textures; -using FinalEngine.Rendering.Pipeline; -using FinalEngine.Rendering.Textures; -using Moq; -using NUnit.Framework; -using OpenTK.Graphics.OpenGL4; - -public class OpenGLPipelineTests -{ - private Mock invoker; - - private OpenGLPipeline pipeline; - - [Test] - public void ConstructorShouldThrowArgumentNullExceptionWhenInvokerIsNull() - { - // Arrange, act and assert - Assert.Throws(() => - { - new OpenGLPipeline(null); - }); - } - - [Test] - public void MaxTextureSlotsShouldInvokeGetIntegerWhenInvoked() - { - // Act - _ = this.pipeline.MaxTextureSlots; - - // Assert - this.invoker.Verify(x => x.GetInteger(GetPName.MaxTextureImageUnits), Times.Once); - } - - [Test] - public void MaxTextureSlotsShouldReturnSameAsGetIntegerWhenInvoked() - { - // Arrange - const int expected = 10; - this.invoker.Setup(x => x.GetInteger(GetPName.MaxTextureImageUnits)).Returns(expected); - - // Act - int actual = this.pipeline.MaxTextureSlots; - - // Assert - Assert.AreEqual(expected, actual); - } - - [Test] - public void SetShaderProgramShouldInvokeProgramBindWhenProgramIsOpenGLShaderProgram() - { - // Arrange - var program = new Mock(); - - // Act - this.pipeline.SetShaderProgram(program.Object); - - // Assert - program.Verify(x => x.Bind(), Times.Once); - } - - [Test] - public void SetShaderProgramShouldThrowArgumentNullExceptionWhenProgramIsNotOpenGLShaderProgram() - { - // Arrange - var program = new Mock(); - - // Act and assert - Assert.Throws(() => - { - this.pipeline.SetShaderProgram(program.Object); - }); - } - - [Test] - public void SetShaderProgramShouldThrowArgumentNullExceptionWhenProgramIsNull() - { - // Act and assert - Assert.Throws(() => - { - this.pipeline.SetShaderProgram(null); - }); - } - - [Test] - public void SetTextureShouldInvokeBindWhenInvoked() - { - // Arrange - var texture = new Mock(); - - // Act - this.pipeline.SetTexture(texture.Object); - - // Assert - texture.Verify(x => x.Bind(0), Times.Once); - } - - [Test] - public void SetTextureShouldThrowArgumentExceptionWhenTextureIsNotIOpenGLTexture() - { - // Act and assert - Assert.Throws(() => - { - this.pipeline.SetTexture(new Mock().Object); - }); - } - - [Test] - public void SetTextureShouldThrowArgumentNullExceptionWhenTextureIsNull() - { - // Act and assert - Assert.Throws(() => - { - this.pipeline.SetTexture(null); - }); - } - - [Test] - public void SetUniformBoolShouldInvokeUniform1WithOneAsParameterWhenGetUniformLocationReturnsPositiveInteger() - { - // Arrange - var program = new Mock(); - program.Setup(x => x.GetUniformLocation(It.IsAny())).Returns(0); - - this.pipeline.SetShaderProgram(program.Object); - - // Act - this.pipeline.SetUniform("name", true); - - // Assert - this.invoker.Verify(x => x.Uniform1(0, 1), Times.Once); - } - - [Test] - public void SetUniformBoolShouldInvokeUniform1WithZeroAsParameterWhenGetUniformLocationReturnsPositiveInteger() - { - // Arrange - var program = new Mock(); - program.Setup(x => x.GetUniformLocation(It.IsAny())).Returns(0); - - this.pipeline.SetShaderProgram(program.Object); - - // Act - this.pipeline.SetUniform("name", false); - - // Assert - this.invoker.Verify(x => x.Uniform1(0, 0), Times.Once); - } - - [Test] - public void SetUniformBoolShouldNotInvokeUniform1WhenBoundProgramIsNull() - { - // Act - this.pipeline.SetUniform("name", true); - - // Assert - this.invoker.Verify(x => x.Uniform1(0, 1), Times.Never); - } - - [Test] - public void SetUniformBoolShouldNotInvokeUniform1WhenUniformLocationNotFound() - { - // Arrange - var program = new Mock(); - program.Setup(x => x.GetUniformLocation(It.IsAny())).Returns(-1); - this.pipeline.SetShaderProgram(program.Object); - - // Act - this.pipeline.SetUniform("name", false); - - // Assert - this.invoker.Verify(x => x.GetUniformLocation(It.IsAny(), It.IsAny()), Times.Never); - } - - [Test] - public void SetUniformBoolShouldThrowArgumentExceptionWhenNameIsEmpty() - { - // Act and assert - Assert.Throws(() => - { - this.pipeline.SetUniform(string.Empty, true); - }); - } - - [Test] - public void SetUniformBoolShouldThrowArgumentExceptionWhenNameIsWhitespace() - { - // Act and assert - Assert.Throws(() => - { - this.pipeline.SetUniform("\t\r\n", true); - }); - } - - [Test] - public void SetUniformBoolShouldThrowArgumentNullExceptionWhenNameIsNull() - { - // Act and assert - Assert.Throws(() => - { - this.pipeline.SetUniform(null, true); - }); - } - - [Test] - public void SetUniformDoubleShouldInvokeUniform1WhenGetUniformLocationReturnsPositiveInteger() - { - // Arrange - var program = new Mock(); - program.Setup(x => x.GetUniformLocation(It.IsAny())).Returns(0); - - this.pipeline.SetShaderProgram(program.Object); - - // Act - this.pipeline.SetUniform("name", 0.0d); - - // Assert - this.invoker.Verify(x => x.Uniform1(0, 0.0d), Times.Once); - } - - [Test] - public void SetUniformDoubleShouldNotInvokeUniform1WhenBoundProgramIsNull() - { - // Act - this.pipeline.SetUniform("name", 0.0d); - - // Assert - this.invoker.Verify(x => x.Uniform1(0, 0.0d), Times.Never); - } - - [Test] - public void SetUniformDoubleShouldNotInvokeUniform1WhenUniformLocationNotFound() - { - // Arrange - var program = new Mock(); - program.Setup(x => x.GetUniformLocation(It.IsAny())).Returns(-1); - this.pipeline.SetShaderProgram(program.Object); - - // Act - this.pipeline.SetUniform("name", 0.0d); - - // Assert - this.invoker.Verify(x => x.GetUniformLocation(It.IsAny(), It.IsAny()), Times.Never); - } - - [Test] - public void SetUniformDoubleShouldThrowArgumentExceptionWhenNameIsEmpty() - { - // Act and assert - Assert.Throws(() => - { - this.pipeline.SetUniform(string.Empty, 0.0d); - }); - } - - [Test] - public void SetUniformDoubleShouldThrowArgumentExceptionWhenNameIsWhitespace() - { - // Act and assert - Assert.Throws(() => - { - this.pipeline.SetUniform("\t\r\n", 0.0d); - }); - } - - [Test] - public void SetUniformDoubleShouldThrowArgumentNullExceptionWhenNameIsNull() - { - // Act and assert - Assert.Throws(() => - { - this.pipeline.SetUniform(null, 0.0d); - }); - } - - [Test] - public void SetUniformFloatShouldInvokeUniform1WhenGetUniformLocationReturnsPositiveInteger() - { - // Arrange - var program = new Mock(); - program.Setup(x => x.GetUniformLocation(It.IsAny())).Returns(0); - - this.pipeline.SetShaderProgram(program.Object); - - // Act - this.pipeline.SetUniform("name", 1.0f); - - // Assert - this.invoker.Verify(x => x.Uniform1(0, 1.0f), Times.Once); - } - - [Test] - public void SetUniformFloatShouldNotInvokeUniform1WhenBoundProgramIsNull() - { - // Act - this.pipeline.SetUniform("name", 1.0f); - - // Assert - this.invoker.Verify(x => x.Uniform1(0, 1.0f), Times.Never); - } - - [Test] - public void SetUniformFloatShouldNotInvokeUniform1WhenUniformLocationNotFound() - { - // Arrange - var program = new Mock(); - program.Setup(x => x.GetUniformLocation(It.IsAny())).Returns(-1); - this.pipeline.SetShaderProgram(program.Object); - - // Act - this.pipeline.SetUniform("name", 0.0f); - - // Assert - this.invoker.Verify(x => x.GetUniformLocation(It.IsAny(), It.IsAny()), Times.Never); - } - - [Test] - public void SetUniformFloatShouldThrowArgumentExceptionWhenNameIsEmpty() - { - // Act and assert - Assert.Throws(() => - { - this.pipeline.SetUniform(string.Empty, 1.0f); - }); - } - - [Test] - public void SetUniformFloatShouldThrowArgumentExceptionWhenNameIsWhitespace() - { - // Act and assert - Assert.Throws(() => - { - this.pipeline.SetUniform("\t\r\n", 1.0f); - }); - } - - [Test] - public void SetUniformFloatShouldThrowArgumentNullExceptionWhenNameIsNull() - { - // Act and assert - Assert.Throws(() => - { - this.pipeline.SetUniform(null, 1.0f); - }); - } - - [Test] - public void SetUniformIntegerShouldNotInvokeUniform1WhenUniformLocationNotFound() - { - // Arrange - var program = new Mock(); - program.Setup(x => x.GetUniformLocation(It.IsAny())).Returns(-1); - this.pipeline.SetShaderProgram(program.Object); - - // Act - this.pipeline.SetUniform("name", 0); - - // Assert - this.invoker.Verify(x => x.GetUniformLocation(It.IsAny(), It.IsAny()), Times.Never); - } - - [Test] - public void SetUniformIntShouldInvokeUniform1WhenGetUniformLocationReturnsPositiveInteger() - { - // Arrange - var program = new Mock(); - program.Setup(x => x.GetUniformLocation(It.IsAny())).Returns(0); - - this.pipeline.SetShaderProgram(program.Object); - - // Act - this.pipeline.SetUniform("name", 0); - - // Assert - this.invoker.Verify(x => x.Uniform1(0, 0), Times.Once); - } - - [Test] - public void SetUniformIntShouldNotInvokeUniform1WhenBoundProgramIsNull() - { - // Act - this.pipeline.SetUniform("name", 0); - - // Assert - this.invoker.Verify(x => x.Uniform1(0, 0), Times.Never); - } - - [Test] - public void SetUniformIntShouldThrowArgumentExceptionWhenNameIsEmpty() - { - // Act and assert - Assert.Throws(() => - { - this.pipeline.SetUniform(string.Empty, 0); - }); - } - - [Test] - public void SetUniformIntShouldThrowArgumentExceptionWhenNameIsWhitespace() - { - // Act and assert - Assert.Throws(() => - { - this.pipeline.SetUniform("\t\r\n", 0); - }); - } - - [Test] - public void SetUniformIntShouldThrowArgumentNullExceptionWhenNameIsNull() - { - // Act and assert - Assert.Throws(() => - { - this.pipeline.SetUniform(null, 0); - }); - } - - [Test] - public void SetUniformMatrix4ShouldNotInvokeUniformMatrix4WhenUniformLocationNotFound() - { - // Arrange - var program = new Mock(); - program.Setup(x => x.GetUniformLocation(It.IsAny())).Returns(-1); - this.pipeline.SetShaderProgram(program.Object); - - // Act - this.pipeline.SetUniform("name", Matrix4x4.Identity); - - // Assert - this.invoker.Verify(x => x.GetUniformLocation(It.IsAny(), It.IsAny()), Times.Never); - } - - [Test] - public void SetUniformMatrix4x4ShouldInvokeUniformMatrix4WhenGetUniformLocationReturnsPositiveInteger() - { - // Arrange - var program = new Mock(); - program.Setup(x => x.GetUniformLocation(It.IsAny())).Returns(0); - - this.pipeline.SetShaderProgram(program.Object); - - var value = Matrix4x4.Identity; - - float[] values = - { - value.M11, value.M12, value.M13, value.M14, - value.M21, value.M22, value.M23, value.M24, - value.M31, value.M32, value.M33, value.M34, - value.M41, value.M42, value.M43, value.M44, - }; - - // Act - this.pipeline.SetUniform("name", Matrix4x4.Identity); - - // Assert - this.invoker.Verify(x => x.UniformMatrix4(0, 1, false, values), Times.Once); - } - - [Test] - public void SetUniformMatrix4x4ShouldNotInvokeUniformMatrix4WhenBoundProgramIsNull() - { - // Arrange - var value = Matrix4x4.Identity; - - float[] values = - { - value.M11, value.M12, value.M13, value.M14, - value.M21, value.M22, value.M23, value.M24, - value.M31, value.M32, value.M33, value.M34, - value.M41, value.M42, value.M43, value.M44, - }; - - // Act - this.pipeline.SetUniform("name", Matrix4x4.Identity); - - // Assert - this.invoker.Verify(x => x.UniformMatrix4(0, 1, false, values), Times.Never); - } - - [Test] - public void SetUniformMatrix4x4ShouldThrowArgumentExceptionWhenNameIsEmpty() - { - // Act and assert - Assert.Throws(() => - { - this.pipeline.SetUniform(string.Empty, Matrix4x4.Identity); - }); - } - - [Test] - public void SetUniformMatrix4x4ShouldThrowArgumentExceptionWhenNameIsWhitespace() - { - // Act and assert - Assert.Throws(() => - { - this.pipeline.SetUniform("\t\r\n", Matrix4x4.Identity); - }); - } - - [Test] - public void SetUniformMatrix4x4ShouldThrowArgumentNullExceptionWhenNameIsNull() - { - // Act and assert - Assert.Throws(() => - { - this.pipeline.SetUniform(null, Matrix4x4.Identity); - }); - } - - [Test] - public void SetUniformVector2ShouldInvokeUniform2WhenGetUniformLocationReturnsPositiveInteger() - { - // Arrange - var program = new Mock(); - program.Setup(x => x.GetUniformLocation(It.IsAny())).Returns(0); - - this.pipeline.SetShaderProgram(program.Object); - - // Act - this.pipeline.SetUniform("name", new Vector2(1.0f, 0.0f)); - - // Assert - this.invoker.Verify(x => x.Uniform2(0, 1.0f, 0.0f), Times.Once); - } - - [Test] - public void SetUniformVector2ShouldNotInvokeUniform2WhenBoundProgramIsNull() - { - // Act - this.pipeline.SetUniform("name", new Vector2(1.0f, 0.0f)); - - // Assert - this.invoker.Verify(x => x.Uniform2(0, 1.0f, 0.0f), Times.Never); - } - - [Test] - public void SetUniformVector2ShouldNotInvokeUniform2WhenUniformLocationNotFound() - { - // Arrange - var program = new Mock(); - program.Setup(x => x.GetUniformLocation(It.IsAny())).Returns(-1); - this.pipeline.SetShaderProgram(program.Object); - - // Act - this.pipeline.SetUniform("name", Vector2.Zero); - - // Assert - this.invoker.Verify(x => x.GetUniformLocation(It.IsAny(), It.IsAny()), Times.Never); - } - - [Test] - public void SetUniformVector2ShouldThrowArgumentExceptionWhenNameIsEmpty() - { - // Act and assert - Assert.Throws(() => - { - this.pipeline.SetUniform(string.Empty, new Vector2(1.0f, 0.0f)); - }); - } - - [Test] - public void SetUniformVector2ShouldThrowArgumentExceptionWhenNameIsWhitespace() - { - // Act and assert - Assert.Throws(() => - { - this.pipeline.SetUniform("\t\r\n", new Vector2(1.0f, 0.0f)); - }); - } - - [Test] - public void SetUniformVector2ShouldThrowArgumentNullExceptionWhenNameIsNull() - { - // Act and assert - Assert.Throws(() => - { - this.pipeline.SetUniform(null, new Vector2(1.0f, 0.0f)); - }); - } - - [Test] - public void SetUniformVector3ShouldInvokeUniform3WhenGetUniformLocationReturnsPositiveInteger() - { - // Arrange - var program = new Mock(); - program.Setup(x => x.GetUniformLocation(It.IsAny())).Returns(0); - - this.pipeline.SetShaderProgram(program.Object); - - // Act - this.pipeline.SetUniform("name", new Vector3(1.0f, 0.0f, 1.0f)); - - // Assert - this.invoker.Verify(x => x.Uniform3(0, 1.0f, 0.0f, 1.0f), Times.Once); - } - - [Test] - public void SetUniformVector3ShouldNotInvokeUniform3WhenBoundProgramIsNull() - { - // Act - this.pipeline.SetUniform("name", new Vector3(1.0f, 0.0f, 1.0f)); - - // Assert - this.invoker.Verify(x => x.Uniform3(0, 1.0f, 0.0f, 1.0f), Times.Never); - } - - [Test] - public void SetUniformVector3ShouldNotInvokeUniform3WhenUniformLocationNotFound() - { - // Arrange - var program = new Mock(); - program.Setup(x => x.GetUniformLocation(It.IsAny())).Returns(-1); - this.pipeline.SetShaderProgram(program.Object); - - // Act - this.pipeline.SetUniform("name", Vector3.Zero); - - // Assert - this.invoker.Verify(x => x.GetUniformLocation(It.IsAny(), It.IsAny()), Times.Never); - } - - [Test] - public void SetUniformVector3ShouldThrowArgumentExceptionWhenNameIsEmpty() - { - // Act and assert - Assert.Throws(() => - { - this.pipeline.SetUniform(string.Empty, new Vector3(1.0f, 0.0f, 1.0f)); - }); - } - - [Test] - public void SetUniformVector3ShouldThrowArgumentExceptionWhenNameIsWhitespace() - { - // Act and assert - Assert.Throws(() => - { - this.pipeline.SetUniform("\t\r\n", new Vector3(1.0f, 0.0f, 1.0f)); - }); - } - - [Test] - public void SetUniformVector3ShouldThrowArgumentNullExceptionWhenNameIsNull() - { - // Act and assert - Assert.Throws(() => - { - this.pipeline.SetUniform(null, new Vector3(1.0f, 0.0f, 1.0f)); - }); - } - - [Test] - public void SetUniformVector4ShouldInvokeUniform4WhenGetUniformLocationReturnsPositiveInteger() - { - // Arrange - var program = new Mock(); - program.Setup(x => x.GetUniformLocation(It.IsAny())).Returns(0); - - this.pipeline.SetShaderProgram(program.Object); - - // Act - this.pipeline.SetUniform("name", new Vector4(1.0f, 0.0f, 1.0f, 1.0f)); - - // Assert - this.invoker.Verify(x => x.Uniform4(0, 1.0f, 0.0f, 1.0f, 1.0f), Times.Once); - } - - [Test] - public void SetUniformVector4ShouldNotInvokeUniform4WhenBoundProgramIsNull() - { - // Act - this.pipeline.SetUniform("name", new Vector4(1.0f, 0.0f, 1.0f, 1.0f)); - - // Assert - this.invoker.Verify(x => x.Uniform4(0, 1.0f, 0.0f, 1.0f, 1.0f), Times.Never); - } - - [Test] - public void SetUniformVector4ShouldNotInvokeUniform4WhenUniformLocationNotFound() - { - // Arrange - var program = new Mock(); - program.Setup(x => x.GetUniformLocation(It.IsAny())).Returns(-1); - this.pipeline.SetShaderProgram(program.Object); - - // Act - this.pipeline.SetUniform("name", Vector4.Zero); - - // Assert - this.invoker.Verify(x => x.GetUniformLocation(It.IsAny(), It.IsAny()), Times.Never); - } - - [Test] - public void SetUniformVector4ShouldThrowArgumentExceptionWhenNameIsEmpty() - { - // Act and assert - Assert.Throws(() => - { - this.pipeline.SetUniform(string.Empty, new Vector4(1.0f, 0.0f, 1.0f, 1.0f)); - }); - } - - [Test] - public void SetUniformVector4ShouldThrowArgumentExceptionWhenNameIsWhitespace() - { - // Act and assert - Assert.Throws(() => - { - this.pipeline.SetUniform("\t\r\n", new Vector4(1.0f, 0.0f, 1.0f, 1.0f)); - }); - } - - [Test] - public void SetUniformVector4ShouldThrowArgumentNullExceptionWhenNameIsNull() - { - // Act and assert - Assert.Throws(() => - { - this.pipeline.SetUniform(null, new Vector4(1.0f, 0.0f, 1.0f, 1.0f)); - }); - } - - [SetUp] - public void Setup() - { - // Arrange - this.invoker = new Mock(); - this.pipeline = new OpenGLPipeline(this.invoker.Object); - } -} +////// +////// Copyright (c) Software Antics. All rights reserved. +////// + +////namespace FinalEngine.Tests.Rendering.OpenGL; + +////using System; +////using System.Numerics; +////using FinalEngine.Rendering.OpenGL; +////using FinalEngine.Rendering.OpenGL.Invocation; +////using FinalEngine.Rendering.OpenGL.Pipeline; +////using FinalEngine.Rendering.OpenGL.Textures; +////using FinalEngine.Rendering.Pipeline; +////using FinalEngine.Rendering.Textures; +////using Moq; +////using NUnit.Framework; +////using OpenTK.Graphics.OpenGL4; + +////public class OpenGLPipelineTests +////{ +//// private Mock invoker; + +//// private OpenGLPipeline pipeline; + +//// [Test] +//// public void ConstructorShouldThrowArgumentNullExceptionWhenInvokerIsNull() +//// { +//// // Arrange, act and assert +//// Assert.Throws(() => +//// { +//// new OpenGLPipeline(null); +//// }); +//// } + +//// [Test] +//// public void MaxTextureSlotsShouldInvokeGetIntegerWhenInvoked() +//// { +//// // Act +//// _ = this.pipeline.MaxTextureSlots; + +//// // Assert +//// this.invoker.Verify(x => x.GetInteger(GetPName.MaxTextureImageUnits), Times.Once); +//// } + +//// [Test] +//// public void MaxTextureSlotsShouldReturnSameAsGetIntegerWhenInvoked() +//// { +//// // Arrange +//// const int expected = 10; +//// this.invoker.Setup(x => x.GetInteger(GetPName.MaxTextureImageUnits)).Returns(expected); + +//// // Act +//// int actual = this.pipeline.MaxTextureSlots; + +//// // Assert +//// Assert.AreEqual(expected, actual); +//// } + +//// [Test] +//// public void SetShaderProgramShouldInvokeProgramBindWhenProgramIsOpenGLShaderProgram() +//// { +//// // Arrange +//// var program = new Mock(); + +//// // Act +//// this.pipeline.SetShaderProgram(program.Object); + +//// // Assert +//// program.Verify(x => x.Bind(), Times.Once); +//// } + +//// [Test] +//// public void SetShaderProgramShouldThrowArgumentNullExceptionWhenProgramIsNotOpenGLShaderProgram() +//// { +//// // Arrange +//// var program = new Mock(); + +//// // Act and assert +//// Assert.Throws(() => +//// { +//// this.pipeline.SetShaderProgram(program.Object); +//// }); +//// } + +//// [Test] +//// public void SetShaderProgramShouldThrowArgumentNullExceptionWhenProgramIsNull() +//// { +//// // Act and assert +//// Assert.Throws(() => +//// { +//// this.pipeline.SetShaderProgram(null); +//// }); +//// } + +//// [Test] +//// public void SetTextureShouldInvokeBindWhenInvoked() +//// { +//// // Arrange +//// var texture = new Mock(); + +//// // Act +//// this.pipeline.SetTexture(texture.Object); + +//// // Assert +//// texture.Verify(x => x.Bind(0), Times.Once); +//// } + +//// [Test] +//// public void SetTextureShouldThrowArgumentExceptionWhenTextureIsNotIOpenGLTexture() +//// { +//// // Act and assert +//// Assert.Throws(() => +//// { +//// this.pipeline.SetTexture(new Mock().Object); +//// }); +//// } + +//// [Test] +//// public void SetTextureShouldThrowArgumentNullExceptionWhenTextureIsNull() +//// { +//// // Act and assert +//// Assert.Throws(() => +//// { +//// this.pipeline.SetTexture(null); +//// }); +//// } + +//// [Test] +//// public void SetUniformBoolShouldInvokeUniform1WithOneAsParameterWhenGetUniformLocationReturnsPositiveInteger() +//// { +//// // Arrange +//// var program = new Mock(); +//// program.Setup(x => x.GetUniformLocation(It.IsAny())).Returns(0); + +//// this.pipeline.SetShaderProgram(program.Object); + +//// // Act +//// this.pipeline.SetUniform("name", true); + +//// // Assert +//// this.invoker.Verify(x => x.Uniform1(0, 1), Times.Once); +//// } + +//// [Test] +//// public void SetUniformBoolShouldInvokeUniform1WithZeroAsParameterWhenGetUniformLocationReturnsPositiveInteger() +//// { +//// // Arrange +//// var program = new Mock(); +//// program.Setup(x => x.GetUniformLocation(It.IsAny())).Returns(0); + +//// this.pipeline.SetShaderProgram(program.Object); + +//// // Act +//// this.pipeline.SetUniform("name", false); + +//// // Assert +//// this.invoker.Verify(x => x.Uniform1(0, 0), Times.Once); +//// } + +//// [Test] +//// public void SetUniformBoolShouldNotInvokeUniform1WhenBoundProgramIsNull() +//// { +//// // Act +//// this.pipeline.SetUniform("name", true); + +//// // Assert +//// this.invoker.Verify(x => x.Uniform1(0, 1), Times.Never); +//// } + +//// [Test] +//// public void SetUniformBoolShouldNotInvokeUniform1WhenUniformLocationNotFound() +//// { +//// // Arrange +//// var program = new Mock(); +//// program.Setup(x => x.GetUniformLocation(It.IsAny())).Returns(-1); +//// this.pipeline.SetShaderProgram(program.Object); + +//// // Act +//// this.pipeline.SetUniform("name", false); + +//// // Assert +//// this.invoker.Verify(x => x.GetUniformLocation(It.IsAny(), It.IsAny()), Times.Never); +//// } + +//// [Test] +//// public void SetUniformBoolShouldThrowArgumentExceptionWhenNameIsEmpty() +//// { +//// // Act and assert +//// Assert.Throws(() => +//// { +//// this.pipeline.SetUniform(string.Empty, true); +//// }); +//// } + +//// [Test] +//// public void SetUniformBoolShouldThrowArgumentExceptionWhenNameIsWhitespace() +//// { +//// // Act and assert +//// Assert.Throws(() => +//// { +//// this.pipeline.SetUniform("\t\r\n", true); +//// }); +//// } + +//// [Test] +//// public void SetUniformBoolShouldThrowArgumentNullExceptionWhenNameIsNull() +//// { +//// // Act and assert +//// Assert.Throws(() => +//// { +//// this.pipeline.SetUniform(null, true); +//// }); +//// } + +//// [Test] +//// public void SetUniformDoubleShouldInvokeUniform1WhenGetUniformLocationReturnsPositiveInteger() +//// { +//// // Arrange +//// var program = new Mock(); +//// program.Setup(x => x.GetUniformLocation(It.IsAny())).Returns(0); + +//// this.pipeline.SetShaderProgram(program.Object); + +//// // Act +//// this.pipeline.SetUniform("name", 0.0d); + +//// // Assert +//// this.invoker.Verify(x => x.Uniform1(0, 0.0d), Times.Once); +//// } + +//// [Test] +//// public void SetUniformDoubleShouldNotInvokeUniform1WhenBoundProgramIsNull() +//// { +//// // Act +//// this.pipeline.SetUniform("name", 0.0d); + +//// // Assert +//// this.invoker.Verify(x => x.Uniform1(0, 0.0d), Times.Never); +//// } + +//// [Test] +//// public void SetUniformDoubleShouldNotInvokeUniform1WhenUniformLocationNotFound() +//// { +//// // Arrange +//// var program = new Mock(); +//// program.Setup(x => x.GetUniformLocation(It.IsAny())).Returns(-1); +//// this.pipeline.SetShaderProgram(program.Object); + +//// // Act +//// this.pipeline.SetUniform("name", 0.0d); + +//// // Assert +//// this.invoker.Verify(x => x.GetUniformLocation(It.IsAny(), It.IsAny()), Times.Never); +//// } + +//// [Test] +//// public void SetUniformDoubleShouldThrowArgumentExceptionWhenNameIsEmpty() +//// { +//// // Act and assert +//// Assert.Throws(() => +//// { +//// this.pipeline.SetUniform(string.Empty, 0.0d); +//// }); +//// } + +//// [Test] +//// public void SetUniformDoubleShouldThrowArgumentExceptionWhenNameIsWhitespace() +//// { +//// // Act and assert +//// Assert.Throws(() => +//// { +//// this.pipeline.SetUniform("\t\r\n", 0.0d); +//// }); +//// } + +//// [Test] +//// public void SetUniformDoubleShouldThrowArgumentNullExceptionWhenNameIsNull() +//// { +//// // Act and assert +//// Assert.Throws(() => +//// { +//// this.pipeline.SetUniform(null, 0.0d); +//// }); +//// } + +//// [Test] +//// public void SetUniformFloatShouldInvokeUniform1WhenGetUniformLocationReturnsPositiveInteger() +//// { +//// // Arrange +//// var program = new Mock(); +//// program.Setup(x => x.GetUniformLocation(It.IsAny())).Returns(0); + +//// this.pipeline.SetShaderProgram(program.Object); + +//// // Act +//// this.pipeline.SetUniform("name", 1.0f); + +//// // Assert +//// this.invoker.Verify(x => x.Uniform1(0, 1.0f), Times.Once); +//// } + +//// [Test] +//// public void SetUniformFloatShouldNotInvokeUniform1WhenBoundProgramIsNull() +//// { +//// // Act +//// this.pipeline.SetUniform("name", 1.0f); + +//// // Assert +//// this.invoker.Verify(x => x.Uniform1(0, 1.0f), Times.Never); +//// } + +//// [Test] +//// public void SetUniformFloatShouldNotInvokeUniform1WhenUniformLocationNotFound() +//// { +//// // Arrange +//// var program = new Mock(); +//// program.Setup(x => x.GetUniformLocation(It.IsAny())).Returns(-1); +//// this.pipeline.SetShaderProgram(program.Object); + +//// // Act +//// this.pipeline.SetUniform("name", 0.0f); + +//// // Assert +//// this.invoker.Verify(x => x.GetUniformLocation(It.IsAny(), It.IsAny()), Times.Never); +//// } + +//// [Test] +//// public void SetUniformFloatShouldThrowArgumentExceptionWhenNameIsEmpty() +//// { +//// // Act and assert +//// Assert.Throws(() => +//// { +//// this.pipeline.SetUniform(string.Empty, 1.0f); +//// }); +//// } + +//// [Test] +//// public void SetUniformFloatShouldThrowArgumentExceptionWhenNameIsWhitespace() +//// { +//// // Act and assert +//// Assert.Throws(() => +//// { +//// this.pipeline.SetUniform("\t\r\n", 1.0f); +//// }); +//// } + +//// [Test] +//// public void SetUniformFloatShouldThrowArgumentNullExceptionWhenNameIsNull() +//// { +//// // Act and assert +//// Assert.Throws(() => +//// { +//// this.pipeline.SetUniform(null, 1.0f); +//// }); +//// } + +//// [Test] +//// public void SetUniformIntegerShouldNotInvokeUniform1WhenUniformLocationNotFound() +//// { +//// // Arrange +//// var program = new Mock(); +//// program.Setup(x => x.GetUniformLocation(It.IsAny())).Returns(-1); +//// this.pipeline.SetShaderProgram(program.Object); + +//// // Act +//// this.pipeline.SetUniform("name", 0); + +//// // Assert +//// this.invoker.Verify(x => x.GetUniformLocation(It.IsAny(), It.IsAny()), Times.Never); +//// } + +//// [Test] +//// public void SetUniformIntShouldInvokeUniform1WhenGetUniformLocationReturnsPositiveInteger() +//// { +//// // Arrange +//// var program = new Mock(); +//// program.Setup(x => x.GetUniformLocation(It.IsAny())).Returns(0); + +//// this.pipeline.SetShaderProgram(program.Object); + +//// // Act +//// this.pipeline.SetUniform("name", 0); + +//// // Assert +//// this.invoker.Verify(x => x.Uniform1(0, 0), Times.Once); +//// } + +//// [Test] +//// public void SetUniformIntShouldNotInvokeUniform1WhenBoundProgramIsNull() +//// { +//// // Act +//// this.pipeline.SetUniform("name", 0); + +//// // Assert +//// this.invoker.Verify(x => x.Uniform1(0, 0), Times.Never); +//// } + +//// [Test] +//// public void SetUniformIntShouldThrowArgumentExceptionWhenNameIsEmpty() +//// { +//// // Act and assert +//// Assert.Throws(() => +//// { +//// this.pipeline.SetUniform(string.Empty, 0); +//// }); +//// } + +//// [Test] +//// public void SetUniformIntShouldThrowArgumentExceptionWhenNameIsWhitespace() +//// { +//// // Act and assert +//// Assert.Throws(() => +//// { +//// this.pipeline.SetUniform("\t\r\n", 0); +//// }); +//// } + +//// [Test] +//// public void SetUniformIntShouldThrowArgumentNullExceptionWhenNameIsNull() +//// { +//// // Act and assert +//// Assert.Throws(() => +//// { +//// this.pipeline.SetUniform(null, 0); +//// }); +//// } + +//// [Test] +//// public void SetUniformMatrix4ShouldNotInvokeUniformMatrix4WhenUniformLocationNotFound() +//// { +//// // Arrange +//// var program = new Mock(); +//// program.Setup(x => x.GetUniformLocation(It.IsAny())).Returns(-1); +//// this.pipeline.SetShaderProgram(program.Object); + +//// // Act +//// this.pipeline.SetUniform("name", Matrix4x4.Identity); + +//// // Assert +//// this.invoker.Verify(x => x.GetUniformLocation(It.IsAny(), It.IsAny()), Times.Never); +//// } + +//// [Test] +//// public void SetUniformMatrix4x4ShouldInvokeUniformMatrix4WhenGetUniformLocationReturnsPositiveInteger() +//// { +//// // Arrange +//// var program = new Mock(); +//// program.Setup(x => x.GetUniformLocation(It.IsAny())).Returns(0); + +//// this.pipeline.SetShaderProgram(program.Object); + +//// var value = Matrix4x4.Identity; + +//// float[] values = +//// { +//// value.M11, value.M12, value.M13, value.M14, +//// value.M21, value.M22, value.M23, value.M24, +//// value.M31, value.M32, value.M33, value.M34, +//// value.M41, value.M42, value.M43, value.M44, +//// }; + +//// // Act +//// this.pipeline.SetUniform("name", Matrix4x4.Identity); + +//// // Assert +//// this.invoker.Verify(x => x.UniformMatrix4(0, 1, false, values), Times.Once); +//// } + +//// [Test] +//// public void SetUniformMatrix4x4ShouldNotInvokeUniformMatrix4WhenBoundProgramIsNull() +//// { +//// // Arrange +//// var value = Matrix4x4.Identity; + +//// float[] values = +//// { +//// value.M11, value.M12, value.M13, value.M14, +//// value.M21, value.M22, value.M23, value.M24, +//// value.M31, value.M32, value.M33, value.M34, +//// value.M41, value.M42, value.M43, value.M44, +//// }; + +//// // Act +//// this.pipeline.SetUniform("name", Matrix4x4.Identity); + +//// // Assert +//// this.invoker.Verify(x => x.UniformMatrix4(0, 1, false, values), Times.Never); +//// } + +//// [Test] +//// public void SetUniformMatrix4x4ShouldThrowArgumentExceptionWhenNameIsEmpty() +//// { +//// // Act and assert +//// Assert.Throws(() => +//// { +//// this.pipeline.SetUniform(string.Empty, Matrix4x4.Identity); +//// }); +//// } + +//// [Test] +//// public void SetUniformMatrix4x4ShouldThrowArgumentExceptionWhenNameIsWhitespace() +//// { +//// // Act and assert +//// Assert.Throws(() => +//// { +//// this.pipeline.SetUniform("\t\r\n", Matrix4x4.Identity); +//// }); +//// } + +//// [Test] +//// public void SetUniformMatrix4x4ShouldThrowArgumentNullExceptionWhenNameIsNull() +//// { +//// // Act and assert +//// Assert.Throws(() => +//// { +//// this.pipeline.SetUniform(null, Matrix4x4.Identity); +//// }); +//// } + +//// [Test] +//// public void SetUniformVector2ShouldInvokeUniform2WhenGetUniformLocationReturnsPositiveInteger() +//// { +//// // Arrange +//// var program = new Mock(); +//// program.Setup(x => x.GetUniformLocation(It.IsAny())).Returns(0); + +//// this.pipeline.SetShaderProgram(program.Object); + +//// // Act +//// this.pipeline.SetUniform("name", new Vector2(1.0f, 0.0f)); + +//// // Assert +//// this.invoker.Verify(x => x.Uniform2(0, 1.0f, 0.0f), Times.Once); +//// } + +//// [Test] +//// public void SetUniformVector2ShouldNotInvokeUniform2WhenBoundProgramIsNull() +//// { +//// // Act +//// this.pipeline.SetUniform("name", new Vector2(1.0f, 0.0f)); + +//// // Assert +//// this.invoker.Verify(x => x.Uniform2(0, 1.0f, 0.0f), Times.Never); +//// } + +//// [Test] +//// public void SetUniformVector2ShouldNotInvokeUniform2WhenUniformLocationNotFound() +//// { +//// // Arrange +//// var program = new Mock(); +//// program.Setup(x => x.GetUniformLocation(It.IsAny())).Returns(-1); +//// this.pipeline.SetShaderProgram(program.Object); + +//// // Act +//// this.pipeline.SetUniform("name", Vector2.Zero); + +//// // Assert +//// this.invoker.Verify(x => x.GetUniformLocation(It.IsAny(), It.IsAny()), Times.Never); +//// } + +//// [Test] +//// public void SetUniformVector2ShouldThrowArgumentExceptionWhenNameIsEmpty() +//// { +//// // Act and assert +//// Assert.Throws(() => +//// { +//// this.pipeline.SetUniform(string.Empty, new Vector2(1.0f, 0.0f)); +//// }); +//// } + +//// [Test] +//// public void SetUniformVector2ShouldThrowArgumentExceptionWhenNameIsWhitespace() +//// { +//// // Act and assert +//// Assert.Throws(() => +//// { +//// this.pipeline.SetUniform("\t\r\n", new Vector2(1.0f, 0.0f)); +//// }); +//// } + +//// [Test] +//// public void SetUniformVector2ShouldThrowArgumentNullExceptionWhenNameIsNull() +//// { +//// // Act and assert +//// Assert.Throws(() => +//// { +//// this.pipeline.SetUniform(null, new Vector2(1.0f, 0.0f)); +//// }); +//// } + +//// [Test] +//// public void SetUniformVector3ShouldInvokeUniform3WhenGetUniformLocationReturnsPositiveInteger() +//// { +//// // Arrange +//// var program = new Mock(); +//// program.Setup(x => x.GetUniformLocation(It.IsAny())).Returns(0); + +//// this.pipeline.SetShaderProgram(program.Object); + +//// // Act +//// this.pipeline.SetUniform("name", new Vector3(1.0f, 0.0f, 1.0f)); + +//// // Assert +//// this.invoker.Verify(x => x.Uniform3(0, 1.0f, 0.0f, 1.0f), Times.Once); +//// } + +//// [Test] +//// public void SetUniformVector3ShouldNotInvokeUniform3WhenBoundProgramIsNull() +//// { +//// // Act +//// this.pipeline.SetUniform("name", new Vector3(1.0f, 0.0f, 1.0f)); + +//// // Assert +//// this.invoker.Verify(x => x.Uniform3(0, 1.0f, 0.0f, 1.0f), Times.Never); +//// } + +//// [Test] +//// public void SetUniformVector3ShouldNotInvokeUniform3WhenUniformLocationNotFound() +//// { +//// // Arrange +//// var program = new Mock(); +//// program.Setup(x => x.GetUniformLocation(It.IsAny())).Returns(-1); +//// this.pipeline.SetShaderProgram(program.Object); + +//// // Act +//// this.pipeline.SetUniform("name", Vector3.Zero); + +//// // Assert +//// this.invoker.Verify(x => x.GetUniformLocation(It.IsAny(), It.IsAny()), Times.Never); +//// } + +//// [Test] +//// public void SetUniformVector3ShouldThrowArgumentExceptionWhenNameIsEmpty() +//// { +//// // Act and assert +//// Assert.Throws(() => +//// { +//// this.pipeline.SetUniform(string.Empty, new Vector3(1.0f, 0.0f, 1.0f)); +//// }); +//// } + +//// [Test] +//// public void SetUniformVector3ShouldThrowArgumentExceptionWhenNameIsWhitespace() +//// { +//// // Act and assert +//// Assert.Throws(() => +//// { +//// this.pipeline.SetUniform("\t\r\n", new Vector3(1.0f, 0.0f, 1.0f)); +//// }); +//// } + +//// [Test] +//// public void SetUniformVector3ShouldThrowArgumentNullExceptionWhenNameIsNull() +//// { +//// // Act and assert +//// Assert.Throws(() => +//// { +//// this.pipeline.SetUniform(null, new Vector3(1.0f, 0.0f, 1.0f)); +//// }); +//// } + +//// [Test] +//// public void SetUniformVector4ShouldInvokeUniform4WhenGetUniformLocationReturnsPositiveInteger() +//// { +//// // Arrange +//// var program = new Mock(); +//// program.Setup(x => x.GetUniformLocation(It.IsAny())).Returns(0); + +//// this.pipeline.SetShaderProgram(program.Object); + +//// // Act +//// this.pipeline.SetUniform("name", new Vector4(1.0f, 0.0f, 1.0f, 1.0f)); + +//// // Assert +//// this.invoker.Verify(x => x.Uniform4(0, 1.0f, 0.0f, 1.0f, 1.0f), Times.Once); +//// } + +//// [Test] +//// public void SetUniformVector4ShouldNotInvokeUniform4WhenBoundProgramIsNull() +//// { +//// // Act +//// this.pipeline.SetUniform("name", new Vector4(1.0f, 0.0f, 1.0f, 1.0f)); + +//// // Assert +//// this.invoker.Verify(x => x.Uniform4(0, 1.0f, 0.0f, 1.0f, 1.0f), Times.Never); +//// } + +//// [Test] +//// public void SetUniformVector4ShouldNotInvokeUniform4WhenUniformLocationNotFound() +//// { +//// // Arrange +//// var program = new Mock(); +//// program.Setup(x => x.GetUniformLocation(It.IsAny())).Returns(-1); +//// this.pipeline.SetShaderProgram(program.Object); + +//// // Act +//// this.pipeline.SetUniform("name", Vector4.Zero); + +//// // Assert +//// this.invoker.Verify(x => x.GetUniformLocation(It.IsAny(), It.IsAny()), Times.Never); +//// } + +//// [Test] +//// public void SetUniformVector4ShouldThrowArgumentExceptionWhenNameIsEmpty() +//// { +//// // Act and assert +//// Assert.Throws(() => +//// { +//// this.pipeline.SetUniform(string.Empty, new Vector4(1.0f, 0.0f, 1.0f, 1.0f)); +//// }); +//// } + +//// [Test] +//// public void SetUniformVector4ShouldThrowArgumentExceptionWhenNameIsWhitespace() +//// { +//// // Act and assert +//// Assert.Throws(() => +//// { +//// this.pipeline.SetUniform("\t\r\n", new Vector4(1.0f, 0.0f, 1.0f, 1.0f)); +//// }); +//// } + +//// [Test] +//// public void SetUniformVector4ShouldThrowArgumentNullExceptionWhenNameIsNull() +//// { +//// // Act and assert +//// Assert.Throws(() => +//// { +//// this.pipeline.SetUniform(null, new Vector4(1.0f, 0.0f, 1.0f, 1.0f)); +//// }); +//// } + +//// [SetUp] +//// public void Setup() +//// { +//// // Arrange +//// this.invoker = new Mock(); +//// this.pipeline = new OpenGLPipeline(this.invoker.Object); +//// } +////} diff --git a/FinalEngine.Tests/Rendering/OpenGL/Pipeline/OpenGLShaderProgramTests.cs b/FinalEngine.Tests/Rendering/OpenGL/Pipeline/OpenGLShaderProgramTests.cs index 85701112..b7ec793b 100644 --- a/FinalEngine.Tests/Rendering/OpenGL/Pipeline/OpenGLShaderProgramTests.cs +++ b/FinalEngine.Tests/Rendering/OpenGL/Pipeline/OpenGLShaderProgramTests.cs @@ -1,201 +1,201 @@ -// -// Copyright (c) Software Antics. All rights reserved. -// - -namespace FinalEngine.Tests.Rendering.OpenGL.Pipeline; - -using System; -using System.Collections.Generic; -using FinalEngine.Rendering.Exceptions; -using FinalEngine.Rendering.OpenGL.Invocation; -using FinalEngine.Rendering.OpenGL.Pipeline; -using Moq; -using NUnit.Framework; - -public class OpenGLShaderProgramTests -{ - private const int ID = 567; - - private Mock invoker; - - private OpenGLShaderProgram program; - - private Mock shader; - - private IReadOnlyCollection shaders; - - [Test] - public void BindShouldInvokeUseProgramWhenProgramIsNotDisposed() - { - // Act - this.program.Bind(); - - // Assert - this.invoker.Verify(x => x.UseProgram(ID), Times.Once); - } - - [Test] - public void BindShouldThrowObjectDisposedExceptionWhenProgramIsDisposed() - { - // Arrange - this.program.Dispose(); - - // Act and assert - Assert.Throws(this.program.Bind); - } - - [Test] - public void ConstructorShouldInvokeAttachWhenInvoked() - { - // Assert - this.shader.Verify(x => x.Attach(ID), Times.Once); - } - - [Test] - public void ConstructorShouldInvokeCreateProgramWhenInvoked() - { - // Assert - this.invoker.Verify(x => x.CreateProgram(), Times.Once); - } - - [Test] - public void ConstructorShouldInvokeGetProgramInfoLogWhenInvoked() - { - // Assert - this.invoker.Verify(x => x.GetProgramInfoLog(ID), Times.Once); - } - - [Test] - public void ConstructorShouldInvokeLinkProgramWhenInvoked() - { - // Assert - this.invoker.Verify(x => x.LinkProgram(ID), Times.Once); - } - - [Test] - public void ConstructorShouldInvokeValidateProgramWhenInvoked() - { - // Assert - this.invoker.Verify(x => x.ValidateProgram(ID), Times.Once); - } - - [Test] - public void ConstructorShouldThrowArgumentNullExceptionWhenInvokerIsNull() - { - // Arrange, act and assert - Assert.Throws(() => - { - new OpenGLShaderProgram(null, this.shaders); - }); - } - - [Test] - public void ConstructorShouldThrowArgumentNullExceptionWhenShadersIsNull() - { - // Arrange, act and assert - Assert.Throws(() => - { - new OpenGLShaderProgram(this.invoker.Object, null); - }); - } - - [Test] - public void ConstructorShouldThrowProgramLinkingErrorExceptionWhenGetProgramInfoLogReturnsNotNullEmptyOrWhitspace() - { - // Arrange - this.invoker.Setup(x => x.GetProgramInfoLog(ID)).Returns("test"); - - // Act and assert - Assert.Throws(() => - { - new OpenGLShaderProgram(this.invoker.Object, this.shaders); - }); - } - - [Test] - public void DisposeShouldInvokeDeleteProgramWhenProgramIsNotDisposed() - { - // Act - this.program.Dispose(); - - // Assert - this.invoker.Verify(x => x.DeleteProgram(ID), Times.Once); - } - - [Test] - public void GetUniformLocationShouldInvokeGetUniformLocationWhenNameIsNotNullAndProgramIsNotDisposed() - { - // Act - this.program.GetUniformLocation("test"); - - // Assert - this.invoker.Verify(x => x.GetUniformLocation(ID, "test"), Times.Once); - } - - [Test] - public void GetUniformLocationShouldThrowArgumentExceptionWhenNameIsEmpty() - { - // Act and assert - Assert.Throws(() => - { - this.program.GetUniformLocation(string.Empty); - }); - } - - [Test] - public void GetUniformLocationShouldThrowArgumentExceptionWhenNameIsWhitespace() - { - // Act and assert - Assert.Throws(() => - { - this.program.GetUniformLocation("\t\r\n"); - }); - } - - [Test] - public void GetUniformLocationShouldThrowArgumentNullExceptionWhenNameIsNull() - { - // Act and assert - Assert.Throws(() => - { - this.program.GetUniformLocation(null); - }); - } - - [Test] - public void GetUniformLocationShouldThrowObjectDisposedExceptionWhenProgramIsDisposed() - { - // Arrange - this.program.Dispose(); - - // Act and assert - Assert.Throws(() => - { - this.program.GetUniformLocation(null); - }); - } - - [SetUp] - public void Setup() - { - // Arrange - this.invoker = new Mock(); - this.invoker.Setup(x => x.CreateProgram()).Returns(ID); - - this.shader = new Mock(); - - this.shaders = new List() - { - null, - this.shader.Object, - }; - - this.program = new OpenGLShaderProgram(this.invoker.Object, this.shaders); - } - - [TearDown] - public void Teardown() - { - this.program.Dispose(); - } -} +////// +////// Copyright (c) Software Antics. All rights reserved. +////// + +////namespace FinalEngine.Tests.Rendering.OpenGL.Pipeline; + +////using System; +////using System.Collections.Generic; +////using FinalEngine.Rendering.Exceptions; +////using FinalEngine.Rendering.OpenGL.Invocation; +////using FinalEngine.Rendering.OpenGL.Pipeline; +////using Moq; +////using NUnit.Framework; + +////public class OpenGLShaderProgramTests +////{ +//// private const int ID = 567; + +//// private Mock invoker; + +//// private OpenGLShaderProgram program; + +//// private Mock shader; + +//// private IReadOnlyCollection shaders; + +//// [Test] +//// public void BindShouldInvokeUseProgramWhenProgramIsNotDisposed() +//// { +//// // Act +//// this.program.Bind(); + +//// // Assert +//// this.invoker.Verify(x => x.UseProgram(ID), Times.Once); +//// } + +//// [Test] +//// public void BindShouldThrowObjectDisposedExceptionWhenProgramIsDisposed() +//// { +//// // Arrange +//// this.program.Dispose(); + +//// // Act and assert +//// Assert.Throws(this.program.Bind); +//// } + +//// [Test] +//// public void ConstructorShouldInvokeAttachWhenInvoked() +//// { +//// // Assert +//// this.shader.Verify(x => x.Attach(ID), Times.Once); +//// } + +//// [Test] +//// public void ConstructorShouldInvokeCreateProgramWhenInvoked() +//// { +//// // Assert +//// this.invoker.Verify(x => x.CreateProgram(), Times.Once); +//// } + +//// [Test] +//// public void ConstructorShouldInvokeGetProgramInfoLogWhenInvoked() +//// { +//// // Assert +//// this.invoker.Verify(x => x.GetProgramInfoLog(ID), Times.Once); +//// } + +//// [Test] +//// public void ConstructorShouldInvokeLinkProgramWhenInvoked() +//// { +//// // Assert +//// this.invoker.Verify(x => x.LinkProgram(ID), Times.Once); +//// } + +//// [Test] +//// public void ConstructorShouldInvokeValidateProgramWhenInvoked() +//// { +//// // Assert +//// this.invoker.Verify(x => x.ValidateProgram(ID), Times.Once); +//// } + +//// [Test] +//// public void ConstructorShouldThrowArgumentNullExceptionWhenInvokerIsNull() +//// { +//// // Arrange, act and assert +//// Assert.Throws(() => +//// { +//// new OpenGLShaderProgram(null, this.shaders); +//// }); +//// } + +//// [Test] +//// public void ConstructorShouldThrowArgumentNullExceptionWhenShadersIsNull() +//// { +//// // Arrange, act and assert +//// Assert.Throws(() => +//// { +//// new OpenGLShaderProgram(this.invoker.Object, null); +//// }); +//// } + +//// [Test] +//// public void ConstructorShouldThrowProgramLinkingErrorExceptionWhenGetProgramInfoLogReturnsNotNullEmptyOrWhitspace() +//// { +//// // Arrange +//// this.invoker.Setup(x => x.GetProgramInfoLog(ID)).Returns("test"); + +//// // Act and assert +//// Assert.Throws(() => +//// { +//// new OpenGLShaderProgram(this.invoker.Object, this.shaders); +//// }); +//// } + +//// [Test] +//// public void DisposeShouldInvokeDeleteProgramWhenProgramIsNotDisposed() +//// { +//// // Act +//// this.program.Dispose(); + +//// // Assert +//// this.invoker.Verify(x => x.DeleteProgram(ID), Times.Once); +//// } + +//// [Test] +//// public void GetUniformLocationShouldInvokeGetUniformLocationWhenNameIsNotNullAndProgramIsNotDisposed() +//// { +//// // Act +//// this.program.GetUniformLocation("test"); + +//// // Assert +//// this.invoker.Verify(x => x.GetUniformLocation(ID, "test"), Times.Once); +//// } + +//// [Test] +//// public void GetUniformLocationShouldThrowArgumentExceptionWhenNameIsEmpty() +//// { +//// // Act and assert +//// Assert.Throws(() => +//// { +//// this.program.GetUniformLocation(string.Empty); +//// }); +//// } + +//// [Test] +//// public void GetUniformLocationShouldThrowArgumentExceptionWhenNameIsWhitespace() +//// { +//// // Act and assert +//// Assert.Throws(() => +//// { +//// this.program.GetUniformLocation("\t\r\n"); +//// }); +//// } + +//// [Test] +//// public void GetUniformLocationShouldThrowArgumentNullExceptionWhenNameIsNull() +//// { +//// // Act and assert +//// Assert.Throws(() => +//// { +//// this.program.GetUniformLocation(null); +//// }); +//// } + +//// [Test] +//// public void GetUniformLocationShouldThrowObjectDisposedExceptionWhenProgramIsDisposed() +//// { +//// // Arrange +//// this.program.Dispose(); + +//// // Act and assert +//// Assert.Throws(() => +//// { +//// this.program.GetUniformLocation(null); +//// }); +//// } + +//// [SetUp] +//// public void Setup() +//// { +//// // Arrange +//// this.invoker = new Mock(); +//// this.invoker.Setup(x => x.CreateProgram()).Returns(ID); + +//// this.shader = new Mock(); + +//// this.shaders = new List() +//// { +//// null, +//// this.shader.Object, +//// }; + +//// this.program = new OpenGLShaderProgram(this.invoker.Object, this.shaders); +//// } + +//// [TearDown] +//// public void Teardown() +//// { +//// this.program.Dispose(); +//// } +////}