2010-04-06 Jb Evain <jbevain@novell.com>
[mcs.git] / class / corlib / Test / System.Runtime.Versioning / FrameworkNameTest.cs
blobdf2a5b1d36074d49d213e098c8e9dd205ee8e59f
1 //
2 // System.Runtime.Versioning.FrameworkNameTest class
3 //
4 // Authors
5 // Marek Habersack <mhabersack@novell.com>
6 //
7 // Copyright (C) 2009 Novell, Inc (http://novell.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 using System;
29 using System.Runtime.Versioning;
30 using System.Text;
32 using NUnit.Framework;
34 #if NET_4_0
35 namespace MonoTests.System.Runtime.Versioning
37 [TestFixture]
38 public class FrameworkNameTest
40 void Throws<TEx> (string message, Action code)
42 bool failed = false;
43 Exception exception = null;
44 try {
45 code ();
46 failed = true;
47 } catch (Exception ex) {
48 if (ex.GetType () != typeof (TEx)) {
49 failed = true;
50 exception = ex;
54 if (failed) {
55 if (exception != null)
56 Assert.Fail ("{0}{1}Expected exception {2}, got {3}",
57 message, Environment.NewLine, typeof (TEx), exception.GetType ());
58 else
59 Assert.Fail ("{0}{1}Expected exception {2}",
60 message, Environment.NewLine, typeof (TEx));
64 [Test]
65 public void Constructor_String ()
67 FrameworkName fn;
69 Throws <ArgumentNullException> ("#A1", () => {
70 fn = new FrameworkName (null);
71 });
73 Throws<ArgumentException> ("#A1-1", () => {
74 fn = new FrameworkName (String.Empty);
75 });
77 Throws <ArgumentException> ("#A1-2", () => {
78 fn = new FrameworkName (".NETFramework");
79 });
81 Throws <ArgumentException> ("#A1-3", () => {
82 fn = new FrameworkName (".NETFramework,Ver=test");
83 });
85 Throws <ArgumentException> ("#A1-4", () => {
86 fn = new FrameworkName (".NETFramework,Version=A");
87 });
89 Throws <ArgumentException> ("#A1-5", () => {
90 fn = new FrameworkName ("Version=1.2,.NETFramework");
91 });
93 Throws <ArgumentException> ("#A1-6", () => {
94 fn = new FrameworkName (".NETFramework,Version=vA");
95 });
97 Throws <ArgumentException> ("#A1-7", () => {
98 fn = new FrameworkName (".NETFramework,Version=A.B");
99 });
101 Throws <ArgumentException> ("#A1-8", () => {
102 fn = new FrameworkName (".NETFramework,Version=vA.B");
105 Throws <ArgumentException> ("#A1-9", () => {
106 fn = new FrameworkName (".NETFramework,Version=VA.B");
109 Throws <ArgumentException> ("#A1-10", () => {
110 fn = new FrameworkName (".NETFramework,Version=vA.B.C");
113 Throws <ArgumentException> ("#A1-11", () => {
114 fn = new FrameworkName (".NETFramework,Version=vA.B.C.D");
117 Throws <ArgumentException> ("#A1-12", () => {
118 fn = new FrameworkName (".NETFramework,Version=2");
121 Throws <ArgumentException> ("#A1-13", () => {
122 fn = new FrameworkName (".NETFramework,Version=v2");
125 Throws <ArgumentException> ("#A1-14", () => {
126 fn = new FrameworkName (".NETFramework,Version=v2.0.1.A");
129 Throws <ArgumentException> ("#A1-15", () => {
130 fn = new FrameworkName (".NETFramework,Version=v2.0.1.0,Some=value");
133 Throws <ArgumentException> ("#A1-16", () => {
134 fn = new FrameworkName (".NETFramework,Version=v2.0.1.0,Profile=profile name, Extra=value");
137 Throws <ArgumentException> ("#A1-17", () => {
138 fn = new FrameworkName (".NETFramework,Profile=profile name");
141 Throws <ArgumentException> ("#A1-18", () => {
142 fn = new FrameworkName ("Profile=profile name,.NETFramework,Version=v2.0.1.0");
145 Throws <ArgumentException> ("#A1-19", () => {
146 var n = new FrameworkName (".NETFramework, ,Version=v2.0.1.0");
149 Throws <ArgumentException> ("#A1-20", () => {
150 fn = new FrameworkName (".NETFramework,Version=v2..0.1.0");
153 Throws <ArgumentException> ("#A1-21", () => {
154 fn = new FrameworkName (".NETFramework,Version=v.0.1.0");
157 Throws <ArgumentException> ("#A1-22", () => {
158 fn = new FrameworkName (".NETFramework,Version=v1.-2.1.0");
161 Throws <ArgumentException> ("#A1-23", () => {
162 fn = new FrameworkName (".NETFramework,Version=v0.0.0.0.0");
165 Throws <ArgumentException> ("#A1-24", () => {
166 fn = new FrameworkName (".NETFramework,Version=vA.0.0.0,Version=v1.2.3.4");
169 Throws <ArgumentException> ("#A1-25", () => {
170 fn = new FrameworkName (".NETFramework,Version=v0.0.0.0,Version=vA.2.3.4");
173 Throws <ArgumentException> ("#A1-26", () => {
174 fn = new FrameworkName ("Version=1.2,profile=test profile");
177 Throws<ArgumentException> ("#A1-27", () => {
178 fn = new FrameworkName (".NETFramework,Version=");
181 fn = new FrameworkName (".NETFramework=test,Version=3.5");
182 Assert.AreEqual (".NETFramework=test", fn.Identifier, "#A2-1");
183 Assert.IsTrue (fn.Version == new Version (3, 5), "#A2-2");
184 Assert.AreEqual (String.Empty, fn.Profile, "#A2-3");
185 Assert.AreEqual (".NETFramework=test,Version=v3.5", fn.FullName, "#A3-4");
187 fn = new FrameworkName (".NETFramework,Version=2.0");
188 Assert.AreEqual (".NETFramework", fn.Identifier, "#A3-1");
189 Assert.IsTrue (fn.Version == new Version (2, 0), "#A3-2");
190 Assert.AreEqual (String.Empty, fn.Profile, "#A3-3");
191 Assert.AreEqual (".NETFramework,Version=v2.0", fn.FullName, "#A3-4");
193 fn = new FrameworkName (".NETFramework,Version=v2.0");
194 Assert.AreEqual (".NETFramework", fn.Identifier, "#A4-1");
195 Assert.IsTrue (fn.Version == new Version (2, 0), "#A4-2");
196 Assert.AreEqual (String.Empty, fn.Profile, "#A4-3");
197 Assert.AreEqual (".NETFramework,Version=v2.0", fn.FullName, "#A4-4");
199 fn = new FrameworkName (".NETFramework,Version=v0.1");
200 Assert.AreEqual (".NETFramework", fn.Identifier, "#A5-1");
201 Assert.IsTrue (fn.Version == new Version (0, 1), "#A5-2");
202 Assert.AreEqual (String.Empty, fn.Profile, "#A5-3");
203 Assert.AreEqual (".NETFramework,Version=v0.1", fn.FullName, "#A5-4");
205 fn = new FrameworkName (".NETFramework,Version=v10.1");
206 Assert.AreEqual (".NETFramework", fn.Identifier, "#A6-1");
207 Assert.IsTrue (fn.Version == new Version (10, 1), "#A6-2");
208 Assert.AreEqual (String.Empty, fn.Profile, "#A6-3");
209 Assert.AreEqual (".NETFramework,Version=v10.1", fn.FullName, "#A6-4");
211 fn = new FrameworkName (".NETFramework,Version=V2.0");
212 Assert.AreEqual (".NETFramework", fn.Identifier, "#A7-1");
213 Assert.IsTrue (fn.Version == new Version (2, 0), "#A7-2");
214 Assert.AreEqual (String.Empty, fn.Profile, "#A7-3");
215 Assert.AreEqual (".NETFramework,Version=v2.0", fn.FullName, "#A7-4");
217 fn = new FrameworkName (".NETFramework,Version=v2.0.1");
218 Assert.AreEqual (".NETFramework", fn.Identifier, "#A8-1");
219 Assert.IsTrue (fn.Version == new Version (2, 0, 1), "#A8-2");
220 Assert.AreEqual (String.Empty, fn.Profile, "#A8-3");
221 Assert.AreEqual (".NETFramework,Version=v2.0.1", fn.FullName, "#A8-4");
223 fn = new FrameworkName (".NETFramework,Version=v2.0.1.0");
224 Assert.AreEqual (".NETFramework", fn.Identifier, "#A9-1");
225 Assert.IsTrue (fn.Version == new Version (2, 0, 1, 0), "#A9-2");
226 Assert.AreEqual (String.Empty, fn.Profile, "#A9-3");
227 Assert.AreEqual (".NETFramework,Version=v2.0.1.0", fn.FullName, "#A9-4");
229 fn = new FrameworkName (".NETFramework,Version=v2.0.1.0,Profile=profile name");
230 Assert.AreEqual (".NETFramework", fn.Identifier, "#A10-1");
231 Assert.IsTrue (fn.Version == new Version (2, 0, 1, 0), "#A10-2");
232 Assert.AreEqual ("profile name", fn.Profile, "#A10-3");
233 Assert.AreEqual (".NETFramework,Version=v2.0.1.0,Profile=profile name", fn.FullName, "#A10-4");
235 fn = new FrameworkName (".NETFramework,Version=v2. 0.1.0");
236 Assert.AreEqual (".NETFramework", fn.Identifier, "#A11-1");
237 Assert.IsTrue (fn.Version == new Version (2, 0, 1, 0), "#A11-2");
238 Assert.AreEqual (String.Empty, fn.Profile, "#A11-3");
239 Assert.AreEqual (".NETFramework,Version=v2.0.1.0", fn.FullName, "#A11-4");
241 fn = new FrameworkName (".NETFramework,Version=v0.0.0.0");
242 Assert.AreEqual (".NETFramework", fn.Identifier, "#A12-1");
243 Assert.IsTrue (fn.Version == new Version (0, 0, 0, 0), "#A12-2");
244 Assert.AreEqual (String.Empty, fn.Profile, "#A12-3");
245 Assert.AreEqual (".NETFramework,Version=v0.0.0.0", fn.FullName, "#A12-4");
247 fn = new FrameworkName (".NETFramework,Version=v0.0.0.0,Version=v1.2.3.4");
248 Assert.AreEqual (".NETFramework", fn.Identifier, "#A13-1");
249 Assert.IsTrue (fn.Version == new Version (1, 2, 3, 4), "#A13-2");
250 Assert.AreEqual (String.Empty, fn.Profile, "#A13-3");
251 Assert.AreEqual (".NETFramework,Version=v1.2.3.4", fn.FullName, "#A13-4");
253 fn = new FrameworkName ("identifier,verSION=1.2,PRofiLE=test profile");
254 Assert.AreEqual ("identifier", fn.Identifier, "#A14-1");
255 Assert.IsTrue (fn.Version == new Version (1, 2), "#A14-2");
256 Assert.AreEqual ("test profile", fn.Profile, "#A14-3");
257 Assert.AreEqual ("identifier,Version=v1.2,Profile=test profile", fn.FullName, "#A14-4");
259 fn = new FrameworkName ("identifier,Version=2.0,Profile=");
260 Assert.AreEqual ("identifier", fn.Identifier, "#A15-1");
261 Assert.IsTrue (fn.Version == new Version (2, 0), "#A15-2");
262 Assert.AreEqual (String.Empty, fn.Profile, "#A15-3");
263 Assert.AreEqual ("identifier,Version=v2.0", fn.FullName, "#A15-4");
266 [Test]
267 public void Constructor_String_Version ()
269 FrameworkName fn;
271 Throws <ArgumentNullException> ("#A1-1", () => {
272 fn = new FrameworkName (null, new Version (2, 0));
275 Throws <ArgumentNullException> ("#A1-2", () => {
276 fn = new FrameworkName ("identifier", null);
279 Throws <ArgumentException> ("#A1-3", () => {
280 fn = new FrameworkName (String.Empty, new Version (2, 0));
283 var v = new Version (1,2,3,4);
284 fn = new FrameworkName ("identifier", v);
285 Assert.AreEqual ("identifier", fn.Identifier, "#A2-1");
286 Assert.IsTrue (fn.Version == v, "#A2-2");
287 Assert.AreEqual (String.Empty, fn.Profile, "#A2-3");
288 Assert.AreEqual ("identifier,Version=v1.2.3.4", fn.FullName, "#A2-4");
290 fn = new FrameworkName ("identifier,v2.0", v);
291 Assert.AreEqual ("identifier,v2.0", fn.Identifier, "#A3-1");
292 Assert.IsTrue (fn.Version == v, "#A3-2");
293 Assert.AreEqual (String.Empty, fn.Profile, "#A3-3");
294 Assert.AreEqual ("identifier,v2.0,Version=v1.2.3.4", fn.FullName, "#A3-4");
296 fn = new FrameworkName ("identifier,Version=v2.0", v);
297 Assert.AreEqual ("identifier,Version=v2.0", fn.Identifier, "#A4-1");
298 Assert.IsTrue (fn.Version == v, "#A4-2");
299 Assert.AreEqual (String.Empty, fn.Profile, "#A4-3");
300 Assert.AreEqual ("identifier,Version=v2.0,Version=v1.2.3.4", fn.FullName, "#A4-4");
303 [Test]
304 public void Constructor_String_Version_String ()
306 FrameworkName fn;
307 var v = new Version (1, 2, 3, 4);
309 Throws <ArgumentNullException> ("#A1-1", () => {
310 fn = new FrameworkName (null, new Version (2, 0), "profile");
313 Throws <ArgumentNullException> ("#A1-2", () => {
314 fn = new FrameworkName ("identifier", null, "profile");
317 Throws <ArgumentException> ("#A1-3", () => {
318 fn = new FrameworkName (String.Empty, new Version (2, 0), "profile");
321 fn = new FrameworkName ("identifier,Version=v2.0", v, "Profile name");
322 Assert.AreEqual ("identifier,Version=v2.0", fn.Identifier, "#A2-1");
323 Assert.IsTrue (fn.Version == v, "#A2-2");
324 Assert.AreEqual ("Profile name", fn.Profile, "#A2-3");
325 Assert.AreEqual ("identifier,Version=v2.0,Version=v1.2.3.4,Profile=Profile name", fn.FullName, "#A2-4");
327 fn = new FrameworkName ("identifier,v2.0,profile=test", v, "Profile name");
328 Assert.AreEqual ("identifier,v2.0,profile=test", fn.Identifier, "#A3-1");
329 Assert.IsTrue (fn.Version == v, "#A3-2");
330 Assert.AreEqual ("Profile name", fn.Profile, "#A3-3");
331 Assert.AreEqual ("identifier,v2.0,profile=test,Version=v1.2.3.4,Profile=Profile name", fn.FullName, "#A3-4");
333 fn = new FrameworkName ("identifier,v2.0,profile=test", v, null);
334 Assert.AreEqual ("identifier,v2.0,profile=test", fn.Identifier, "#A4-1");
335 Assert.IsTrue (fn.Version == v, "#A4-2");
336 Assert.AreEqual (String.Empty, fn.Profile, "#A4-3");
337 Assert.AreEqual ("identifier,v2.0,profile=test,Version=v1.2.3.4", fn.FullName, "#A4-4");
339 fn = new FrameworkName ("identifier,v2.0,profile=test", v, String.Empty);
340 Assert.AreEqual ("identifier,v2.0,profile=test", fn.Identifier, "#A5-1");
341 Assert.IsTrue (fn.Version == v, "#A5-2");
342 Assert.AreEqual (String.Empty, fn.Profile, "#A5-3");
343 Assert.AreEqual ("identifier,v2.0,profile=test,Version=v1.2.3.4", fn.FullName, "#A5-4");
346 [Test]
347 public void EqualityOperator ()
349 var fn = new FrameworkName ("identifier,Version=v2.0");
351 Assert.IsTrue (fn == new FrameworkName ("identifier,Version=v2.0"), "#A1");
353 FrameworkName fn1 = null;
354 FrameworkName fn2 = null;
356 Assert.IsTrue (fn1 == fn2, "#A2");
357 Assert.IsFalse (fn == new FrameworkName ("identifier,Version=v2.1"), "#A3");
358 Assert.IsFalse (fn == null, "#A4");
361 [Test]
362 public void InequalityOperator ()
364 var fn = new FrameworkName ("identifier,Version=v2.0");
366 Assert.IsFalse (fn != new FrameworkName ("identifier,Version=v2.0"), "#A1");
368 FrameworkName fn1 = null;
369 FrameworkName fn2 = null;
371 Assert.IsFalse (fn1 != fn2, "#A2");
372 Assert.IsTrue (fn != new FrameworkName ("identifier,Version=v2.1"), "#A3");
373 Assert.IsTrue (fn != null, "#A4");
376 [Test]
377 public void ToStringTest ()
379 var fn = new FrameworkName (".NETFramework,Version=v2.0.1");
380 Assert.AreEqual (".NETFramework,Version=v2.0.1", fn.FullName, "#A1-1");
381 Assert.AreEqual (fn.FullName, fn.ToString (), "#A1-2");
383 fn = new FrameworkName (".NETFramework,Version=v2.0.1.0");
384 Assert.AreEqual (".NETFramework,Version=v2.0.1.0", fn.FullName, "#A2-1");
385 Assert.AreEqual (fn.FullName, fn.ToString (), "#A2-2");
389 #endif