Implemented overloaded versions of Parse and TryParse functions for BigInteger.
[mono.git] / mcs / class / Microsoft.Build.Utilities / Test / Microsoft.Build.Utilities / TaskItemTest.cs
1 //
2 // TaskItemTest.cs:
3 //
4 // Author:
5 //   Marek Sieradzki (marek.sieradzki@gmail.com)
6 //
7 // (C) 2005 Marek Sieradzki
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 using System;
29 using System.Collections;
30 using System.Collections.Specialized;
31 using Microsoft.Build.Framework;
32 using Microsoft.Build.Utilities;
33 using NUnit.Framework;
34
35 namespace MonoTests.Microsoft.Build.Utilities {
36
37         [TestFixture]
38         public class TaskItemTest {
39
40                 ITaskItem item,item1,item2;
41                 ICollection metadataNames;
42
43                 [SetUp]
44                 public void SetUp ()
45                 {
46                         string[] temp = new string[] {"FullPath", "RootDir", "Filename", "Extension", "RelativeDir", "Directory",
47                                 "RecursiveDir", "Identity", "ModifiedTime", "CreatedTime", "AccessedTime"};
48                         ArrayList al = new ArrayList ();
49                         foreach (string s in temp)
50                                 al.Add (s);
51                         metadataNames = al;
52                 }
53                 
54                 private bool CompareStringCollections (ICollection compared, ICollection reference)
55                 {
56                         Hashtable comparedHash;
57                         comparedHash = CollectionsUtil.CreateCaseInsensitiveHashtable ();
58                         
59                         foreach (string s in compared)
60                                 comparedHash.Add (s, null);
61                         
62                         foreach (string s in reference) {
63                                 if (comparedHash.ContainsKey (s) == false) {
64                                         return false;
65                                 }
66                         }
67                         
68                         return true;
69                 }
70
71                 public void TestCloneCustomMetadata ()
72                 {
73                         item = new TaskItem ();
74                         item.SetMetadata ("AAA", "111");
75                         item.SetMetadata ("aaa", "222");
76                         item.SetMetadata ("BBB", "111");
77
78                         string [] metakeys = new string [] { "aaa", "BBB" };
79                         IDictionary meta = item.CloneCustomMetadata ();
80
81                         Assert.IsTrue (CompareStringCollections (meta.Keys, metakeys), "A1");
82                         metakeys [0] = "aAa";
83                         Assert.IsTrue (CompareStringCollections (meta.Keys, metakeys), "A2");
84                         Assert.AreEqual ("222", meta ["aaa"], "A3");
85                         Assert.AreEqual ("222", meta ["AAA"], "A4");
86                         Assert.AreEqual ("222", meta ["aAa"], "A5");
87                         Assert.AreEqual ("111", meta ["BbB"], "A5");
88                 }
89
90                 [Test]
91                 [Ignore ("NRE on .NET 2.0")]
92                 public void TestCtor1 ()
93                 {
94                         new TaskItem ((ITaskItem) null);
95                 }
96
97                 [Test]
98                 [ExpectedException (typeof (ArgumentNullException))]
99                 public void TestCtor2 ()
100                 {
101                         new TaskItem ((string) null);
102                 }
103
104                 [Test]
105                 [ExpectedException (typeof (ArgumentNullException))]
106                 public void TestCtor3 ()
107                 {
108                         new TaskItem ((string) null, new Hashtable ());
109                 }
110
111                 [Test]
112                 [ExpectedException (typeof (ArgumentNullException))]
113                 public void TestCtor4 ()
114                 {
115                         new TaskItem ("itemspec", null);
116                 }
117
118                 [Test]
119                 public void TestCopyConstructor ()
120                 {
121                         item1 = new TaskItem ("itemSpec");
122                         item1.SetMetadata ("meta1", "val1");
123                         item2 = new TaskItem (item1);
124                         Assert.AreEqual (item1.GetMetadata ("meta1"), item2.GetMetadata ("meta1"), "A1");
125                         item1.SetMetadata ("meta1", "val2");
126                         Assert.AreEqual ("val2", item1.GetMetadata ("meta1"), "A2");
127                         Assert.AreEqual ("val1", item2.GetMetadata ("meta1"), "A3");
128                         item2.SetMetadata ("meta1", "val3");
129                         Assert.AreEqual ("val2", item1.GetMetadata ("meta1"), "A4");
130                         Assert.AreEqual ("val3", item2.GetMetadata ("meta1"), "A5");
131                 }
132
133                 [Test]
134                 public void TestCopyMetadataTo ()
135                 {
136                         item1 = new TaskItem ("itemSpec");
137                         item2 = new TaskItem ("itemSpec");
138                         item1.SetMetadata ("A", "1");
139                         item1.SetMetadata ("B", "1");
140                         item1.SetMetadata ("C", "1");
141                         item2.SetMetadata ("B", "2");
142                         item1.CopyMetadataTo (item2);
143                         Assert.AreEqual ("1", item2.GetMetadata ("A"), "1");
144                         Assert.AreEqual ("2", item2.GetMetadata ("B"), "2");
145                         Assert.AreEqual ("1", item2.GetMetadata ("C"), "3");
146                 }
147
148                 [Test]
149                 public void TestGetMetadata ()
150                 {
151                         item = new TaskItem ("itemSpec");
152                         item.SetMetadata ("Metadata", "Value");
153                         Assert.AreEqual ("Value", item.GetMetadata ("Metadata"), "A1");
154                         Assert.AreEqual (String.Empty, item.GetMetadata ("lala"), "A2");
155                         Assert.AreEqual ("itemSpec", item.GetMetadata ("iDentity"), "A3");
156                         Assert.AreEqual ("", item.GetMetadata ("extension"), "A4");
157                         Assert.AreEqual ("", item.GetMetadata ("ModifiedTime"), "A5");
158                         Assert.AreEqual ("", item.GetMetadata ("CreatedTime"), "A6");
159                         Assert.AreEqual ("", item.GetMetadata ("ModifiedTime"), "A7");
160                         Assert.AreEqual ("", item.GetMetadata ("AccessedTime"), "A8");
161                 }
162
163                 [Test]
164                 public void TestMetadataNames ()
165                 {
166                         item = new TaskItem ("itemSpec");
167
168                         Assert.IsTrue (CompareStringCollections (item.MetadataNames, metadataNames), "A1");
169
170                         item.SetMetadata ("a", "b");
171
172                         Assert.AreEqual (12, item.MetadataNames.Count, "A2");
173                 }
174
175                 [Test]
176                 public void TestOpExplicit ()
177                 {
178                         TaskItem item = new TaskItem ("itemSpec");
179                         item.SetMetadata ("a", "b");
180
181                         Assert.AreEqual ("itemSpec", (string) item, "A1");
182                 }
183
184                 [Test]
185                 [ExpectedException (typeof (ArgumentException))]
186                 public void TestRemoveMetadata1 ()
187                 {
188                         item = new TaskItem ("lalala");
189                         item.RemoveMetadata ("EXTension");
190                 }
191
192                 [Test]
193                 [ExpectedException (typeof (ArgumentNullException))]
194                 public void TestRemoveMetadata2 ()
195                 {
196                         item = new TaskItem ("lalala");
197                         item.RemoveMetadata (null);
198                 }
199
200                 [Test]
201                 public void TestRemoveMetadata3 ()
202                 {
203                         item = new TaskItem ("lalala");
204                         item.SetMetadata ("a", "b");
205                         item.RemoveMetadata ("a");
206
207                         Assert.AreEqual (11, item.MetadataCount, "A1");
208                 }
209
210                 [Test]
211                 public void TestSetMetadata1 ()
212                 {
213                         item = new TaskItem ("itemSpec");
214                         item.SetMetadata ("Metadata", "Value1");
215                         item.SetMetadata ("Metadata", "Value2");
216                         Assert.AreEqual (item.MetadataCount, 12, "MetadataCount");
217                         Assert.AreEqual ("Value2", item.GetMetadata ("Metadata"));
218                 }
219
220                 [Test]
221                 [ExpectedException (typeof (ArgumentNullException))]
222                 public void TestSetMetadata2 ()
223                 {
224                         item = new TaskItem ("itemSpec");
225                         item.SetMetadata (null, "value");
226                 }
227
228                 [Test]
229                 [ExpectedException (typeof (ArgumentNullException))]
230                 public void TestSetMetadata3 ()
231                 {
232                         item = new TaskItem ("itemSpec");
233                         item.SetMetadata ("name", null);
234                 }
235
236                 [Test]
237                 [ExpectedException (typeof (ArgumentException))]
238                 public void TestSetReservedMetadata ()
239                 {
240                         item = new TaskItem ("lalala");
241                         item.SetMetadata ("Identity", "some value");
242                 }
243         }
244 }