Skip to content

Commit

Permalink
Add some unit tests for LegacyASL
Browse files Browse the repository at this point in the history
git-svn-id: https://quest.svn.codeplex.com/svn/trunk@5322 4a90e977-6436-4932-9605-20e10c2b6fb3
  • Loading branch information
alexwarren committed Jan 30, 2011
1 parent 44f5798 commit 691c335
Show file tree
Hide file tree
Showing 7 changed files with 318 additions and 10 deletions.
10 changes: 0 additions & 10 deletions Legacy/LegacyGame.vb
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,8 @@ Public Class LegacyGame
Public Const LOGTYPE_USERERROR As Integer = 6
Public Const LOGTYPE_INTERNALERROR As Integer = 7

Private Const PANEVIEW_ON As Integer = 1
Private Const PANEVIEW_OFF As Integer = 2
Private Const PANEVIEW_DISABLED As Integer = 3

Private m_CurrentDirectory As String

Private Const LOAD_FAIL_FILENOTFOUND As Integer = 1
Private Const LOAD_FAIL_ERRORS As Integer = 2
Private Const LOAD_FAIL_INVALIDFILE As Integer = 3
Private Const LOAD_FAIL_BADSTRUCTURE As Integer = 4
Private Const LOAD_FAIL_NODEFINEGAMEBLOCK As Integer = 5

Private m_oDefineBlockParams As Dictionary(Of String, Dictionary(Of String, String))

Friend Enum eDirection
Expand Down
73 changes: 73 additions & 0 deletions LegacyASLTests/LegacyASLTests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>
</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{9D7478AE-52D8-41B6-8E5C-D3F483919993}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>LegacyASLTests</RootNamespace>
<AssemblyName>LegacyASLTests</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
</ItemGroup>
<ItemGroup>
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
<Visible>False</Visible>
</CodeAnalysisDependentAssemblyPaths>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="LegacyGameTests.cs" />
<Compile Include="TestPlayer.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\IASL\IASL.csproj">
<Project>{BE34CB28-317F-4732-AA32-9D715B4F2C7E}</Project>
<Name>IASL</Name>
</ProjectReference>
<ProjectReference Include="..\Legacy\LegacyASL.vbproj">
<Project>{42EEDC11-C395-4CE8-80E3-057AF4100DDE}</Project>
<Name>LegacyASL</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="test1.asl" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
76 changes: 76 additions & 0 deletions LegacyASLTests/LegacyGameTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using AxeSoftware.Quest;
using AxeSoftware.Quest.LegacyASL;

namespace LegacyASLTests
{
[TestClass]
public class LegacyGameTests
{
private IASL m_game;
private TestPlayer m_player = new TestPlayer();

[TestInitialize]
public void Init()
{
m_game = new LegacyGame(@"..\..\..\LegacyASLTests\test1.asl");
m_game.PrintText += m_player.PrintText;
m_game.RequestRaised += m_player.RequestRaised;
m_game.Initialise(m_player);
m_game.Begin();
}

[TestMethod]
public void TestLookAt()
{
m_player.ClearBuffer();
m_game.SendCommand("look at object");
Assert.AreEqual("&gt; look at object", m_player.Buffer(0));
Assert.AreEqual("object look desc", m_player.Buffer(1));
}

[TestMethod]
public void TestWait()
{
m_player.ClearBuffer();
m_game.SendCommand("wait");
Assert.AreEqual("Start wait", m_player.Buffer(1));
Assert.AreEqual(true, m_player.IsWaiting);
Assert.AreEqual(2, m_player.BufferLength, "Expected nothing else in the output buffer after the wait command");
m_player.IsWaiting = false;
m_game.FinishWait();
Assert.AreEqual("Done wait", m_player.Buffer(2));
}

[TestMethod]
public void TestEnter()
{
m_player.ClearBuffer();
m_game.SendCommand("enter");
Assert.AreEqual("Enter text", m_player.Buffer(1));
Assert.AreEqual(2, m_player.BufferLength, "Expected nothing else in the output buffer after the enter command");
m_game.SendCommand("response");
Assert.AreEqual("You entered: response", m_player.Buffer(2));
}

[TestMethod]
public void TestMenu()
{
m_player.ClearBuffer();
m_player.LatestMenu = null;
m_game.SendCommand("x twin");
Assert.AreEqual("- <i>Please select which twin you mean:</i>", m_player.Buffer(1));
Assert.AreEqual(2, m_player.BufferLength, "Expected nothing else in the output buffer after menu displayed");
Assert.AreNotEqual(null, m_player.LatestMenu);
Assert.AreEqual(2, m_player.LatestMenu.Options.Count);
Assert.AreEqual("Twin 1", m_player.LatestMenu.Options.ElementAt(0).Value);
Assert.AreEqual("Twin 2", m_player.LatestMenu.Options.ElementAt(1).Value);
m_game.SetMenuResponse(m_player.LatestMenu.Options.ElementAt(0).Key);
Assert.AreEqual("It's twin 1", m_player.Buffer(3));
}
}
}
35 changes: 35 additions & 0 deletions LegacyASLTests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("LegacyASLTests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LegacyASLTests")]
[assembly: AssemblyCopyright("Copyright © 2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("84f50461-ce87-4992-8a6d-e037badea771")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
82 changes: 82 additions & 0 deletions LegacyASLTests/TestPlayer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AxeSoftware.Quest;

namespace LegacyASLTests
{
class TestPlayer : IPlayer
{
private List<string> m_output = new List<string>();

public void ClearBuffer()
{
m_output.Clear();
}

public string Buffer(int index)
{
return m_output[index];
}

public int BufferLength
{
get { return m_output.Count; }
}

public void PrintText(string text)
{
if (!text.StartsWith("<output>") || !text.EndsWith("</output>"))
{
throw new ArgumentException("Invalid output format");
}
// remove <output> and </output>
text = text.Substring(8, text.Length - 17);
m_output.Add(text);
}

public void RequestRaised(Request request, string data)
{
}

public void ShowMenu(MenuData menuData)
{
LatestMenu = menuData;
}

public MenuData LatestMenu { get; set; }

public void DoWait()
{
IsWaiting = true;
}

public bool IsWaiting { get; set; }

public bool ShowMsgBox(string caption)
{
throw new NotImplementedException();
}

public void SetWindowMenu(MenuData menuData)
{
throw new NotImplementedException();
}

public string GetNewGameFile(string originalFilename, string extensions)
{
throw new NotImplementedException();
}

public void PlaySound(string filename, bool synchronous, bool looped)
{
throw new NotImplementedException();
}

public void StopSound()
{
throw new NotImplementedException();
}
}
}
44 changes: 44 additions & 0 deletions LegacyASLTests/test1.asl
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
!include <stdverbs.lib>

define game <Unit Test 1>
asl-version <410>
start <room>
end define

define options
debug on
panes on
abbreviations on
end define

define room <room>

command <wait> {
wait <Start wait>
msg <Done wait>
}

command <enter> {
msg <Enter text>
enter <test>
msg <You entered: #test#>
}

define object <object>
look <object look desc>
end define

define object <twin1>
alias <twin>
detail <Twin 1>
look <It's twin 1>
end define

define object <twin2>
alias <twin>
detail <Twin 2>
look <It's twin 2>
end define

end define

8 changes: 8 additions & 0 deletions Quest 5.0.sln
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "LegacyASL", "Legacy\LegacyA
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebPlayer", "WebPlayer\WebPlayer.csproj", "{803A5B78-3FBA-4836-80EF-9BA104FC1D3E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LegacyASLTests", "LegacyASLTests\LegacyASLTests.csproj", "{9D7478AE-52D8-41B6-8E5C-D3F483919993}"
EndProject
Global
GlobalSection(TestCaseManagementSettings) = postSolution
CategoryFile = Quest 5.0.vsmdi
Expand Down Expand Up @@ -119,6 +121,12 @@ Global
{803A5B78-3FBA-4836-80EF-9BA104FC1D3E}.Release|Any CPU.Build.0 = Release|Any CPU
{803A5B78-3FBA-4836-80EF-9BA104FC1D3E}.ReleaseSetup|Any CPU.ActiveCfg = Release|Any CPU
{803A5B78-3FBA-4836-80EF-9BA104FC1D3E}.ReleaseSetup|Any CPU.Build.0 = Release|Any CPU
{9D7478AE-52D8-41B6-8E5C-D3F483919993}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9D7478AE-52D8-41B6-8E5C-D3F483919993}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9D7478AE-52D8-41B6-8E5C-D3F483919993}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9D7478AE-52D8-41B6-8E5C-D3F483919993}.Release|Any CPU.Build.0 = Release|Any CPU
{9D7478AE-52D8-41B6-8E5C-D3F483919993}.ReleaseSetup|Any CPU.ActiveCfg = Release|Any CPU
{9D7478AE-52D8-41B6-8E5C-D3F483919993}.ReleaseSetup|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit 691c335

Please sign in to comment.