sharpemu/tests/SharpEmu.Libs.Tests/Audio/AudioOut2ContextQueryMemoryExportsTests.cs
Berk b02c06181a
Unity fixes 1016p2 (#1062)
* [Audio] Snapshot AudioOut2 PCM when the guest submits it

Co-authored-by: Sekai <140012992+igettingit@users.noreply.github.com>

* [Audio] Drop the ports of a destroyed AudioOut2 context

Co-authored-by: Sekai <140012992+igettingit@users.noreply.github.com>

* [Audio] Accept sceAudioOut2MasteringSetParam

Co-authored-by: Sekai <140012992+igettingit@users.noreply.github.com>

* [Audio] Resolve AudioOut2 out-buffers from either ABI slot

Co-authored-by: Sekai <140012992+igettingit@users.noreply.github.com>

* [Audio] Report the AudioOut2 context memory size through its out pointer

Co-authored-by: Sekai <140012992+igettingit@users.noreply.github.com>

* [Audio] Keep the AudioOut2 queue level and availability pointers apart

Co-authored-by: Sekai <140012992+igettingit@users.noreply.github.com>

* [Audio] Report full volume in the AudioOut2 port state

Co-authored-by: Sekai <140012992+igettingit@users.noreply.github.com>

* [Audio] Trace AudioOut2 port, attribute and bed calls

Co-authored-by: Sekai <140012992+igettingit@users.noreply.github.com>

* [Audio] Let tests replace the AudioOut2 host streams

Co-authored-by: Sekai <140012992+igettingit@users.noreply.github.com>

* [Audio] Add the AudioOut2 vibration port type

Co-authored-by: Sekai <140012992+igettingit@users.noreply.github.com>

* [SaveData] Lay out save data events with their title ID

Co-authored-by: Sekai <140012992+igettingit@users.noreply.github.com>

* [SaveData] Add sceSaveDataBackup

Co-authored-by: Sekai <140012992+igettingit@users.noreply.github.com>

* [SaveData] Add sceSaveDataDirNameSearch2

Co-authored-by: Sekai <140012992+igettingit@users.noreply.github.com>

* [Network] Track Http2 template and request options

Co-authored-by: Sekai <140012992+igettingit@users.noreply.github.com>

* [Network] Add Http2 option, cookie and request exports

Co-authored-by: Sekai <140012992+igettingit@users.noreply.github.com>

* [CommonDialog] Add the web browser dialog lifecycle

Co-authored-by: Sekai <140012992+igettingit@users.noreply.github.com>

* [Json] Add the InitParameter2 base constructor

Co-authored-by: Sekai <140012992+igettingit@users.noreply.github.com>

* [Json] Add InitParameterRtti2::setAllocatorRtti

Co-authored-by: Sekai <140012992+igettingit@users.noreply.github.com>

* [AvPlayer] Accept available bandwidth hints

Co-authored-by: Sekai <140012992+igettingit@users.noreply.github.com>

* [Tests] Cover the AudioOut2, save data, Http2 and dialog exports

Co-authored-by: Sekai <140012992+igettingit@users.noreply.github.com>

---------

Co-authored-by: Sekai <140012992+igettingit@users.noreply.github.com>
2026-10-07 18:47:42 +03:00

68 lines
2.5 KiB
C#

// Copyright (C) 2026 SharpEmu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
using System.Buffers.Binary;
using SharpEmu.HLE;
using SharpEmu.Libs.Audio;
using Xunit;
namespace SharpEmu.Libs.Tests.Audio;
public sealed class AudioOut2ContextQueryMemoryExportsTests
{
private const int InvalidPointer = unchecked((int)0x8026_800C);
private const ulong MemoryBase = 0x10_0000_0000;
private const ulong ParamAddress = MemoryBase + 0x100;
private const ulong StackPointer = MemoryBase + 0x400;
private const ulong MemorySizeAddress = StackPointer + 0x10;
private const ulong StaleThirdArgument = MemoryBase + 0x800;
[Fact]
public void ContextQueryMemory_WritesOnlyOneSizeTAndIgnoresRdx()
{
var memory = new FakeCpuMemory(MemoryBase, 0x1000);
var ctx = new CpuContext(memory, Generation.Gen5);
Span<byte> param = stackalloc byte[0x40];
param.Clear();
BinaryPrimitives.WriteUInt32LittleEndian(param[0x0C..], 4);
Assert.True(memory.TryWrite(ParamAddress, param));
Span<byte> guard = stackalloc byte[0x10];
guard.Fill(0xA5);
Assert.True(memory.TryWrite(MemorySizeAddress, guard));
Assert.True(memory.TryWrite(StaleThirdArgument, guard));
ctx[CpuRegister.Rdi] = ParamAddress;
ctx[CpuRegister.Rsi] = MemorySizeAddress;
ctx[CpuRegister.Rdx] = StaleThirdArgument;
ctx[CpuRegister.Rsp] = StackPointer;
ctx[CpuRegister.Rbp] = StackPointer + 0x48;
Assert.Equal(0, AudioOut2Exports.AudioOut2ContextQueryMemory(ctx));
Span<byte> output = stackalloc byte[0x10];
Assert.True(memory.TryRead(MemorySizeAddress, output));
Assert.Equal(0x11640UL, BinaryPrimitives.ReadUInt64LittleEndian(output));
Assert.Equal(new byte[] { 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5, 0xA5 }, output[8..].ToArray());
Span<byte> stale = stackalloc byte[0x10];
Assert.True(memory.TryRead(StaleThirdArgument, stale));
Assert.Equal(guard.ToArray(), stale.ToArray());
}
[Fact]
public void ContextQueryMemory_RejectsMissingSecondArgument()
{
var memory = new FakeCpuMemory(MemoryBase, 0x1000);
var ctx = new CpuContext(memory, Generation.Gen5);
ctx[CpuRegister.Rdi] = ParamAddress;
ctx[CpuRegister.Rsi] = 0;
ctx[CpuRegister.Rdx] = StaleThirdArgument;
Assert.Equal(
InvalidPointer,
AudioOut2Exports.AudioOut2ContextQueryMemory(ctx));
}
}