Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,136 @@
2010-04-13 Jonathan Pryor <jpryor@novell.com>
* CodeGeneratorTest.cs: Add some testing for CodeRegionDirectives.
2008-05-09 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromTypeTestBase.cs: Added tests for
System.ParamArrayAttribute custom attribute.
2008-04-30 Gert Driesen <drieseng@users.sourceforge.net>
* ExecutorTest.cs: Use Assert.Ignore when ping is not available.
Avoid using ExpectedException in ExecWait test, and added link to
MS bug report.
2008-04-08 Jb Evain <jbevain@novell.com>
* CodeGeneratorFromTypeTestBase.cs: add a generator for
abstract properties.
2008-01-29 Zoltan Varga <vargaz@gmail.com>
* ExecutorTest.cs (ExecWait_NullTempFileCollection): Fix the cmdNoFound case.
* ExecutorTest.cs: Handle cases when ping is not in the PATH, or when it
returns a non standard error code.
2007-12-21 Rolf Bjarne Kvinge <RKvinge@novell.com>
* CodeGeneratorFromTypeTestBase.cs: Added PartialTypeTest.
2007-01-18 Atsushi Enomoto <atsushi@ximian.com>
* CodeGeneratorFromTypeTestBase.cs :
added GenerateGenericCodeTypeReferences() for generic type test.
2005-11-30 Gert Driesen <drieseng@users.sourceforge.net>
* IndentedTextWriterTest.cs: Added tests for Indent property.
2005-11-30 Sebastien Pouliot <sebastien@ximian.com>
* CodeCompilerCas.cs: MS doesn't demand EnvironmentPermission under
1.x.
2005-11-26 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromTypeTestBase.cs: Modified GetMethodMembersType3 to
add parameter with no name.
2005-11-02 Sebastien Pouliot <sebastien@ximian.com>
* CodeCompilerCas.cs: New. CAS unit tests.
* ExecutorCas.cs: New. CAS unit tests.
* ExecutorTest.cs: New. Unit tests for Executor.
2005-11-01 Sebastien Pouliot <sebastien@ximian.com>
* CodeGeneratorCas.cs: New. CAS unit tests.
2005-11-01 Sebastien Pouliot <sebastien@ximian.com>
* CodeDomProviderCas.cs: New. CAS unit tests.
2005-10-28 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorTestBase.cs: Set eol-style to native.
* CodeGeneratorTest.cs: Set eol-style to native.
* CodeGeneratorFromTypeTestBase.cs: Added tests for
CodeEntryPointMethod and bug #76580. Set eol-style to native.
* IndentedTextWriterTest.cs: Set eol-style to native.
2005-10-25 Sebastien Pouliot <sebastien@ximian.com>
* CompilerErrorCas.cs: Under 1.x CompilerError is protected by a
LinkDemand for Unrestricted.
* CompilerErrorCollectionCas.cs: Under 1.x CompilerError is protected
by a LinkDemand for Unrestricted.
* TempFileCollectionCas.cs: Moved precompiler directive to the right
method (to ignore a test under MS 1.x).
2005-10-25 Sebastien Pouliot <sebastien@ximian.com>
* TempFileCollectionCas.cs: New. CAS unit tests.
* TempFileCollectionTest.cs: New. Very basic tests to check the
behaviour of the TempDir property.
2005-10-24 Sebastien Pouliot <sebastien@ximian.com>
* CodeGeneratorOptionsCas.cs: New. CAS unit tests.
* CodeGeneratorOptionsTest.cs: New. Unit tests.
* CodeParserCas.cs: New. CAS unit tests.
* CompilerErrorCas.cs: New. CAS unit tests.
* CompilerErrorCollectionCas.cs: New. CAS unit tests.
* CompilerInfoCas.cs: New. CAS unit tests.
* CompilerParametersCas.cs: New. CAS unit tests.
* CompilerResultsCas.cs: New. CAS unit tests.
* GeneratedCodeAttributeCas.cs: New. CAS unit tests.
* GeneratedCodeAttributeTest.cs: New. Unit tests.
* IndentedTextWriterCas.cs: New. CAS unit tests.
2005-10-15 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorTestBase.cs: No longer keep instance of StringWriter to
allow GenerateCodeFromType to be executed multiple times with relying
on user to reset writer. Allow CodeGeneratorOptions to be passed in,
in order to support bracing style tests.
* CodeGeneratorFromTypeTestBase.cs: Modify Generate* methods to take
CodeGeneratorOptions instance and pass it on to GenerateCodeFromType.
2005-07-30 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromTypeTestBase.cs: Added NewSlot tests.
2005-07-24 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorTest.cs: Removed duplicate import of NUNit.Framework
namespace.
* CodeGeneratorFromTypeTestBase.cs: Added BaseTypes and
TypeConstructor tests.
2005-07-21 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorTest.cs: Added unit tests for CodeGenerator.IsCurrent*.
2005-07-21 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromTypeTestBase.cs: Base class for unit tests for
CodeGenerator.GenerateCodeFromType.
* CodeGeneratorTestBase.cs: Base class for CodeGenerator unit tests.
2004-06-13 Gert Driesen <drieseng@users.sourceforge.net>
* IndentedTextWriterTest.cs: added test for IndentedTextWriter

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,346 @@
//
// CodeDomProviderCas.cs
// - CAS unit tests for System.CodeDom.Compiler.CodeDomProvider
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Configuration;
using System.IO;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
namespace MonoCasTests.System.CodeDom.Compiler {
class CodeDomProviderTest: CodeDomProvider {
public CodeDomProviderTest ()
{
}
public override ICodeCompiler CreateCompiler ()
{
return null;
}
public override ICodeGenerator CreateGenerator ()
{
return null;
}
}
[TestFixture]
[Category ("CAS")]
public class CodeDomProviderCas {
private StringWriter writer;
private CodeDomProviderTest cdp;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
// at full trust
writer = new StringWriter ();
cdp = new CodeDomProviderTest ();
}
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Defaults ()
{
cdp = new CodeDomProviderTest (); // execute ctor not a full trust
Assert.AreEqual (String.Empty, cdp.FileExtension, "FileExtension");
Assert.AreEqual (LanguageOptions.None, cdp.LanguageOptions, "LanguageOptions");
Assert.IsNull (cdp.CreateCompiler (), "CreateCompiler");
Assert.IsNull (cdp.CreateGenerator (), "CreateGenerator");
Assert.IsNull (cdp.CreateGenerator (String.Empty), "CreateGenerator(string)");
Assert.IsNull (cdp.CreateGenerator (writer), "CreateGenerator(TextWriter)");
Assert.IsNull (cdp.CreateParser (), "CreateParser()");
Assert.IsNotNull (cdp.GetConverter (typeof (string)), "GetConverter");
#if NET_2_0
Assert.IsNotNull (CodeDomProvider.GetAllCompilerInfo (), "GetAllCompilerInfo");
// mono returns null (missing config?)
CodeDomProvider.GetCompilerInfo ("cs");
CodeDomProvider.GetLanguageFromExtension ("cs");
Assert.IsFalse (CodeDomProvider.IsDefinedExtension (String.Empty), "String.Empty");
Assert.IsFalse (CodeDomProvider.IsDefinedLanguage (String.Empty), "String.Empty");
#endif
}
#if NET_2_0
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (NotImplementedException))]
public void CompileAssemblyFromDom_Deny_Unrestricted ()
{
cdp.CompileAssemblyFromDom (null, null);
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (NotImplementedException))]
public void CompileAssemblyFromFile_Deny_Unrestricted ()
{
cdp.CompileAssemblyFromFile (null, null);
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (NotImplementedException))]
public void CompileAssemblyFromSource_Deny_Unrestricted ()
{
cdp.CompileAssemblyFromSource (null, null);
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (NotImplementedException))]
public void CreateEscapedIdentifier_Deny_Unrestricted ()
{
cdp.CreateEscapedIdentifier (null);
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (NotImplementedException))]
public void CreateValidIdentifier_Deny_Unrestricted ()
{
cdp.CreateValidIdentifier (null);
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (NotImplementedException))]
public void GenerateCodeFromCompileUnit_Deny_Unrestricted ()
{
cdp.GenerateCodeFromCompileUnit (null, writer, null);
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (NotImplementedException))]
public void GenerateCodeFromExpression_Deny_Unrestricted ()
{
cdp.GenerateCodeFromExpression (null, writer, null);
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (NotImplementedException))]
public void GenerateCodeFromMember_Deny_Unrestricted ()
{
cdp.GenerateCodeFromMember (null, writer, null);
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (NotImplementedException))]
public void GenerateCodeFromNamespace_Deny_Unrestricted ()
{
cdp.GenerateCodeFromNamespace (null, writer, null);
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (NotImplementedException))]
public void GenerateCodeFromStatement_Deny_Unrestricted ()
{
cdp.GenerateCodeFromStatement (null, writer, null);
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (NotImplementedException))]
public void GenerateCodeFromType_Deny_Unrestricted ()
{
cdp.GenerateCodeFromType (null, writer, null);
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (NotImplementedException))]
public void GetTypeOutput_Deny_Unrestricted ()
{
cdp.GetTypeOutput (new CodeTypeReference ());
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (NotImplementedException))]
public void IsValidIdentifier_Deny_Unrestricted ()
{
cdp.IsValidIdentifier (null);
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (NotImplementedException))]
public void Parse_Deny_Unrestricted ()
{
cdp.Parse (null);
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (NotImplementedException))]
public void Supports_Deny_Unrestricted ()
{
cdp.Supports (GeneratorSupport.ArraysOfArrays);
}
// static methods
[Test]
public void CreateProvider_Allow_Everything ()
{
CodeDomProvider.CreateProvider ("cs");
// returns null on mono (missing config?)
}
[Test]
[EnvironmentPermission (SecurityAction.Deny, Read = "MONO")]
[ExpectedException (typeof (SecurityException))]
[Category ("NotWorking")] // mono returns null not an instance
public void CreateProvider_Deny_Anything ()
{
CodeDomProvider cdp = CodeDomProvider.CreateProvider ("cs");
// requires full trust (i.e. unrestricted permission set)
}
[Test]
public void LinkDemand_StaticMethods_Allow_Everything ()
{
object[] language = new object[1] { "cs" };
object[] empty = new object[1] { String.Empty };
MethodInfo mi = typeof (CodeDomProvider).GetMethod ("CreateProvider");
mi.Invoke (null, language); // returns null on mono (missing config?)
mi = typeof (CodeDomProvider).GetMethod ("GetAllCompilerInfo");
Assert.IsNotNull (mi.Invoke (null, null), "GetAllCompilerInfo()");
mi = typeof (CodeDomProvider).GetMethod ("GetCompilerInfo");
mi.Invoke (null, language); // returns null on mono (missing config?)
mi = typeof (CodeDomProvider).GetMethod ("GetLanguageFromExtension");
mi.Invoke (null, language); // returns null on mono (missing config?)
mi = typeof (CodeDomProvider).GetMethod ("IsDefinedExtension");
Assert.IsFalse ((bool)mi.Invoke (null, empty), "IsDefinedExtension('')");
mi = typeof (CodeDomProvider).GetMethod ("IsDefinedLanguage");
Assert.IsFalse ((bool)mi.Invoke (null, empty), "IsDefinedLanguage('')");
}
[Test]
[EnvironmentPermission (SecurityAction.Deny, Read = "MONO")]
[ExpectedException (typeof (SecurityException))]
public void LinkDemand_CreateProvider_Deny_Anything ()
{
MethodInfo mi = typeof (CodeDomProvider).GetMethod ("CreateProvider");
Assert.IsNotNull (mi, "CreateProvider");
Assert.IsNotNull (mi.Invoke (null, new object[1] { "cs" }), "CreateProvider(cs)");
}
[Test]
[EnvironmentPermission (SecurityAction.Deny, Read = "MONO")]
[ExpectedException (typeof (SecurityException))]
public void LinkDemand_GetAllCompilerInfo_Deny_Anything ()
{
MethodInfo mi = typeof (CodeDomProvider).GetMethod ("GetAllCompilerInfo");
Assert.IsNotNull (mi, "GetAllCompilerInfo");
Assert.IsNotNull (mi.Invoke (null, null), "GetAllCompilerInfo()");
// requires full trust (i.e. unrestricted permission set)
}
[Test]
[EnvironmentPermission (SecurityAction.Deny, Read = "MONO")]
[ExpectedException (typeof (SecurityException))]
public void LinkDemand_GetCompilerInfo_Deny_Anything ()
{
MethodInfo mi = typeof (CodeDomProvider).GetMethod ("GetCompilerInfo");
Assert.IsNotNull (mi, "GetCompilerInfo");
Assert.IsNotNull (mi.Invoke (null, new object[1] { "cs" }), "GetCompilerInfo(cs)");
// requires full trust (i.e. unrestricted permission set)
}
[Test]
[EnvironmentPermission (SecurityAction.Deny, Read = "MONO")]
[ExpectedException (typeof (SecurityException))]
public void LinkDemand_GetLanguageFromExtension_Deny_Anything ()
{
MethodInfo mi = typeof (CodeDomProvider).GetMethod ("GetLanguageFromExtension");
Assert.IsNotNull (mi, "GetLanguageFromExtension");
Assert.IsNotNull (mi.Invoke (null, new object[1] { null }), "invoke (null)");
// requires full trust (i.e. unrestricted permission set)
}
[Test]
[EnvironmentPermission (SecurityAction.Deny, Read = "MONO")]
[ExpectedException (typeof (SecurityException))]
public void LinkDemand_IsDefinedExtension_Deny_Anything ()
{
MethodInfo mi = mi = typeof (CodeDomProvider).GetMethod ("IsDefinedExtension");
Assert.IsNotNull (mi, "IsDefinedExtension");
Assert.IsFalse ((bool) mi.Invoke (null, new object[1] { String.Empty }), "IsDefinedExtension('')");
// requires full trust (i.e. unrestricted permission set)
}
[Test]
[EnvironmentPermission (SecurityAction.Deny, Read = "MONO")]
[ExpectedException (typeof (SecurityException))]
public void LinkDemand_IsDefinedLanguage_Deny_Anything ()
{
MethodInfo mi = mi = typeof (CodeDomProvider).GetMethod ("IsDefinedLanguage");
Assert.IsNotNull (mi, "IsDefinedLanguage");
Assert.IsFalse ((bool) mi.Invoke (null, new object[1] { String.Empty }), "IsDefinedLanguage('')");
// requires full trust (i.e. unrestricted permission set)
}
#endif
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void LinkDemand_Deny_Unrestricted ()
{
ConstructorInfo ci = typeof (CodeDomProviderTest).GetConstructor (new Type[0]);
Assert.IsNotNull (ci, "default .ctor()");
Assert.IsNotNull (ci.Invoke (null), "invoke");
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,192 @@
//
// CodeGenerator.GenerateFromCompileUnit Tests
//
// Authors:
// Ilker Cetinkaya (mail@ilker.de)
//
// This is a specific test for an issue on GenerateFromCompileUnit.
// Up until 2012 (version 2.10.n) the method emits attribute first
// and imports afterwards on global namespace scope. Example:
//
// ~~~~
// [assembly: AssemblyVersion("1.0")]
// using System.Reflection;
// ~~~~
//
// This in particular causes compiler to bail with CS1529.
// Albeit well aware that this is a _language specific_ issue
// (or requirement), the actual fix is aimed on CodeGenerator since
// the wrong emit order is as well in GenerateFromCompileUnit of abstract
// base. The probability to harm any other language generators
// is very low. It's near common sense to have imports on top
// on global namespace / file level.
//
// The test is being repeated for the internal `CSharpCodeGenerator`.
// See `Microsoft.CSharp` (Mono.CSharp namespace) for details.
//
// This test verifies the issue as well as describes correct expectation.
using System;
using System.CodeDom;
using System.CodeDom.Compiler;
using Microsoft.CSharp;
using System.IO;
using NUnit.Framework;
namespace MonoTests.System.CodeDom.Compiler
{
[TestFixture]
public class CodeGeneratorGenerateFromCompileUnitTest {
[Test]
public void When_Having_AssemblyAttribute_And_Using_Namespace_It_Should_Generate_Namespace_First_And_Attribute_Afterwards () {
ICodeGenerator generator = new SampleCodeGenerator ();
var compileUnit = ACompileUnitWithAttributeAndNamespace ();
var writer = new StringWriter ();
var options = new CodeGeneratorOptions ();
generator.GenerateCodeFromCompileUnit (compileUnit, writer, options);
string result = writer.ToString ();
int importPosition = result.IndexOf (IMPORT);
int attributePosition = result.IndexOf (ATTRIBUTE);
Assert.Greater (attributePosition, importPosition, "Actual order: " + result);
}
[Test]
public void CodeSnippetBlankLines ()
{
var opt = new CodeGeneratorOptions () {
BlankLinesBetweenMembers = false,
VerbatimOrder = false
};
var ccu = new CodeCompileUnit ();
var ns = new CodeNamespace ("Foo");
ccu.Namespaces.Add (ns);
var t = new CodeTypeDeclaration ("Bar");
ns.Types.Add (t);
t.Members.Add (new CodeSnippetTypeMember ("#line hidden"));
t.Members.Add (new CodeSnippetTypeMember ("#line hidden2"));
t.Members.Add (new CodeMemberMethod () { Name = "Foo" });
using (var sw = new StringWriter ()) {
new CSharpCodeProvider ().GenerateCodeFromCompileUnit (ccu, sw, opt);
var str = sw.ToString ();
Assert.IsFalse (str.Contains ("hidden2private"), "#0");
Assert.IsTrue (str.Contains( "#line hidden#line hidden2"), "#1");
}
}
[Test]
public void CodeSnippetBlankLinesVerbatimOrder ()
{
var opt = new CodeGeneratorOptions () {
BlankLinesBetweenMembers = false,
VerbatimOrder = true
};
var ccu = new CodeCompileUnit ();
var ns = new CodeNamespace ("Foo");
ccu.Namespaces.Add (ns);
var t = new CodeTypeDeclaration ("Bar");
ns.Types.Add (t);
t.Members.Add (new CodeSnippetTypeMember ("#line hidden"));
t.Members.Add (new CodeSnippetTypeMember ("#line hidden2"));
t.Members.Add (new CodeMemberMethod () { Name = "Foo" });
using (var sw = new StringWriter ()) {
new CSharpCodeProvider ().GenerateCodeFromCompileUnit (ccu, sw, opt);
var str = sw.ToString ();
Assert.IsFalse (str.Contains ("hidden2private"), "#0");
Assert.IsFalse (str.Contains( "#line hidden#line hidden2"), "#1");
Assert.IsTrue (str.Contains( "#line hidden" + Environment.NewLine), "#2");
Assert.IsTrue (str.Contains( "#line hidden2" + Environment.NewLine), "#3");
}
}
private const string ATTRIBUTE = "ATTRIBUTE";
private const string IMPORT = "IMPORT";
private CodeCompileUnit ACompileUnitWithAttributeAndNamespace () {
var compileUnit = new CodeCompileUnit ();
var importNs = new CodeNamespace ();
importNs.Imports.Add (new CodeNamespaceImport (IMPORT));
compileUnit.AssemblyCustomAttributes.Add (new CodeAttributeDeclaration (ATTRIBUTE));
compileUnit.Namespaces.Add (importNs);
return compileUnit;
}
private class SampleCodeGenerator : CodeGenerator {
/* test overrides */
protected override void GenerateAttributeDeclarationsStart (CodeAttributeDeclarationCollection attributes) { Output.Write ("ATTRIBUTE"); }
protected override void GenerateAttributeDeclarationsEnd (CodeAttributeDeclarationCollection attributes) {}
protected override void GenerateNamespaceImport (CodeNamespaceImport i) { Output.Write ("IMPORT"); }
/* must overrides */
protected override string NullToken { get { return string.Empty; } }
protected override void GenerateArgumentReferenceExpression (CodeArgumentReferenceExpression e) {}
protected override void GenerateArrayCreateExpression (CodeArrayCreateExpression e) {}
protected override void GenerateArrayIndexerExpression (CodeArrayIndexerExpression e) {}
protected override void GenerateAssignStatement (CodeAssignStatement s) {}
protected override void GenerateAttachEventStatement (CodeAttachEventStatement s) {}
protected override void GenerateBaseReferenceExpression (CodeBaseReferenceExpression e) {}
protected override void GenerateCastExpression (CodeCastExpression e) {}
protected override void GenerateComment (CodeComment comment) {}
protected override void GenerateConditionStatement (CodeConditionStatement s) {}
protected override void GenerateConstructor (CodeConstructor x, CodeTypeDeclaration d) {}
protected override void GenerateDelegateCreateExpression (CodeDelegateCreateExpression e) {}
protected override void GenerateDelegateInvokeExpression (CodeDelegateInvokeExpression e) {}
protected override void GenerateEntryPointMethod (CodeEntryPointMethod m, CodeTypeDeclaration d) {}
protected override void GenerateEvent (CodeMemberEvent ev, CodeTypeDeclaration d) {}
protected override void GenerateEventReferenceExpression (CodeEventReferenceExpression e) {}
protected override void GenerateExpressionStatement (CodeExpressionStatement statement) {}
protected override void GenerateField (CodeMemberField f) {}
protected override void GenerateFieldReferenceExpression (CodeFieldReferenceExpression e) {}
protected override void GenerateGotoStatement (CodeGotoStatement statement) {}
protected override void GenerateIndexerExpression (CodeIndexerExpression e) {}
protected override void GenerateIterationStatement (CodeIterationStatement s) {}
protected override void GenerateLabeledStatement (CodeLabeledStatement statement) {}
protected override void GenerateLinePragmaStart (CodeLinePragma p) {}
protected override void GenerateLinePragmaEnd (CodeLinePragma p) {}
protected override void GenerateMethod (CodeMemberMethod m, CodeTypeDeclaration d) {}
protected override void GenerateMethodInvokeExpression (CodeMethodInvokeExpression e) {}
protected override void GenerateMethodReferenceExpression (CodeMethodReferenceExpression e) {}
protected override void GenerateMethodReturnStatement (CodeMethodReturnStatement e) {}
protected override void GenerateNamespaceStart (CodeNamespace ns) {}
protected override void GenerateNamespaceEnd (CodeNamespace ns) {}
protected override void GenerateObjectCreateExpression (CodeObjectCreateExpression e) {}
protected override void GenerateProperty (CodeMemberProperty p, CodeTypeDeclaration d) {}
protected override void GeneratePropertyReferenceExpression (CodePropertyReferenceExpression e) {}
protected override void GeneratePropertySetValueReferenceExpression (CodePropertySetValueReferenceExpression e) {}
protected override void GenerateRemoveEventStatement (CodeRemoveEventStatement statement) {}
protected override void GenerateSnippetExpression (CodeSnippetExpression e) {}
protected override void GenerateSnippetMember (CodeSnippetTypeMember m) {}
protected override void GenerateThisReferenceExpression (CodeThisReferenceExpression e) {}
protected override void GenerateThrowExceptionStatement (CodeThrowExceptionStatement s) {}
protected override void GenerateTryCatchFinallyStatement (CodeTryCatchFinallyStatement s) {}
protected override void GenerateTypeEnd (CodeTypeDeclaration declaration) {}
protected override void GenerateTypeConstructor (CodeTypeConstructor constructor) {}
protected override void GenerateTypeStart (CodeTypeDeclaration declaration) {}
protected override void GenerateVariableDeclarationStatement (CodeVariableDeclarationStatement e) {}
protected override void GenerateVariableReferenceExpression (CodeVariableReferenceExpression e) {}
protected override void OutputType (CodeTypeReference t) {}
protected override string QuoteSnippetString (string value) { return string.Empty; }
protected override string CreateEscapedIdentifier (string value) { return string.Empty; }
protected override string CreateValidIdentifier (string value) { return string.Empty; }
protected override string GetTypeOutput (CodeTypeReference type) { return string.Empty; }
protected override bool IsValidIdentifier (string value) { return false; }
protected override bool Supports (GeneratorSupport supports) { return false; }
}
}
}

View File

@@ -0,0 +1,83 @@
//
// CodeGeneratorOptionsCas.cs
// - CAS unit tests for System.CodeDom.Compiler.CodeGeneratorOptions
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.CodeDom.Compiler;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using MonoTests.System.CodeDom.Compiler;
namespace MonoCasTests.System.CodeDom.Compiler {
[TestFixture]
[Category ("CAS")]
public class CodeGeneratorOptionsCas {
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void ReuseUnitTests ()
{
CodeGeneratorOptionsTest unit = new CodeGeneratorOptionsTest ();
unit.Defaults ();
unit.ReSetDefault ();
unit.Nullify ();
}
[Test]
// no restriction
public void LinkDemand ()
{
ConstructorInfo ci = typeof (CodeGeneratorOptions).GetConstructor (new Type[0]);
Assert.IsNotNull (ci, "default .ctor()");
Assert.IsNotNull (ci.Invoke (null), "invoke");
}
[Test]
[EnvironmentPermission (SecurityAction.Deny, Read = "Mono")]
[ExpectedException (typeof (SecurityException))]
public void LinkDemand_Deny_Anything ()
{
// denying anything results in a non unrestricted permission set
ConstructorInfo ci = typeof (CodeGeneratorOptions).GetConstructor (new Type[0]);
Assert.IsNotNull (ci, "default .ctor()");
Assert.IsNotNull (ci.Invoke (null), "invoke");
}
}
}

View File

@@ -0,0 +1,110 @@
//
// CodeGeneratorOptionsTest.cs
// - Unit tests for System.CodeDom.Compiler.CodeGeneratorOptions
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.CodeDom.Compiler;
namespace MonoTests.System.CodeDom.Compiler {
[TestFixture]
public class CodeGeneratorOptionsTest {
[Test]
public void Defaults ()
{
CodeGeneratorOptions cgo = new CodeGeneratorOptions ();
Assert.IsTrue (cgo.BlankLinesBetweenMembers, "BlankLinesBetweenMembers");
Assert.AreEqual ("Block", cgo.BracingStyle, "BracingStyle");
Assert.IsFalse (cgo.ElseOnClosing, "ElseOnClosing");
Assert.AreEqual (" ", cgo.IndentString, "IndentString");
#if NET_2_0
Assert.IsFalse (cgo.VerbatimOrder, "VerbatimOrder");
#endif
Assert.IsNull (cgo["BlankLinesBetweenMembers"], "this[BlankLinesBetweenMembers]");
Assert.IsNull (cgo["BracingStyle"], "this[BracingStyle]");
Assert.IsNull (cgo["ElseOnClosing"], "this[ElseOnClosing]");
Assert.IsNull (cgo["IndentString"], "this[IndentString]");
#if NET_2_0
Assert.IsNull (cgo["VerbatimOrder"], "this[VerbatimOrder]");
#endif
}
[Test]
public void ReSetDefault ()
{
CodeGeneratorOptions cgo = new CodeGeneratorOptions ();
cgo.BlankLinesBetweenMembers = cgo.BlankLinesBetweenMembers;
Assert.IsNotNull (cgo["BlankLinesBetweenMembers"], "this[BlankLinesBetweenMembers]");
cgo.BracingStyle = cgo.BracingStyle;
Assert.IsNotNull (cgo["BracingStyle"], "this[BracingStyle]");
cgo.ElseOnClosing = cgo.ElseOnClosing;
Assert.IsNotNull (cgo["ElseOnClosing"], "this[ElseOnClosing]");
cgo.IndentString = cgo.IndentString;
Assert.IsNotNull (cgo["IndentString"], "this[IndentString]");
#if NET_2_0
cgo.VerbatimOrder = cgo.VerbatimOrder;
Assert.IsNotNull (cgo["VerbatimOrder"], "this[VerbatimOrder]");
#endif
}
[Test]
public void Nullify ()
{
CodeGeneratorOptions cgo = new CodeGeneratorOptions ();
cgo.BlankLinesBetweenMembers = false;
Assert.IsFalse (cgo.BlankLinesBetweenMembers, "BlankLinesBetweenMembers-1");
cgo["BlankLinesBetweenMembers"] = null;
Assert.IsTrue (cgo.BlankLinesBetweenMembers, "BlankLinesBetweenMembers-2");
cgo.BracingStyle = "C";
Assert.AreEqual ("C", cgo.BracingStyle, "BracingStyle-1");
cgo["BracingStyle"] = null;
Assert.AreEqual ("Block", cgo.BracingStyle, "BracingStyle-2");
cgo.ElseOnClosing = true;
Assert.IsTrue (cgo.ElseOnClosing, "ElseOnClosing-1");
cgo["ElseOnClosing"] = null;
Assert.IsFalse (cgo.ElseOnClosing, "ElseOnClosing-2");
cgo.IndentString = "\t";
Assert.AreEqual ("\t", cgo.IndentString, "IndentString-1");
cgo["IndentString"] = null;
Assert.AreEqual (" ", cgo.IndentString, "IndentString-2");
#if NET_2_0
cgo.VerbatimOrder = true;
Assert.IsTrue (cgo.VerbatimOrder, "VerbatimOrder-1");
cgo["VerbatimOrder"] = null;
Assert.IsFalse (cgo.VerbatimOrder, "VerbatimOrder-2");
#endif
}
}
}

View File

@@ -0,0 +1,451 @@
//
// CodeGenerator unit tests
//
// Authors:
// Gert Driesen (drieseng@users.sourceforge.net)
//
// (c) Novell
//
using System;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.IO;
using NUnit.Framework;
namespace MonoTests.System.CodeDom.Compiler
{
[TestFixture]
public class MockCodeGenerator : CodeGenerator
{
[Test]
public void IsCurrentTest ()
{
MockCodeGenerator codeGenerator = new MockCodeGenerator ();
Assert.AreEqual (false, codeGenerator.IsCurrentClass, "#A1");
Assert.AreEqual (false, codeGenerator.IsCurrentDelegate, "#A2");
Assert.AreEqual (false, codeGenerator.IsCurrentEnum, "#A3");
Assert.AreEqual (false, codeGenerator.IsCurrentInterface, "#A4");
Assert.AreEqual (false, codeGenerator.IsCurrentStruct, "#A5");
((ICodeGenerator) codeGenerator).GenerateCodeFromType (GetClassType (),
new StringWriter (), new CodeGeneratorOptions ());
Assert.AreEqual (true, codeGenerator.IsCurrentClass, "#B1");
Assert.AreEqual (false, codeGenerator.IsCurrentDelegate, "#B2");
Assert.AreEqual (false, codeGenerator.IsCurrentEnum, "#B3");
Assert.AreEqual (false, codeGenerator.IsCurrentInterface, "#B4");
Assert.AreEqual (false, codeGenerator.IsCurrentStruct, "#B5");
((ICodeGenerator) codeGenerator).GenerateCodeFromType (GetDelegateType (),
new StringWriter (), new CodeGeneratorOptions ());
Assert.AreEqual (false, codeGenerator.IsCurrentClass, "#C1");
Assert.AreEqual (true, codeGenerator.IsCurrentDelegate, "#C2");
Assert.AreEqual (false, codeGenerator.IsCurrentEnum, "#C3");
Assert.AreEqual (false, codeGenerator.IsCurrentInterface, "#C4");
Assert.AreEqual (false, codeGenerator.IsCurrentStruct, "#C5");
((ICodeGenerator) codeGenerator).GenerateCodeFromType (GetEnumType (),
new StringWriter (), new CodeGeneratorOptions ());
Assert.AreEqual (false, codeGenerator.IsCurrentClass, "#D1");
Assert.AreEqual (false, codeGenerator.IsCurrentDelegate, "#D2");
Assert.AreEqual (true, codeGenerator.IsCurrentEnum, "#D3");
Assert.AreEqual (false, codeGenerator.IsCurrentInterface, "#D4");
Assert.AreEqual (false, codeGenerator.IsCurrentStruct, "#D5");
((ICodeGenerator) codeGenerator).GenerateCodeFromType (GetInterfaceType (),
new StringWriter (), new CodeGeneratorOptions ());
Assert.AreEqual (false, codeGenerator.IsCurrentClass, "#E1");
Assert.AreEqual (false, codeGenerator.IsCurrentDelegate, "#E2");
Assert.AreEqual (false, codeGenerator.IsCurrentEnum, "#E3");
Assert.AreEqual (true, codeGenerator.IsCurrentInterface, "#E4");
Assert.AreEqual (false, codeGenerator.IsCurrentStruct, "#E5");
((ICodeGenerator) codeGenerator).GenerateCodeFromType (GetStructType (),
new StringWriter (), new CodeGeneratorOptions ());
Assert.AreEqual (false, codeGenerator.IsCurrentClass, "#F1");
Assert.AreEqual (false, codeGenerator.IsCurrentDelegate, "#F2");
Assert.AreEqual (false, codeGenerator.IsCurrentEnum, "#F3");
Assert.AreEqual (false, codeGenerator.IsCurrentInterface, "#F4");
Assert.AreEqual (true, codeGenerator.IsCurrentStruct, "#F5");
}
[Test]
public void IsValidLanguageIndependentIdentifierTest ()
{
Assert.AreEqual (true,
CodeGenerator.IsValidLanguageIndependentIdentifier("hello"), "#G1");
Assert.AreEqual (true,
CodeGenerator.IsValidLanguageIndependentIdentifier("good1"), "#G2");
Assert.AreEqual (false,
CodeGenerator.IsValidLanguageIndependentIdentifier("2bad"), "#G3");
Assert.AreEqual (false,
CodeGenerator.IsValidLanguageIndependentIdentifier("@start"), "#G4");
Assert.AreEqual (false,
CodeGenerator.IsValidLanguageIndependentIdentifier("not@start"), "#G5");
Assert.AreEqual (false,
CodeGenerator.IsValidLanguageIndependentIdentifier(" spaceatstart"), "#G6");
Assert.AreEqual (false,
CodeGenerator.IsValidLanguageIndependentIdentifier("spaceatend "), "#G7");
Assert.AreEqual (false,
CodeGenerator.IsValidLanguageIndependentIdentifier("a spacein2ndplace"), "#G8");
}
[Test]
public void CurrentMemberShouldBeClearedBetweenTypes ()
{
ICodeGenerator codeGenerator = new MockCodeGenerator ();
var o = new StringWriter () {
NewLine = "\n",
};
var t = new CodeTypeDeclaration() {
Name = "Foo",
Members = {
new CodeMemberField() {
Name = "f",
},
new CodeMemberMethod() {
Name = "M",
StartDirectives = {
new CodeRegionDirective(CodeRegionMode.Start, "foo..."),
},
EndDirectives = {
new CodeRegionDirective(CodeRegionMode.End, null),
},
}
}
};
var opts = new CodeGeneratorOptions () {
IndentString = "\t",
};
codeGenerator.GenerateCodeFromType (t, o, opts);
t.Name = "Bar";
codeGenerator.GenerateCodeFromType (t, o, opts);
var expected =
"(type Foo\n" +
"\t\n" +
"\t(field f (TypeRef System.Void))\n" +
"\t\n" +
"\t(region foo...\n" +
"\t\t(method M)))\n" +
"(type Bar\n" +
"\t\n" +
"\t(field f (TypeRef System.Void))\n" +
"\t\n" +
"\t(region foo...\n" +
"\t\t(method M)))\n";
Assert.AreEqual (expected, o.ToString ());
}
private CodeTypeDeclaration GetClassType ()
{
return new CodeTypeDeclaration ();
}
private CodeTypeDeclaration GetDelegateType ()
{
CodeTypeDeclaration type = new CodeTypeDelegate ();
return type;
}
private CodeTypeDeclaration GetEnumType ()
{
CodeTypeDeclaration type = new CodeTypeDeclaration ();
type.IsEnum = true;
return type;
}
private CodeTypeDeclaration GetInterfaceType ()
{
CodeTypeDeclaration type = new CodeTypeDeclaration ();
type.IsInterface = true;
return type;
}
private CodeTypeDeclaration GetStructType ()
{
CodeTypeDeclaration type = new CodeTypeDeclaration ();
type.IsStruct = true;
return type;
}
#region Override implementation of CodeGenerator
protected override string NullToken
{
get { return "zip"; }
}
protected override void OutputType (CodeTypeReference typeRef)
{
Output.Write ("(TypeRef ");
Output.Write (typeRef.BaseType);
Output.Write (")");
}
protected override void GenerateArrayCreateExpression (CodeArrayCreateExpression e)
{
}
protected override void GenerateBaseReferenceExpression (CodeBaseReferenceExpression e)
{
}
protected override void GenerateCastExpression (CodeCastExpression e)
{
}
protected override void GenerateDelegateCreateExpression (CodeDelegateCreateExpression e)
{
}
protected override void GenerateFieldReferenceExpression (CodeFieldReferenceExpression e)
{
}
protected override void GenerateArgumentReferenceExpression (CodeArgumentReferenceExpression e)
{
}
protected override void GenerateVariableReferenceExpression (CodeVariableReferenceExpression e)
{
}
protected override void GenerateIndexerExpression (CodeIndexerExpression e)
{
}
protected override void GenerateArrayIndexerExpression (CodeArrayIndexerExpression e)
{
}
protected override void GenerateSnippetExpression (CodeSnippetExpression e)
{
}
protected override void GenerateMethodInvokeExpression (CodeMethodInvokeExpression e)
{
}
protected override void GenerateMethodReferenceExpression (CodeMethodReferenceExpression e)
{
}
protected override void GenerateEventReferenceExpression (CodeEventReferenceExpression e)
{
}
protected override void GenerateDelegateInvokeExpression (CodeDelegateInvokeExpression e)
{
}
protected override void GenerateObjectCreateExpression (CodeObjectCreateExpression e)
{
}
protected override void GeneratePropertyReferenceExpression (CodePropertyReferenceExpression e)
{
}
protected override void GeneratePropertySetValueReferenceExpression (CodePropertySetValueReferenceExpression e)
{
}
protected override void GenerateThisReferenceExpression (CodeThisReferenceExpression e)
{
}
protected override void GenerateExpressionStatement (CodeExpressionStatement e)
{
}
protected override void GenerateIterationStatement (CodeIterationStatement e)
{
}
protected override void GenerateThrowExceptionStatement (CodeThrowExceptionStatement e)
{
}
protected override void GenerateComment (CodeComment e)
{
}
protected override void GenerateMethodReturnStatement (CodeMethodReturnStatement e)
{
}
protected override void GenerateConditionStatement (CodeConditionStatement e)
{
}
protected override void GenerateTryCatchFinallyStatement (CodeTryCatchFinallyStatement e)
{
}
protected override void GenerateAssignStatement (CodeAssignStatement e)
{
}
protected override void GenerateAttachEventStatement (CodeAttachEventStatement e)
{
}
protected override void GenerateRemoveEventStatement (CodeRemoveEventStatement e)
{
}
protected override void GenerateLabeledStatement (CodeLabeledStatement e)
{
}
protected override void GenerateVariableDeclarationStatement (CodeVariableDeclarationStatement e)
{
}
protected override void GenerateLinePragmaStart (CodeLinePragma e)
{
}
protected override void GenerateGotoStatement (CodeGotoStatement e)
{
}
protected override void GenerateLinePragmaEnd (CodeLinePragma e)
{
}
protected override void GenerateEvent (CodeMemberEvent e, CodeTypeDeclaration c)
{
}
protected override void GenerateField (CodeMemberField e)
{
Output.WriteLine ();
Output.Write ("(field ");
Output.Write (e.Name);
Output.Write (" ");
OutputType (e.Type);
Output.Write (")");
}
protected override void GenerateSnippetMember (CodeSnippetTypeMember e)
{
}
protected override void GenerateEntryPointMethod (CodeEntryPointMethod e, CodeTypeDeclaration c)
{
}
protected override void GenerateMethod (CodeMemberMethod e, CodeTypeDeclaration c)
{
Output.WriteLine ();
Output.Write ("(method ");
Output.Write (e.Name);
Output.Write (")");
}
protected override void GenerateProperty (CodeMemberProperty e, CodeTypeDeclaration c)
{
}
protected override void GenerateConstructor (CodeConstructor e, CodeTypeDeclaration c)
{
}
protected override void GenerateTypeConstructor (CodeTypeConstructor e)
{
}
protected override void GenerateTypeStart (CodeTypeDeclaration e)
{
Output.Write ("(type ");
Output.Write (e.Name);
++Indent;
}
protected override void GenerateTypeEnd (CodeTypeDeclaration e)
{
Output.WriteLine (")");
--Indent;
}
protected override void GenerateNamespaceStart (CodeNamespace e)
{
}
protected override void GenerateNamespaceEnd (CodeNamespace e)
{
}
protected override void GenerateNamespaceImport (CodeNamespaceImport e)
{
}
protected override void GenerateAttributeDeclarationsStart (CodeAttributeDeclarationCollection attributes)
{
}
protected override void GenerateAttributeDeclarationsEnd (CodeAttributeDeclarationCollection attributes)
{
}
protected override bool Supports (GeneratorSupport support)
{
return true;
}
protected override bool IsValidIdentifier (string value)
{
return true;
}
protected override string CreateEscapedIdentifier (string value)
{
return value;
}
protected override string CreateValidIdentifier (string value)
{
return value;
}
protected override string GetTypeOutput (CodeTypeReference value)
{
return "typeoutput";
}
protected override string QuoteSnippetString (string value)
{
return value;
}
#if NET_2_0
protected override void GenerateDirectives (CodeDirectiveCollection directives)
{
foreach (CodeDirective d in directives) {
var r = d as CodeRegionDirective;
if (r != null) {
if (r.RegionMode == CodeRegionMode.Start) {
Output.WriteLine ();
Output.Write ("(region ");
Output.Write (r.RegionText);
++Indent;
}
else if (r.RegionMode == CodeRegionMode.End) {
Output.Write (")");
--Indent;
}
}
}
}
#endif
#endregion Override implementation of CodeGenerator
}
}

View File

@@ -0,0 +1,59 @@
//
// Base class for CodeGenerator unit tests
//
// Authors:
// Gert Driesen (drieseng@users.sourceforge.net)
//
// (c) Novell
//
using System;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.IO;
using NUnit.Framework;
namespace MonoTests.System.CodeDom.Compiler
{
public abstract class CodeGeneratorTestBase
{
private CodeGeneratorOptions _options;
[SetUp]
public virtual void SetUp ()
{
_options = new CodeGeneratorOptions ();
}
protected abstract ICodeGenerator CodeGenerator
{
get;
}
protected virtual string NewLine
{
get { return "\n"; }
}
protected CodeGeneratorOptions Options
{
get { return _options; }
}
protected string GenerateCodeFromType (CodeTypeDeclaration type)
{
return GenerateCodeFromType (type, _options);
}
protected virtual string GenerateCodeFromType (CodeTypeDeclaration type, CodeGeneratorOptions options)
{
using (StringWriter writer = new StringWriter ()) {
writer.NewLine = NewLine;
CodeGenerator.GenerateCodeFromType (type, writer, options);
writer.Close ();
return writer.ToString ();
}
}
}
}

View File

@@ -0,0 +1,80 @@
//
// CodeParserCas.cs
// - CAS unit tests for System.CodeDom.Compiler.CodeParser
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.IO;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using MonoTests.System.CodeDom.Compiler;
namespace MonoCasTests.System.CodeDom.Compiler {
class CodeParserTest: CodeParser {
public override CodeCompileUnit Parse (TextReader codeStream)
{
return new CodeCompileUnit ();
}
}
[TestFixture]
[Category ("CAS")]
public class CodeParserCas {
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Constructor ()
{
CodeParserTest cp = new CodeParserTest ();
Assert.IsNotNull (cp.Parse (null), "Parse");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void LinkDemand_Deny_Unrestricted ()
{
ConstructorInfo ci = typeof (CodeParserTest).GetConstructor (new Type[0]);
Assert.IsNotNull (ci, "default .ctor");
Assert.IsNotNull (ci.Invoke (null), "invoke");
}
}
}

View File

@@ -0,0 +1,113 @@
//
// CompilerErrorCas.cs
// - CAS unit tests for System.CodeDom.Compiler.CompilerError
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.IO;
using System.CodeDom.Compiler;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
namespace MonoCasTests.System.CodeDom.Compiler {
[TestFixture]
[Category ("CAS")]
public class CompilerErrorCas {
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
private string fname;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
// at full trust
fname = Path.GetTempFileName ();
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Constructor0_Deny_Unrestricted ()
{
CompilerError ce = new CompilerError ();
Assert.AreEqual (0, ce.Column, "Column");
ce.Column = 1;
Assert.AreEqual (String.Empty, ce.ErrorNumber, "ErrorNumber");
ce.ErrorNumber = "cs0000";
Assert.AreEqual (String.Empty, ce.ErrorText, "ErrorText");
ce.ErrorText = "error text";
Assert.AreEqual (String.Empty, ce.FileName, "FileName");
ce.FileName = fname;
Assert.IsFalse (ce.IsWarning, "IsWarning");
ce.IsWarning = true;
Assert.AreEqual (0, ce.Line, "Line");
ce.Line = 1;
Assert.IsNotNull (ce.ToString (), "ToString");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Constructor5_Deny_Unrestricted ()
{
CompilerError ce = new CompilerError (fname, 1, 1, "cs0000", "error text");
Assert.IsTrue ((ce.ToString ().IndexOf (fname) >= 0), "ToString");
Assert.AreEqual (1, ce.Column, "Column");
ce.Column = Int32.MinValue;
Assert.AreEqual ("cs0000", ce.ErrorNumber, "ErrorNumber");
ce.ErrorNumber = String.Empty;
Assert.AreEqual ("error text", ce.ErrorText, "ErrorText");
ce.ErrorText = String.Empty;
Assert.AreEqual (fname, ce.FileName, "FileName");
ce.FileName = String.Empty;
Assert.IsFalse (ce.IsWarning, "IsWarning");
ce.IsWarning = true;
Assert.AreEqual (1, ce.Line, "Line");
ce.Line = Int32.MinValue;
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
#if ONLY_1_1
[ExpectedException (typeof (SecurityException))]
#endif
public void LinkDemand_Deny_Unrestricted ()
{
ConstructorInfo ci = typeof (CompilerError).GetConstructor (new Type [0]);
Assert.IsNotNull (ci, "default .ctor()");
Assert.IsNotNull (ci.Invoke (null), "invoke");
}
}
}

View File

@@ -0,0 +1,134 @@
//
// CompilerErrorCollectionCas.cs
// - CAS unit tests for System.CodeDom.Compiler.CompilerErrorCollection
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.CodeDom.Compiler;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
namespace MonoCasTests.System.CodeDom.Compiler {
[TestFixture]
[Category ("CAS")]
public class CompilerErrorCollectionCas {
private CompilerError ce;
private CompilerError[] array;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
ce = new CompilerError ();
array = new CompilerError[1] { ce };
}
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Constructor0_Deny_Unrestricted ()
{
CompilerErrorCollection coll = new CompilerErrorCollection ();
Assert.AreEqual (0, coll.Add (ce), "Add");
Assert.AreSame (ce, coll[0], "this[int]");
coll[0] = ce;
coll.CopyTo (array, 0);
coll.AddRange (array);
coll.AddRange (coll);
Assert.IsTrue (coll.Contains (ce), "Contains");
Assert.AreEqual (0, coll.IndexOf (ce), "IndexOf");
coll.Insert (0, ce);
coll.Remove (ce);
ce.IsWarning = false;
Assert.IsTrue (coll.HasErrors, "HasErrors");
Assert.IsFalse (coll.HasWarnings, "HasWarnings");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Constructor1_Deny_Unrestricted ()
{
CompilerErrorCollection coll = new CompilerErrorCollection (array);
coll.CopyTo (array, 0);
Assert.AreEqual (1, coll.Add (ce), "Add");
Assert.AreSame (ce, coll[0], "this[int]");
coll[0] = ce;
coll.AddRange (array);
coll.AddRange (coll);
Assert.IsTrue (coll.Contains (ce), "Contains");
Assert.AreEqual (0, coll.IndexOf (ce), "IndexOf");
coll.Insert (0, ce);
coll.Remove (ce);
ce.IsWarning = true;
Assert.IsFalse (coll.HasErrors, "HasErrors");
Assert.IsTrue (coll.HasWarnings, "HasWarnings");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Constructor2_Deny_Unrestricted ()
{
CompilerErrorCollection c = new CompilerErrorCollection ();
CompilerErrorCollection coll = new CompilerErrorCollection (c);
Assert.AreEqual (0, coll.Add (ce), "Add");
Assert.AreSame (ce, coll[0], "this[int]");
coll[0] = ce;
coll.CopyTo (array, 0);
coll.AddRange (array);
coll.AddRange (coll);
Assert.IsTrue (coll.Contains (ce), "Contains");
Assert.AreEqual (0, coll.IndexOf (ce), "IndexOf");
coll.Insert (0, ce);
coll.Remove (ce);
ce.IsWarning = false;
Assert.IsTrue (coll.HasErrors, "HasErrors");
Assert.IsFalse (coll.HasWarnings, "HasWarnings");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
#if ONLY_1_1
[ExpectedException (typeof (SecurityException))]
#endif
public void LinkDemand_Deny_Unrestricted ()
{
ConstructorInfo ci = typeof (CompilerErrorCollection).GetConstructor (new Type[0]);
Assert.IsNotNull (ci, "default .ctor");
Assert.IsNotNull (ci.Invoke (null), "invoke");
}
}
}

View File

@@ -0,0 +1,123 @@
//
// CompilerInfoCas.cs -
// CAS unit tests for System.CodeDom.Compiler.CompilerInfo
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using NUnit.Framework;
using System;
using System.IO;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using MCSharp = Microsoft.CSharp;
using MonoTests.System.CodeDom.Compiler;
namespace MonoCasTests.System.CodeDom.Compiler {
[TestFixture]
[Category ("CAS")]
[Category ("NotWorking")] // FIXME: missing config stuff ???
public class CompilerInfoCas {
private CompilerInfo ci;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
ci = CodeDomProvider.GetCompilerInfo ("c#");
}
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Default ()
{
Assert.AreEqual (typeof (MCSharp.CSharpCodeProvider), ci.CodeDomProviderType, "CodeDomProviderType");
Assert.IsTrue (ci.IsCodeDomProviderTypeValid, "IsCodeDomProviderTypeValid");
Assert.IsTrue (ci.Equals (ci), "Equals");
Assert.IsTrue (ci.GetHashCode () != 0, "GetHashCode");
Assert.AreEqual (2, ci.GetExtensions ().Length, "GetExtensions"); // .cs cs
Assert.AreEqual (3, ci.GetLanguages ().Length, "GetLanguages"); // c# cs csharp
try {
Assert.IsNotNull (ci.CreateDefaultCompilerParameters (), "CreateDefaultCompilerParameters");
}
catch (NotImplementedException) {
// mono
}
}
[Test]
// no restriction
public void CreateProvider_No_Restriction ()
{
Assert.IsNotNull (ci.CreateProvider (), "CreateProvider");
}
[Test]
[EnvironmentPermission (SecurityAction.Deny, Read = "Mono")]
[ExpectedException (typeof (SecurityException))]
public void CreateProvider_Deny_Anything ()
{
ci.CreateProvider ();
}
[Test]
public void LinkDemand_No_Restriction ()
{
MethodInfo mi = typeof (CompilerInfo).GetProperty ("IsCodeDomProviderTypeValid").GetGetMethod ();
Assert.IsNotNull (mi, "IsCodeDomProviderTypeValid");
Assert.IsTrue ((bool) mi.Invoke (ci, null), "invoke");
}
[Test]
[EnvironmentPermission (SecurityAction.Deny, Read = "Mono")]
[ExpectedException (typeof (SecurityException))]
public void LinkDemand_Deny_Anything ()
{
// denying anything results in a non unrestricted permission set
MethodInfo mi = typeof (CompilerInfo).GetProperty ("IsCodeDomProviderTypeValid").GetGetMethod ();
Assert.IsNotNull (mi, "IsCodeDomProviderTypeValid");
Assert.IsTrue ((bool) mi.Invoke (ci, null), "invoke");
}
}
}
#endif

View File

@@ -0,0 +1,220 @@
//
// CompilerParametersCas.cs
// - CAS unit tests for System.CodeDom.Compiler.CompilerParameters
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.CodeDom.Compiler;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Security.Policy;
namespace MonoCasTests.System.CodeDom.Compiler {
[TestFixture]
[Category ("CAS")]
public class CompilerParametersCas {
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Constructor0_Deny_Unrestricted ()
{
CompilerParameters cp = new CompilerParameters ();
Assert.IsNull (cp.CompilerOptions, "CompilerOptions");
cp.CompilerOptions = "-debug";
Assert.IsNull (cp.Evidence, "Evidence");
Assert.IsFalse (cp.GenerateExecutable, "GenerateExecutable");
cp.GenerateExecutable = true;
Assert.IsFalse (cp.GenerateInMemory, "GenerateInMemory");
cp.GenerateInMemory = true;
Assert.IsFalse (cp.IncludeDebugInformation, "IncludeDebugInformation");
cp.IncludeDebugInformation = true;
Assert.IsNull (cp.MainClass, "MainClass");
cp.MainClass = "Program";
Assert.IsNull (cp.OutputAssembly, "OutputAssembly");
cp.OutputAssembly = "mono.dll";
Assert.AreEqual (0, cp.ReferencedAssemblies.Count, "ReferencedAssemblies");
Assert.AreEqual (0, cp.TempFiles.Count, "TempFiles");
cp.TempFiles = new TempFileCollection ();
Assert.AreEqual (IntPtr.Zero, cp.UserToken, "UserToken");
cp.UserToken = (IntPtr) 1;
Assert.AreEqual (-1, cp.WarningLevel, "WarningLevel");
cp.WarningLevel = 0;
Assert.IsNull (cp.Win32Resource, "Win32Resource");
cp.Win32Resource = "*";
#if NET_2_0
Assert.AreEqual (0, cp.EmbeddedResources.Count, "EmbeddedResources");
Assert.AreEqual (0, cp.LinkedResources.Count, "LinkedResources");
#endif
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Constructor1_Deny_Unrestricted ()
{
CompilerParameters cp = new CompilerParameters (new string[1] { "mono.exe" });
Assert.IsNull (cp.CompilerOptions, "CompilerOptions");
cp.CompilerOptions = "-debug";
Assert.IsNull (cp.Evidence, "Evidence");
Assert.IsFalse (cp.GenerateExecutable, "GenerateExecutable");
cp.GenerateExecutable = true;
Assert.IsFalse (cp.GenerateInMemory, "GenerateInMemory");
cp.GenerateInMemory = true;
Assert.IsFalse (cp.IncludeDebugInformation, "IncludeDebugInformation");
cp.IncludeDebugInformation = true;
Assert.IsNull (cp.MainClass, "MainClass");
cp.MainClass = "Program";
Assert.IsNull (cp.OutputAssembly, "OutputAssembly");
cp.OutputAssembly = "mono.dll";
Assert.AreEqual (1, cp.ReferencedAssemblies.Count, "ReferencedAssemblies");
Assert.AreEqual (0, cp.TempFiles.Count, "TempFiles");
cp.TempFiles = new TempFileCollection ();
Assert.AreEqual (IntPtr.Zero, cp.UserToken, "UserToken");
cp.UserToken = (IntPtr) 1;
Assert.AreEqual (-1, cp.WarningLevel, "WarningLevel");
cp.WarningLevel = 0;
Assert.IsNull (cp.Win32Resource, "Win32Resource");
cp.Win32Resource = "*";
#if NET_2_0
Assert.AreEqual (0, cp.EmbeddedResources.Count, "EmbeddedResources");
Assert.AreEqual (0, cp.LinkedResources.Count, "LinkedResources");
#endif
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Constructor2_Deny_Unrestricted ()
{
CompilerParameters cp = new CompilerParameters (new string[1] { "mono.exe" }, "mono.dll");
Assert.IsNull (cp.CompilerOptions, "CompilerOptions");
cp.CompilerOptions = "-debug";
Assert.IsNull (cp.Evidence, "Evidence");
Assert.IsFalse (cp.GenerateExecutable, "GenerateExecutable");
cp.GenerateExecutable = true;
Assert.IsFalse (cp.GenerateInMemory, "GenerateInMemory");
cp.GenerateInMemory = true;
Assert.IsFalse (cp.IncludeDebugInformation, "IncludeDebugInformation");
cp.IncludeDebugInformation = true;
Assert.IsNull (cp.MainClass, "MainClass");
cp.MainClass = "Program";
Assert.AreEqual ("mono.dll", cp.OutputAssembly, "OutputAssembly");
cp.OutputAssembly = null;
Assert.AreEqual (1, cp.ReferencedAssemblies.Count, "ReferencedAssemblies");
Assert.AreEqual (0, cp.TempFiles.Count, "TempFiles");
cp.TempFiles = new TempFileCollection ();
Assert.AreEqual (IntPtr.Zero, cp.UserToken, "UserToken");
cp.UserToken = (IntPtr) 1;
Assert.AreEqual (-1, cp.WarningLevel, "WarningLevel");
cp.WarningLevel = 0;
Assert.IsNull (cp.Win32Resource, "Win32Resource");
cp.Win32Resource = "*";
#if NET_2_0
Assert.AreEqual (0, cp.EmbeddedResources.Count, "EmbeddedResources");
Assert.AreEqual (0, cp.LinkedResources.Count, "LinkedResources");
#endif
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Constructor3_Deny_Unrestricted ()
{
CompilerParameters cp = new CompilerParameters (new string[1] { "mono.exe" }, "mono.dll", true);
Assert.IsNull (cp.CompilerOptions, "CompilerOptions");
cp.CompilerOptions = "-debug";
Assert.IsNull (cp.Evidence, "Evidence");
Assert.IsFalse (cp.GenerateExecutable, "GenerateExecutable");
cp.GenerateExecutable = true;
Assert.IsFalse (cp.GenerateInMemory, "GenerateInMemory");
cp.GenerateInMemory = true;
Assert.IsTrue (cp.IncludeDebugInformation, "IncludeDebugInformation");
cp.IncludeDebugInformation = false;
Assert.IsNull (cp.MainClass, "MainClass");
cp.MainClass = "Program";
Assert.AreEqual ("mono.dll", cp.OutputAssembly, "OutputAssembly");
cp.OutputAssembly = null;
Assert.AreEqual (1, cp.ReferencedAssemblies.Count, "ReferencedAssemblies");
Assert.AreEqual (0, cp.TempFiles.Count, "TempFiles");
cp.TempFiles = new TempFileCollection ();
Assert.AreEqual (IntPtr.Zero, cp.UserToken, "UserToken");
cp.UserToken = (IntPtr) 1;
Assert.AreEqual (-1, cp.WarningLevel, "WarningLevel");
cp.WarningLevel = 0;
Assert.IsNull (cp.Win32Resource, "Win32Resource");
cp.Win32Resource = "*";
#if NET_2_0
Assert.AreEqual (0, cp.EmbeddedResources.Count, "EmbeddedResources");
Assert.AreEqual (0, cp.LinkedResources.Count, "LinkedResources");
#endif
}
[Test]
[SecurityPermission (SecurityAction.PermitOnly, ControlEvidence = true)]
public void Evidence_PermitOnly_Unrestricted ()
{
CompilerParameters cp = new CompilerParameters ();
cp.Evidence = new Evidence ();
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlEvidence = true)]
[ExpectedException (typeof (SecurityException))]
public void Evidence_Deny_Unrestricted ()
{
CompilerParameters cp = new CompilerParameters ();
cp.Evidence = new Evidence ();
}
[Test]
public void LinkDemand_No_Restriction ()
{
ConstructorInfo ci = typeof (CompilerParameters).GetConstructor (new Type[0]);
Assert.IsNotNull (ci, "default .ctor()");
Assert.IsNotNull (ci.Invoke (null), "invoke");
}
[Test]
[EnvironmentPermission (SecurityAction.Deny, Read = "Mono")]
[ExpectedException (typeof (SecurityException))]
public void LinkDemand_Deny_Anything ()
{
// denying anything results in a non unrestricted permission set
ConstructorInfo ci = typeof (CompilerParameters).GetConstructor (new Type[0]);
Assert.IsNotNull (ci, "default .ctor()");
Assert.IsNotNull (ci.Invoke (null), "invoke");
}
}
}

View File

@@ -0,0 +1,121 @@
//
// CompilerResultsCas.cs
// - CAS unit tests for System.CodeDom.Compiler.CompilerResults
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.CodeDom.Compiler;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Security.Policy;
namespace MonoCasTests.System.CodeDom.Compiler {
[TestFixture]
[Category ("CAS")]
public class CompilerResultsCas {
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
private TempFileCollection temps;
private Assembly assembly;
private string path;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
// at full trust
temps = new TempFileCollection ();
assembly = Assembly.GetExecutingAssembly ();
path = assembly.Location;
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Deny_Unrestricted ()
{
CompilerResults cr = new CompilerResults (temps);
Assert.IsNull (cr.CompiledAssembly, "CompiledAssembly");
cr.CompiledAssembly = assembly;
Assert.AreEqual (0, cr.Errors.Count, "Errors");
Assert.IsNull (cr.Evidence, "Evidence");
Assert.AreEqual (0, cr.NativeCompilerReturnValue, "NativeCompilerReturnValue");
cr.NativeCompilerReturnValue = 1;
Assert.AreEqual (0, cr.Output.Count, "Output");
Assert.IsNull (cr.PathToAssembly, "PathToAssembly");
cr.PathToAssembly = path;
Assert.AreEqual (0, cr.TempFiles.Count, "TempFiles");
cr.TempFiles = new TempFileCollection ();
}
[Test]
[SecurityPermission (SecurityAction.PermitOnly, ControlEvidence = true)]
public void Evidence_PermitOnly_Unrestricted ()
{
CompilerResults cr = new CompilerResults (temps);
cr.Evidence = new Evidence ();
}
[Test]
[SecurityPermission (SecurityAction.Deny, ControlEvidence = true)]
[ExpectedException (typeof (SecurityException))]
public void Evidence_Deny_Unrestricted ()
{
CompilerResults cr = new CompilerResults (temps);
cr.Evidence = new Evidence ();
}
[Test]
public void LinkDemand_No_Restriction ()
{
Type[] types = new Type[1] { typeof (TempFileCollection) };
ConstructorInfo ci = typeof (CompilerResults).GetConstructor (types);
Assert.IsNotNull (ci, ".ctor(TempFileCollection)");
Assert.IsNotNull (ci.Invoke (new object[1] { temps }), "invoke");
}
[Test]
[EnvironmentPermission (SecurityAction.Deny, Read = "Mono")]
[ExpectedException (typeof (SecurityException))]
public void LinkDemand_Deny_Anything ()
{
// denying anything results in a non unrestricted permission set
Type[] types = new Type[1] { typeof (TempFileCollection) };
ConstructorInfo ci = typeof (CompilerResults).GetConstructor (types);
Assert.IsNotNull (ci, ".ctor(TempFileCollection)");
Assert.IsNotNull (ci.Invoke (new object[1] { temps }), "invoke");
}
}
}

View File

@@ -0,0 +1,174 @@
//
// ExecutorCas.cs
// - CAS unit tests for System.CodeDom.Compiler.Executor
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.CodeDom.Compiler;
using System.IO;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Security.Policy;
using MonoTests.System.CodeDom.Compiler;
namespace MonoCasTests.System.CodeDom.Compiler {
[TestFixture]
[Category ("CAS")]
public class ExecutorCas {
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
private string cmd;
private TempFileCollection tfc;
private ExecutorTest unit;
private MethodInfo execWaitWithCapture;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
// at fulltrust
tfc = new TempFileCollection ();
cmd = "ping"; // available everywhere
unit = new ExecutorTest ();
unit.FixtureSetUp ();
// for linkdemands tests
MethodInfo[] methods = typeof (Executor).GetMethods ();
foreach (MethodInfo mi in methods) {
if ((mi.Name == "ExecWaitWithCapture") && (mi.GetParameters ().Length == 4)) {
execWaitWithCapture = mi;
break;
}
}
}
[Test]
[FileIOPermission (SecurityAction.PermitOnly, Unrestricted = true)]
[SecurityPermission (SecurityAction.PermitOnly, UnmanagedCode = true)]
[EnvironmentPermission (SecurityAction.PermitOnly, Unrestricted = true)]
public void ReuseUnitTests_PermitOnly ()
{
unit.ExecWaitWithCapture ();
unit.ExecWaitWithCapture_CurrentDir ();
unit.ExecWaitWithCapture_Token ();
unit.ExecWaitWithCapture_Token_CurrentDir ();
}
[Test]
[FileIOPermission (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (SecurityException))]
public void ExecWaitWithCapture_Deny_FileIO ()
{
unit.ExecWaitWithCapture ();
}
[Test]
[SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
[ExpectedException (typeof (SecurityException))]
public void ExecWaitWithCapture_Deny_UnmanagedCode ()
{
unit.ExecWaitWithCapture ();
}
[Test]
[EnvironmentPermission (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (SecurityException))]
public void ExecWaitWithCapture_Deny_Environment ()
{
unit.ExecWaitWithCapture ();
}
[Test]
public void LinkDemand_No_Restriction ()
{
Assert.IsNotNull (execWaitWithCapture, "ExecWaitWithCapture");
string output = null;
string error = null;
Assert.IsNotNull (execWaitWithCapture.Invoke (null, new object[4] { cmd, tfc, output, error }), "invoke");
}
[Test]
[FileIOPermission (SecurityAction.PermitOnly, Unrestricted = true)]
[SecurityPermission (SecurityAction.PermitOnly, UnmanagedCode = true)]
[EnvironmentPermission (SecurityAction.PermitOnly, Unrestricted = true)]
[ExpectedException (typeof (SecurityException))]
public void LinkDemand_PermitOnly ()
{
Assert.IsNotNull (execWaitWithCapture, "ExecWaitWithCapture");
string output = null;
string error = null;
Assert.IsNotNull (execWaitWithCapture.Invoke (null, new object[4] { cmd, tfc, output, error }), "invoke");
// it's not enough, so there's a LinkDemand on the class
}
[Test]
[SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
[ExpectedException (typeof (SecurityException))]
public void LinkDemand_Deny_UnmanagedCode ()
{
// denying anything results in a non unrestricted permission set
Assert.IsNotNull (execWaitWithCapture, "ExecWaitWithCapture");
string output = null;
string error = null;
Assert.IsNotNull (execWaitWithCapture.Invoke (null, new object[4] { cmd, tfc, output, error }), "invoke");
}
[Test]
[FileIOPermission (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (SecurityException))]
public void LinkDemand_Deny_FileIO ()
{
Assert.IsNotNull (execWaitWithCapture, "ExecWaitWithCapture");
string output = null;
string error = null;
Assert.IsNotNull (execWaitWithCapture.Invoke (null, new object[4] { cmd, tfc, output, error }), "invoke");
}
[Test]
[EnvironmentPermission (SecurityAction.Deny, Read = "Mono")]
[ExpectedException (typeof (SecurityException))]
public void LinkDemand_Deny_Environment ()
{
// denying anything results in a non unrestricted permission set
Assert.IsNotNull (execWaitWithCapture, "ExecWaitWithCapture");
string output = null;
string error = null;
Assert.IsNotNull (execWaitWithCapture.Invoke (null, new object[4] { cmd, tfc, output, error }), "invoke");
}
}
}

View File

@@ -0,0 +1,190 @@
//
// ExecutorTest.cs
// - Unit tests for System.CodeDom.Compiler.Executor
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.CodeDom.Compiler;
using System.IO;
using System.Runtime.InteropServices;
using System.Security.Principal;
namespace MonoTests.System.CodeDom.Compiler
{
[TestFixture]
public class ExecutorTest
{
private bool posix;
private bool cmdNotFound;
private int errcode;
private string cmd;
private string cd;
private string temp;
private TempFileCollection tfc;
private WindowsIdentity winid;
private IntPtr token;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
cmd = "ping"; // available everywhere
cd = Environment.CurrentDirectory;
temp = Path.GetTempPath ();
tfc = new TempFileCollection ();
winid = WindowsIdentity.GetCurrent ();
token = winid.Token;
try {
string output = null;
string error = null;
errcode = Executor.ExecWaitWithCapture (cmd, tfc, ref output, ref error);
}
catch (Exception) {
// cmd might not be in the PATH
cmdNotFound = true;
}
}
[TestFixtureTearDown]
public void FixtureTearDown ()
{
#if NET_2_0
winid.Dispose ();
#else
GC.KeepAlive (winid);
#endif
}
[Test]
[ExpectedException (typeof (ExternalException))]
public void ExecWait_NullCmd ()
{
Executor.ExecWait (null, new TempFileCollection ());
}
[Test]
[ExpectedException (typeof (NullReferenceException))]
public void ExecWait_NullTempFileCollection ()
{
if (cmdNotFound)
Assert.Ignore ("ping command not found.");
Executor.ExecWait (cmd, null);
}
[Test]
[Category ("NotWorking")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=341293
public void ExecWait ()
{
if (cmdNotFound)
Assert.Ignore ("ping command not found.");
try {
Executor.ExecWait (cmd, new TempFileCollection ());
Assert.Fail ("#1");
} catch (ExternalException ex) {
// Cannot execute a program. The command being executed was .
Assert.AreEqual (typeof (ExternalException), ex.GetType (), "#2");
Assert.AreEqual (2, ex.ErrorCode, "#3");
Assert.IsNull (ex.InnerException, "#4");
Assert.IsNotNull (ex.Message, "#5");
}
}
[Test]
public void ExecWaitWithCapture ()
{
if (cmdNotFound)
Assert.Ignore ("ping command not found.");
string output = null;
string error = null;
TempFileCollection tfc = new TempFileCollection ();
Assert.AreEqual (errcode, Executor.ExecWaitWithCapture (cmd, tfc, ref output, ref error), "ErrorCode");
Assert.IsTrue (File.Exists (output), "output");
Assert.IsTrue (output.StartsWith (temp), "output-path");
Assert.IsTrue (File.Exists (error), "error");
Assert.IsTrue (error.StartsWith (temp), "error-path");
Assert.IsTrue (tfc.Count >= 2, "TempFileCollection");
}
[Test]
public void ExecWaitWithCapture_CurrentDir ()
{
if (cmdNotFound)
Assert.Ignore ("ping command not found.");
string output = null;
string error = null;
TempFileCollection tfc = new TempFileCollection ();
Assert.AreEqual (errcode, Executor.ExecWaitWithCapture (cmd, cd, tfc, ref output, ref error), "ErrorCode");
Assert.IsTrue (File.Exists (output), "output");
Assert.IsTrue (output.StartsWith (temp), "output-path");
Assert.IsTrue (File.Exists (error), "error");
Assert.IsTrue (error.StartsWith (temp), "error-path");
// output/error file are relative to temp path
Assert.IsTrue (tfc.Count >= 2, "TempFileCollection");
}
[Test]
public void ExecWaitWithCapture_Token ()
{
if (cmdNotFound)
Assert.Ignore ("ping command not found.");
string output = null;
string error = null;
TempFileCollection tfc = new TempFileCollection ();
Assert.AreEqual (errcode, Executor.ExecWaitWithCapture (token, cmd, tfc, ref output, ref error), "ErrorCode");
Assert.IsTrue (File.Exists (output), "output");
Assert.IsTrue (output.StartsWith (temp), "output-path");
Assert.IsTrue (File.Exists (error), "error");
Assert.IsTrue (error.StartsWith (temp), "error-path");
Assert.IsTrue (tfc.Count >= 2, "TempFileCollection");
}
[Test]
public void ExecWaitWithCapture_Token_CurrentDir ()
{
if (cmdNotFound)
Assert.Ignore ("ping command not found.");
string output = null;
string error = null;
TempFileCollection tfc = new TempFileCollection ();
Assert.AreEqual (errcode, Executor.ExecWaitWithCapture (token, cmd, cd, tfc, ref output, ref error), "ErrorCode");
Assert.IsTrue (File.Exists (output), "output");
Assert.IsTrue (output.StartsWith (temp), "output-path");
Assert.IsTrue (File.Exists (error), "error");
Assert.IsTrue (error.StartsWith (temp), "error-path");
// output/error file are relative to temp path
Assert.IsTrue (tfc.Count >= 2, "TempFileCollection");
}
}
}

View File

@@ -0,0 +1,74 @@
//
// GeneratedCodeAttributeCas.cs
// - CAS unit tests for System.CodeDom.Compiler.GeneratedCodeAttribute
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using NUnit.Framework;
using System;
using System.CodeDom.Compiler;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
namespace MonoCasTests.System.CodeDom.Compiler {
[TestFixture]
[Category ("CAS")]
public class GeneratedCodeAttributeCas {
[SetUp]
public void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Constructor_Deny_Unrestricted ()
{
GeneratedCodeAttribute gca = new GeneratedCodeAttribute ("Mono", "1.2");
Assert.AreEqual ("Mono", gca.Tool, "Tool");
Assert.AreEqual ("1.2", gca.Version, "Version");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void LinkDemand_Deny_Unrestricted ()
{
Type[] types = new Type[2] { typeof (string), typeof (string) };
ConstructorInfo ci = typeof (GeneratedCodeAttribute).GetConstructor (types);
Assert.IsNotNull (ci, ".ctor(string,string)");
Assert.IsNotNull (ci.Invoke (new object[2] { "Mono", "1.2" }), "invoke");
}
}
}
#endif

View File

@@ -0,0 +1,68 @@
//
// GeneratedCodeAttributeTest.cs
// - Unit tests for System.CodeDom.Compiler.GeneratedCodeAttribute
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using NUnit.Framework;
using System;
using System.CodeDom.Compiler;
namespace MonoTests.System.CodeDom.Compiler {
[TestFixture]
public class GeneratedCodeAttributeTest {
[Test]
public void Constructor ()
{
GeneratedCodeAttribute gca = new GeneratedCodeAttribute ("Mono", "1.2");
Assert.AreEqual ("Mono", gca.Tool, "Tool");
Assert.AreEqual ("1.2", gca.Version, "Version");
}
[Test]
public void Constructor_Null_Tool ()
{
GeneratedCodeAttribute gca = new GeneratedCodeAttribute (null, "1.2");
Assert.IsNull (gca.Tool, "Tool");
Assert.AreEqual ("1.2", gca.Version, "Version");
}
[Test]
public void Constructor_Null_Version ()
{
GeneratedCodeAttribute gca = new GeneratedCodeAttribute ("Mono", null);
Assert.AreEqual ("Mono", gca.Tool, "Tool");
Assert.IsNull (gca.Version, "Version");
}
}
}
#endif

Some files were not shown because too many files have changed in this diff Show More