| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666 |
- //
- // CodeCompilerCas.cs
- // - CAS unit tests for System.CodeDom.Compiler.CodeCompiler
- //
- // 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 CodeCompilerTest : CodeCompiler {
- public CodeCompilerTest ()
- {
- }
- protected override string CmdArgsFromParameters (CompilerParameters options)
- {
- return String.Empty;
- }
- protected override string CompilerName {
- get { return String.Empty; }
- }
- protected override string FileExtension {
- get { return String.Empty; }
- }
- protected override void ProcessCompilerOutputLine (CompilerResults results, string line)
- {
- }
- 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;
- }
- // publicity
- public CompilerResults _FromDom (CompilerParameters options, CodeCompileUnit e)
- {
- return FromDom (options, e);
- }
- public CompilerResults _FromDomBatch (CompilerParameters options, CodeCompileUnit[] ea)
- {
- return FromDomBatch (options, ea);
- }
- public CompilerResults _FromFile (CompilerParameters options, string fileName)
- {
- return FromFile (options, fileName);
- }
- public CompilerResults _FromFileBatch (CompilerParameters options, string[] fileNames)
- {
- return FromFileBatch (options, fileNames);
- }
- public CompilerResults _FromSource (CompilerParameters options, string source)
- {
- return FromSource (options, source);
- }
- public CompilerResults _FromSourceBatch (CompilerParameters options, string[] sources)
- {
- return FromSourceBatch (options, sources);
- }
- public string _GetResponseFileCmdArgs (CompilerParameters options, string cmdArgs)
- {
- return GetResponseFileCmdArgs (options, cmdArgs);
- }
- static public string _JoinStringArray (string[] sa, string separator)
- {
- return CodeCompiler.JoinStringArray (sa, separator);
- }
- }
- [TestFixture]
- [Category ("CAS")]
- public class CodeCompilerCas {
- private string filename;
- [TestFixtureSetUp]
- public void FixtureSetUp ()
- {
- // at full trust
- filename = Path.GetTempFileName ();
- }
- [SetUp]
- public void SetUp ()
- {
- if (!SecurityManager.SecurityEnabled)
- Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
- }
- [Test]
- [SecurityPermission (SecurityAction.PermitOnly, UnmanagedCode = true)]
- [EnvironmentPermission (SecurityAction.PermitOnly, Unrestricted = true)]
- [FileIOPermission (SecurityAction.PermitOnly, Unrestricted = true)]
- [ExpectedException (typeof (InvalidOperationException))]
- public void FromDom_PermitOnly ()
- {
- CodeCompilerTest cc = new CodeCompilerTest ();
- cc._FromDom (new CompilerParameters (), new CodeCompileUnit ());
- }
- [Test]
- [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
- [ExpectedException (typeof (SecurityException))]
- public void FromDom_Deny_UnmanagedCode ()
- {
- CodeCompilerTest cc = new CodeCompilerTest ();
- cc._FromDom (new CompilerParameters (), new CodeCompileUnit ());
- }
- [Test]
- [FileIOPermission (SecurityAction.Deny, Unrestricted = true)]
- [ExpectedException (typeof (SecurityException))]
- public void FromDom_Deny_FileIO ()
- {
- CodeCompilerTest cc = new CodeCompilerTest ();
- cc._FromDom (new CompilerParameters (), new CodeCompileUnit ());
- }
- [Test]
- [EnvironmentPermission (SecurityAction.Deny, Unrestricted = true)]
- [ExpectedException (typeof (SecurityException))]
- #if ONLY_1_1
- [Category ("NotDotNet")] // MS doesn't check for Environment under 1.x
- #endif
- public void FromDom_Deny_Environment ()
- {
- CodeCompilerTest cc = new CodeCompilerTest ();
- cc._FromDom (new CompilerParameters (), new CodeCompileUnit ());
- }
- [Test]
- [SecurityPermission (SecurityAction.PermitOnly, UnmanagedCode = true)]
- [EnvironmentPermission (SecurityAction.PermitOnly, Unrestricted = true)]
- [FileIOPermission (SecurityAction.PermitOnly, Unrestricted = true)]
- [ExpectedException (typeof (InvalidOperationException))]
- public void FromDomBatch_PermitOnly ()
- {
- CodeCompilerTest cc = new CodeCompilerTest ();
- cc._FromDomBatch (new CompilerParameters (), new CodeCompileUnit[] { new CodeCompileUnit () });
- }
- [Test]
- [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
- [ExpectedException (typeof (SecurityException))]
- public void FromDomBatch_Deny_UnmanagedCode ()
- {
- CodeCompilerTest cc = new CodeCompilerTest ();
- cc._FromDomBatch (new CompilerParameters (), new CodeCompileUnit[] { new CodeCompileUnit () });
- }
- [Test]
- [FileIOPermission (SecurityAction.Deny, Unrestricted = true)]
- [ExpectedException (typeof (SecurityException))]
- public void FromDomBatch_Deny_FileIO ()
- {
- CodeCompilerTest cc = new CodeCompilerTest ();
- cc._FromDomBatch (new CompilerParameters (), new CodeCompileUnit[] { new CodeCompileUnit () });
- }
- [Test]
- [EnvironmentPermission (SecurityAction.Deny, Unrestricted = true)]
- [ExpectedException (typeof (SecurityException))]
- #if ONLY_1_1
- [Category ("NotDotNet")] // MS doesn't check for Environment under 1.x
- #endif
- public void FromDomBatch_Deny_Environment ()
- {
- CodeCompilerTest cc = new CodeCompilerTest ();
- cc._FromDomBatch (new CompilerParameters (), new CodeCompileUnit[] { new CodeCompileUnit () });
- }
- [Test]
- [SecurityPermission (SecurityAction.PermitOnly, UnmanagedCode = true)]
- [EnvironmentPermission (SecurityAction.PermitOnly, Unrestricted = true)]
- [FileIOPermission (SecurityAction.PermitOnly, Unrestricted = true)]
- [ExpectedException (typeof (InvalidOperationException))]
- public void FromFile_PermitOnly ()
- {
- CodeCompilerTest cc = new CodeCompilerTest ();
- cc._FromFile (new CompilerParameters (), filename);
- }
- [Test]
- [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
- [ExpectedException (typeof (SecurityException))]
- public void FromFile_Deny_UnmanagedCode ()
- {
- CodeCompilerTest cc = new CodeCompilerTest ();
- cc._FromFile (new CompilerParameters (), String.Empty);
- }
- [Test]
- [FileIOPermission (SecurityAction.Deny, Unrestricted = true)]
- [ExpectedException (typeof (SecurityException))]
- public void FromFile_Deny_FileIO ()
- {
- CodeCompilerTest cc = new CodeCompilerTest ();
- cc._FromFile (new CompilerParameters (), filename);
- }
- [Test]
- [EnvironmentPermission (SecurityAction.Deny, Unrestricted = true)]
- [ExpectedException (typeof (SecurityException))]
- #if ONLY_1_1
- [Category ("NotDotNet")] // MS doesn't check for Environment under 1.x
- #endif
- public void FromFile_Deny_Environment ()
- {
- CodeCompilerTest cc = new CodeCompilerTest ();
- cc._FromFile (new CompilerParameters (), filename);
- }
- [Test]
- [SecurityPermission (SecurityAction.PermitOnly, UnmanagedCode = true)]
- [EnvironmentPermission (SecurityAction.PermitOnly, Unrestricted = true)]
- [FileIOPermission (SecurityAction.PermitOnly, Unrestricted = true)]
- [ExpectedException (typeof (InvalidOperationException))]
- public void FromFileBatch_PermitOnly ()
- {
- CodeCompilerTest cc = new CodeCompilerTest ();
- cc._FromFileBatch (new CompilerParameters (), new string[] { String.Empty });
- }
- [Test]
- [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
- [ExpectedException (typeof (SecurityException))]
- public void FromFileBatch_Deny_UnmanagedCode ()
- {
- CodeCompilerTest cc = new CodeCompilerTest ();
- cc._FromFileBatch (new CompilerParameters (), new string[] { String.Empty });
- }
- [Test]
- [FileIOPermission (SecurityAction.Deny, Unrestricted = true)]
- [ExpectedException (typeof (SecurityException))]
- public void FromFileBatch_Deny_FileIO ()
- {
- CodeCompilerTest cc = new CodeCompilerTest ();
- cc._FromFileBatch (new CompilerParameters (), new string[] { String.Empty });
- }
- [Test]
- [EnvironmentPermission (SecurityAction.Deny, Unrestricted = true)]
- [ExpectedException (typeof (SecurityException))]
- #if ONLY_1_1
- [Category ("NotDotNet")] // MS doesn't check for Environment under 1.x
- #endif
- public void FromFileBatch_Deny_Environment ()
- {
- CodeCompilerTest cc = new CodeCompilerTest ();
- cc._FromFileBatch (new CompilerParameters (), new string[] { String.Empty });
- }
- [Test]
- [SecurityPermission (SecurityAction.PermitOnly, UnmanagedCode = true)]
- [EnvironmentPermission (SecurityAction.PermitOnly, Unrestricted = true)]
- [FileIOPermission (SecurityAction.PermitOnly, Unrestricted = true)]
- [ExpectedException (typeof (InvalidOperationException))]
- public void FromSource_PermitOnly ()
- {
- CodeCompilerTest cc = new CodeCompilerTest ();
- cc._FromSource (new CompilerParameters (), String.Empty);
- }
- [Test]
- [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
- [ExpectedException (typeof (SecurityException))]
- public void FromSource_Deny_UnmanagedCode ()
- {
- CodeCompilerTest cc = new CodeCompilerTest ();
- cc._FromSource (new CompilerParameters (), String.Empty);
- }
- [Test]
- [FileIOPermission (SecurityAction.Deny, Unrestricted = true)]
- [ExpectedException (typeof (SecurityException))]
- public void FromSource_Deny_FileIO ()
- {
- CodeCompilerTest cc = new CodeCompilerTest ();
- cc._FromSource (new CompilerParameters (), String.Empty);
- }
- [Test]
- [EnvironmentPermission (SecurityAction.Deny, Unrestricted = true)]
- [ExpectedException (typeof (SecurityException))]
- #if ONLY_1_1
- [Category ("NotDotNet")] // MS doesn't check for Environment under 1.x
- #endif
- public void FromSource_Deny_Environment ()
- {
- CodeCompilerTest cc = new CodeCompilerTest ();
- cc._FromSource (new CompilerParameters (), String.Empty);
- }
- [Test]
- [SecurityPermission (SecurityAction.PermitOnly, UnmanagedCode = true)]
- [EnvironmentPermission (SecurityAction.PermitOnly, Unrestricted = true)]
- [FileIOPermission (SecurityAction.PermitOnly, Unrestricted = true)]
- [ExpectedException (typeof (InvalidOperationException))]
- public void FromSourceBatch_PermitOnly ()
- {
- CodeCompilerTest cc = new CodeCompilerTest ();
- cc._FromSourceBatch (new CompilerParameters (), new string[] { String.Empty });
- }
- [Test]
- [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
- [ExpectedException (typeof (SecurityException))]
- public void FromSourceBatch_Deny_UnmanagedCode ()
- {
- CodeCompilerTest cc = new CodeCompilerTest ();
- cc._FromSourceBatch (new CompilerParameters (), new string[] { String.Empty });
- }
- [Test]
- [FileIOPermission (SecurityAction.Deny, Unrestricted = true)]
- [ExpectedException (typeof (SecurityException))]
- public void FromSourceBatch_Deny_FileIO ()
- {
- CodeCompilerTest cc = new CodeCompilerTest ();
- cc._FromSourceBatch (new CompilerParameters (), new string[] { String.Empty });
- }
- [Test]
- [EnvironmentPermission (SecurityAction.Deny, Unrestricted = true)]
- [ExpectedException (typeof (SecurityException))]
- #if ONLY_1_1
- [Category ("NotDotNet")] // MS doesn't check for Environment under 1.x
- #endif
- public void FromSourceBatch_Deny_Environment ()
- {
- CodeCompilerTest cc = new CodeCompilerTest ();
- cc._FromSourceBatch (new CompilerParameters (), new string[] { String.Empty });
- }
- [Test]
- [EnvironmentPermission (SecurityAction.PermitOnly, Unrestricted = true)]
- [FileIOPermission (SecurityAction.PermitOnly, Unrestricted = true)]
- public void GetResponseFileCmdArgs_PermitOnly ()
- {
- CodeCompilerTest cc = new CodeCompilerTest ();
- try {
- Assert.IsNotNull (cc._GetResponseFileCmdArgs (new CompilerParameters (), String.Empty));
- }
- catch (NotImplementedException) {
- // mono
- }
- }
- [Test]
- [EnvironmentPermission (SecurityAction.Deny, Unrestricted = true)]
- [ExpectedException (typeof (SecurityException))]
- #if ONLY_1_1
- [Category ("NotDotNet")] // MS doesn't check for Environment under 1.x
- #endif
- public void GetResponseFileCmdArgs_Deny_Environment ()
- {
- CodeCompilerTest cc = new CodeCompilerTest ();
- try {
- cc._GetResponseFileCmdArgs (new CompilerParameters (), String.Empty);
- }
- catch (NotImplementedException) {
- Assert.Ignore ("GetResponseFileCmdArgs not implemented");
- }
- }
- [Test]
- [FileIOPermission (SecurityAction.Deny, Unrestricted = true)]
- [ExpectedException (typeof (SecurityException))]
- public void GetResponseFileCmdArgs_Deny_FileIO ()
- {
- CodeCompilerTest cc = new CodeCompilerTest ();
- try {
- cc._GetResponseFileCmdArgs (new CompilerParameters (), String.Empty);
- }
- catch (NotImplementedException) {
- Assert.Ignore ("GetResponseFileCmdArgs not implemented");
- }
- }
- [Test]
- [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
- public void JoinStringArray ()
- {
- string[] data = new string[] { "a", "b", "c" };
- Assert.AreEqual ("\"a\"#\"b\"#\"c\"", CodeCompilerTest._JoinStringArray (data, "#"), "JoinStringArray");
- }
- [Test]
- [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
- public void LinkDemand_Deny_Unrestricted ()
- {
- ConstructorInfo ci = typeof (CodeCompilerTest).GetConstructor (new Type[0]);
- Assert.IsNotNull (ci, "default .ctor()");
- Assert.IsNotNull (ci.Invoke (null), "invoke");
- }
- }
- }
|