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,118 @@
//
// CSharpCodeProviderCas.cs
// - CAS unit tests for Microsoft.CSharp.CSharpCodeProvider
//
// 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.IO;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using Microsoft.CSharp;
namespace MonoCasTests.Microsoft.CSharp {
[TestFixture]
[Category ("CAS")]
public class CSharpCodeProviderCas {
[SetUp]
public virtual void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Deny_Unrestricted ()
{
CSharpCodeProvider csprov = new CSharpCodeProvider ();
Assert.AreEqual ("cs", csprov.FileExtension, "FileExtension");
Assert.IsNotNull (csprov.CreateCompiler (), "CreateCompiler");
Assert.IsNotNull (csprov.CreateGenerator (), "CreateGenerator");
try {
Assert.IsNotNull (csprov.GetConverter (typeof (string)), "GetConverter");
}
catch (NotImplementedException) {
// mono
}
#if NET_2_0
CodeTypeMember ctm = new CodeTypeMember ();
StringWriter sw = new StringWriter ();
CodeGeneratorOptions cgo = new CodeGeneratorOptions ();
try {
csprov.GenerateCodeFromMember (ctm, sw, cgo);
}
catch (NotImplementedException) {
// mono
}
#endif
}
// LinkDemand
// we use reflection to call this class as it is protected by a LinkDemand
// (which will be converted into full demand, i.e. a stack walk) when
// reflection is used (i.e. it gets testable).
public virtual object Create ()
{
ConstructorInfo ci = typeof (CSharpCodeProvider).GetConstructor (new Type[0]);
Assert.IsNotNull (ci, "default .ctor");
return ci.Invoke (null);
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (SecurityException))]
public void LinkDemand_Deny_Unrestricted ()
{
Assert.IsNotNull (Create ());
}
[Test]
[EnvironmentPermission (SecurityAction.Deny, Read = "MONO")]
[ExpectedException (typeof (SecurityException))]
public void LinkDemand_Deny_Anything ()
{
// denying any permissions -> not full trust!
Assert.IsNotNull (Create ());
}
[Test]
[PermissionSet (SecurityAction.PermitOnly, Unrestricted = true)]
public void LinkDemand_PermitOnly_Unrestricted ()
{
Assert.IsNotNull (Create ());
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,268 @@
2010-04-12 Jonathan Pryor <jpryor@novell.com>
* CodeGeneratorFromExpressionTest.cs: Test CodeDefaultValueExpression
generation.
2009-06-26 Robert Jordan <robertj@gmx.net>
* CodeGeneratorIdentifierTest.cs: Upgrade to new NUnit style.
2009-06-08 Zoltan Varga <vargaz@gmail.com>
* CSharpCodeProviderTest.cs: Avoid depending on the order in which
GetManifestResourceNames () returns resource names.
2008-05-09 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromTypeTest.cs: Added tests for
System.ParamArrayAttribute custom attribute.
2008-04-08 Jb Evain <jbevain@novell.com>
* CodeGeneratorFromTypeTest.cs: add test for abstract properties.
2008-01-27 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromExpressionTest.cs: Copied some tests from VB, and
improved existing tests.
2008-01-16 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromCompileUnitTest.cs: Avoid using "", and use
Assert instead of Assertion.
* CodeGeneratorFromNamespaceTest.cs: Added tests for type parameters.
2007-12-21 Rolf Bjarne Kvinge <RKvinge@novell.com>
* CodeGeneratorFromTypeTest.cs: Added PartialTypeTest.
2007-10-26 Atsushi Enomoto <atsushi@ximian.com>
* CodeGeneratorFromTypeTest.cs : added test case for escaped
CodeProperty output name (keyword).
2007-02-21 Gert Driesen <drieseng@users.sourceforge.net>
* CSharpCodeProviderTest.cs: No longer use Assert class in separate
AppDomain since it will only work if nunit.framework assembly is in
the GAC.
2007-02-21 Gert Driesen <drieseng@users.sourceforge.net>
* CSharpCodeProviderTest.cs: Added test for generating executable.
Modified existing test to use zero-length OutputAssembly, and verify
expected OutputAssembly after generating assembly.
2007-01-18 Atsushi Enomoto <atsushi@ximian.com>
* CodeGeneratorFromTypeTest.cs :
Added test for generic type references output.
2006-12-30 Marek Habersack <grendello@gmail.com>
* CodeGeneratorIdentifierTest.cs: added tests for C# code generator
IsValidIdentifier method.
2006-08-08 Gert Driesen <drieseng@users.sourceforge.net>
* CSharpCodeProviderTest.cs: Modified tests to verify fix for bug
#78384, and check support for linked resources.
2006-04-20 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromNamespaceTest.cs: Added tests for namespace imports
and types.
2005-12-07 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromExpressionTest.cs: Added tests for
CodePrimitiveExpression.
2005-11-30 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromStatementTest.cs: Added tests for
CodeAssignStatement, CodeAttachEventStatement,
CodeConditionStatement, CodeExpressionStatement,
CodeIterationStatement, CodeLabeledStatement,
CodeMethodReturnStatement, CodeRemoveEventStatement,
CodeSnippetStatement, CodeStatement, CodeVariableDeclarationStatement.
2005-11-26 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromExpressionTest.cs: Added test for
CodeParameterDeclarationExpression.
* CodeGeneratorFromTypeTest.cs: Modified tests to check result
for zero-length event, field and parameter name.
* CodeGeneratorFromStatementTest.cs: Added CodeCommentStatement,
CodeThrowExceptionStatement, CodeGotoStatement and
CodeTryCatchFinallyStatement tests.
2005-10-28 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromTypeTest.cs: Added tests for CodeEntryPointMethod
and bug #76580.
2005-10-25 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorTestBase.cs: Fixed line endings. Set eol-style to
native.
* CodeGeneratorFromCompileUnitTest.cs: Fixed line endings. Set
eol-style to native. Modified test to also check output for
CodeAttributeArgument with no name.
* CodeGeneratorFromNamespaceTest.cs: Fixed line endings. Set eol-style
to native.
* CodeGeneratorIdentifierTest.cs: Set eol-style to native.
* CodeGeneratorFromExpressionTest.cs: Fixed line endings. Set
eol-style to native.
* CSharpCodeProviderTest.cs: Set eol-style to native.
* CodeGeneratorFromTypeTest.cs: Fixed line endings. Set eol-style to
native.
* CodeGeneratorFromStatementTest.cs: Fixed line endings. Set
eol-style to native.
2005-10-17 Sebastien Pouliot <sebastien@ximian.com>
* CSharpCodeProviderCas.cs: New. CAS unit tests.
2005-10-15 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorTestBase.cs: Generate now returns code that was output,
and take CodeGeneratorOptions instance in order to support testing
bracing style.
* CodeGeneratorFromCompileUnitTest.cs: Added tests for C bracing style.
* CodeGeneratorFromNamespaceTest.cs: Added tests for C bracing style.
* CodeGeneratorFromExpressionTest.cs: Clean up.
* CodeGeneratorFromTypeTest.cs: Added tests for C bracing style.
2005-10-07 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorTypeOutputTest.cs: Added tests for
CSharpCodeGenerator.GetTypeOutput.
2005-07-30 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromTypeTest.cs: Added NewSlot tests.
2005-07-24 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromTypeTest.cs: Added BaseTypes and TypeConstructor
tests. Added enum, interface and delegate tests.
2005-07-02 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromTypeTest.cs: Added test for
ReturnTypeCustomAttributes.
2005-07-02 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromTypeTest.cs: Added event ImplementationTypes
tests. Added PrivateImplementationType and property and method
overload tests. Added property indexer tests.
2005-07-01 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromTypeTest.cs: Added tests to ensure Implementation
Types are ignored in C# CodeDOM.
2005-06-30 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromTypeTest.cs: Added property indexer and parameter
tests.
2005-06-28 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromTypeTest.cs: Added additional property tests.
2005-06-28 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromExpressionTest.cs: No longer inherit from
CodeGeneratorTestBase. Added tests for CodeTypeReference.
2005-06-26 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromTypeTest.cs: Added tests to verify code generated
for events, fields, properties, methods and ctors to match MS.NET.
2005-06-25 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromTypeTest.cs: Added tests to verify code generated
for Type (with and without custom attributes).
2005-06-25 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromCompileUnitTest.cs: Added tests to verify code
that is generated for assembly-level custom attributes.
2005-06-25 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromCompileUnitTest.cs: enabled test for bug
#75190.
2005-06-10 Gert Driesen <drieseng@users.sourceforge.net>
* CSharpCodeProviderTest.cs: added tests for bug #75221 and
#75218.
2005-06-09 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromCompileUnitTest.cs: added test for bug #75190.
2005-06-05 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromCompileUnitTest.cs: re-enabled tests as
IndentedTextWriter now matches MS.NET
2005-06-04 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromNamespaceTest.cs: re-enabled SimpleNamespaceTest
and InvalidNamespaceTest as IndentedTextWriter now matches MS.NET
2005-05-30 Gert Driesen <drieseng@users.sourceforge.net>
* CSharpCodeGeneratorTest.cs: Added tests for GenerateInMemory
compiler parameter.
2004-06-18 Atsushi Enomoto <atsushi@ximian.com>
* CodeGeneratorIdentifierTest.cs : [TestFixture] was missing.
2004-01-21 Atsushi Enomoto <atsushi@ximian.com>
* Added CodeGeneratorIdentifierTest.cs.
2003-11-21 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* Test/Microsoft.CSharp/CodeGeneratorFromCompileUnitTest.cs: don't
compare whitespace for assembly level attribute.
2003-07-09 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* system_linux_test.args: added new tests in Microsoft.CSharp.
* Microsoft.CSharp/CodeGeneratorFromCompileUnitTest.cs:
* Microsoft.CSharp/CodeGeneratorFromExpressionTest.cs:
* Microsoft.CSharp/CodeGeneratorFromNamespaceTest.cs:
* Microsoft.CSharp/CodeGeneratorFromStatementTest.cs:
* Microsoft.CSharp/CodeGeneratorFromTypeTest.cs:
* Microsoft.CSharp/CodeGeneratorTestBase.cs: new tests from Erik LeBel
<eriklebel@yahoo.ca>.
2002-12-08 Jackson Harper <jackson@latitudegeo.com>
* CompilerTest.cs CompilerErrorTest.cs: Removed files
2002-12-08 Jackson Harper <jackson@latitudegeo.com>
* AllTests.cs: Remove references to soon to be removed Tests
2002-11-13 Jackson Harper <jackson@latitudegeo.com>
* CompilerTest.cs: Added more tests
2002-11-11 Jackson Harper <jackson@latitudegeo.com>
* CompilerErrorTest.cs AllTests.cs: Added tests for the Microsoft.CSharp.CompilerError class
2002-11-06 Jackson Harper <jackson@latitudegeo.com>
* AllTests.cs CompilerTest.cs: Added files

View File

@@ -0,0 +1,225 @@
//
// Microsoft.CSharp.* Test Cases
//
// Authors:
// Erik LeBel (eriklebel@yahoo.ca)
// Ilker Cetinkaya (mail@ilker.de)
//
// (c) 2003 Erik LeBel
//
using System;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Globalization;
using System.IO;
using System.Text;
using NUnit.Framework;
namespace MonoTests.Microsoft.CSharp
{
/// <summary>
/// Test ICodeGenerator's GenerateCodeFromCompileUnit, along with a
/// minimal set CodeDom components.
/// </summary>
[TestFixture]
public class CodeGeneratorFromCompileUnitTest : CodeGeneratorTestBase
{
private string codeUnitHeader = string.Empty;
private CodeCompileUnit codeUnit;
public CodeGeneratorFromCompileUnitTest ()
{
Init();
codeUnitHeader = Generate ();
}
[SetUp]
public void Init ()
{
InitBase ();
codeUnit = new CodeCompileUnit ();
}
protected override string Generate (CodeGeneratorOptions options)
{
StringWriter writer = new StringWriter ();
writer.NewLine = NewLine;
generator.GenerateCodeFromCompileUnit (codeUnit, writer, options);
writer.Close ();
return writer.ToString ().Substring (codeUnitHeader.Length);
}
[Test]
public void DefaultCodeUnitTest ()
{
Assert.AreEqual (string.Empty, Generate ());
}
[Test]
[ExpectedException (typeof (NullReferenceException))]
public void NullCodeUnitTest ()
{
codeUnit = null;
Generate ();
}
[Test]
public void ReferencedTest ()
{
codeUnit.ReferencedAssemblies.Add ("System.dll");
Assert.AreEqual (string.Empty, Generate ());
}
[Test]
public void SimpleNamespaceTest ()
{
string code = null;
CodeNamespace ns = new CodeNamespace ("A");
codeUnit.Namespaces.Add (ns);
code = Generate ();
Assert.AreEqual ("namespace A {\n \n}\n", code, "#1");
CodeGeneratorOptions options = new CodeGeneratorOptions ();
options.BracingStyle = "C";
code = Generate (options);
Assert.AreEqual ("namespace A\n{\n \n}\n", code, "#2");
}
[Test]
public void ReferenceAndSimpleNamespaceTest()
{
CodeNamespace ns = new CodeNamespace ("A");
codeUnit.Namespaces.Add (ns);
codeUnit.ReferencedAssemblies.Add ("using System;");
Assert.AreEqual ("namespace A {\n \n}\n", Generate ());
}
[Test]
public void SimpleAttributeTest ()
{
CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
attrDec.Name = "A";
codeUnit.AssemblyCustomAttributes.Add (attrDec);
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"[assembly: A()]{0}{0}", NewLine), Generate ());
}
[Test]
public void AttributeWithValueTest ()
{
CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
attrDec.Name = "A";
attrDec.Arguments.Add (new CodeAttributeArgument ("A1",
new CodePrimitiveExpression (false)));
attrDec.Arguments.Add (new CodeAttributeArgument ("A2",
new CodePrimitiveExpression (true)));
// null name should not be output
attrDec.Arguments.Add (new CodeAttributeArgument (null,
new CodePrimitiveExpression (true)));
// zero length name should not be output
attrDec.Arguments.Add (new CodeAttributeArgument (string.Empty,
new CodePrimitiveExpression (false)));
codeUnit.AssemblyCustomAttributes.Add (attrDec);
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"[assembly: A(A1=false, A2=true, true, false)]{0}{0}", NewLine),
Generate ());
}
[Test]
public void MultipleAttributeTest ()
{
CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
attrDec.Name = "A";
codeUnit.AssemblyCustomAttributes.Add (attrDec);
attrDec = new CodeAttributeDeclaration ();
attrDec.Name = "B";
codeUnit.AssemblyCustomAttributes.Add (attrDec);
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"[assembly: A()]{0}[assembly: B()]{0}{0}", NewLine),
Generate ());
}
[Test]
public void AttributeAndSimpleNamespaceTest ()
{
CodeNamespace ns = new CodeNamespace ("A");
codeUnit.Namespaces.Add (ns);
CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
attrDec.Name = "A";
codeUnit.AssemblyCustomAttributes.Add (attrDec);
attrDec = new CodeAttributeDeclaration ();
attrDec.Name = "B";
codeUnit.AssemblyCustomAttributes.Add (attrDec);
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"[assembly: A()]{0}[assembly: B()]{0}{0}namespace A {{{0} {0}"
+ "}}{0}", NewLine), Generate ());
}
[Test]
public void CodeSnippetTest ()
{
StringWriter writer = new StringWriter ();
writer.NewLine = NewLine;
codeUnit = new CodeSnippetCompileUnit ("public class Test1 {}");
generator.GenerateCodeFromCompileUnit (codeUnit, writer, options);
writer.Close ();
Assert.AreEqual ("public class Test1 {}" + writer.NewLine, writer.ToString ());
}
[Test]
public void AttributeAndGlobalNamespaceWithImportTest ()
{
CodeNamespace ns = new CodeNamespace ();
ns.Imports.Add (new CodeNamespaceImport ("Z"));
ns.Imports.Add (new CodeNamespaceImport ("A"));
codeUnit.Namespaces.Add (ns);
CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
attrDec.Name = "A";
codeUnit.AssemblyCustomAttributes.Add (attrDec);
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"using A;{0}using Z;{0}{0}[assembly: A()]{0}{0}{0}", NewLine), Generate ());
}
[Test]
public void GlobalAttributeBeforeType ()
{
StringWriter writer = new StringWriter ();
writer.NewLine = NewLine;
codeUnit = new CodeCompileUnit () {
AssemblyCustomAttributes = {
new CodeAttributeDeclaration (
new CodeTypeReference (typeof (CLSCompliantAttribute)),
new CodeAttributeArgument (new CodePrimitiveExpression (false))),
},
Namespaces = {
new CodeNamespace () {
Types = {
new CodeTypeDeclaration ("Resources"),
},
}
},
};
generator.GenerateCodeFromCompileUnit (codeUnit, writer, options);
writer.Close ();
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"[assembly: System.CLSCompliantAttribute(false)]{0}{0}{0}{0}public class Resources {{{0}}}{0}", NewLine), Generate ());
}
}
}

File diff suppressed because it is too large Load Diff

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 @@
3fcc1d6d3b7c329eaaf86b7566cb5d50a7b77b74

View File

@@ -0,0 +1,97 @@
//
// CodeGeneratorIdentifierTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// (C)2004 Novell inc.
//
using System;
using System.CodeDom.Compiler;
using NUnit.Framework;
using Microsoft.CSharp;
namespace MonoTests.Microsoft.CSharp
{
[TestFixture]
public class CodeGeneratorIdentifierTest
{
private ICodeGenerator gen;
public CodeGeneratorIdentifierTest ()
{
gen = new CSharpCodeProvider ().CreateGenerator ();
}
[Test]
[ExpectedException (typeof (NullReferenceException))]
public void TestCreateValidIdentifierNullArg ()
{
gen.CreateValidIdentifier (null);
}
[Test]
public void TestCreateValidIdentifier ()
{
Assert.AreEqual ("a", gen.CreateValidIdentifier ("a"));
Assert.AreEqual ("_int", gen.CreateValidIdentifier ("int"));
Assert.AreEqual ("_", gen.CreateValidIdentifier ("_"));
Assert.AreEqual ("1", gen.CreateValidIdentifier ("1"));
Assert.AreEqual ("1a", gen.CreateValidIdentifier ("1a"));
Assert.AreEqual ("1*2", gen.CreateValidIdentifier ("1*2"));
Assert.AreEqual ("-", gen.CreateValidIdentifier ("-"));
Assert.AreEqual ("+", gen.CreateValidIdentifier ("+"));
Assert.AreEqual ("", gen.CreateValidIdentifier (""));
Assert.AreEqual ("--", gen.CreateValidIdentifier ("--"));
Assert.AreEqual ("++", gen.CreateValidIdentifier ("++"));
Assert.AreEqual ("\u3042", gen.CreateValidIdentifier ("\u3042"));
}
[Test]
[ExpectedException (typeof (NullReferenceException))]
public void TestCreateEscapedIdentifierNullArg ()
{
gen.CreateEscapedIdentifier (null);
}
[Test]
public void TestCreateEscapedIdentifier ()
{
Assert.AreEqual ("a", gen.CreateEscapedIdentifier ("a"));
Assert.AreEqual ("@int", gen.CreateEscapedIdentifier ("int"));
Assert.AreEqual ("_", gen.CreateEscapedIdentifier ("_"));
Assert.AreEqual ("1", gen.CreateEscapedIdentifier ("1"));
Assert.AreEqual ("1a", gen.CreateEscapedIdentifier ("1a"));
Assert.AreEqual ("1*2", gen.CreateEscapedIdentifier ("1*2"));
Assert.AreEqual ("-", gen.CreateEscapedIdentifier ("-"));
Assert.AreEqual ("+", gen.CreateEscapedIdentifier ("+"));
Assert.AreEqual ("", gen.CreateEscapedIdentifier (""));
Assert.AreEqual ("--", gen.CreateEscapedIdentifier ("--"));
Assert.AreEqual ("++", gen.CreateEscapedIdentifier ("++"));
Assert.AreEqual ("\u3042", gen.CreateEscapedIdentifier ("\u3042"));
}
[Test]
public void TestIsValidIdentifier ()
{
Assert.AreEqual (true, gen.IsValidIdentifier ("_a"));
Assert.AreEqual (true, gen.IsValidIdentifier ("_"));
Assert.AreEqual (true, gen.IsValidIdentifier ("@return"));
Assert.AreEqual (true, gen.IsValidIdentifier ("d1"));
Assert.AreEqual (true, gen.IsValidIdentifier ("_1"));
Assert.AreEqual (true, gen.IsValidIdentifier ("_a_1"));
Assert.AreEqual (true, gen.IsValidIdentifier ("@a"));
Assert.AreEqual (false, gen.IsValidIdentifier ("1"));
Assert.AreEqual (false, gen.IsValidIdentifier (" "));
Assert.AreEqual (false, gen.IsValidIdentifier ("?"));
Assert.AreEqual (false, gen.IsValidIdentifier (":_:"));
Assert.AreEqual (false, gen.IsValidIdentifier ("_ "));
Assert.AreEqual (false, gen.IsValidIdentifier ("@ "));
Assert.AreEqual (false, gen.IsValidIdentifier ("1*2"));
Assert.AreEqual (false, gen.IsValidIdentifier ("1_2"));
Assert.AreEqual (gen.IsValidIdentifier ("a, b"), false);
}
}
}

View File

@@ -0,0 +1,56 @@
//
// Microsoft.CSharp.* Test Cases
//
// Authors:
// Erik LeBel (eriklebel@yahoo.ca)
//
// (c) 2003 Erik LeBel
//
using System;
using System.IO;
using System.Text;
using System.CodeDom;
using System.CodeDom.Compiler;
using Microsoft.CSharp;
using NUnit.Framework;
namespace MonoTests.Microsoft.CSharp
{
///
/// <summary>
/// Base test for a variety of CodeGenerator GenerateCodeXXX methods.
///
/// This testing is a form of hybrid test, it tests the variety of CodeDom
/// classes as well as the C# code generator.
///
/// The implementations bellow provide a template as well as guidlines for
/// implementing further tests.
/// </summary>
///
public abstract class CodeGeneratorTestBase
{
private CodeDomProvider provider = null;
protected ICodeGenerator generator = null;
protected CodeGeneratorOptions options = null;
public void InitBase()
{
provider = new CSharpCodeProvider ();
generator = provider.CreateGenerator ();
options = new CodeGeneratorOptions ();
}
protected string Generate ()
{
return Generate (options);
}
protected virtual string NewLine
{
get { return "\n"; }
}
protected abstract string Generate (CodeGeneratorOptions options);
}
}

View File

@@ -0,0 +1,122 @@
//
// CodeGeneratorTypeOutputTest.cs
//
// Author:
// Gert Driesen <drieseng@users.sourceforge.net>
//
// (C)2005 Novell inc.
//
using System;
using System.CodeDom;
using System.CodeDom.Compiler;
#if NET_2_0
using System.Collections.Generic;
#endif
using NUnit.Framework;
using Microsoft.CSharp;
namespace MonoTests.Microsoft.CSharp
{
[TestFixture]
public class CodeGeneratorTypeOutputTest
{
private ICodeGenerator gen;
[SetUp]
public void SetUp ()
{
gen = new CSharpCodeProvider ().CreateGenerator ();
}
#if NET_2_0
// This test fails on 2.0 profile, because our CodeTypeReference does not
// parse basetype from right to left.
[Test]
[Category ("NotWorking")]
public void GetTypeOutputFailure ()
{
Assert.AreEqual ("A[,,][,]", gen.GetTypeOutput (new CodeTypeReference ("A[,,][,]")), "#5");
Assert.AreEqual ("A<B, D>[,]", gen.GetTypeOutput (new CodeTypeReference ("A[B,,D][,]")), "#6");
}
#endif
[Test]
public void GetTypeOutput ()
{
Assert.AreEqual ("A", gen.GetTypeOutput (new CodeTypeReference ("A")), "#1");
Assert.AreEqual ("A[]", gen.GetTypeOutput (new CodeTypeReference ("A[]")), "#2");
Assert.AreEqual ("int[]", gen.GetTypeOutput (new CodeTypeReference (typeof (int).FullName, 1)), "#3");
Assert.AreEqual ("int[,]", gen.GetTypeOutput (new CodeTypeReference (typeof (int).FullName, 2)), "#4");
#if NET_2_0
Assert.AreEqual ("System.Nullable<int>", gen.GetTypeOutput (new CodeTypeReference (typeof (int?))), "#7");
Assert.AreEqual ("System.Collections.Generic.Dictionary<int, string>", gen.GetTypeOutput (new CodeTypeReference (typeof (Dictionary<int, string>))), "#8");
#else
Assert.AreEqual ("A[,,][,]", gen.GetTypeOutput (new CodeTypeReference ("A[,,][,]")), "#5");
Assert.AreEqual ("A[B,,D][,]", gen.GetTypeOutput (new CodeTypeReference ("A[B,,D][,]")), "#6");
Assert.AreEqual ("System.Nullable`1[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]",
gen.GetTypeOutput (new CodeTypeReference ("System.Nullable`1[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]")),
"#9");
Assert.AreEqual ("System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]",
gen.GetTypeOutput (new CodeTypeReference ("System.Collections.Generic.Dictionary`2[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]")),
"#10");
#endif
}
[Test]
public void Shortcuts () {
Assert.AreEqual ("int", gen.GetTypeOutput (new CodeTypeReference (typeof(int))), "#1");
Assert.AreEqual ("int", gen.GetTypeOutput (new CodeTypeReference ("systeM.inT32")), "#2");
Assert.AreEqual ("long", gen.GetTypeOutput (new CodeTypeReference (typeof(long))), "#3");
Assert.AreEqual ("long", gen.GetTypeOutput (new CodeTypeReference ("systeM.inT64")), "#4");
Assert.AreEqual ("short", gen.GetTypeOutput (new CodeTypeReference (typeof(short))), "#5");
Assert.AreEqual ("short", gen.GetTypeOutput (new CodeTypeReference ("systeM.inT16")), "#6");
Assert.AreEqual ("bool", gen.GetTypeOutput (new CodeTypeReference (typeof(bool))), "#7");
Assert.AreEqual ("bool", gen.GetTypeOutput (new CodeTypeReference ("systeM.BooLean")), "#8");
Assert.AreEqual ("char", gen.GetTypeOutput (new CodeTypeReference (typeof(char))), "#9");
Assert.AreEqual ("char", gen.GetTypeOutput (new CodeTypeReference ("systeM.cHar")), "#10");
Assert.AreEqual ("string", gen.GetTypeOutput (new CodeTypeReference (typeof(string))), "#11");
Assert.AreEqual ("string", gen.GetTypeOutput (new CodeTypeReference ("systeM.sTring")), "#12");
Assert.AreEqual ("object", gen.GetTypeOutput (new CodeTypeReference (typeof(object))), "#13");
Assert.AreEqual ("object", gen.GetTypeOutput (new CodeTypeReference ("systeM.oBject")), "#14");
Assert.AreEqual ("void", gen.GetTypeOutput (new CodeTypeReference (typeof(void))), "#15");
Assert.AreEqual ("void", gen.GetTypeOutput (new CodeTypeReference ("systeM.vOid")), "#16");
#if NET_2_0
Assert.AreEqual ("byte", gen.GetTypeOutput (new CodeTypeReference (typeof(byte))), "#17");
Assert.AreEqual ("byte", gen.GetTypeOutput (new CodeTypeReference ("systeM.bYte")), "#18");
Assert.AreEqual ("sbyte", gen.GetTypeOutput (new CodeTypeReference (typeof(sbyte))), "#19");
Assert.AreEqual ("sbyte", gen.GetTypeOutput (new CodeTypeReference ("systeM.sBYte")), "#20");
Assert.AreEqual ("decimal", gen.GetTypeOutput (new CodeTypeReference (typeof(decimal))), "#21");
Assert.AreEqual ("decimal", gen.GetTypeOutput (new CodeTypeReference ("systeM.dEcimal")), "#22");
Assert.AreEqual ("double", gen.GetTypeOutput (new CodeTypeReference (typeof(double))), "#23");
Assert.AreEqual ("double", gen.GetTypeOutput (new CodeTypeReference ("systeM.dOuble")), "#24");
Assert.AreEqual ("float", gen.GetTypeOutput (new CodeTypeReference (typeof(float))), "#25");
Assert.AreEqual ("float", gen.GetTypeOutput (new CodeTypeReference ("systeM.SiNgle")), "#26");
Assert.AreEqual ("uint", gen.GetTypeOutput (new CodeTypeReference (typeof (uint))), "#27");
Assert.AreEqual ("uint", gen.GetTypeOutput (new CodeTypeReference ("systeM.UinT32")), "#28");
Assert.AreEqual ("ulong", gen.GetTypeOutput (new CodeTypeReference (typeof (ulong))), "#29");
Assert.AreEqual ("ulong", gen.GetTypeOutput (new CodeTypeReference ("systeM.uinT64")), "#30");
Assert.AreEqual ("ushort", gen.GetTypeOutput (new CodeTypeReference (typeof (ushort))), "#31");
Assert.AreEqual ("ushort", gen.GetTypeOutput (new CodeTypeReference ("systeM.uinT16")), "#32");
#else
Assert.AreEqual (typeof (byte).FullName, gen.GetTypeOutput (new CodeTypeReference (typeof (byte))), "#17");
Assert.AreEqual ("systeM.bYte", gen.GetTypeOutput (new CodeTypeReference ("systeM.bYte")), "#18");
Assert.AreEqual (typeof (sbyte).FullName, gen.GetTypeOutput (new CodeTypeReference (typeof (sbyte))), "#19");
Assert.AreEqual ("systeM.sBYte", gen.GetTypeOutput (new CodeTypeReference ("systeM.sBYte")), "#20");
Assert.AreEqual (typeof (decimal).FullName, gen.GetTypeOutput (new CodeTypeReference (typeof (decimal))), "#21");
Assert.AreEqual ("systeM.dEcimal", gen.GetTypeOutput (new CodeTypeReference ("systeM.dEcimal")), "#22");
Assert.AreEqual (typeof (double).FullName, gen.GetTypeOutput (new CodeTypeReference (typeof (double))), "#23");
Assert.AreEqual ("systeM.dOuble", gen.GetTypeOutput (new CodeTypeReference ("systeM.dOuble")), "#24");
Assert.AreEqual (typeof (float).FullName, gen.GetTypeOutput (new CodeTypeReference (typeof (float))), "#25");
Assert.AreEqual ("systeM.SiNgle", gen.GetTypeOutput (new CodeTypeReference ("systeM.SiNgle")), "#26");
Assert.AreEqual (typeof (uint).FullName, gen.GetTypeOutput (new CodeTypeReference (typeof (uint))), "#27");
Assert.AreEqual ("systeM.UinT32", gen.GetTypeOutput (new CodeTypeReference ("systeM.UinT32")), "#28");
Assert.AreEqual (typeof (ulong).FullName, gen.GetTypeOutput (new CodeTypeReference (typeof (ulong))), "#29");
Assert.AreEqual ("systeM.uinT64", gen.GetTypeOutput (new CodeTypeReference ("systeM.uinT64")), "#30");
Assert.AreEqual (typeof (ushort).FullName, gen.GetTypeOutput (new CodeTypeReference (typeof (ushort))), "#31");
Assert.AreEqual ("systeM.uinT16", gen.GetTypeOutput (new CodeTypeReference ("systeM.uinT16")), "#32");
#endif
}
}
}

View File

@@ -0,0 +1,303 @@
2008-05-09 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromTypeTest.cs: Added tests for
System.ParamArrayAttribute custom attribute.
2008-04-30 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromTypeTest.cs: Added tests for static and abstract
property.
2008-03-13 Rolf Bjarne Kvinge <RKvinge@novell.com>
* CodeGeneratorFromCompileUnitTest.cs: Added ExternalSourceTest.
2008-01-27 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromExpressionTest.cs: Numbered tests. Fixed test for
DelegateInvokeExpression to pass on MS 2.0 and improved coverage.
2008-01-16 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromNamespaceTest.cs: Added tests for type parameters.
2007-12-21 Rolf Bjarne Kvinge <RKvinge@novell.com>
* CodeGeneratorFromTypeTest.cs: Added PartialTypeTest.
2007-10-30 Rolf Bjarne Kvinge <RKvinge@novell.com>
* CodeGeneratorFromExpressionTest.cs: Added ArrayIndexerExpressionTest.
2007-05-18 Rolf Bjarne Kvinge <RKvinge@novell.com>
* CodeGeneratorFromExpressionTest.cs: Added EventReferenceTest and DelegateInvokeTest.
* CodeGeneratorFromTypeTest.cs: Added DelegateWithParameterTest.
2007-05-17 Rolf Bjarne Kvinge <RKvinge@novell.com>
* CodeGeneratorFromExpressionTest.cs: Added EscapedIdentifierTest.
* CodeGeneratorFromStatementTest.cs: Added CodeAttachEventStatementKeywordTest.
2007-05-08 Rolf Bjarne Kvinge <RKvinge@novell.com>
* CodeGeneratorFromExpressionTest.cs: Added ArrayCreateExpressionTest.
2007-04-13 Frederik Carlier <frederik.carlier@carlier-online.be>
* CodeGeneratorFromBinaryOperatorTest.cs: Regression test for bug 81372, test
for code generated when comparing against null (Nothing in Visual Basic)
2007-02-21 Gert Driesen <drieseng@users.sourceforge.net>
* VBCodeProviderTest.cs: Modified tests to also cover fix for bug
#80920. No longer use Assert class in separate AppDomain since it
will only work if nunit.framework assembly is in the GAC.
* CodeGeneratorFromTypeTest.cs: Fixed tests to pass on MS.
2007-02-21 Gert Driesen <drieseng@users.sourceforge.net>
* VBCodeProviderTest.cs: Mark tests that rely on vbnc as NotWorking,
and remove comment about mbas.
2006-10-22 Zoltan Varga <vargaz@gmail.com>
* VBCodeProviderTest.cs: Mark this as NotWorking since mbas is no more.
2006-08-08 Gert Driesen <drieseng@users.sourceforge.net>
* VBCodeProviderTest.cs: Modified tests to verify fix for bug
#78384, and check support for linked resources.
2006-04-20 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromNamespaceTest.cs: Added tests for
GenerateCodeFromNamespace.
2005-12-07 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromExpressionTest.cs: Added tests for
CodePrimitiveExpression.
2005-11-30 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromStatementTest.cs: Added tests for
CodeAssignStatement, CodeAttachEventStatement, CodeConditionStatement,
CodeExpressionStatement, CodeIterationStatement,
CodeLabeledStatement, CodeMethodReturnStatement,
CodeRemoveEventStatement and CodeSnippetStatement.
2005-11-26 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorTestBase.cs: Removed Code property, added Generate
overload taking CodeGeneratorOptions, added NewLine property.
* CodeGeneratorCompileUnitTest.cs: Use Generate method instead of
Code property.
* CodeGeneratorFromExpressionTest.cs: Added test for
CodeParameterDeclarationExpression.
* CodeGeneratorFromTypeTest.cs: Added tests for __exception name that
is output for zero-length field, event and parameter name in 2.0
profile.
* CodeGeneratorFromStatementTest.cs: Added.
2005-10-28 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromTypeTest.cs: Added tests for CodeEntryPointMethod
and bug #76580.
2005-10-25 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorTestBase.cs: Set eol-style to native.
* VBCodeProviderTest.cs: Set eol-style to native.
* CodeGeneratorFromCompileUnitTest.cs: Modified test to check
output for CodeAttributeArgument with no name. Set eol-style to
native.
* CodeGeneratorFromExpressionTest.cs: Set eol-style to native.
* CodeGeneratorFromTypeTest.cs: Fixed line endings. Set eol-style to
native.
2005-10-24 Raja R Harinath <harinath@gmail.com>
* CodeGeneratorFromTypeTest.cs (CodeGeneratorFromTypeTest_Class)
(CodeGeneratorFromTypeTest_Struct): Update to reflect mbas workaround.
2005-10-17 Sebastien Pouliot <sebastien@ximian.com>
* VBCodeProviderCas.cs: New. CAS unit tests.
2005-10-15 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromTypeTest.cs: Reworked tests to pass
CodeGeneratorOptions to Generate* methods.
2005-09-12 Gert Driesen <drieseng@users.sourceforge.net>
* VBCodeProviderTest.cs: Re-enabled CreateCompiler test as bug #75223
is fixed.
2005-07-30 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromTypeTest.cs: Added NewSlot tests.
2005-07-24 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromTypeTest.cs: Added BaseTypes and TypeConstructor
tests. Enabled enum, interface and delegate tests.
2005-07-21 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromTypeTest.cs: Inherit from
System.CodeDom.CodeGeneratorFromTypeTestBase. Added testfixture
for testing enum, interface and delegate, but for now these are
marked NotWorking.
2005-07-02 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromTypeTest.cs: Added test for
ReturnTypeCustomAttributes.
2005-07-02 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromTypeTest.cs: Modified test to ensure that scope
modifiers are not output for events.
2005-07-02 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromTypeTest.cs: Added PrivateImplementationType tests
for property, event, method. Added Overloads tests for property and
method.
2005-07-01 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromTypeTest.cs: Added ImplementationTypes tests for
property, event, method, ctor.
2005-06-30 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromTypeTest.cs: Added property indexer and
parameter tests.
2005-06-28 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromExpressionTest.cs: Renumbered tests for
TypeReferenceExpressionTest. Added tests for zero-length or null
type name, and object type.
2005-06-27 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromExpressionTest.cs: Added tests for
GenerateCodeFromExpression.
2005-06-26 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromTypeTest.cs: Make tests pass on MS.NET 1.x and 2.0,
and Mono (1.0/2.0).
2005-06-26 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromTypeTest.cs: Added tests for ctor level attributes
and Base/Chained ctor args.
2005-06-26 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromCompileUnitTest.cs: Removed last usage of
Assertion class.
* CodeGeneratorFromTypeTest.cs: Added tests for method, property and
parameter level attributes.
2005-06-25 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromCompileUnitTest.cs: Added test for assembly-level
attribute without value. Use Assert instead of deprecated Assertion.
* CodeGeneratorFromTypeTest.cs: Use Assert instead of Assertion.
2005-06-25 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromTypeTest.cs: Added tests to verify code generated
for field and event members.
2005-06-25 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromTypeTest.cs: Added tests to verify code generated
for Type (with and without custom attributes).
2005-06-25 Gert Driesen <drieseng@users.sourceforge.net>
* CodeGeneratorFromCompileUnitTest.cs: several tests to ensure
code generated by GenerateCodeFromCompileUnit matches that of
MS.NET.
2005-06-12 Gert Driesen <drieseng@users.sourceforge.net>
* VBCodeProviderTest.cs: Marked tests NotWorking on 2.0 profile
as we don't yet have an mbas for that profile.
2005-06-12 Gert Driesen <drieseng@users.sourceforge.net>
* VBCodeProviderTest.cs: fixed line endings
2005-06-10 Gert Driesen <drieseng@users.sourceforge.net>
* VBCodeProviderTest.cs: improve reporting of test failures as a
result of compile errors. Added a ICodeGenerator.Supports tests
for .NET 2.0.
2005-06-10 Gert Driesen <drieseng@users.sourceforge.net>
* VBCodeProviderTest.cs: removed unnecessary test, added test
for ICodeGenerator.Supports.
2005-06-09 Gert Driesen <drieseng@users.sourceforge.net>
* VBCodeProviderTest.cs: added batch of tests that check whether
temporary files are cleaned up, compile multiple sources/compile units
and files. Use separate AppDomain for tests that actually loaded
the compiled assembly, to ensure no test output is left on the system.
2005-06-05 Gert Driesen <drieseng@users.sourceforge.net>
* VBCodeProviderTest.cs: moved to using NUnit 2.x Assert, improve
failure output of CreateCompiler test.
2005-05-30 Gert Driesen <drieseng@users.sourceforge.net>
* VBCodeProviderTest.cs: Added tests for GenerateInMemory
compiler parameter.
2004-12-03 Raja R Harinath <rharinath@novell.com>
* VBCodeProviderTest.cs: Change namespace to
MonoTests.Microsoft.VisualBasic.
2004-11-19 Raja R Harinath <rharinath@novell.com>
* VBCodeProviderTest.cs (CreateCompiler): Be more verbose about
error exit.
2004-03-08 Nick Drochak <ndrochak@ieee.org>
* VBCodeProviderTest.cs: On windows, do not use mono to execute
assembly. Actually, this should be if running on MS's CLR, but
for now it will do.
2004-02-04 Jackson Harper <jackson@ximian.com>
* VBCodeProviderTest.cs: Use mono to execute assembly.
2003-12-11 Nick Drochak <ndrochak@ieee.org>
* VBCodeProviderTest.cs: Console.WriteLine's don't really belong in
unit tests.
2003-12-11 Nick Drochak <ndrochak@ieee.org>
* VBCodeProviderTest.cs: Fixed subtle namespace issues preventing
build with csc.
2003-12-10 Jochen Wezel <jwezel@compumaster.de>
* VBCodeProviderTest.cs: moved into proper subdir
and also extended for additional testings
* CodeGenerator*.cs: C# units copied and changed for VB use

View File

@@ -0,0 +1,80 @@
//
// Microsoft.VisualBasic.* Test Cases
//
// Authors:
// Frederik Carlier <frederik.carlier@carlier-online.be>
// Rolf Bjarne Kvinge <RKvinge@novell.com>
//
// (c) 2005 Novell
//
using System;
using System.IO;
using System.Text;
using System.CodeDom;
using System.CodeDom.Compiler;
using Microsoft.VisualBasic;
using NUnit.Framework;
namespace MonoTests.Microsoft.VisualBasic
{
[TestFixture]
public class CodeGeneratorFromBinaryOperatorTest
{
VBCodeProvider provider;
ICodeGenerator generator;
CodeGeneratorOptions options;
[SetUp]
public void SetUp ()
{
provider = new VBCodeProvider ();
generator = provider.CreateGenerator ();
options = new CodeGeneratorOptions ();
}
[Test]
public void TypeReferenceExpressionTest ()
{
StringBuilder sb = new StringBuilder();
using (StringWriter sw = new StringWriter (sb)) {
CodeThisReferenceExpression thisRef = new CodeThisReferenceExpression();
CodeFieldReferenceExpression parentField = new CodeFieldReferenceExpression();
parentField.TargetObject = thisRef;
parentField.FieldName = "Parent";
CodeBinaryOperatorExpression expression = new CodeBinaryOperatorExpression(
parentField,
CodeBinaryOperatorType.IdentityInequality,
new CodePrimitiveExpression(null));
Assert.AreEqual ("(Not (Me.Parent) Is Nothing)", Generate (expression, sw), "#1");
sw.Close ();
}
sb = new StringBuilder();
using (StringWriter sw = new StringWriter (sb)) {
CodeThisReferenceExpression thisRef = new CodeThisReferenceExpression();
CodeFieldReferenceExpression parentField = new CodeFieldReferenceExpression();
parentField.TargetObject = thisRef;
parentField.FieldName = "Parent";
CodeBinaryOperatorExpression expression = new CodeBinaryOperatorExpression(
new CodePrimitiveExpression(null),
CodeBinaryOperatorType.IdentityInequality,
parentField);
Assert.AreEqual ("(Not (Me.Parent) Is Nothing)", Generate (expression, sw), "#2");
sw.Close ();
}
}
private string Generate (CodeExpression expression, StringWriter sw)
{
generator.GenerateCodeFromExpression (expression, sw, options);
return sw.ToString ();
}
}
}

View File

@@ -0,0 +1,199 @@
//
// Microsoft.VisualBasic.* Test Cases
//
// Authors:
// Gert Driesen (drieseng@users.sourceforge.net)
//
// (c) 2005 Novell
//
using System;
using System.Globalization;
using System.IO;
using System.Text;
using System.CodeDom;
using System.CodeDom.Compiler;
using NUnit.Framework;
namespace MonoTests.Microsoft.VisualBasic
{
[TestFixture]
public class CodeGeneratorFromCompileUnitTest : CodeGeneratorTestBase
{
string codeUnitHeader = "";
CodeCompileUnit codeUnit = null;
public CodeGeneratorFromCompileUnitTest ()
{
Init();
codeUnitHeader = Generate ();
}
[SetUp]
public void Init ()
{
InitBase ();
codeUnit = new CodeCompileUnit ();
}
protected override string Generate (CodeGeneratorOptions options)
{
StringWriter writer = new StringWriter ();
writer.NewLine = NewLine;
generator.GenerateCodeFromCompileUnit (codeUnit, writer, options);
writer.Close ();
return writer.ToString ().Substring (codeUnitHeader.Length);
}
[Test]
public void DefaultCodeUnitTest ()
{
Assert.AreEqual ("", Generate ());
}
[Test]
[ExpectedException (typeof (NullReferenceException))]
public void NullCodeUnitTest ()
{
codeUnit = null;
Generate();
}
[Test]
public void ReferencedTest ()
{
codeUnit.ReferencedAssemblies.Add ("System.dll");
Assert.AreEqual ("", Generate ());
}
[Test]
public void SimpleNamespaceTest ()
{
CodeNamespace ns = new CodeNamespace ("A");
codeUnit.Namespaces.Add (ns);
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"{0}Namespace A{0}End Namespace{0}", NewLine), Generate ());
}
[Test]
public void ReferenceAndSimpleNamespaceTest()
{
CodeNamespace ns = new CodeNamespace ("A");
codeUnit.Namespaces.Add (ns);
codeUnit.ReferencedAssemblies.Add ("using System;");
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"{0}Namespace A{0}End Namespace{0}", NewLine), Generate ());
}
[Test]
public void SimpleAttributeTest ()
{
CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
attrDec.Name = "A";
codeUnit.AssemblyCustomAttributes.Add (attrDec);
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"<Assembly: A()> {0}", NewLine), Generate ());
}
[Test]
public void AttributeWithValueTest ()
{
CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
attrDec.Name = "A";
attrDec.Arguments.Add (new CodeAttributeArgument("A1",
new CodePrimitiveExpression(false)));
attrDec.Arguments.Add (new CodeAttributeArgument("A2",
new CodePrimitiveExpression(true)));
// null name should not be output
attrDec.Arguments.Add (new CodeAttributeArgument (null,
new CodePrimitiveExpression (true)));
// zero length name should not be output
attrDec.Arguments.Add (new CodeAttributeArgument (string.Empty,
new CodePrimitiveExpression (false)));
codeUnit.AssemblyCustomAttributes.Add (attrDec);
Assert.AreEqual ("<Assembly: A(A1:=false, A2:=true, true, false)> " +
NewLine, Generate ());
}
[Test]
public void MultipleAttributeTest ()
{
CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
attrDec.Name = "A";
codeUnit.AssemblyCustomAttributes.Add (attrDec);
attrDec = new CodeAttributeDeclaration ();
attrDec.Name = "B";
codeUnit.AssemblyCustomAttributes.Add (attrDec);
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"<Assembly: A(), _{0} Assembly: B()> {0}", NewLine),
Generate ());
}
[Test]
public void AttributeAndSimpleNamespaceTest ()
{
CodeNamespace ns = new CodeNamespace ("A");
codeUnit.Namespaces.Add (ns);
CodeAttributeDeclaration attrDec = new CodeAttributeDeclaration ();
attrDec.Name = "A";
codeUnit.AssemblyCustomAttributes.Add (attrDec);
attrDec = new CodeAttributeDeclaration ();
attrDec.Name = "B";
codeUnit.AssemblyCustomAttributes.Add (attrDec);
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"<Assembly: A(), _{0} Assembly: B()> {0}{0}Namespace A{0}End "
+ "Namespace{0}", NewLine), Generate ());
}
[Test]
public void CodeSnippetTest ()
{
StringBuilder sb = new StringBuilder();
sb.Append ("Public Class Test1");
sb.Append (Environment.NewLine);
sb.Append ("End Class");
StringWriter writer = new StringWriter ();
writer.NewLine = NewLine;
codeUnit = new CodeSnippetCompileUnit (sb.ToString ());
generator.GenerateCodeFromCompileUnit (codeUnit, writer, options);
writer.Close ();
Assert.AreEqual (sb.ToString () + NewLine, writer.ToString());
}
[Test]
public void ExternalSourceTest ()
{
CodeSnippetCompileUnit snippet;
StringBuilder sb = new StringBuilder();
sb.Append ("\n");
sb.Append ("#ExternalSource(\"file.vb\",123)");
sb.Append ("\n");
sb.Append ("\n");
sb.Append ("\n");
sb.Append ("#End ExternalSource");
sb.Append ("\n");
StringWriter writer = new StringWriter ();
writer.NewLine = NewLine;
codeUnit = new CodeSnippetCompileUnit ("");
snippet = (CodeSnippetCompileUnit) codeUnit;
snippet.LinePragma = new CodeLinePragma ("file.vb", 123);
generator.GenerateCodeFromCompileUnit (codeUnit, writer, options);
writer.Close ();
Assert.AreEqual (sb.ToString (), writer.ToString());
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,483 @@
//
// Microsoft.VisualBasic.* Test Cases
//
// Authors:
// Gert Driesen (drieseng@users.sourceforge.net)
//
// (c) 2006 Novell
//
using System;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Globalization;
using System.IO;
using System.Text;
using NUnit.Framework;
namespace MonoTests.Microsoft.VisualBasic
{
/// <summary>
/// Test ICodeGenerator's GenerateCodeFromNamespace, along with a
/// minimal set CodeDom components.
/// </summary>
[TestFixture]
public class CodeGeneratorFromNamespaceTest : CodeGeneratorTestBase
{
CodeNamespace codeNamespace = null;
[SetUp]
public void Init ()
{
InitBase ();
codeNamespace = new CodeNamespace ();
}
protected override string Generate (CodeGeneratorOptions options)
{
StringWriter writer = new StringWriter ();
writer.NewLine = NewLine;
generator.GenerateCodeFromNamespace (codeNamespace, writer, options);
writer.Close ();
return writer.ToString ();
}
[Test]
[ExpectedException (typeof (NullReferenceException))]
public void NullNamespaceTest ()
{
codeNamespace = null;
Generate ();
}
[Test]
public void NullNamespaceNameTest ()
{
codeNamespace.Name = null;
Assert.AreEqual ("\n", Generate ());
}
[Test]
public void DefaultNamespaceTest ()
{
Assert.AreEqual ("\n", Generate ());
}
[Test]
public void SimpleNamespaceTest ()
{
codeNamespace.Name = "A";
Assert.AreEqual ("\nNamespace A\nEnd Namespace\n", Generate ());
}
[Test]
public void InvalidNamespaceTest ()
{
codeNamespace.Name = "A,B";
Assert.AreEqual ("\nNamespace A,B\nEnd Namespace\n", Generate ());
}
[Test]
public void CommentOnlyNamespaceTest ()
{
CodeCommentStatement comment = new CodeCommentStatement ("a");
codeNamespace.Comments.Add (comment);
Assert.AreEqual ("\n'a\n", Generate ());
}
[Test]
public void ImportsTest ()
{
codeNamespace.Imports.Add (new CodeNamespaceImport ("System"));
codeNamespace.Imports.Add (new CodeNamespaceImport ("System.Collections"));
Assert.AreEqual (string.Format(CultureInfo.InvariantCulture,
"Imports System{0}" +
"Imports System.Collections{0}" +
"{0}", NewLine), Generate (), "#1");
codeNamespace.Name = "A";
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"Imports System{0}" +
"Imports System.Collections{0}" +
"{0}" +
"Namespace A{0}" +
"End Namespace{0}", NewLine), Generate (), "#2");
codeNamespace.Name = null;
codeNamespace.Comments.Add (new CodeCommentStatement ("a"));
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"Imports System{0}" +
"Imports System.Collections{0}" +
"{0}" +
"'a{0}", NewLine), Generate (), "#3");
codeNamespace.Name = "A";
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"Imports System{0}" +
"Imports System.Collections{0}" +
"{0}" +
"'a{0}" +
"Namespace A{0}" +
"End Namespace{0}", NewLine), Generate (), "#4");
}
[Test]
public void TypeTest ()
{
codeNamespace.Types.Add (new CodeTypeDeclaration ("Person"));
Assert.AreEqual (string.Format(CultureInfo.InvariantCulture,
"{0}" +
"{0}" +
"Public Class Person{0}" +
"End Class{0}", NewLine), Generate (), "#A1");
CodeGeneratorOptions options = new CodeGeneratorOptions ();
options.BlankLinesBetweenMembers = false;
Assert.AreEqual (string.Format(CultureInfo.InvariantCulture,
"{0}" +
"Public Class Person{0}" +
"End Class{0}", NewLine), Generate (options), "#A2");
codeNamespace.Name = "A";
Assert.AreEqual (string.Format(CultureInfo.InvariantCulture,
"{0}" +
"Namespace A{0}" +
" {0}" +
" Public Class Person{0}" +
" End Class{0}" +
"End Namespace{0}", NewLine), Generate (), "#B1");
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"{0}" +
"Namespace A{0}" +
" Public Class Person{0}" +
" End Class{0}" +
"End Namespace{0}", NewLine), Generate (options), "#B2");
}
#if NET_2_0
[Test]
public void Type_TypeParameters ()
{
codeNamespace.Name = "SomeNS";
CodeTypeDeclaration type = new CodeTypeDeclaration ("SomeClass");
codeNamespace.Types.Add (type);
type.TypeParameters.Add (new CodeTypeParameter ("T"));
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"{0}" +
"Namespace SomeNS{0}" +
" {0}" +
" Public Class SomeClass(Of T){0}" +
" End Class{0}" +
"End Namespace{0}", NewLine), Generate (), "#1");
type.TypeParameters.Add (new CodeTypeParameter ("As"));
type.TypeParameters.Add (new CodeTypeParameter ("New"));
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"{0}" +
"Namespace SomeNS{0}" +
" {0}" +
" Public Class SomeClass(Of T, As, New){0}" +
" End Class{0}" +
"End Namespace{0}", NewLine), Generate (), "#2");
CodeTypeParameter typeParamR = new CodeTypeParameter ("R");
typeParamR.Constraints.Add (new CodeTypeReference (typeof (IComparable)));
type.TypeParameters.Add (typeParamR);
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"{0}" +
"Namespace SomeNS{0}" +
" {0}" +
" Public Class SomeClass(Of T, As, New, R As System.IComparable){0}" +
" End Class{0}" +
"End Namespace{0}", NewLine), Generate (), "#3");
type.TypeParameters.Add (new CodeTypeParameter ("S"));
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"{0}" +
"Namespace SomeNS{0}" +
" {0}" +
" Public Class SomeClass(Of T, As, New, R As System.IComparable, S){0}" +
" End Class{0}" +
"End Namespace{0}", NewLine), Generate (), "#4");
}
[Test]
public void Type_TypeParameters_Constraints ()
{
codeNamespace.Name = "SomeNS";
CodeTypeDeclaration type = new CodeTypeDeclaration ("SomeClass");
codeNamespace.Types.Add (type);
CodeTypeParameter typeParamT = new CodeTypeParameter ("T");
typeParamT.Constraints.Add (new CodeTypeReference (typeof (IComparable)));
type.TypeParameters.Add (typeParamT);
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"{0}" +
"Namespace SomeNS{0}" +
" {0}" +
" Public Class SomeClass(Of T As System.IComparable){0}" +
" End Class{0}" +
"End Namespace{0}", NewLine), Generate (), "#1");
typeParamT.Constraints.Add (new CodeTypeReference (typeof (ICloneable)));
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"{0}" +
"Namespace SomeNS{0}" +
" {0}" +
" Public Class SomeClass(Of T As {{System.IComparable, System.ICloneable}}){0}" +
" End Class{0}" +
"End Namespace{0}", NewLine), Generate (), "#2");
typeParamT.HasConstructorConstraint = true;
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"{0}" +
"Namespace SomeNS{0}" +
" {0}" +
" Public Class SomeClass(Of T As {{System.IComparable, System.ICloneable, New}}){0}" +
" End Class{0}" +
"End Namespace{0}", NewLine), Generate (), "#3");
CodeTypeParameter typeParamS = new CodeTypeParameter ("S");
typeParamS.Constraints.Add (new CodeTypeReference (typeof (IDisposable)));
type.TypeParameters.Add (typeParamS);
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"{0}" +
"Namespace SomeNS{0}" +
" {0}" +
" Public Class SomeClass(Of T As {{System.IComparable, System.ICloneable, New}}, S As System.IDisposable){0}" +
" End Class{0}" +
"End Namespace{0}", NewLine), Generate (), "#4");
CodeTypeParameter typeParamR = new CodeTypeParameter ("R");
typeParamR.HasConstructorConstraint = true;
type.TypeParameters.Add (typeParamR);
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"{0}" +
"Namespace SomeNS{0}" +
" {0}" +
" Public Class SomeClass(Of T As {{System.IComparable, System.ICloneable, New}}, S As System.IDisposable, R As New){0}" +
" End Class{0}" +
"End Namespace{0}", NewLine), Generate (), "#5");
}
[Test]
public void Type_TypeParameters_ConstructorConstraint ()
{
codeNamespace.Name = "SomeNS";
CodeTypeDeclaration type = new CodeTypeDeclaration ("SomeClass");
codeNamespace.Types.Add (type);
CodeTypeParameter typeParam = new CodeTypeParameter ("T");
typeParam.HasConstructorConstraint = true;
type.TypeParameters.Add (typeParam);
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"{0}" +
"Namespace SomeNS{0}" +
" {0}" +
" Public Class SomeClass(Of T As New){0}" +
" End Class{0}" +
"End Namespace{0}", NewLine), Generate ());
}
[Test]
public void Method_TypeParameters ()
{
codeNamespace.Name = "SomeNS";
CodeTypeDeclaration type = new CodeTypeDeclaration ("SomeClass");
codeNamespace.Types.Add (type);
CodeMemberMethod method = new CodeMemberMethod ();
method.Name = "SomeMethod";
type.Members.Add (method);
method.TypeParameters.Add (new CodeTypeParameter ("T"));
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"{0}" +
"Namespace SomeNS{0}" +
" {0}" +
" Public Class SomeClass{0}" +
" {0}" +
" Private Sub SomeMethod(Of T)(){0}" +
" End Sub{0}" +
" End Class{0}" +
"End Namespace{0}", NewLine), Generate (), "#1");
method.TypeParameters.Add (new CodeTypeParameter ("As"));
method.TypeParameters.Add (new CodeTypeParameter ("New"));
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"{0}" +
"Namespace SomeNS{0}" +
" {0}" +
" Public Class SomeClass{0}" +
" {0}" +
" Private Sub SomeMethod(Of T, As, New)(){0}" +
" End Sub{0}" +
" End Class{0}" +
"End Namespace{0}", NewLine), Generate (), "#2");
CodeTypeParameter typeParamR = new CodeTypeParameter ("R");
typeParamR.Constraints.Add (new CodeTypeReference (typeof (IComparable)));
method.TypeParameters.Add (typeParamR);
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"{0}" +
"Namespace SomeNS{0}" +
" {0}" +
" Public Class SomeClass{0}" +
" {0}" +
" Private Sub SomeMethod(Of T, As, New, R As System.IComparable)(){0}" +
" End Sub{0}" +
" End Class{0}" +
"End Namespace{0}", NewLine), Generate (), "#3");
method.TypeParameters.Add (new CodeTypeParameter ("S"));
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"{0}" +
"Namespace SomeNS{0}" +
" {0}" +
" Public Class SomeClass{0}" +
" {0}" +
" Private Sub SomeMethod(Of T, As, New, R As System.IComparable, S)(){0}" +
" End Sub{0}" +
" End Class{0}" +
"End Namespace{0}", NewLine), Generate (), "#4");
}
[Test]
public void Method_TypeParameters_Constraints ()
{
codeNamespace.Name = "SomeNS";
CodeTypeDeclaration type = new CodeTypeDeclaration ("SomeClass");
codeNamespace.Types.Add (type);
CodeMemberMethod method = new CodeMemberMethod ();
method.Name = "SomeMethod";
type.Members.Add (method);
CodeTypeParameter typeParamT = new CodeTypeParameter ("T");
typeParamT.Constraints.Add (new CodeTypeReference (typeof (IComparable)));
method.TypeParameters.Add (typeParamT);
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"{0}" +
"Namespace SomeNS{0}" +
" {0}" +
" Public Class SomeClass{0}" +
" {0}" +
" Private Sub SomeMethod(Of T As System.IComparable)(){0}" +
" End Sub{0}" +
" End Class{0}" +
"End Namespace{0}", NewLine), Generate (), "#1");
typeParamT.Constraints.Add (new CodeTypeReference (typeof (ICloneable)));
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"{0}" +
"Namespace SomeNS{0}" +
" {0}" +
" Public Class SomeClass{0}" +
" {0}" +
" Private Sub SomeMethod(Of T As {{System.IComparable, System.ICloneable}})(){0}" +
" End Sub{0}" +
" End Class{0}" +
"End Namespace{0}", NewLine), Generate (), "#2");
typeParamT.HasConstructorConstraint = true;
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"{0}" +
"Namespace SomeNS{0}" +
" {0}" +
" Public Class SomeClass{0}" +
" {0}" +
" Private Sub SomeMethod(Of T As {{System.IComparable, System.ICloneable, New}})(){0}" +
" End Sub{0}" +
" End Class{0}" +
"End Namespace{0}", NewLine), Generate (), "#3");
CodeTypeParameter typeParamS = new CodeTypeParameter ("S");
typeParamS.Constraints.Add (new CodeTypeReference (typeof (IDisposable)));
method.TypeParameters.Add (typeParamS);
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"{0}" +
"Namespace SomeNS{0}" +
" {0}" +
" Public Class SomeClass{0}" +
" {0}" +
" Private Sub SomeMethod(Of T As {{System.IComparable, System.ICloneable, New}}, S As System.IDisposable)(){0}" +
" End Sub{0}" +
" End Class{0}" +
"End Namespace{0}", NewLine), Generate (), "#4");
CodeTypeParameter typeParamR = new CodeTypeParameter ("R");
typeParamR.HasConstructorConstraint = true;
method.TypeParameters.Add (typeParamR);
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"{0}" +
"Namespace SomeNS{0}" +
" {0}" +
" Public Class SomeClass{0}" +
" {0}" +
" Private Sub SomeMethod(Of T As {{System.IComparable, System.ICloneable, New}}, S As System.IDisposable, R As New)(){0}" +
" End Sub{0}" +
" End Class{0}" +
"End Namespace{0}", NewLine), Generate (), "#5");
}
[Test]
public void Method_TypeParameters_ConstructorConstraint ()
{
codeNamespace.Name = "SomeNS";
CodeTypeDeclaration type = new CodeTypeDeclaration ("SomeClass");
codeNamespace.Types.Add (type);
CodeMemberMethod method = new CodeMemberMethod ();
method.Name = "SomeMethod";
type.Members.Add (method);
CodeTypeParameter typeParam = new CodeTypeParameter ("T");
typeParam.HasConstructorConstraint = true;
method.TypeParameters.Add (typeParam);
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"{0}" +
"Namespace SomeNS{0}" +
" {0}" +
" Public Class SomeClass{0}" +
" {0}" +
" Private Sub SomeMethod(Of T As New)(){0}" +
" End Sub{0}" +
" End Class{0}" +
"End Namespace{0}", NewLine), Generate ());
}
#endif
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1 @@
207bb9f47864178e6c88bf4d5a4dd313bed99f8e

View File

@@ -0,0 +1,59 @@
//
// Microsoft.VisualBasic.* Test Cases
//
// Authors:
// Jochen Wezel (jwezel@compumaster.de)
//
// Based on the C# units of
// Erik LeBel (eriklebel@yahoo.ca)
//
// (c) 2003 Jochen Wezel, CompuMaster GmbH
//
using System;
using System.IO;
using System.Text;
using System.CodeDom;
using System.CodeDom.Compiler;
using Microsoft.VisualBasic;
using NUnit.Framework;
namespace MonoTests.Microsoft.VisualBasic
{
///
/// <summary>
/// Base test for a variety of CodeGenerator GenerateCodeXXX methods.
///
/// This testing is a form of hybrid test, it tests the variety of CodeDom
/// classes as well as the VB code generator.
///
/// The implementations bellow provide a template as well as guidlines for
/// implementing further tests.
/// </summary>
///
public abstract class CodeGeneratorTestBase
{
CodeDomProvider provider = null;
protected ICodeGenerator generator = null;
protected CodeGeneratorOptions options = null;
public void InitBase()
{
provider = new VBCodeProvider ();
generator = provider.CreateGenerator ();
options = new CodeGeneratorOptions ();
}
protected string Generate ()
{
return Generate (options);
}
protected virtual string NewLine
{
get { return "\n"; }
}
protected abstract string Generate (CodeGeneratorOptions options);
}
}

View File

@@ -0,0 +1,119 @@
//
// VBCodeProviderCas.cs
// - CAS unit tests for Microsoft.VisualBasic.VBCodeProvider
//
// 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.IO;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using Microsoft.VisualBasic;
namespace MonoCasTests.Microsoft.VisualBasic {
[TestFixture]
[Category ("CAS")]
public class VBCodeProviderCas {
[SetUp]
public virtual void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Deny_Unrestricted ()
{
VBCodeProvider vbprov = new VBCodeProvider ();
Assert.AreEqual ("vb", vbprov.FileExtension, "FileExtension");
Assert.AreEqual (LanguageOptions.CaseInsensitive, vbprov.LanguageOptions, "LanguageOptions");
Assert.IsNotNull (vbprov.CreateCompiler (), "CreateCompiler");
Assert.IsNotNull (vbprov.CreateGenerator (), "CreateGenerator");
try {
Assert.IsNotNull (vbprov.GetConverter (typeof (string)), "GetConverter");
}
catch (NotImplementedException) {
// mono
}
#if NET_2_0
CodeTypeMember ctm = new CodeTypeMember ();
StringWriter sw = new StringWriter ();
CodeGeneratorOptions cgo = new CodeGeneratorOptions ();
try {
vbprov.GenerateCodeFromMember (ctm, sw, cgo);
}
catch (NotImplementedException) {
// mono
}
#endif
}
// LinkDemand
// we use reflection to call this class as it is protected by a LinkDemand
// (which will be converted into full demand, i.e. a stack walk) when
// reflection is used (i.e. it gets testable).
public virtual object Create ()
{
ConstructorInfo ci = typeof (VBCodeProvider).GetConstructor (new Type[0]);
Assert.IsNotNull (ci, "default .ctor");
return ci.Invoke (null);
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (SecurityException))]
public void LinkDemand_Deny_Unrestricted ()
{
Assert.IsNotNull (Create ());
}
[Test]
[EnvironmentPermission (SecurityAction.Deny, Read = "MONO")]
[ExpectedException (typeof (SecurityException))]
public void LinkDemand_Deny_Anything ()
{
// denying any permissions -> not full trust!
Assert.IsNotNull (Create ());
}
[Test]
[PermissionSet (SecurityAction.PermitOnly, Unrestricted = true)]
public void LinkDemand_PermitOnly_Unrestricted ()
{
Assert.IsNotNull (Create ());
}
}
}

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