Merge pull request #4212 from BrzVlad/fix-ephemeron-leak
[mono.git] / mcs / class / System.Data / Test / System.Data / TypedDataSetGeneratorTest.cs
1 //
2 // TypedDataSetGeneratorTest.cs
3 //
4 // Author:
5 //      Atsushi Enomoto <atsushi@ximian.com>
6 //
7
8 //
9 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 #if !MOBILE && !MONOMAC
32
33 using System;
34 using System.CodeDom;
35 using System.CodeDom.Compiler;
36 using System.Data;
37 using NUnit.Framework;
38 using Microsoft.CSharp;
39
40 namespace MonoTests.System.Data
41 {
42         [TestFixture]
43         public class TypedDataSetGeneratorTest
44         {
45                 private ICodeGenerator gen;
46                 private ICodeCompiler compiler;
47
48                 public TypedDataSetGeneratorTest ()
49                 {
50                         CodeDomProvider p = new CSharpCodeProvider ();
51                         gen = p.CreateGenerator ();
52                         compiler = p.CreateCompiler ();
53                 }
54
55                 [Test]
56                 [ExpectedException (typeof (NullReferenceException))]
57                 public void TestGenerateIdNameNullName ()
58                 {
59                         TypedDataSetGenerator.GenerateIdName (null, gen);
60                 }
61
62                 [Test]
63                 [ExpectedException (typeof (NullReferenceException))]
64                 public void TestGenerateIdNameNullProvider ()
65                 {
66                         TypedDataSetGenerator.GenerateIdName ("a", null);
67                 }
68
69                 [Test]
70                 public void TestGenerateIdName ()
71                 {
72                 
73                         Assert.AreEqual ("a", TypedDataSetGenerator.GenerateIdName ("a", gen), "#1");
74                         Assert.AreEqual ("_int", TypedDataSetGenerator.GenerateIdName ("int", gen), "#2");
75                         Assert.AreEqual ("_", TypedDataSetGenerator.GenerateIdName ("_", gen), "#3");
76                         Assert.AreEqual ("_", TypedDataSetGenerator.GenerateIdName ("_", gen), "#3-2");
77                         Assert.AreEqual ("_1", TypedDataSetGenerator.GenerateIdName ("1", gen), "#4");
78                         Assert.AreEqual ("_1", TypedDataSetGenerator.GenerateIdName ("1", gen), "#4-2");
79                         Assert.AreEqual ("_1a", TypedDataSetGenerator.GenerateIdName ("1a", gen), "#5");
80                         Assert.AreEqual ("_1_2", TypedDataSetGenerator.GenerateIdName ("1*2", gen), "#6");
81                         Assert.AreEqual ("__", TypedDataSetGenerator.GenerateIdName ("-", gen), "#7");
82                         Assert.AreEqual ("__", TypedDataSetGenerator.GenerateIdName ("+", gen), "#8");
83                         Assert.AreEqual ("_", TypedDataSetGenerator.GenerateIdName ("", gen), "#9");
84                         Assert.AreEqual ("___", TypedDataSetGenerator.GenerateIdName ("--", gen), "#10");
85                         Assert.AreEqual ("___", TypedDataSetGenerator.GenerateIdName ("++", gen), "#11");
86                         Assert.AreEqual ("\u3042", TypedDataSetGenerator.GenerateIdName ("\u3042", gen), "#12");
87                 }
88
89                 [Test]
90                 [Ignore ("We cannot depend on CodeCompiler since it expects mcs to exist.")]
91                 public void RelationConnectsSameTable ()
92                 {
93                         DataSet ds = new DataSet ();
94                         ds.ReadXmlSchema ("Test/System.Data/schemas/bug77248.xsd");
95                         CodeNamespace cns = new CodeNamespace ();
96                         TypedDataSetGenerator.Generate (ds, cns, gen);
97                         CodeCompileUnit ccu = new CodeCompileUnit ();
98                         ccu.Namespaces.Add (cns);
99                         CompilerResults r = compiler.CompileAssemblyFromDom (
100                                 new CompilerParameters (), ccu);
101                         Assert.AreEqual (0, r.Errors.Count);
102                 }
103         }
104 }
105
106 #endif