Add a few simple tests

Ensure the struct sizes are correct
This commit is contained in:
TSR Berry 2023-12-05 01:27:12 +01:00
parent 734db17bb9
commit c42241d834
No known key found for this signature in database
GPG Key ID: 52353C0A4CCA15E2
3 changed files with 75 additions and 1 deletions

View File

@ -304,7 +304,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl
_udpEndpoint = new IPEndPoint(response.BoundAddress, response.BoundPort);
_udpSocket = new Socket(AddressFamily, SocketType, ProtocolType)
{
Blocking = Socket.Blocking
Blocking = Socket.Blocking,
};
_udpSocket.Bind(endpoint);

View File

@ -0,0 +1,28 @@
using NUnit.Framework;
using Ryujinx.HLE.HOS.Services.Sockets.Bsd.Proxy.Auth;
using System;
namespace Ryujinx.Tests.HLE.HOS.Services.Sockets.Bsd.Proxy.Auth
{
public class AuthMethodTests
{
[Test]
public void GetAuth_ReturnValue([Values] AuthMethod authMethod)
{
// TODO: Remove this as soon as we have an implementation for these
if (authMethod is AuthMethod.UsernameAndPassword or AuthMethod.GSSAPI)
{
Assert.Throws<NotImplementedException>(() => authMethod.GetAuth());
return;
}
if (authMethod is AuthMethod.NoAcceptableMethods)
{
Assert.Throws<ArgumentException>(() => authMethod.GetAuth());
return;
}
Assert.IsInstanceOf<IProxyAuth>(authMethod.GetAuth());
}
}
}

View File

@ -0,0 +1,46 @@
using NUnit.Framework;
using Ryujinx.Common.Memory;
using Ryujinx.HLE.HOS.Services.Sockets.Bsd.Proxy;
using Ryujinx.HLE.HOS.Services.Sockets.Bsd.Proxy.Auth;
using Ryujinx.HLE.HOS.Services.Sockets.Bsd.Proxy.Packets;
using System.Runtime.InteropServices;
namespace Ryujinx.Tests.HLE.HOS.Services.Sockets.Bsd.Proxy.Packets
{
public class MethodSelectionTests
{
[Test]
public void MethodSelectionRequest1_Size()
{
// Version: 1 byte
// Number of methods: 1 byte
// Methods: 1 - 255 bytes (in this case: 1)
// Total: 3 bytes
var request = new MethodSelectionRequest1
{
Version = ProxyConsts.Version,
NumOfMethods = 1,
Methods = new Array1<AuthMethod> { [0] = AuthMethod.NoAuthenticationRequired },
};
Assert.AreEqual(3, Marshal.SizeOf(request));
}
[Test]
public void MethodSelectionResponse_Size()
{
// Version: 1 byte
// Method: 1 byte
// Total: 2 bytes
var response = new MethodSelectionResponse()
{
Version = ProxyConsts.Version,
Method = AuthMethod.NoAuthenticationRequired,
};
Assert.AreEqual(2, Marshal.SizeOf(response));
}
}
}