Skip to content

Commit

Permalink
rmvwht, depad, stripb and zonkhl tests, fixes to majorbbs (#232)
Browse files Browse the repository at this point in the history
* rmvwht and zonkhl tests, fixes to majorbbs

* Add trailing CR

* Fixed trailing CRs and using

* Fixed blank space

* Updated Tests/Ordinals

* Format

* format

* Formatting

* Updated depad test

* Update stripb()

* Update stripb()

* stripb tests

* Update stripb declaration

* add update AX check
  • Loading branch information
tuday2 authored Oct 31, 2020
1 parent 39a1f69 commit 7a5adc7
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 44 deletions.
35 changes: 35 additions & 0 deletions MBBSEmu.Tests/ExportedModules/Majorbbs/depad_Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Collections.Generic;
using System.Text;
using MBBSEmu.Memory;
using Xunit;

namespace MBBSEmu.Tests.ExportedModules.Majorbbs
{
public class depad_Tests : ExportedModuleTestBase
{
private const int DEPAD_ORDINAL = 164;

[Theory]
[InlineData("% ", 3, "%\0")]
[InlineData("T ", 4, "T\0")]
[InlineData("T ", 1, "T\0")]
[InlineData("TeSt ", 2, "TeSt\0")]
[InlineData("TeSt", 0, "TeSt\0")]
[InlineData("", 0, "\0")]
public void DEPAD_Test(string inputString, ushort expected, string expectedString)
{
//Reset State
Reset();

var stringPointer = mbbsEmuMemoryCore.AllocateVariable("INPUT_STRING", (ushort)(inputString.Length + 1));
mbbsEmuMemoryCore.SetArray("INPUT_STRING", Encoding.ASCII.GetBytes(inputString));

//Execute Test
ExecuteApiTest(HostProcess.ExportedModules.Majorbbs.Segment, DEPAD_ORDINAL, new List<IntPtr16> { stringPointer });

//Verify Results
Assert.Equal(expected, mbbsEmuCpuRegisters.AX);
Assert.Equal(expectedString, Encoding.ASCII.GetString(mbbsEmuMemoryCore.GetString("INPUT_STRING")));
}
}
}
33 changes: 33 additions & 0 deletions MBBSEmu.Tests/ExportedModules/Majorbbs/rmvwht_Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Collections.Generic;
using System.Text;
using MBBSEmu.Memory;
using Xunit;

namespace MBBSEmu.Tests.ExportedModules.Majorbbs
{
public class rmvwht_Tests : ExportedModuleTestBase
{
private const int RMVWHT_ORDINAL = 501;

[Theory]
[InlineData("upper case", "uppercase\0")]
[InlineData(" capitalize me", "capitalizeme\0")]
[InlineData("lower case words", "lowercasewords\0")]
[InlineData(" ---&&&^^^ hello", "---&&&^^^hello\0")]
[InlineData(" hi", "hi\0")]
public void RMVWHT_Test(string inputString, string expectedString)
{
//Reset State
Reset();

var stringPointer = mbbsEmuMemoryCore.AllocateVariable("INPUT_STRING", (ushort)(inputString.Length + 1));
mbbsEmuMemoryCore.SetArray("INPUT_STRING", Encoding.ASCII.GetBytes(inputString));

//Execute Test
ExecuteApiTest(HostProcess.ExportedModules.Majorbbs.Segment, RMVWHT_ORDINAL, new List<IntPtr16> { stringPointer });

//Verify Results
Assert.Equal(expectedString, Encoding.ASCII.GetString(mbbsEmuMemoryCore.GetString("INPUT_STRING")));
}
}
}
2 changes: 1 addition & 1 deletion MBBSEmu.Tests/ExportedModules/Majorbbs/skpwht_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ public void SKPWHT_Test(string inputString, string expectedString)
mbbsEmuMemoryCore.GetString(mbbsEmuCpuRegisters.GetPointer())));
}
}
}
}
2 changes: 1 addition & 1 deletion MBBSEmu.Tests/ExportedModules/Majorbbs/stlcpy_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ public void stlcpy_Test(ushort dstChars, string srcString, string expected)
Assert.Equal(destinationStringPointer.Offset, mbbsEmuCpuRegisters.AX);
}
}
}
}
34 changes: 34 additions & 0 deletions MBBSEmu.Tests/ExportedModules/Majorbbs/stripb_Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Collections.Generic;
using System.Text;
using MBBSEmu.Memory;
using Xunit;

namespace MBBSEmu.Tests.ExportedModules.Majorbbs
{
public class stripb_Tests : ExportedModuleTestBase
{
private const int STRIPB_ORDINAL = 577;

[Theory]
[InlineData("T", "T\0")]
[InlineData("T ", "T\0")]
[InlineData(" ", " \0")]
[InlineData(" XX ", " XX\0")]
[InlineData("TEST test TEST\0", "TEST test TEST\0")]
[InlineData("TeSt \0", "TeSt\0")]
public void STRIPB_Test(string inputString, string expectedString)
{
//Reset State
Reset();

var stringPointer = mbbsEmuMemoryCore.AllocateVariable("INPUT_STRING", (ushort)(inputString.Length + 1));
mbbsEmuMemoryCore.SetArray("INPUT_STRING", Encoding.ASCII.GetBytes(inputString));

//Execute Test
ExecuteApiTest(HostProcess.ExportedModules.Majorbbs.Segment, STRIPB_ORDINAL, new List<IntPtr16> { stringPointer });

//Verify Results
Assert.Equal(expectedString, Encoding.ASCII.GetString(mbbsEmuMemoryCore.GetString("INPUT_STRING")));
}
}
}
34 changes: 34 additions & 0 deletions MBBSEmu.Tests/ExportedModules/Majorbbs/zonkhl_Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Collections.Generic;
using System.Text;
using MBBSEmu.Memory;
using Xunit;

namespace MBBSEmu.Tests.ExportedModules.Majorbbs
{
public class zonkhl_Tests : ExportedModuleTestBase
{
private const int ZONKHL_ORDINAL = 652;

[Theory]
[InlineData("upper case", "Upper Case\0")]
[InlineData(" capitalize me", " Capitalize Me\0")]
[InlineData("lower case words", "Lower Case Words\0")]
[InlineData("loWER caSE worDS", "Lower Case Words\0")]
[InlineData(" ---&&&^^^ hello", " ---&&&^^^ Hello\0")]
[InlineData(" hi", " Hi\0")]
public void ZONKHL_Test(string inputString, string expectedString)
{
//Reset State
Reset();

var stringPointer = mbbsEmuMemoryCore.AllocateVariable("INPUT_STRING", (ushort)(inputString.Length + 1));
mbbsEmuMemoryCore.SetArray("INPUT_STRING", Encoding.ASCII.GetBytes(inputString));

//Execute Test
ExecuteApiTest(HostProcess.ExportedModules.Majorbbs.Segment, ZONKHL_ORDINAL, new List<IntPtr16> { stringPointer });

//Verify Results
Assert.Equal(expectedString, Encoding.ASCII.GetString(mbbsEmuMemoryCore.GetString("INPUT_STRING")));
}
}
}
64 changes: 22 additions & 42 deletions MBBSEmu/HostProcess/ExportedModules/Majorbbs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4300,7 +4300,7 @@ private void strstr()
///
/// Signature: int nremoved=depad(char *string)
/// </summary>
private void depad()
private void depad(bool updateAX = true)
{
var stringPointer = GetParameterPointer(0);

Expand All @@ -4320,7 +4320,9 @@ private void depad()
}

Module.Memory.SetArray(stringPointer, stringToSearch);
Registers.AX = numRemoved;

if (updateAX)
Registers.AX = numRemoved;
}

private ReadOnlySpan<byte> othusn => Module.Memory.GetVariablePointer("OTHUSN").Data;
Expand Down Expand Up @@ -5993,27 +5995,26 @@ private void getdate()
/// </summary>
private void zonkhl()
{
var stgPointer = GetParameterPointer(0);

var stgToParse = Module.Memory.GetString(stgPointer).ToArray();

var toUpper = true;
for (var i = 0; i < stgToParse.Length; i++)
var inputStringPointer = GetParameterPointer(0);
var inputString = Module.Memory.GetString(inputStringPointer).ToArray();
var isSpace = true;

for (var i = 0; i < inputString.Length; i++)
{
if (toUpper)
{
if (stgToParse[i] >= 'a' && stgToParse[i] <= 'z')
stgToParse[i] -= 32;

toUpper = false;
}
else if (stgToParse[i] == 32)
if (char.IsUpper((char)inputString[i]))
inputString[i] = (byte)char.ToLower((char)inputString[i]);

if (inputString[i] == (byte) ' ')
isSpace = true;

if (char.IsLower((char)inputString[i]) && isSpace)
{
toUpper = true;
inputString[i] = (byte)char.ToUpper((char)inputString[i]);
isSpace = false;
}
}

Module.Memory.SetArray(stgPointer, stgToParse);
Module.Memory.SetArray(inputStringPointer, inputString);
}

/// <summary>
Expand Down Expand Up @@ -6044,9 +6045,8 @@ private void rmvwht()
{
var stringPointer = GetParameterPointer(0);

var stringToParse = Encoding.ASCII.GetString(Module.Memory.GetString(stringPointer, true));

var parsedString = stringToParse.Trim() + '\0';
var stringToParse = Encoding.ASCII.GetString(Module.Memory.GetString(stringPointer));
var parsedString = string.Concat(stringToParse.Where(c => !char.IsWhiteSpace(c)));

Module.Memory.SetArray(stringPointer, Encoding.ASCII.GetBytes(parsedString));
}
Expand Down Expand Up @@ -7028,27 +7028,7 @@ private void injoth()
///
/// Signature: void stripb(char *stg);
/// </summary>
private void stripb()
{
var stringToParsePointer = GetParameterPointer(0);

var stringToParse = Module.Memory.GetString(stringToParsePointer).ToArray();

for (var i = 2; i < stringToParse.Length; i++)
{
if (stringToParse[^i] == (byte)' ')
continue;

//String had no trailing spaces
if (i == 1)
return;

stringToParse[^(i - 1)] = 0;

//Write the new terminated string back
Module.Memory.SetArray(stringToParsePointer, stringToParse);
}
}
private void stripb() => depad(false);

/// <summary>
/// Formats a String for use in btrieve (best I can tell)
Expand Down

0 comments on commit 7a5adc7

Please sign in to comment.