2 // ApplicationIdTest.cs - NUnit Test Cases for ApplicationId
5 // Sebastien Pouliot (sebastien@ximian.com)
7 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
31 using NUnit
.Framework
;
34 namespace MonoTests
.System
{
37 public class ApplicationIdTest
{
39 static byte[] defaultPublicKeyToken
= new byte [0];
40 static string defaultName
= "name";
41 static Version defaultVersion
= new Version (1, 0, 0, 0);
42 static string defaultProc
= "proc";
43 static string defaultCulture
= "culture";
46 public void ApplicationId ()
48 ApplicationId id
= new ApplicationId (defaultPublicKeyToken
, defaultName
, defaultVersion
, defaultProc
, defaultCulture
);
49 Assert
.IsNotNull (id
, "ApplicationId");
50 // wait for NUnit 2.2 Assert.AreEqual (defaultPublicKeyToken, id.PublicKeyToken, "PublicKeyToken");
51 Assert
.AreEqual (defaultName
, id
.Name
, "Name");
52 Assert
.AreEqual (defaultVersion
, id
.Version
, "Version");
53 Assert
.AreEqual (defaultProc
, id
.ProcessorArchitecture
, "ProcessorArchitecture");
54 Assert
.AreEqual (defaultCulture
, id
.Culture
, "Culture");
55 Assert
.AreEqual ("name, culture=\"culture\", version=\"1.0.0.0\", publicKeyToken=\"\", processorArchitecture =\"proc\"", id
.ToString (), "ToString");
59 [ExpectedException (typeof (ArgumentNullException
))]
60 public void ApplicationId_PublicKeyTokenNull ()
62 new ApplicationId (null, defaultName
, defaultVersion
, defaultProc
, defaultCulture
);
66 [ExpectedException (typeof (ArgumentNullException
))]
67 public void ApplicationId_NameNull ()
69 new ApplicationId (defaultPublicKeyToken
, null, defaultVersion
, defaultProc
, defaultCulture
);
73 [ExpectedException (typeof (ArgumentNullException
))]
74 public void ApplicationId_VersionNull ()
76 new ApplicationId (defaultPublicKeyToken
, defaultName
, null, defaultProc
, defaultCulture
);
80 public void ApplicationId_ProcessorArchitectureNull ()
82 ApplicationId id
= new ApplicationId (defaultPublicKeyToken
, defaultName
, defaultVersion
, null, defaultCulture
);
83 // wait for NUnit 2.2 Assert.AreEqual (defaultPublicKeyToken, id.PublicKeyToken, "PublicKeyToken");
84 Assert
.AreEqual (defaultName
, id
.Name
, "Name");
85 Assert
.AreEqual (defaultVersion
, id
.Version
, "Version");
86 Assert
.IsNull (id
.ProcessorArchitecture
, "ProcessorArchitecture");
87 Assert
.AreEqual (defaultCulture
, id
.Culture
, "Culture");
88 Assert
.AreEqual ("name, culture=\"culture\", version=\"1.0.0.0\", publicKeyToken=\"\"", id
.ToString (), "ToString");
92 public void ApplicationId_CultureNull ()
94 ApplicationId id
= new ApplicationId (defaultPublicKeyToken
, defaultName
, defaultVersion
, defaultProc
, null);
95 // wait for NUnit 2.2 Assert.AreEqual (defaultPublicKeyToken, id.PublicKeyToken, "PublicKeyToken");
96 Assert
.AreEqual (defaultName
, id
.Name
, "Name");
97 Assert
.AreEqual (defaultVersion
, id
.Version
, "Version");
98 Assert
.AreEqual (defaultProc
, id
.ProcessorArchitecture
, "ProcessorArchitecture");
99 Assert
.IsNull (id
.Culture
, "Culture");
100 Assert
.AreEqual ("name, version=\"1.0.0.0\", publicKeyToken=\"\", processorArchitecture =\"proc\"", id
.ToString (), "ToString");
104 public void PublicKeyToken ()
106 byte[] token
= new byte [1];
107 ApplicationId id
= new ApplicationId (token
, defaultName
, defaultVersion
, null, null);
108 token
= id
.PublicKeyToken
;
109 Assert
.AreEqual (0, token
[0], "PublicKeyToken");
111 Assert
.AreEqual (1, token
[0], "token");
112 token
= id
.PublicKeyToken
;
113 Assert
.AreEqual (0, token
[0], "PublicKeyToken");
119 ApplicationId id1
= new ApplicationId (defaultPublicKeyToken
, defaultName
, defaultVersion
, defaultProc
, defaultCulture
);
120 ApplicationId id2
= id1
.Copy ();
121 Assert
.IsTrue (id1
.Equals (id2
), "Equals-1");
122 Assert
.IsTrue (id2
.Equals (id1
), "Equals-2");
123 Assert
.IsFalse (Object
.ReferenceEquals (id1
, id2
), "ReferenceEquals");
127 public void Equals ()
129 ApplicationId id1
= new ApplicationId (defaultPublicKeyToken
, defaultName
, defaultVersion
, defaultProc
, defaultCulture
);
130 ApplicationId id2
= new ApplicationId (defaultPublicKeyToken
, defaultName
, defaultVersion
, defaultProc
, defaultCulture
);
131 Assert
.IsTrue (id1
.Equals (id2
), "Equals-1");
132 Assert
.IsTrue (id2
.Equals (id1
), "Equals-2");
133 Assert
.AreEqual (id1
.GetHashCode (), id2
.GetHashCode (), "GetHashCode");
137 public void Equals_Subset ()
139 ApplicationId id1
= new ApplicationId (defaultPublicKeyToken
, defaultName
, defaultVersion
, defaultProc
, defaultCulture
);
140 ApplicationId id2
= new ApplicationId (defaultPublicKeyToken
, defaultName
, defaultVersion
, null, defaultCulture
);
141 Assert
.IsFalse (id1
.Equals (id2
), "Equals-A1");
142 Assert
.IsFalse (id2
.Equals (id1
), "Equals-A2");
143 // would have expected IsFalse
144 Assert
.IsTrue (id1
.GetHashCode () == id2
.GetHashCode (), "GetHashCode-A");
146 ApplicationId id3
= new ApplicationId (defaultPublicKeyToken
, defaultName
, defaultVersion
, defaultProc
, null);
147 Assert
.IsFalse (id1
.Equals (id3
), "Equals-B1");
148 Assert
.IsFalse (id3
.Equals (id1
), "Equals-B2");
149 // would have expected IsFalse
150 Assert
.IsTrue (id1
.GetHashCode () == id3
.GetHashCode (), "GetHashCode-B");
154 public void ToString_ ()
156 byte[] token
= new byte [256];
157 for (int i
=0; i
< token
.Length
; i
++)
159 ApplicationId id
= new ApplicationId (token
, "Mono", new Version (1, 2), "Multiple", "neutral");
160 Assert
.AreEqual ("Mono, culture=\"neutral\", version=\"1.2\", publicKeyToken=\"000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF\", processorArchitecture =\"Multiple\"", id
.ToString (), "ToString");