Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ResourceReaderTest.cs « System.Resources « Test « corlib « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9fc95af4f1eb988cd05a2d1478b722335044e2a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//
// MonoTests.System.Resources.ResourceReaderTest.cs
//
// Author:
//   Nick Drochak (ndrochak@gol.com)
//
// (C) 2001 Nick Drochak II
//


using System;
using System.Resources;
using System.IO;

using System.Collections;
using MonoTests.System.Resources;
using NUnit.Framework;

namespace MonoTests.System.Resources {

	public class ResourceReaderTest : TestCase {
		private static string m_ResourceFile = "resources" + Path.DirectorySeparatorChar + "MyResources.resources";
		private static string m_BadResourceFile = "resources" + Path.DirectorySeparatorChar + "Empty.resources";
		
		public ResourceReaderTest() : base ("MonoTests.System.Resources.ResourceReaderTest testcase") { }
		public ResourceReaderTest(String name) : base(name) {
		}
		
		public static ITest Suite {
			get {
				return new TestSuite(typeof(ResourceReaderTest));
			}
		}

		protected override void SetUp() {
		}

		public void TestConstructorStringExceptions() {
			ResourceReader r;
			try {
				r = new ResourceReader((String)null);
				Fail("Should throw exception on null");
			} catch{}
			try {
				r = new ResourceReader("");
				Fail("Should throw exception on empty path");
			} catch{}
			try {
				// use a file name that is *very* unlikely to exsist
				r = new ResourceReader("j38f8axvnn9h38hfa9nxn93f8hav4zvag87vvah32o");
				Fail("Should throw exception on file not found");
			} catch{}
			try {
				r = new ResourceReader(m_BadResourceFile);
				Fail("Should throw exception on bad resource file");
			}
			catch {}
		}

		public void TestConstructorString() {
			if (!File.Exists(m_ResourceFile)) {
				Fail("Resource file is not where it should be:" + Directory.GetCurrentDirectory()+ "\\" + m_ResourceFile);
			}
			ResourceReader r = null;
			try {
				r = new ResourceReader(m_ResourceFile);
			}
			catch {
				Fail("Should have been able to open resource file.");
			}
			finally {
				if (null != r)
					r.Close();
			}
			Assert("String constructor should not be null", null != r);
		}

		public void TestConstructorStreamExceptions() {
			ResourceReader r;
			try {
				r = new ResourceReader((Stream)null);
				Fail("Should throw exception on null");
			} catch{}

			try {
				Stream stream = new FileStream (m_ResourceFile, FileMode.Open);
				stream.Close();
				r = new ResourceReader(stream);
				Fail("Should throw exception on cannot read");
			} catch{}
		}

		public void TestStream(){
			ResourceReader r = null;
			try {
				Stream stream = new FileStream (m_ResourceFile, FileMode.Open);
				r = new ResourceReader(stream);
			} 
			catch{
				Fail("Should not throw exception constructing from stream");
			}
			finally {
				if (null != r) {
					r.Close();
				}
			}
		}

		public void TestClose() {
			ResourceReader r = null;
			Stream stream = new FileStream (m_ResourceFile, FileMode.Open);
			r = new ResourceReader(stream);
			r.Close();
			try {
				stream = new FileStream (m_ResourceFile, FileMode.Open);
			} 
			catch{
				Fail("Should be able to open the stream again after close");
			}
			finally {
				if (null != stream) {
					stream.Close();
				}
			}
		}

		public void TestEnumerator(){
			ResourceReader reader = null;
			Stream stream = new FileStream (m_ResourceFile, FileMode.Open);
			reader = new ResourceReader(stream);
			IDictionaryEnumerator en = reader.GetEnumerator();
			// Goes through the enumerator, printing out the key and value pairs.
			while (en.MoveNext()) {
				DictionaryEntry de = (DictionaryEntry)en.Current;
				Assert("Current.Key should not be empty",String.Empty != (string)de.Key);
				Assert("Current.Value should not be empty",String.Empty != (string)de.Value);
				Assert("Current.Value should not be empty",String.Empty != (string)de.Value);
				Assert("Entry.Key should not be empty",String.Empty != (string)en.Key);
				Assert("Entry.Value should not be empty",String.Empty != (string)en.Value);
			}
			reader.Close();
		}
	}  // class ResourceReaderTest
}  // namespace MonoTests.System.Resources