eol style
[mono.git] / mcs / class / corlib / Test / System.Resources / ResourceReaderTest.cs
1 //
2 // MonoTests.System.Resources.ResourceReaderTest.cs
3 //
4 // Author:
5 //   Nick Drochak (ndrochak@gol.com)
6 //
7 // (C) 2001 Nick Drochak II
8 // Copyright (C) 2004 Novell (http://www.novell.com)
9 //
10
11 using System;
12 using System.Collections;
13 using System.IO;
14 using System.Reflection;
15 using System.Resources;
16 using NUnit.Framework;
17
18 namespace MonoTests.System.Resources {
19
20         [TestFixture]
21         public class ResourceReaderTest : Assertion {
22                 internal static string m_ResourceFile;
23                 private static string m_BadResourceFile;
24
25                 [TestFixtureSetUp]
26                 public void FixtureSetUp ()
27                 {
28                         char ds = Path.DirectorySeparatorChar;
29                         if (ds == '/') {
30                                 FileInfo code_base = new FileInfo (Assembly.GetExecutingAssembly ().Location);
31                                 string base_path = Path.Combine (code_base.Directory.FullName, Path.Combine ("Test", "resources"));
32                                 m_ResourceFile = Path.Combine (base_path, "MyResources.resources");
33                                 m_BadResourceFile = Path.Combine (base_path, "Empty.resources");
34                         } else {
35                                 m_ResourceFile = Path.Combine ("Test", Path.Combine ("resources","MyResources.resources"));
36                                 m_BadResourceFile = "resources" + ds + "Empty.resources";
37                         }
38                 }
39
40                 [Test]
41                 [ExpectedException (typeof (ArgumentNullException))]
42                 public void ConstructorString_Null () 
43                 {
44                         string s = null;
45                         ResourceReader r = new ResourceReader (s);
46                 }
47
48                 [Test]
49                 [ExpectedException (typeof (ArgumentException))]
50                 public void ConstructorString_Empty () 
51                 {
52                         ResourceReader r = new ResourceReader (String.Empty);
53                 }
54
55
56                 [Test]
57                 [ExpectedException (typeof (FileNotFoundException))]
58                 public void ConstructorString_NotFound () 
59                 {
60                         // use a file name that is *very* unlikely to exsist
61                         ResourceReader r = new ResourceReader("j38f8axvnn9h38hfa9nxn93f8hav4zvag87vvah32o");
62                 }
63
64                 [Test]
65                 [Ignore("Not covered in the docs, not sure what the correct behavior should be for this")]
66                 [ExpectedException (typeof (DirectoryNotFoundException))]
67                 public void ConstructorString_Bad () 
68                 {
69                         Assert (File.Exists (m_BadResourceFile));
70                         ResourceReader r = new ResourceReader(m_BadResourceFile);
71                 }
72
73                 [Test]
74                 public void ConstructorString () 
75                 {
76                         if (!File.Exists(m_ResourceFile)) {
77                                 Fail ("Resource file is not where it should be:" + Path.Combine (Directory.GetCurrentDirectory(), m_ResourceFile));
78                         }
79                         ResourceReader r = new ResourceReader(m_ResourceFile);
80                         AssertNotNull ("ResourceReader", r);
81                         r.Close();
82                 }
83
84                 [Test]
85                 [ExpectedException (typeof (ArgumentNullException))]
86                 public void ConstructorStream_Null ()
87                 {
88                         Stream s = null;
89                         ResourceReader r = new ResourceReader (s);
90                         Fail("Should throw exception on null");
91                 }
92
93                 [Test]
94                 [ExpectedException (typeof (ArgumentException))]
95                 public void ConstructorStream_Closed ()
96                 {
97                         Stream stream = new FileStream (m_ResourceFile, FileMode.Open);
98                         stream.Close ();
99                         ResourceReader r = new ResourceReader (stream);
100                 }
101
102                 [Test]
103                 public void Stream ()
104                 {
105                         Stream stream = new FileStream (m_ResourceFile, FileMode.Open);
106                         ResourceReader r = new ResourceReader (stream);
107                         AssertNotNull ("ResourceReader", r);
108                         r.Close();
109                 }
110
111                 [Test]
112                 public void Close () 
113                 {
114                         Stream stream = new FileStream (m_ResourceFile, FileMode.Open);
115                         ResourceReader r = new ResourceReader (stream);
116                         r.Close ();
117
118                         stream = new FileStream (m_ResourceFile, FileMode.Open);
119                         AssertNotNull ("FileStream", stream);
120                         stream.Close ();
121                 }
122
123                 [Test]
124                 public void Enumerator ()
125                 {
126                         Stream stream = new FileStream (m_ResourceFile, FileMode.Open);
127                         ResourceReader reader = new ResourceReader (stream);
128
129                         IDictionaryEnumerator en = reader.GetEnumerator();
130                         // Goes through the enumerator, printing out the key and value pairs.
131                         while (en.MoveNext()) {
132                                 DictionaryEntry de = (DictionaryEntry)en.Current;
133                                 Assert("Current.Key should not be empty",String.Empty != (string)de.Key);
134                                 Assert("Current.Value should not be empty",String.Empty != (string)de.Value);
135                                 Assert("Entry.Key should not be empty",String.Empty != (string)en.Key);
136                                 Assert("Entry.Value should not be empty",String.Empty != (string)en.Value);
137                         }
138                         reader.Close();
139                 }
140         }  // class ResourceReaderTest
141 }  // namespace MonoTests.System.Resources