2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / corlib / Test / System / ApplicationIdTest.cs
1 //
2 // ApplicationIdTest.cs - NUnit Test Cases for ApplicationId
3 //
4 // Author:
5 //      Sebastien Pouliot (sebastien@ximian.com)
6 //
7 // Copyright (C) 2004 Novell, Inc (http://www.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.
27 //
28
29 #if NET_2_0
30
31 using NUnit.Framework;
32 using System;
33
34 namespace MonoTests.System {
35
36         [TestFixture]
37         public class ApplicationIdTest {
38
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";
44
45                 [Test]
46                 public void ApplicationId ()
47                 {
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");
56                 }
57
58                 [Test]
59                 [ExpectedException (typeof (ArgumentNullException))]
60                 public void ApplicationId_PublicKeyTokenNull ()
61                 {
62                         new ApplicationId (null, defaultName, defaultVersion, defaultProc, defaultCulture);
63                 }
64
65                 [Test]
66                 [ExpectedException (typeof (ArgumentNullException))]
67                 public void ApplicationId_NameNull ()
68                 {
69                         new ApplicationId (defaultPublicKeyToken, null, defaultVersion, defaultProc, defaultCulture);
70                 }
71
72                 [Test]
73                 [ExpectedException (typeof (ArgumentNullException))]
74                 public void ApplicationId_VersionNull ()
75                 {
76                         new ApplicationId (defaultPublicKeyToken, defaultName, null, defaultProc, defaultCulture);
77                 }
78
79                 [Test]
80                 public void ApplicationId_ProcessorArchitectureNull ()
81                 {
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");
89                 }
90
91                 [Test]
92                 public void ApplicationId_CultureNull ()
93                 {
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");
101                 }
102
103                 [Test]
104                 public void PublicKeyToken ()
105                 {
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");
110                         token [0] = 1;
111                         Assert.AreEqual (1, token [0], "token");
112                         token = id.PublicKeyToken;
113                         Assert.AreEqual (0, token [0], "PublicKeyToken");
114                 }
115
116                 [Test]
117                 public void Copy () 
118                 {
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");
124                 }
125
126                 [Test]
127                 public void Equals ()
128                 {
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");
134                 }
135
136                 [Test]
137                 public void Equals_Subset ()
138                 {
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");
145
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");
151                 }
152
153                 [Test]
154                 public void ToString_ ()
155                 {
156                         byte[] token = new byte [256];
157                         for (int i=0; i < token.Length; i++)
158                                 token [i] = (byte)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");
161                 }
162         }
163 }
164
165 #endif