| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589 |
- //
- // CodeGeneratorCas.cs
- // - CAS unit tests for System.CodeDom.Compiler.CodeGenerator
- //
- // Author:
- // Sebastien Pouliot <[email protected]>
- //
- // 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;
- namespace MonoCasTests.System.CodeDom.Compiler {
- class CodeGeneratorTest: CodeGenerator {
- public CodeGeneratorTest ()
- {
- }
- protected override string CreateEscapedIdentifier (string value)
- {
- return String.Empty;
- }
- protected override string CreateValidIdentifier (string value)
- {
- 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 e)
- {
- }
- protected override void GenerateAttachEventStatement (CodeAttachEventStatement e)
- {
- }
- protected override void GenerateAttributeDeclarationsEnd (CodeAttributeDeclarationCollection attributes)
- {
- }
- protected override void GenerateAttributeDeclarationsStart (CodeAttributeDeclarationCollection attributes)
- {
- }
- protected override void GenerateBaseReferenceExpression (CodeBaseReferenceExpression e)
- {
- }
- protected override void GenerateCastExpression (CodeCastExpression e)
- {
- }
- protected override void GenerateComment (CodeComment e)
- {
- }
- protected override void GenerateConditionStatement (CodeConditionStatement e)
- {
- }
- protected override void GenerateConstructor (CodeConstructor e, CodeTypeDeclaration c)
- {
- }
- protected override void GenerateDelegateCreateExpression (CodeDelegateCreateExpression e)
- {
- }
- protected override void GenerateDelegateInvokeExpression (CodeDelegateInvokeExpression e)
- {
- }
- protected override void GenerateEntryPointMethod (CodeEntryPointMethod e, CodeTypeDeclaration c)
- {
- }
- protected override void GenerateEvent (CodeMemberEvent e, CodeTypeDeclaration c)
- {
- }
- protected override void GenerateEventReferenceExpression (CodeEventReferenceExpression e)
- {
- }
- protected override void GenerateExpressionStatement (CodeExpressionStatement e)
- {
- }
- protected override void GenerateField (CodeMemberField e)
- {
- }
- protected override void GenerateFieldReferenceExpression (CodeFieldReferenceExpression e)
- {
- }
- protected override void GenerateGotoStatement (CodeGotoStatement e)
- {
- }
- protected override void GenerateIndexerExpression (CodeIndexerExpression e)
- {
- }
- protected override void GenerateIterationStatement (CodeIterationStatement e)
- {
- }
- protected override void GenerateLabeledStatement (CodeLabeledStatement e)
- {
- }
- protected override void GenerateLinePragmaEnd (CodeLinePragma e)
- {
- }
- protected override void GenerateLinePragmaStart (CodeLinePragma e)
- {
- }
- protected override void GenerateMethod (CodeMemberMethod e, CodeTypeDeclaration c)
- {
- }
- protected override void GenerateMethodInvokeExpression (CodeMethodInvokeExpression e)
- {
- }
- protected override void GenerateMethodReferenceExpression (CodeMethodReferenceExpression e)
- {
- }
- protected override void GenerateMethodReturnStatement (CodeMethodReturnStatement e)
- {
- }
- protected override void GenerateNamespaceEnd (CodeNamespace e)
- {
- }
- protected override void GenerateNamespaceImport (CodeNamespaceImport e)
- {
- }
- protected override void GenerateNamespaceStart (CodeNamespace e)
- {
- }
- protected override void GenerateObjectCreateExpression (CodeObjectCreateExpression e)
- {
- }
- protected override void GenerateProperty (CodeMemberProperty e, CodeTypeDeclaration c)
- {
- }
- protected override void GeneratePropertyReferenceExpression (CodePropertyReferenceExpression e)
- {
- }
- protected override void GeneratePropertySetValueReferenceExpression (CodePropertySetValueReferenceExpression e)
- {
- }
- protected override void GenerateRemoveEventStatement (CodeRemoveEventStatement e)
- {
- }
- protected override void GenerateSnippetExpression (CodeSnippetExpression e)
- {
- }
- protected override void GenerateSnippetMember (CodeSnippetTypeMember e)
- {
- }
- protected override void GenerateThisReferenceExpression (CodeThisReferenceExpression e)
- {
- }
- protected override void GenerateThrowExceptionStatement (CodeThrowExceptionStatement e)
- {
- }
- protected override void GenerateTryCatchFinallyStatement (CodeTryCatchFinallyStatement e)
- {
- }
- protected override void GenerateTypeConstructor (CodeTypeConstructor e)
- {
- }
- protected override void GenerateTypeEnd (CodeTypeDeclaration e)
- {
- }
- protected override void GenerateTypeStart (CodeTypeDeclaration e)
- {
- }
- protected override void GenerateVariableDeclarationStatement (CodeVariableDeclarationStatement e)
- {
- }
- protected override void GenerateVariableReferenceExpression (CodeVariableReferenceExpression e)
- {
- }
- protected override string GetTypeOutput (CodeTypeReference value)
- {
- return String.Empty;
- }
- protected override bool IsValidIdentifier (string value)
- {
- return true;
- }
- protected override string NullToken {
- get {
- return String.Empty;
- }
- }
- protected override void OutputType (CodeTypeReference typeRef)
- {
- }
- protected override string QuoteSnippetString (string value)
- {
- return String.Empty;
- }
- protected override bool Supports (GeneratorSupport support)
- {
- return true;
- }
- public void TestProtectedProperties ()
- {
- #if NET_2_0
- Assert.IsNull (CurrentClass, "CurrentClass");
- #endif
- Assert.IsNull (CurrentMember, "CurrentMember");
- Assert.AreEqual ("<% unknown %>", CurrentMemberName, "CurrentMemberName");
- Assert.AreEqual ("<% unknown %>", CurrentTypeName, "CurrentTypeName");
- try {
- Assert.AreEqual (0, Indent, "Indent");
- }
- catch (NullReferenceException) {
- }
- try {
- Indent = Int32.MinValue;
- }
- catch (NullReferenceException) {
- }
- Assert.IsFalse (IsCurrentClass, "IsCurrentClass");
- Assert.IsFalse (IsCurrentDelegate, "IsCurrentDelegate");
- Assert.IsFalse (IsCurrentEnum, "IsCurrentEnum");
- Assert.IsFalse (IsCurrentInterface, "IsCurrentInterface");
- Assert.IsFalse (IsCurrentStruct, "IsCurrentStruct");
- Assert.AreEqual (String.Empty, NullToken, "NullToken");
- Assert.IsNull (Options, "Options");
- Assert.IsNull (Output, "Output");
- }
- public void TestProtectedMethods ()
- {
- try {
- ContinueOnNewLine (String.Empty);
- }
- catch (NullReferenceException) {
- }
- try {
- GenerateBinaryOperatorExpression (null);
- }
- catch (NullReferenceException) {
- }
- try {
- GenerateCommentStatement (null);
- }
- catch (NullReferenceException) {
- }
- try {
- GenerateCommentStatements (null);
- }
- catch (NullReferenceException) {
- }
- try {
- GenerateCompileUnit (null);
- }
- catch (NullReferenceException) {
- }
- try {
- GenerateCompileUnitEnd (null);
- }
- catch (NullReferenceException) {
- }
- try {
- GenerateCompileUnitStart (null);
- }
- catch (NullReferenceException) {
- }
- try {
- GenerateDecimalValue (0);
- }
- catch (NullReferenceException) {
- }
- #if NET_2_0
- try {
- GenerateDefaultValueExpression (null);
- }
- catch (NotImplementedException) {
- // both mono & ms
- }
- #endif
- try {
- GenerateDirectionExpression (null);
- }
- catch (NullReferenceException) {
- }
- #if NET_2_0
- GenerateDirectives (null);
- #endif
- try {
- GenerateDoubleValue (Double.MaxValue);
- }
- catch (NullReferenceException) {
- }
- try {
- GenerateExpression (null);
- }
- catch (ArgumentNullException) {
- }
- try {
- GenerateNamespace (null);
- }
- catch (NullReferenceException) {
- }
- try {
- GenerateNamespaceImports (null);
- }
- catch (NullReferenceException) {
- }
- try {
- GenerateNamespaces (null);
- }
- catch (NullReferenceException) {
- }
- try {
- GenerateParameterDeclarationExpression (null);
- }
- catch (NullReferenceException) {
- }
- try {
- GeneratePrimitiveExpression (null);
- }
- catch (NullReferenceException) {
- }
- try {
- GenerateSingleFloatValue (Single.MinValue);
- }
- catch (NullReferenceException) {
- }
- try {
- GenerateSnippetCompileUnit (null);
- }
- catch (NullReferenceException) {
- }
- try {
- GenerateSnippetStatement (null);
- }
- catch (NullReferenceException) {
- }
- try {
- GenerateStatement (null);
- }
- catch (NullReferenceException) {
- }
- try {
- GenerateStatements (null);
- }
- catch (NullReferenceException) {
- }
- try {
- GenerateTypeOfExpression (null);
- }
- catch (NullReferenceException) {
- }
- try {
- GenerateTypeReferenceExpression (null);
- }
- catch (NullReferenceException) {
- }
- try {
- GenerateTypes (null);
- }
- catch (NullReferenceException) {
- }
- try {
- OutputAttributeArgument (null);
- }
- catch (NullReferenceException) {
- }
- try {
- OutputAttributeDeclarations (null);
- }
- catch (NullReferenceException) {
- }
- try {
- OutputDirection (FieldDirection.In);
- }
- catch (NullReferenceException) {
- }
- try {
- OutputExpressionList (null);
- }
- catch (NullReferenceException) {
- }
- try {
- OutputExpressionList (null, true);
- }
- catch (NullReferenceException) {
- }
- try {
- OutputFieldScopeModifier (MemberAttributes.Abstract);
- }
- catch (NullReferenceException) {
- }
- try {
- OutputIdentifier (null);
- }
- catch (NullReferenceException) {
- }
- try {
- OutputMemberAccessModifier (MemberAttributes.Abstract);
- }
- catch (NullReferenceException) {
- }
- try {
- OutputMemberScopeModifier (MemberAttributes.Abstract);
- }
- catch (NullReferenceException) {
- }
- try {
- OutputOperator (CodeBinaryOperatorType.Add);
- }
- catch (NullReferenceException) {
- }
- try {
- OutputParameters (null);
- }
- catch (NullReferenceException) {
- }
- try {
- OutputTypeAttributes (TypeAttributes.Abstract, false, false);
- }
- catch (NullReferenceException) {
- }
- try {
- OutputTypeNamePair (null, null);
- }
- catch (NullReferenceException) {
- }
- try {
- Supports (GeneratorSupport.ArraysOfArrays);
- }
- catch (NullReferenceException) {
- }
- try {
- ValidateIdentifier (null);
- }
- catch (NullReferenceException) {
- }
- }
- }
- [TestFixture]
- [Category ("CAS")]
- public class CodeGeneratorCas {
- private StringWriter writer;
- [TestFixtureSetUp]
- public void FixtureSetUp ()
- {
- // at full trust
- writer = new StringWriter ();
- }
- [SetUp]
- public void SetUp ()
- {
- if (!SecurityManager.SecurityEnabled)
- Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
- }
- #if NET_2_0
- [Test]
- [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
- public void Public ()
- {
- CodeGeneratorTest cg = new CodeGeneratorTest ();
- try {
- cg.GenerateCodeFromMember (new CodeTypeMember (), writer, null);
- }
- catch (NotImplementedException) {
- // mono
- }
- }
- #endif
- [Test]
- [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
- public void Protected ()
- {
- CodeGeneratorTest cg = new CodeGeneratorTest ();
- // test protected (but not abstract) stuff from within the class itself
- cg.TestProtectedProperties ();
- cg.TestProtectedMethods ();
- }
- [Test]
- [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
- public void StaticMethods ()
- {
- Assert.IsFalse (CodeGenerator.IsValidLanguageIndependentIdentifier ("@"), "IsValidLanguageIndependentIdentifier");
- try {
- CodeGenerator.ValidateIdentifiers (new CodeCompileUnit ());
- }
- catch (NotImplementedException) {
- // mono
- }
- }
- [Test]
- [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
- public void LinkDemand_Deny_Unrestricted ()
- {
- ConstructorInfo ci = typeof (CodeGeneratorTest).GetConstructor (new Type[0]);
- Assert.IsNotNull (ci, "default .ctor()");
- Assert.IsNotNull (ci.Invoke (null), "invoke");
- }
- }
- }
|