diff --git a/crates/servicepoint_binding_c/src/cp437_grid.rs b/crates/servicepoint_binding_c/src/cp437_grid.rs index a393a98..c82e5b7 100644 --- a/crates/servicepoint_binding_c/src/cp437_grid.rs +++ b/crates/servicepoint_binding_c/src/cp437_grid.rs @@ -70,7 +70,7 @@ pub unsafe extern "C" fn sp_cp437_grid_load( data: *const u8, data_length: usize, ) -> NonNull { - assert!(data.is_null()); + assert!(!data.is_null()); let data = std::slice::from_raw_parts(data, data_length); let result = Box::new(SPCp437Grid(servicepoint::Cp437Grid::load( width, height, data, diff --git a/crates/servicepoint_binding_cs/ServicePoint.Tests/BitVecTests.cs b/crates/servicepoint_binding_cs/ServicePoint.Tests/BitVecTests.cs new file mode 100644 index 0000000..a04c822 --- /dev/null +++ b/crates/servicepoint_binding_cs/ServicePoint.Tests/BitVecTests.cs @@ -0,0 +1,12 @@ +namespace ServicePoint.Tests; + +public class BitVecTests +{ + [Fact] + public void UseAfterFree() + { + var bitvec = new BitVec(8); + _ = Command.BitmapLinear(0, bitvec, CompressionCode.Uncompressed); + Assert.Throws(() => _ = Command.BitmapLinear(0, bitvec, CompressionCode.Uncompressed)); + } +} diff --git a/crates/servicepoint_binding_cs/ServicePoint.Tests/BitmapTests.cs b/crates/servicepoint_binding_cs/ServicePoint.Tests/BitmapTests.cs new file mode 100644 index 0000000..e0e8c62 --- /dev/null +++ b/crates/servicepoint_binding_cs/ServicePoint.Tests/BitmapTests.cs @@ -0,0 +1,12 @@ +namespace ServicePoint.Tests; + +public class BitmapTests +{ + [Fact] + public void UseAfterFree() + { + var bitmap = Bitmap.NewScreenSized(); + _ = Command.BitmapLinearWin(0, 0, bitmap, CompressionCode.Uncompressed); + Assert.Throws(() => _ = Command.BitmapLinearWin(0, 0, bitmap, CompressionCode.Uncompressed)); + } +} diff --git a/crates/servicepoint_binding_cs/ServicePoint.Tests/BrightnessGridTests.cs b/crates/servicepoint_binding_cs/ServicePoint.Tests/BrightnessGridTests.cs new file mode 100644 index 0000000..fc0a8bb --- /dev/null +++ b/crates/servicepoint_binding_cs/ServicePoint.Tests/BrightnessGridTests.cs @@ -0,0 +1,12 @@ +namespace ServicePoint.Tests; + +public class BBrightnessGridTests +{ + [Fact] + public void UseAfterFree() + { + var grid = new BrightnessGrid(23, 42); + _ = Command.CharBrightness(0, 0, grid); + Assert.Throws(() => _ = Command.CharBrightness(0, 0, grid)); + } +} diff --git a/crates/servicepoint_binding_cs/ServicePoint.Tests/CommandTests.cs b/crates/servicepoint_binding_cs/ServicePoint.Tests/CommandTests.cs index bea8149..af44f8a 100644 --- a/crates/servicepoint_binding_cs/ServicePoint.Tests/CommandTests.cs +++ b/crates/servicepoint_binding_cs/ServicePoint.Tests/CommandTests.cs @@ -5,10 +5,11 @@ public class CommandTests private Connection _fakeConnection = Connection.Fake(); [Fact] - public void Test1() + public void UseAfterSend() { var command = Command.Clear(); _fakeConnection.Send(command); Assert.Throws(() => _fakeConnection.Send(command)); + _fakeConnection.Send(Command.Clear()); } } diff --git a/crates/servicepoint_binding_cs/ServicePoint.Tests/Cp437GridTests.cs b/crates/servicepoint_binding_cs/ServicePoint.Tests/Cp437GridTests.cs new file mode 100644 index 0000000..73f2c98 --- /dev/null +++ b/crates/servicepoint_binding_cs/ServicePoint.Tests/Cp437GridTests.cs @@ -0,0 +1,32 @@ +using System.Runtime.CompilerServices; + +namespace ServicePoint.Tests; + +public class Cp437GridTests +{ + [Fact] + public void UseAfterFree() + { + var grid = new Cp437Grid(2, 3); + _ = Command.Cp437Data(0, 0, grid.Clone()); + _ = Command.Cp437Data(0, 0, grid); + Assert.Throws(() => _ = Command.Cp437Data(0, 0, grid)); + } + + [Fact] + public void ReadAndWriteString() + { + var grid = new Cp437Grid(3, 2); + grid[1] = "abc"; + Assert.Equal("abc", grid[1]); + } + + [Fact] + public void LoadSpan() + { + var ascii_str = "abc123"u8; + var grid = Cp437Grid.Load(3, 2, ascii_str); + Assert.Equal("abc", grid[0]); + Assert.Equal("123", grid[1]); + } +}