[mono-config] use right type for result of strlen
[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
30 using NUnit.Framework;
31 using System;
32
33 namespace MonoTests.System {
34
35         [TestFixture]
36         public class ApplicationIdTest {
37
38                 static byte[] defaultPublicKeyToken = new byte [0];
39                 static string defaultName = "name";
40                 static Version defaultVersion = new Version (1, 0, 0, 0);
41                 static string defaultProc = "proc";
42                 static string defaultCulture = "culture";
43
44                 [Test]
45                 public void ApplicationId ()
46                 {
47                         ApplicationId id = new ApplicationId (defaultPublicKeyToken, defaultName, defaultVersion, defaultProc, defaultCulture);
48                         Assert.IsNotNull (id, "ApplicationId");
49                         // wait for NUnit 2.2 Assert.AreEqual (defaultPublicKeyToken, id.PublicKeyToken, "PublicKeyToken");
50                         Assert.AreEqual (defaultName, id.Name, "Name");
51                         Assert.AreEqual (defaultVersion, id.Version, "Version");
52                         Assert.AreEqual (defaultProc, id.ProcessorArchitecture, "ProcessorArchitecture");
53                         Assert.AreEqual (defaultCulture, id.Culture, "Culture");
54                         Assert.AreEqual ("name, culture=\"culture\", version=\"1.0.0.0\", publicKeyToken=\"\", processorArchitecture =\"proc\"", id.ToString (), "ToString");
55                 }
56
57                 [Test]
58                 [ExpectedException (typeof (ArgumentNullException))]
59                 public void ApplicationId_PublicKeyTokenNull ()
60                 {
61                         new ApplicationId (null, defaultName, defaultVersion, defaultProc, defaultCulture);
62                 }
63
64                 [Test]
65                 [ExpectedException (typeof (ArgumentNullException))]
66                 public void ApplicationId_NameNull ()
67                 {
68                         new ApplicationId (defaultPublicKeyToken, null, defaultVersion, defaultProc, defaultCulture);
69                 }
70
71                 [Test]
72                 [ExpectedException (typeof (ArgumentNullException))]
73                 public void ApplicationId_VersionNull ()
74                 {
75                         new ApplicationId (defaultPublicKeyToken, defaultName, null, defaultProc, defaultCulture);
76                 }
77
78                 [Test]
79                 public void ApplicationId_ProcessorArchitectureNull ()
80                 {
81                         ApplicationId id = new ApplicationId (defaultPublicKeyToken, defaultName, defaultVersion, null, defaultCulture);
82                         // wait for NUnit 2.2 Assert.AreEqual (defaultPublicKeyToken, id.PublicKeyToken, "PublicKeyToken");
83                         Assert.AreEqual (defaultName, id.Name, "Name");
84                         Assert.AreEqual (defaultVersion, id.Version, "Version");
85                         Assert.IsNull (id.ProcessorArchitecture, "ProcessorArchitecture");
86                         Assert.AreEqual (defaultCulture, id.Culture, "Culture");
87                         Assert.AreEqual ("name, culture=\"culture\", version=\"1.0.0.0\", publicKeyToken=\"\"", id.ToString (), "ToString");
88                 }
89
90                 [Test]
91                 public void ApplicationId_CultureNull ()
92                 {
93                         ApplicationId id = new ApplicationId (defaultPublicKeyToken, defaultName, defaultVersion, defaultProc, null);
94                         // wait for NUnit 2.2 Assert.AreEqual (defaultPublicKeyToken, id.PublicKeyToken, "PublicKeyToken");
95                         Assert.AreEqual (defaultName, id.Name, "Name");
96                         Assert.AreEqual (defaultVersion, id.Version, "Version");
97                         Assert.AreEqual (defaultProc, id.ProcessorArchitecture, "ProcessorArchitecture");
98                         Assert.IsNull (id.Culture, "Culture");
99                         Assert.AreEqual ("name, version=\"1.0.0.0\", publicKeyToken=\"\", processorArchitecture =\"proc\"", id.ToString (), "ToString");
100                 }
101
102                 [Test]
103                 public void PublicKeyToken ()
104                 {
105                         byte[] token = new byte [1];
106                         ApplicationId id = new ApplicationId (token, defaultName, defaultVersion, null, null);
107                         token = id.PublicKeyToken;
108                         Assert.AreEqual (0, token [0], "PublicKeyToken");
109                         token [0] = 1;
110                         Assert.AreEqual (1, token [0], "token");
111                         token = id.PublicKeyToken;
112                         Assert.AreEqual (0, token [0], "PublicKeyToken");
113                 }
114
115                 [Test]
116                 public void Copy () 
117                 {
118                         ApplicationId id1 = new ApplicationId (defaultPublicKeyToken, defaultName, defaultVersion, defaultProc, defaultCulture);
119                         ApplicationId id2 = id1.Copy ();
120                         Assert.IsTrue (id1.Equals (id2), "Equals-1");
121                         Assert.IsTrue (id2.Equals (id1), "Equals-2");
122                         Assert.IsFalse (Object.ReferenceEquals (id1, id2), "ReferenceEquals");
123                 }
124
125                 [Test]
126                 public void Equals ()
127                 {
128                         ApplicationId id1 = new ApplicationId (defaultPublicKeyToken, defaultName, defaultVersion, defaultProc, defaultCulture);
129                         ApplicationId id2 = new ApplicationId (defaultPublicKeyToken, defaultName, defaultVersion, defaultProc, defaultCulture);
130                         Assert.IsTrue (id1.Equals (id2), "Equals-1");
131                         Assert.IsTrue (id2.Equals (id1), "Equals-2");
132                         Assert.AreEqual (id1.GetHashCode (), id2.GetHashCode (), "GetHashCode");
133                 }
134
135                 [Test]
136                 public void Equals_Subset ()
137                 {
138                         ApplicationId id1 = new ApplicationId (defaultPublicKeyToken, defaultName, defaultVersion, defaultProc, defaultCulture);
139                         ApplicationId id2 = new ApplicationId (defaultPublicKeyToken, defaultName, defaultVersion, null, defaultCulture);
140                         Assert.IsFalse (id1.Equals (id2), "Equals-A1");
141                         Assert.IsFalse (id2.Equals (id1), "Equals-A2");
142                         // would have expected IsFalse
143                         Assert.IsTrue (id1.GetHashCode () == id2.GetHashCode (), "GetHashCode-A");
144
145                         ApplicationId id3 = new ApplicationId (defaultPublicKeyToken, defaultName, defaultVersion, defaultProc, null);
146                         Assert.IsFalse (id1.Equals (id3), "Equals-B1");
147                         Assert.IsFalse (id3.Equals (id1), "Equals-B2");
148                         // would have expected IsFalse
149                         Assert.IsTrue (id1.GetHashCode () == id3.GetHashCode (), "GetHashCode-B");
150                 }
151
152                 [Test]
153                 public void ToString_ ()
154                 {
155                         byte[] token = new byte [256];
156                         for (int i=0; i < token.Length; i++)
157                                 token [i] = (byte)i;
158                         ApplicationId id = new ApplicationId (token, "Mono", new Version (1, 2), "Multiple", "neutral");
159                         Assert.AreEqual ("Mono, culture=\"neutral\", version=\"1.2\", publicKeyToken=\"000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF\", processorArchitecture =\"Multiple\"", id.ToString (), "ToString");
160                 }
161         }
162 }
163