New test.
[mono.git] / mcs / class / System / Test / System.CodeDom / CodeTypeReferenceTest.cs
1 //
2 // CodeTypeReferenceTest.cs - NUnit Test Cases for System.CodeDom.CodeTypeReference
3 //
4 // Authors:
5 //   Gert Driesen (drieseng@users.sourceforge.net)
6 //
7 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
8 //
9
10 using System;
11 using System.CodeDom;
12 #if NET_2_0
13 using System.Collections.Generic;
14 #endif
15
16 using NUnit.Framework;
17
18 namespace MonoTests.System.CodeDom
19 {
20         [TestFixture]
21         public class CodeTypeReferenceTest
22         {
23                 [Test]
24                 public void EmptyTypeName ()
25                 {
26                         CodeTypeReference reference = new CodeTypeReference (string.Empty);
27                         Assert.AreEqual (typeof (void).FullName, reference.BaseType);
28                         Assert.AreEqual (0, reference.ArrayRank);
29                         Assert.IsNull (reference.ArrayElementType);
30 #if NET_2_0
31                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, reference.Options, "#4");
32                         Assert.IsNotNull (reference.TypeArguments, "#5");
33                         Assert.AreEqual (0, reference.TypeArguments.Count, "#6");
34 #endif
35                 }
36
37                 [Test]
38                 public void NullTypeName ()
39                 {
40                         CodeTypeReference reference = new CodeTypeReference ((string) null);
41                         Assert.AreEqual (typeof (void).FullName, reference.BaseType, "#1");
42                         Assert.AreEqual (0, reference.ArrayRank, "#2");
43                         Assert.IsNull (reference.ArrayElementType, "#3");
44 #if NET_2_0
45                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, reference.Options, "#4");
46                         Assert.IsNotNull (reference.TypeArguments, "#5");
47                         Assert.AreEqual (0, reference.TypeArguments.Count, "#6");
48 #endif
49                 }
50
51                 [Test]
52 #if NET_2_0
53                 [ExpectedException (typeof(ArgumentNullException))]
54 #else
55                 [ExpectedException (typeof (NullReferenceException))]
56 #endif
57                 public void NullType ()
58                 {
59                         new CodeTypeReference ((Type) null);
60                 }
61
62                 [Test]
63                 public void NullBaseType ()
64                 {
65                         CodeTypeReference reference = new CodeTypeReference ((string) null);
66                         Assert.AreEqual (typeof (void).FullName, reference.BaseType);
67                 }
68
69                 [Test]
70                 public void ZeroLengthBaseType ()
71                 {
72                         CodeTypeReference reference = new CodeTypeReference (string.Empty);
73                         Assert.AreEqual (typeof (void).FullName, reference.BaseType, "#1");
74                 }
75
76                 [Test]
77                 public void BaseTypeTest1 ()
78                 {
79                         CodeTypeReference reference = new CodeTypeReference ("A[B]");
80 #if NET_2_0
81                         Assert.AreEqual ("A", reference.BaseType, "#1");
82                         Assert.AreEqual (0, reference.ArrayRank, "#2");
83                         Assert.IsNull (reference.ArrayElementType, "#3");
84                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, reference.Options, "#4");
85                         Assert.IsNotNull (reference.TypeArguments, "#5");
86                         Assert.AreEqual (1, reference.TypeArguments.Count, "#6");
87
88                         CodeTypeReference typeArgument = reference.TypeArguments[0];
89                         Assert.AreEqual ("B", typeArgument.BaseType, "#7");
90                         Assert.AreEqual (0, typeArgument.ArrayRank, "#8");
91                         Assert.IsNull (typeArgument.ArrayElementType, "#9");
92                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#10");
93                         Assert.IsNotNull (typeArgument.TypeArguments, "#11");
94                         Assert.AreEqual (0, typeArgument.TypeArguments.Count, "#12");
95 #else
96                         Assert.AreEqual ("A[B]", reference.BaseType, "#1");
97                         Assert.AreEqual (0, reference.ArrayRank, "#2");
98                         Assert.IsNull (reference.ArrayElementType, "#3");
99 #endif
100                 }
101
102                 [Test]
103                 public void BaseTypeTest2 ()
104                 {
105                         CodeTypeReference reference = new CodeTypeReference ("A[]");
106                         Assert.AreEqual ("A", reference.BaseType, "#1");
107                         Assert.AreEqual (1, reference.ArrayRank, "#2");
108                         Assert.IsNotNull (reference.ArrayElementType, "#3");
109 #if NET_2_0
110                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, reference.Options, "#4");
111                         Assert.IsNotNull (reference.TypeArguments, "#5");
112                         Assert.AreEqual (0, reference.TypeArguments.Count, "#6");
113 #endif
114
115                         CodeTypeReference arrayElementType = reference.ArrayElementType;
116                         Assert.AreEqual ("A", arrayElementType.BaseType, "#7");
117                         Assert.AreEqual (0, arrayElementType.ArrayRank, "#8");
118                         Assert.IsNull (arrayElementType.ArrayElementType, "#9");
119 #if NET_2_0
120                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, arrayElementType.Options, "#10");
121                         Assert.IsNotNull (arrayElementType.TypeArguments, "#11");
122                         Assert.AreEqual (0, arrayElementType.TypeArguments.Count, "#12");
123 #endif
124                 }
125
126                 [Test]
127                 public void BaseTypeTest3 ()
128                 {
129                         CodeTypeReference reference = new CodeTypeReference ("A[,]");
130                         Assert.AreEqual ("A", reference.BaseType, "#1");
131                         Assert.AreEqual (2, reference.ArrayRank, "#2");
132                         Assert.IsNotNull (reference.ArrayElementType, "#3");
133 #if NET_2_0
134                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, reference.Options, "#4");
135                         Assert.IsNotNull (reference.TypeArguments, "#5");
136                         Assert.AreEqual (0, reference.TypeArguments.Count, "#6");
137 #endif
138
139                         CodeTypeReference arrayElementType = reference.ArrayElementType;
140                         Assert.AreEqual ("A", arrayElementType.BaseType, "#7");
141                         Assert.AreEqual (0, arrayElementType.ArrayRank, "#8");
142                         Assert.IsNull (arrayElementType.ArrayElementType, "#9");
143 #if NET_2_0
144                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, arrayElementType.Options, "#10");
145                         Assert.IsNotNull (arrayElementType.TypeArguments, "#11");
146                         Assert.AreEqual (0, arrayElementType.TypeArguments.Count, "#12");
147 #endif
148                 }
149
150                 [Test]
151                 public void BaseTypeTest4 ()
152                 {
153                         CodeTypeReference reference = new CodeTypeReference ("A[,,]");
154                         Assert.AreEqual ("A", reference.BaseType, "#1");
155                         Assert.AreEqual (3, reference.ArrayRank, "#2");
156                         Assert.IsNotNull (reference.ArrayElementType, "#3");
157 #if NET_2_0
158                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, reference.Options, "#4");
159                         Assert.IsNotNull (reference.TypeArguments, "#5");
160                         Assert.AreEqual (0, reference.TypeArguments.Count, "#6");
161 #endif
162
163                         CodeTypeReference arrayElementType = reference.ArrayElementType;
164                         Assert.AreEqual ("A", arrayElementType.BaseType, "#7");
165                         Assert.AreEqual (0, arrayElementType.ArrayRank, "#8");
166                         Assert.IsNull (arrayElementType.ArrayElementType, "#9");
167 #if NET_2_0
168                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, arrayElementType.Options, "#10");
169                         Assert.IsNotNull (arrayElementType.TypeArguments, "#11");
170                         Assert.AreEqual (0, arrayElementType.TypeArguments.Count, "#12");
171 #endif
172                 }
173
174                 [Test]
175                 public void BaseTypeTest5 ()
176                 {
177                         CodeTypeReference reference = new CodeTypeReference ("A[B,C]");
178 #if NET_2_0
179                         Assert.AreEqual ("A", reference.BaseType, "#1");
180                         Assert.AreEqual (0, reference.ArrayRank, "#2");
181                         Assert.IsNull (reference.ArrayElementType, "#3");
182                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, reference.Options, "#4");
183                         Assert.IsNotNull (reference.TypeArguments, "#5");
184                         Assert.AreEqual (2, reference.TypeArguments.Count, "#6");
185
186                         CodeTypeReference typeArgument = reference.TypeArguments[0];
187                         Assert.AreEqual ("B", typeArgument.BaseType, "#7");
188                         Assert.AreEqual (0, typeArgument.ArrayRank, "#8");
189                         Assert.IsNull (typeArgument.ArrayElementType, "#9");
190                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#10");
191                         Assert.IsNotNull (typeArgument.TypeArguments, "#11");
192                         Assert.AreEqual (0, typeArgument.TypeArguments.Count, "#12");
193
194                         typeArgument = reference.TypeArguments[1];
195                         Assert.AreEqual ("C", typeArgument.BaseType, "#13");
196                         Assert.AreEqual (0, typeArgument.ArrayRank, "#14");
197                         Assert.IsNull (typeArgument.ArrayElementType, "#15");
198                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#16");
199                         Assert.IsNotNull (typeArgument.TypeArguments, "#17");
200                         Assert.AreEqual (0, typeArgument.TypeArguments.Count, "#18");
201 #else
202                         Assert.AreEqual ("A[B,C]", reference.BaseType, "#1");
203                         Assert.AreEqual (0, reference.ArrayRank, "#2");
204                         Assert.IsNull (reference.ArrayElementType, "#3");
205 #endif
206                 }
207
208                 [Test]
209                 public void BaseTypeTest6 ()
210                 {
211                         CodeTypeReference reference = new CodeTypeReference ("A[");
212                         Assert.AreEqual ("A[", reference.BaseType, "#1");
213                         Assert.AreEqual (0, reference.ArrayRank, "#2");
214                         Assert.IsNull (reference.ArrayElementType, "#3");
215 #if NET_2_0
216                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, reference.Options, "#4");
217                         Assert.IsNotNull (reference.TypeArguments, "#5");
218                         Assert.AreEqual (0, reference.TypeArguments.Count, "#6");
219 #endif
220                 }
221
222                 [Test]
223                 public void BaseTypeTest7 ()
224                 {
225                         CodeTypeReference reference = new CodeTypeReference ("A[,B,,C]");
226 #if NET_2_0
227                         Assert.AreEqual ("A", reference.BaseType, "#1");
228                         Assert.AreEqual (0, reference.ArrayRank, "#2");
229                         Assert.IsNull (reference.ArrayElementType, "#3");
230                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, reference.Options, "#4");
231                         Assert.IsNotNull (reference.TypeArguments, "#5");
232                         Assert.AreEqual (2, reference.TypeArguments.Count, "#6");
233
234                         CodeTypeReference typeArgument = reference.TypeArguments[0];
235                         Assert.AreEqual ("B", typeArgument.BaseType, "#7");
236                         Assert.AreEqual (0, typeArgument.ArrayRank, "#8");
237                         Assert.IsNull (typeArgument.ArrayElementType, "#9");
238                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#10");
239                         Assert.IsNotNull (typeArgument.TypeArguments, "#11");
240                         Assert.AreEqual (0, typeArgument.TypeArguments.Count, "#12");
241
242                         typeArgument = reference.TypeArguments[1];
243                         Assert.AreEqual ("C", typeArgument.BaseType, "#13");
244                         Assert.AreEqual (0, typeArgument.ArrayRank, "#14");
245                         Assert.IsNull (typeArgument.ArrayElementType, "#15");
246                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#16");
247                         Assert.IsNotNull (typeArgument.TypeArguments, "#17");
248                         Assert.AreEqual (0, typeArgument.TypeArguments.Count, "#18");
249 #else
250                         Assert.AreEqual ("A[,B,,C]", reference.BaseType, "#1");
251                         Assert.AreEqual (0, reference.ArrayRank, "#2");
252                         Assert.IsNull (reference.ArrayElementType, "#3");
253 #endif
254                 }
255
256                 [Test]
257 #if NET_2_0
258                 // CodeTypeReference should parse basetype from right to left in 2.0 
259                 // profile
260                 [Category ("NotWorking")]
261 #endif
262                 public void BaseTypeTest8 ()
263                 {
264                         CodeTypeReference reference = new CodeTypeReference ("A[,,][,]");
265                         Assert.AreEqual ("A", reference.BaseType, "#1");
266 #if NET_2_0
267                         Assert.AreEqual (3, reference.ArrayRank, "#2");
268 #else
269                         Assert.AreEqual (2, reference.ArrayRank, "#2");
270 #endif
271                         Assert.IsNotNull (reference.ArrayElementType, "#3");
272
273 #if NET_2_0
274                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, reference.Options, "#4");
275                         Assert.IsNotNull (reference.TypeArguments, "#5");
276                         Assert.AreEqual (0, reference.TypeArguments.Count, "#6");
277 #endif
278
279                         CodeTypeReference arrayElementType = reference.ArrayElementType;
280                         Assert.AreEqual ("A", arrayElementType.BaseType, "#7");
281 #if NET_2_0
282                         Assert.AreEqual (2, arrayElementType.ArrayRank, "#8");
283 #else
284                         Assert.AreEqual (3, arrayElementType.ArrayRank, "#8");
285 #endif
286                         Assert.IsNotNull (arrayElementType.ArrayElementType, "#9");
287 #if NET_2_0
288                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, arrayElementType.Options, "#10");
289                         Assert.IsNotNull (arrayElementType.TypeArguments, "#11");
290                         Assert.AreEqual (0, arrayElementType.TypeArguments.Count, "#12");
291 #endif
292
293                         arrayElementType = arrayElementType.ArrayElementType;
294                         Assert.AreEqual ("A", arrayElementType.BaseType, "#13");
295                         Assert.AreEqual (0, arrayElementType.ArrayRank, "#14");
296                         Assert.IsNull (arrayElementType.ArrayElementType, "#15");
297 #if NET_2_0
298                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, arrayElementType.Options, "#16");
299                         Assert.IsNotNull (arrayElementType.TypeArguments, "#17");
300                         Assert.AreEqual (0, arrayElementType.TypeArguments.Count, "#18");
301 #endif
302                 }
303
304                 [Test]
305 #if NET_2_0
306                 // CodeTypeReference should parse basetype from right to left in 2.0 
307                 // profile
308                 [Category ("NotWorking")]
309 #endif
310                 public void BaseTypeTest9 ()
311                 {
312                         CodeTypeReference reference = new CodeTypeReference ("A[B,,D][,]");
313 #if NET_2_0
314                         Assert.AreEqual ("A`2", reference.BaseType, "#1");
315                         Assert.AreEqual (2, reference.ArrayRank, "#2");
316 #else
317                         Assert.AreEqual ("A[B,,D]", reference.BaseType, "#1");
318                         Assert.AreEqual (2, reference.ArrayRank, "#2");
319 #endif
320                         Assert.IsNotNull (reference.ArrayElementType, "#3");
321
322 #if NET_2_0
323                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, reference.Options, "#4");
324                         Assert.IsNotNull (reference.TypeArguments, "#5");
325                         Assert.AreEqual (2, reference.TypeArguments.Count, "#6");
326 #endif
327
328                         CodeTypeReference arrayElementType = reference.ArrayElementType;
329 #if NET_2_0
330                         Assert.AreEqual ("A`2", arrayElementType.BaseType, "#7");
331                         Assert.AreEqual (0, arrayElementType.ArrayRank, "#8");
332 #else
333                         Assert.AreEqual ("A[B,,D]", arrayElementType.BaseType, "#7");
334                         Assert.AreEqual (0, arrayElementType.ArrayRank, "#8");
335 #endif
336                         Assert.IsNull (arrayElementType.ArrayElementType, "#9");
337 #if NET_2_0
338                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, arrayElementType.Options, "#10");
339                         Assert.IsNotNull (arrayElementType.TypeArguments, "#11");
340                         Assert.AreEqual (2, arrayElementType.TypeArguments.Count, "#12");
341
342                         CodeTypeReference typeArgument = reference.TypeArguments[0];
343                         Assert.AreEqual ("B", typeArgument.BaseType, "#13");
344                         Assert.AreEqual (0, typeArgument.ArrayRank, "#14");
345                         Assert.IsNull (typeArgument.ArrayElementType, "#15");
346                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#16");
347                         Assert.IsNotNull (typeArgument.TypeArguments, "#17");
348                         Assert.AreEqual (0, typeArgument.TypeArguments.Count, "#18");
349
350                         typeArgument = reference.TypeArguments[1];
351                         Assert.AreEqual ("D", typeArgument.BaseType, "#19");
352                         Assert.AreEqual (0, typeArgument.ArrayRank, "#20");
353                         Assert.IsNull (typeArgument.ArrayElementType, "#21");
354                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#22");
355                         Assert.IsNotNull (typeArgument.TypeArguments, "#23");
356                         Assert.AreEqual (0, typeArgument.TypeArguments.Count, "#24");
357 #endif
358                 }
359
360 #if NET_2_0
361                 [Test]
362                 public void Defaults ()
363                 {
364                         CodeTypeReference reference = new CodeTypeReference ();
365
366                         Assert.IsNull (reference.ArrayElementType, "#1");
367                         Assert.AreEqual (0, reference.ArrayRank, "#2");
368                         Assert.AreEqual (string.Empty, reference.BaseType, "#3");
369                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, reference.Options, "#4");
370                         Assert.IsNotNull (reference.TypeArguments, "#5");
371                         Assert.AreEqual (0, reference.TypeArguments.Count, "#6");
372                 }
373
374                 [Test]
375                 public void CodeTypeParameter1 ()
376                 {
377                         CodeTypeReference reference = new CodeTypeReference(
378                                 new CodeTypeParameter ("A"));
379                         Assert.AreEqual ("A", reference.BaseType, "#1");
380                         Assert.AreEqual (0, reference.ArrayRank, "#2");
381                         Assert.IsNull (reference.ArrayElementType, "#3");
382                         Assert.AreEqual (CodeTypeReferenceOptions.GenericTypeParameter, reference.Options, "#4");
383                         Assert.IsNotNull (reference.TypeArguments, "#5");
384                         Assert.AreEqual (0, reference.TypeArguments.Count, "#6");
385                 }
386         
387                 [Test]
388                 public void CodeTypeParameter2 ()
389                 {
390                         CodeTypeReference reference = new CodeTypeReference (
391                                 new CodeTypeParameter ("A[B]"));
392                         Assert.AreEqual ("A", reference.BaseType, "#1");
393                         Assert.AreEqual (0, reference.ArrayRank, "#2");
394                         Assert.IsNull (reference.ArrayElementType, "#3");
395                         Assert.AreEqual (CodeTypeReferenceOptions.GenericTypeParameter, reference.Options, "#4");
396                         Assert.IsNotNull (reference.TypeArguments, "#5");
397                         Assert.AreEqual (1, reference.TypeArguments.Count, "#6");
398
399                         CodeTypeReference typeArgument = reference.TypeArguments[0];
400                         Assert.AreEqual ("B", typeArgument.BaseType, "#7");
401                         Assert.AreEqual (0, typeArgument.ArrayRank, "#8");
402                         Assert.IsNull (typeArgument.ArrayElementType, "#9");
403                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#10");
404                         Assert.IsNotNull (typeArgument.TypeArguments, "#11");
405                         Assert.AreEqual (0, typeArgument.TypeArguments.Count, "#12");
406                 }
407
408                 [Test]
409                 public void CodeTypeParameter3 ()
410                 {
411                         CodeTypeReference reference = new CodeTypeReference (
412                                 new CodeTypeParameter ("A[B, C]"));
413                         Assert.AreEqual ("A", reference.BaseType, "#1");
414                         Assert.AreEqual (0, reference.ArrayRank, "#2");
415                         Assert.IsNull (reference.ArrayElementType, "#3");
416                         Assert.AreEqual (CodeTypeReferenceOptions.GenericTypeParameter, reference.Options, "#4");
417                         Assert.IsNotNull (reference.TypeArguments, "#5");
418                         Assert.AreEqual (2, reference.TypeArguments.Count, "#6");
419
420                         CodeTypeReference typeArgument = reference.TypeArguments[0];
421                         Assert.AreEqual ("B", typeArgument.BaseType, "#7");
422                         Assert.AreEqual (0, typeArgument.ArrayRank, "#8");
423                         Assert.IsNull (typeArgument.ArrayElementType, "#9");
424                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#10");
425                         Assert.IsNotNull (typeArgument.TypeArguments, "#11");
426                         Assert.AreEqual (0, typeArgument.TypeArguments.Count, "#12");
427
428                         typeArgument = reference.TypeArguments[1];
429                         Assert.AreEqual (" C", typeArgument.BaseType, "#13");
430                         Assert.AreEqual (0, typeArgument.ArrayRank, "#14");
431                         Assert.IsNull (typeArgument.ArrayElementType, "#15");
432                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#16");
433                         Assert.IsNotNull (typeArgument.TypeArguments, "#17");
434                         Assert.AreEqual (0, typeArgument.TypeArguments.Count, "#18");
435                 }
436
437                 [Test]
438                 public void CodeTypeParameter4 ()
439                 {
440                         CodeTypeReference reference = new CodeTypeReference (
441                                 new CodeTypeParameter ("A[]"));
442                         Assert.AreEqual ("A", reference.BaseType, "#1");
443                         Assert.AreEqual (1, reference.ArrayRank, "#2");
444                         Assert.IsNotNull (reference.ArrayElementType, "#3");
445                         Assert.AreEqual (CodeTypeReferenceOptions.GenericTypeParameter, reference.Options, "#4");
446                         Assert.IsNotNull (reference.TypeArguments, "#5");
447                         Assert.AreEqual (0, reference.TypeArguments.Count, "#6");
448
449                         CodeTypeReference arrayElementType = reference.ArrayElementType;
450                         Assert.AreEqual ("A", arrayElementType.BaseType, "#7");
451                         Assert.AreEqual (0, arrayElementType.ArrayRank, "#8");
452                         Assert.IsNull (arrayElementType.ArrayElementType, "#9");
453                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, arrayElementType.Options, "#10");
454                         Assert.IsNotNull (arrayElementType.TypeArguments, "#11");
455                         Assert.AreEqual (0, arrayElementType.TypeArguments.Count, "#12");
456                 }
457
458                 [Test]
459                 public void CodeTypeParameter5 ()
460                 {
461                         CodeTypeReference reference = new CodeTypeReference (
462                                 new CodeTypeParameter ("A[,"));
463                         Assert.AreEqual ("A[,", reference.BaseType, "#1");
464                         Assert.AreEqual (0, reference.ArrayRank, "#2");
465                         Assert.IsNull (reference.ArrayElementType, "#3");
466                         Assert.AreEqual (CodeTypeReferenceOptions.GenericTypeParameter, reference.Options, "#4");
467                         Assert.IsNotNull (reference.TypeArguments, "#5");
468                         Assert.AreEqual (0, reference.TypeArguments.Count, "#6");
469                 }
470
471                 public void GenericTypeTest1 () {
472                         CodeTypeReference reference = new CodeTypeReference (
473                                 typeof (Dictionary<int,string>));
474                         Assert.AreEqual ("System.Collections.Generic.Dictionary`2", reference.BaseType, "#1");
475                         Assert.AreEqual (0, reference.ArrayRank, "#2");
476                         Assert.IsNull (reference.ArrayElementType, "#3");
477                         Assert.AreEqual (CodeTypeReferenceOptions.GenericTypeParameter, reference.Options, "#4");
478                         Assert.IsNotNull (reference.TypeArguments, "#5");
479                         Assert.AreEqual (2, reference.TypeArguments.Count, "#6");
480
481                         CodeTypeReference typeArgument = reference.TypeArguments[0];
482                         Assert.AreEqual ("System.Int32", typeArgument.BaseType, "#7");
483                         Assert.AreEqual (0, typeArgument.ArrayRank, "#8");
484                         Assert.IsNull (typeArgument.ArrayElementType, "#9");
485                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#10");
486                         Assert.IsNotNull (typeArgument.TypeArguments, "#11");
487                         Assert.AreEqual (0, typeArgument.TypeArguments.Count, "#12");
488
489                         typeArgument = reference.TypeArguments[1];
490                         Assert.AreEqual ("System.String", typeArgument.BaseType, "#13");
491                         Assert.AreEqual (0, typeArgument.ArrayRank, "#14");
492                         Assert.IsNull (typeArgument.ArrayElementType, "#15");
493                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#16");
494                         Assert.IsNotNull (typeArgument.TypeArguments, "#17");
495                         Assert.AreEqual (0, typeArgument.TypeArguments.Count, "#18");
496                 }
497
498                 public void GenericTypeTest2 () {
499                         CodeTypeReference reference = new CodeTypeReference (
500                                 typeof (Dictionary<List<int>, string>));
501                         Assert.AreEqual ("System.Collections.Generic.Dictionary`2", reference.BaseType, "#1");
502                         Assert.AreEqual (0, reference.ArrayRank, "#2");
503                         Assert.IsNull (reference.ArrayElementType, "#3");
504                         Assert.AreEqual (CodeTypeReferenceOptions.GenericTypeParameter, reference.Options, "#4");
505                         Assert.IsNotNull (reference.TypeArguments, "#5");
506                         Assert.AreEqual (2, reference.TypeArguments.Count, "#6");
507
508                         CodeTypeReference typeArgument = reference.TypeArguments[0];
509                         Assert.AreEqual ("System.Collections.Generic.List`1", typeArgument.BaseType, "#7");
510                         Assert.AreEqual (0, typeArgument.ArrayRank, "#8");
511                         Assert.IsNull (typeArgument.ArrayElementType, "#9");
512                         Assert.AreEqual (CodeTypeReferenceOptions.GenericTypeParameter, typeArgument.Options, "#10");
513                         Assert.IsNotNull (typeArgument.TypeArguments, "#11");
514                         Assert.AreEqual (1, typeArgument.TypeArguments.Count, "#12");
515
516                         CodeTypeReference nestedTypeArgument = typeArgument.TypeArguments[0];
517                         Assert.AreEqual ("System.Int32", nestedTypeArgument.BaseType, "#13");
518                         Assert.AreEqual (0, nestedTypeArgument.ArrayRank, "#14");
519                         Assert.IsNull (nestedTypeArgument.ArrayElementType, "#15");
520                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#16");
521                         Assert.IsNotNull (nestedTypeArgument.TypeArguments, "#17");
522                         Assert.AreEqual (0, nestedTypeArgument.TypeArguments.Count, "#18");
523
524                         typeArgument = reference.TypeArguments[1];
525                         Assert.AreEqual ("System.String", typeArgument.BaseType, "#19");
526                         Assert.AreEqual (0, typeArgument.ArrayRank, "#20");
527                         Assert.IsNull (typeArgument.ArrayElementType, "#21");
528                         Assert.AreEqual ((CodeTypeReferenceOptions) 0, typeArgument.Options, "#22");
529                         Assert.IsNotNull (typeArgument.TypeArguments, "#23");
530                         Assert.AreEqual (0, typeArgument.TypeArguments.Count, "#24");
531                 }
532 #endif
533
534                 // bug #76535
535                 [Test]
536                 public void BaseType_ArrayElementType ()
537                 {
538                         CodeTypeReference ctr = new CodeTypeReference ("System.Int32");
539                         Assert.IsNull (ctr.ArrayElementType, "#1");
540                         Assert.AreEqual (0, ctr.ArrayRank, "#2");
541                         ctr.ArrayElementType = new CodeTypeReference ("System.String");
542                         Assert.IsNotNull (ctr.ArrayElementType, "#3");
543                         Assert.AreEqual (0, ctr.ArrayRank, "#4");
544                         Assert.AreEqual ("System.Int32", ctr.BaseType, "#4");
545                         ctr.ArrayRank = -1;
546                         Assert.AreEqual (-1, ctr.ArrayRank, "#5");
547                         Assert.AreEqual ("System.Int32", ctr.BaseType, "#6");
548                         ctr.ArrayRank = 1;
549                         Assert.AreEqual (1, ctr.ArrayRank, "#7");
550                         Assert.AreEqual ("System.String", ctr.BaseType, "#8");
551                 }
552
553                 [Test]
554                 public void Null_ArrayElementType ()
555                 {
556                         CodeTypeReference ctr = new CodeTypeReference ((string) null, 0);
557                         Assert.IsNotNull (ctr.ArrayElementType, "#1");
558                         Assert.AreEqual (typeof(void).FullName, ctr.ArrayElementType.BaseType, "#2");
559                         Assert.AreEqual (0, ctr.ArrayRank, "#3");
560                         Assert.AreEqual (string.Empty, ctr.BaseType, "#4");
561                         ctr.ArrayRank = 1;
562                         Assert.AreEqual (1, ctr.ArrayRank, "#5");
563                         Assert.AreEqual (typeof (void).FullName, ctr.BaseType, "#6");
564
565                         ctr = new CodeTypeReference ((string) null, 1);
566                         Assert.IsNotNull (ctr.ArrayElementType, "#7");
567                         Assert.AreEqual (typeof (void).FullName, ctr.ArrayElementType.BaseType, "#8");
568                         Assert.AreEqual (1, ctr.ArrayRank, "#9");
569                         Assert.AreEqual (typeof (void).FullName, ctr.BaseType, "#10");
570
571                         ctr = new CodeTypeReference ((CodeTypeReference) null, 0);
572                         Assert.IsNull (ctr.ArrayElementType, "#11");
573                         Assert.AreEqual (0, ctr.ArrayRank, "#12");
574                         Assert.AreEqual (string.Empty, ctr.BaseType, "#13");
575                         ctr.ArrayRank = 1;
576                         Assert.AreEqual (1, ctr.ArrayRank, "#14");
577                         Assert.AreEqual (string.Empty, ctr.BaseType, "#15");
578
579                         ctr = new CodeTypeReference ((CodeTypeReference) null, 1);
580                         Assert.IsNull (ctr.ArrayElementType, "#16");
581                         Assert.AreEqual (1, ctr.ArrayRank, "#17");
582                         Assert.AreEqual (string.Empty, ctr.BaseType, "#18");
583                 }
584
585                 [Test]
586                 public void Empty_ArrayElementType ()
587                 {
588                         CodeTypeReference ctr = new CodeTypeReference (string.Empty, 0);
589                         Assert.IsNotNull (ctr.ArrayElementType, "#1");
590                         Assert.AreEqual (typeof (void).FullName, ctr.ArrayElementType.BaseType, "#2");
591                         Assert.AreEqual (0, ctr.ArrayRank, "#3");
592                         Assert.AreEqual (string.Empty, ctr.BaseType, "#4");
593                         ctr.ArrayRank = 1;
594                         Assert.AreEqual (1, ctr.ArrayRank, "#5");
595                         Assert.AreEqual (typeof (void).FullName, ctr.BaseType, "#6");
596
597                         ctr = new CodeTypeReference (string.Empty, 1);
598                         Assert.IsNotNull (ctr.ArrayElementType, "#7");
599                         Assert.AreEqual (typeof (void).FullName, ctr.ArrayElementType.BaseType, "#8");
600                         Assert.AreEqual (1, ctr.ArrayRank, "#9");
601                         Assert.AreEqual (typeof (void).FullName, ctr.BaseType, "#10");
602                 }
603         }
604 }