* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Resources / WriterTest.cs
1 //
2 // WriterTest.cs: Unit Tests for ResXResourceWriter.
3 //
4 // Authors:
5 //     Robert Jordan <robertj@gmx.net>
6 //
7
8 using System;
9 using System.Collections;
10 using System.Drawing;
11 using System.IO;
12 using System.Resources;
13 using NUnit.Framework;
14
15 namespace MonoTests.System.Resources
16 {
17         [TestFixture]
18         public class WriterTest
19         {
20                 string fileName = Path.GetTempFileName ();
21
22                 [Test]
23                 public void TestWriter ()
24                 {
25                         ResXResourceWriter w = new ResXResourceWriter (fileName);
26                         w.AddResource ("String", "hola");
27                         w.AddResource ("String2", (object) "hello");
28                         w.AddResource ("Int", 42);
29                         w.AddResource ("Enum", PlatformID.Win32NT);
30                         w.AddResource ("Convertible", new Point (43, 45));
31                         w.AddResource ("Serializable", new ArrayList(new byte[] {1, 2, 3, 4}));
32                         w.AddResource ("ByteArray", new byte[] {12, 13, 14});
33                         w.AddResource ("ByteArray2", (object) new byte[] {15, 16, 17});
34                         w.AddResource ("IntArray", new int[] {1012, 1013, 1014});
35                         w.AddResource ("StringArray", new string[] {"hello", "world"});
36                         w.Generate ();
37                         w.Close ();
38
39                         ResXResourceReader r = new ResXResourceReader (fileName);
40                         Hashtable h = new Hashtable();
41                         foreach (DictionaryEntry e in r) {
42                                 h.Add (e.Key, e.Value);
43                         }
44                         r.Close ();
45
46                         Assert.AreEqual ("hola", (string) h["String"], "#1");
47                         Assert.AreEqual ("hello", (string) h["String2"], "#2");
48                         Assert.AreEqual (42, (int) h["Int"], "#3");
49                         Assert.AreEqual (PlatformID.Win32NT, (PlatformID) h["Enum"], "#4");
50                         Assert.AreEqual (43, ((Point) h["Convertible"]).X, "#5");
51                         Assert.AreEqual (2, (byte) ((ArrayList) h["Serializable"])[1], "#6");
52                         Assert.AreEqual (13, ((byte[]) h["ByteArray"])[1], "#7");
53                         Assert.AreEqual (16, ((byte[]) h["ByteArray2"])[1], "#8");
54                         Assert.AreEqual (1013, ((int[]) h["IntArray"])[1], "#9");
55                         Assert.AreEqual ("world", ((string[]) h["StringArray"])[1], "#10");
56
57                         File.Delete (fileName);
58                 }
59         }
60 }