mirror of
https://github.com/pleonex/NitroDebugger.git
synced 2025-06-19 05:35:32 -04:00
Closed #38. Implements a base for plugins.
This commit is contained in:
parent
1ae07b9bef
commit
ccdf3980a9
@ -51,6 +51,7 @@
|
||||
<Compile Include="GdbStreamTests.cs" />
|
||||
<Compile Include="GdbTestingBase.cs" />
|
||||
<Compile Include="GdbSessionManagerTests.cs" />
|
||||
<Compile Include="PluginTests.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
|
63
NitroDebugger.UnitTests/PluginTests.cs
Normal file
63
NitroDebugger.UnitTests/PluginTests.cs
Normal file
@ -0,0 +1,63 @@
|
||||
//
|
||||
// PluginTests.cs
|
||||
//
|
||||
// Author:
|
||||
// Benito Palacios Sánchez <benito356@gmail.com>
|
||||
//
|
||||
// Copyright (c) 2015 Benito Palacios Sánchez
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Moq;
|
||||
using NitroDebugger;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace UnitTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class PluginTests
|
||||
{
|
||||
[Test]
|
||||
public void GetInstance()
|
||||
{
|
||||
TestPlugin plugin = new TestPlugin();
|
||||
Assert.AreSame(Plugin.Instances[0], plugin);
|
||||
plugin.Dispose();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetFirstInstance()
|
||||
{
|
||||
TestPlugin plugin1 = new TestPlugin();
|
||||
TestPlugin plugin2 = new TestPlugin();
|
||||
Assert.AreSame(Plugin.Instances.First(), plugin1);
|
||||
plugin1.Dispose();
|
||||
plugin2.Dispose();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RemoveAfterDispose()
|
||||
{
|
||||
TestPlugin plugin = new TestPlugin();
|
||||
plugin.Dispose();
|
||||
Assert.Throws<InvalidOperationException>(() => Plugin.Instances.First());
|
||||
}
|
||||
}
|
||||
|
||||
class TestPlugin : Plugin
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -36,6 +36,9 @@
|
||||
<Reference Include="libgame">
|
||||
<HintPath>..\libgame\bin\Debug\libgame.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Mono.Addins">
|
||||
<HintPath>..\libgame\libs\mono-addins\bin\Mono.Addins.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
@ -65,6 +68,7 @@
|
||||
<Compile Include="RSP\ExecutionManager.cs" />
|
||||
<Compile Include="RSP\GdbStream.cs" />
|
||||
<Compile Include="RSP\GdbSessionManager.cs" />
|
||||
<Compile Include="Plugin.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
|
59
NitroDebugger/Plugin.cs
Normal file
59
NitroDebugger/Plugin.cs
Normal file
@ -0,0 +1,59 @@
|
||||
//
|
||||
// Plugin.cs
|
||||
//
|
||||
// Author:
|
||||
// Benito Palacios Sánchez <benito356@gmail.com>
|
||||
//
|
||||
// Copyright (c) 2015 Benito Palacios Sánchez
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using Mono.Addins;
|
||||
|
||||
namespace NitroDebugger
|
||||
{
|
||||
[TypeExtensionPoint]
|
||||
public abstract class Plugin : IDisposable
|
||||
{
|
||||
static List<Plugin> instances = new List<Plugin>();
|
||||
|
||||
public Plugin()
|
||||
{
|
||||
instances.Add(this);
|
||||
}
|
||||
|
||||
~Plugin()
|
||||
{
|
||||
this.Dispose(false);
|
||||
}
|
||||
|
||||
public static ReadOnlyCollection<Plugin> Instances {
|
||||
get { return new ReadOnlyCollection<Plugin>(instances); }
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
this.Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool freeManagedResourcesAlso)
|
||||
{
|
||||
instances.Remove(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Mono.Addins;
|
||||
|
||||
// Information about this assembly is defined by the following attributes.
|
||||
// Change them to the values specific to your project.
|
||||
@ -40,3 +41,4 @@ using System.Runtime.CompilerServices;
|
||||
//[assembly: AssemblyDelaySign(false)]
|
||||
//[assembly: AssemblyKeyFile("")]
|
||||
|
||||
[assembly:AddinRoot("NitroDebugger", "1.0")]
|
Loading…
Reference in New Issue
Block a user