1 /*-
2  * Copyright (c) 2009, 2020 Oracle and/or its affiliates.  All rights reserved.
3  *
4  * See the file LICENSE for license information.
5  *
6  */
7 using System;
8 using System.Collections.Generic;
9 using System.IO;
10 using System.Text;
11 using System.Xml;
12 using BerkeleyDB;
13 using NUnit.Framework;
14 
15 namespace CsharpAPITest
16 {
17 	public class Configuration
18 	{
19 		public static Random random = new Random();
20 
21 		/*
22 		 * Configure the value with data in xml and return true or
23 		 * false to indicate if the value is configured. If there
24 		 * is no testing data and it is optional, return false. If
25 		 * there is no testing data in xml and it is compulsory,
26 		 * ConfigNotFoundException will be thrown. If any testing
27 		 * data is provided, the value will be set by the testing
28 		 * data and true will be returned.
29 		 */
30 		#region Config
ConfigAckPolicy(XmlElement xmlElem, string name, ref AckPolicy ackPolicy, bool compulsory)31 		public static void ConfigAckPolicy(XmlElement xmlElem,
32 		    string name, ref AckPolicy ackPolicy, bool compulsory)
33 		{
34 			XmlNode xmlNode = XMLReader.GetNode(xmlElem,
35 			    name);
36 			if (xmlNode == null && compulsory == true)
37 				throw new ConfigNotFoundException(name);
38 			else if (xmlNode != null)
39 			{
40 				string policy = xmlNode.InnerText;
41 				if (policy == "ALL")
42 					ackPolicy = AckPolicy.ALL;
43 				else if (policy == "ALL_PEERS")
44 					ackPolicy = AckPolicy.ALL_PEERS;
45 				else if (policy == "NONE")
46 					ackPolicy = AckPolicy.NONE;
47 				else if (policy == "ONE")
48 					ackPolicy = AckPolicy.ONE;
49 				else if (policy == "ONE_PEER")
50 					ackPolicy = AckPolicy.ONE_PEER;
51 				else if (policy == "QUORUM")
52 					ackPolicy = AckPolicy.QUORUM;
53 				else
54 					throw new InvalidConfigException(name);
55 			}
56 		}
57 
ConfigBool(XmlElement xmlElem, string name, ref bool value, bool compulsory)58 		public static bool ConfigBool(XmlElement xmlElem,
59 		    string name, ref bool value, bool compulsory)
60 		{
61 			XmlNode xmlNode;
62 
63 			xmlNode = XMLReader.GetNode(xmlElem, name);
64 			if (xmlNode == null && compulsory == false)
65 				return false;
66 			else if (xmlNode == null && compulsory == true)
67 				throw new ConfigNotFoundException(name);
68 
69 			value = bool.Parse(xmlNode.InnerText);
70 			return true;
71 		}
72 
ConfigByteOrder(XmlElement xmlElem, string name, ref ByteOrder byteOrder, bool compulsory)73 		public static bool ConfigByteOrder(XmlElement xmlElem,
74 		    string name, ref ByteOrder byteOrder, bool compulsory)
75 		{
76 			XmlNode xmlNode;
77 
78 			xmlNode = XMLReader.GetNode(xmlElem, name);
79 			if (xmlNode == null && compulsory == false)
80 				return false;
81 			else if (xmlNode == null && compulsory == true)
82 				throw new ConfigNotFoundException(name);
83 
84 			byteOrder = ByteOrder.FromConst(
85 			int.Parse(xmlNode.InnerText));
86 			return true;
87 		}
88 
ConfigByteMatrix(XmlElement xmlElem, string name, ref byte[,] byteMatrix, bool compulsory)89 		public static bool ConfigByteMatrix(XmlElement xmlElem,
90 		    string name, ref byte[,] byteMatrix, bool compulsory)
91 		{
92 			int i, j, matrixLen;
93 
94 			XmlNode xmlNode = XMLReader.GetNode(xmlElem, name);
95 			if (xmlNode == null && compulsory == false)
96 				return false;
97 			else if (xmlNode == null && compulsory == true)
98 				throw new ConfigNotFoundException(name);
99 
100 			matrixLen = xmlNode.ChildNodes.Count;
101 			byte[,] matrix = new byte[matrixLen, matrixLen];
102 			for (i = 0; i < matrixLen; i++)
103 			{
104 				if (xmlNode.ChildNodes[i].ChildNodes.Count != matrixLen)
105 					throw new ConfigNotFoundException(name);
106 				for (j = 0; j < matrixLen; j++)
107 				{
108 					matrix[i, j] = byte.Parse(
109                         xmlNode.ChildNodes[i].ChildNodes[j].InnerText);
110 				}
111 			}
112 
113 			byteMatrix = matrix;
114 			return true;
115 		}
116 
ConfigCacheInfo(XmlElement xmlElem, string name, ref CacheInfo cacheSize, bool compulsory)117 		public static bool ConfigCacheInfo(XmlElement xmlElem,
118 		    string name, ref CacheInfo cacheSize, bool compulsory)
119 		{
120 			XmlNode xmlNode;
121 			XmlNode xmlChildNode;
122 			uint bytes;
123 			uint gigabytes;
124 			int nCaches;
125 
126 			xmlNode = XMLReader.GetNode(xmlElem, name);
127 			if (xmlNode == null && compulsory == true)
128 				throw new ConfigNotFoundException(name);
129 			else if (xmlNode != null)
130 			{
131 				if ((xmlChildNode = XMLReader.GetNode(
132 				    (XmlElement)xmlNode, "Bytes")) != null)
133 				{
134                     bytes = uint.Parse(xmlChildNode.InnerText);
135                     if ((xmlChildNode = XMLReader.GetNode(
136                          (XmlElement)xmlNode, "Gigabytes")) != null)
137                     {
138                         gigabytes = uint.Parse(xmlChildNode.InnerText);
139                         if ((xmlChildNode = XMLReader.GetNode(
140                             (XmlElement)xmlNode, "NCaches")) != null)
141                         {
142                             nCaches = int.Parse(xmlChildNode.InnerText);
143                             cacheSize = new CacheInfo(gigabytes,bytes,nCaches);
144                             return true;
145                         }
146                     }
147 				}
148 			}
149 
150 			return false;
151 		}
152 
ConfigCachePriority(XmlElement xmlElem, string name, ref CachePriority cachePriority, bool compulsory)153 		public static bool ConfigCachePriority(XmlElement xmlElem,
154 		    string name, ref CachePriority cachePriority, bool compulsory)
155 		{
156 			XmlNode xmlNode;
157 			string priority;
158 
159 			xmlNode = XMLReader.GetNode(xmlElem, name);
160 			if (xmlNode == null && compulsory == false)
161 				return false;
162 			else if (xmlNode == null && compulsory == true)
163 				throw new ConfigNotFoundException(name);
164 
165 			priority = xmlNode.InnerText;
166 			if (priority == "DEFAULT")
167 				cachePriority = CachePriority.DEFAULT;
168 			else if (priority == "HIGH")
169 				cachePriority = CachePriority.HIGH;
170 			else if (priority == "LOW")
171 				cachePriority = CachePriority.LOW;
172 			else if (priority == "VERY_HIGH")
173 				cachePriority = CachePriority.VERY_HIGH;
174 			else if (priority == "VERY_LOW")
175 				cachePriority = CachePriority.VERY_LOW;
176 			else
177 				throw new InvalidConfigException(name);
178 
179 			return true;
180 		}
181 
ConfigCreatePolicy(XmlElement xmlElem, string name, ref CreatePolicy createPolicy, bool compulsory)182 		public static bool ConfigCreatePolicy(XmlElement xmlElem,
183 		    string name, ref CreatePolicy createPolicy, bool compulsory)
184 		{
185 			XmlNode xmlNode;
186 
187 			xmlNode = XMLReader.GetNode(xmlElem, name);
188 			if (xmlNode == null && compulsory == false)
189 				return false;
190 			else if (xmlNode == null && compulsory == true)
191 				throw new ConfigNotFoundException(name);
192 
193 			if (xmlNode.InnerText == "ALWAYS")
194 				createPolicy = CreatePolicy.ALWAYS;
195 			else if (xmlNode.InnerText == "IF_NEEDED")
196 				createPolicy = CreatePolicy.IF_NEEDED;
197 			else if (xmlNode.InnerText == "NEVER")
198 				createPolicy = CreatePolicy.NEVER;
199 			else
200 				throw new InvalidConfigException(name);
201 
202 			return true;
203 		}
204 
ConfigDuplicatesPolicy(XmlElement xmlElem, string name, ref DuplicatesPolicy duplicatePolicy,bool compulsory)205 		public static bool ConfigDuplicatesPolicy(XmlElement xmlElem,
206 		    string name, ref DuplicatesPolicy duplicatePolicy,bool compulsory)
207 		{
208 			XmlNode xmlNode;
209 
210 			xmlNode = XMLReader.GetNode(xmlElem, name);
211 			if (xmlNode == null && compulsory == false)
212 				return false;
213 			else if (xmlNode == null && compulsory == true)
214 				throw new ConfigNotFoundException(name);
215 
216 			if (xmlNode.InnerText == "NONE")
217 				duplicatePolicy = DuplicatesPolicy.NONE;
218 			else if (xmlNode.InnerText == "SORTED")
219 				duplicatePolicy = DuplicatesPolicy.SORTED;
220 			else if (xmlNode.InnerText == "UNSORTED")
221 				duplicatePolicy = DuplicatesPolicy.UNSORTED;
222 			else
223 				throw new InvalidConfigException(name);
224 
225 			return true;
226 		}
227 
ConfigDateTime(XmlElement xmlElem, string name, ref DateTime time, bool compulsory)228 		public static bool ConfigDateTime(XmlElement xmlElem,
229 		    string name, ref DateTime time, bool compulsory)
230 		{
231 			XmlNode xmlNode;
232 
233 			xmlNode = XMLReader.GetNode(xmlElem, name);
234 			if (xmlNode == null && compulsory == false)
235 				return false;
236 			else if (xmlNode == null && compulsory == true)
237 				throw new ConfigNotFoundException(name);
238 
239 			time = DateTime.Parse(xmlNode.InnerText);
240 			return true;
241 		}
242 
ConfigDeadlockPolicy(XmlElement xmlElem, string name, ref DeadlockPolicy deadlockPolicy, bool compulsory)243 		public static bool ConfigDeadlockPolicy(XmlElement xmlElem,
244 		    string name, ref DeadlockPolicy deadlockPolicy, bool compulsory)
245 		{
246 			XmlNode xmlNode = XMLReader.GetNode(xmlElem, name);
247 			if (xmlNode == null && compulsory == false)
248 				return false;
249 			else if (xmlNode == null && compulsory == true)
250 				throw new ConfigNotFoundException(name);
251 
252 			string policy = xmlNode.InnerText;
253 			if (policy == "DEFAULT")
254 				deadlockPolicy = DeadlockPolicy.DEFAULT;
255 			else if (policy == "EXPIRE")
256 				deadlockPolicy = DeadlockPolicy.EXPIRE;
257 			else if (policy == "MAX_LOCKS")
258 				deadlockPolicy = DeadlockPolicy.MAX_LOCKS;
259 			else if (policy == "MAX_WRITE")
260 				deadlockPolicy = DeadlockPolicy.MAX_WRITE;
261 			else if (policy == "MIN_LOCKS")
262 				deadlockPolicy = DeadlockPolicy.MIN_LOCKS;
263 			else if (policy == "MIN_WRITE")
264 				deadlockPolicy = DeadlockPolicy.MIN_WRITE;
265 			else if (policy == "OLDEST")
266 				deadlockPolicy = DeadlockPolicy.OLDEST;
267 			else if (policy == "RANDOM")
268 				deadlockPolicy = DeadlockPolicy.RANDOM;
269 			else if (policy == "YOUNGEST")
270 				deadlockPolicy = DeadlockPolicy.YOUNGEST;
271 			else
272 				throw new InvalidConfigException(name);
273 			return true;
274 		}
275 
ConfigEncryption(XmlElement xmlElem, string name, DatabaseConfig dbConfig, bool compulsory)276 		public static bool ConfigEncryption(XmlElement xmlElem,
277 		    string name, DatabaseConfig dbConfig, bool compulsory)
278 		{
279             EncryptionAlgorithm alg;
280             XmlNode xmlNode;
281             string tmp, password;
282 
283 			xmlNode = XMLReader.GetNode(xmlElem, name);
284 			if (xmlNode == null && compulsory == false)
285 				return false;
286 			else if (xmlNode == null && compulsory == true)
287 				throw new ConfigNotFoundException(name);
288 
289 			password = XMLReader.GetNode((XmlElement)xmlNode,
290 			    "password").InnerText;
291 			tmp = XMLReader.GetNode((XmlElement)xmlNode, "algorithm").InnerText;
292             if (tmp == "AES")
293                 alg = EncryptionAlgorithm.AES;
294             else
295                 alg = EncryptionAlgorithm.DEFAULT;
296 			dbConfig.SetEncryption(password, alg);
297 			return true;
298 		}
299 
ConfigInt(XmlElement xmlElem, string name, ref int value, bool compulsory)300 		public static bool ConfigInt(XmlElement xmlElem,
301 		    string name, ref int value, bool compulsory)
302 		{
303 			XmlNode xmlNode;
304 
305 			xmlNode = XMLReader.GetNode(xmlElem, name);
306 			if (xmlNode == null && compulsory == false)
307 				return false;
308 			else if (xmlNode == null && compulsory == true)
309 				throw new ConfigNotFoundException(name);
310 
311 			value = int.Parse(xmlNode.InnerText);
312 			return true;
313 		}
314 
ConfigIsolation(XmlElement xmlElem, string name, ref Isolation value, bool compulsory)315 		public static bool ConfigIsolation(XmlElement xmlElem,
316 		    string name, ref Isolation value, bool compulsory)
317 		{
318 			XmlNode xmlNode;
319 			int isolationDegree;
320 
321 			xmlNode = XMLReader.GetNode(xmlElem, name);
322 			if (xmlNode == null && compulsory == false)
323 				return false;
324 			else if (xmlNode == null && compulsory == true)
325 				throw new ConfigNotFoundException(name);
326 
327 			isolationDegree = int.Parse(xmlNode.InnerText);
328 			if (isolationDegree == 1)
329 				value = Isolation.DEGREE_ONE;
330 			else if (isolationDegree == 2)
331 				value = Isolation.DEGREE_TWO;
332 			else if (isolationDegree == 3)
333 				value = Isolation.DEGREE_THREE;
334 			else
335 				throw new InvalidConfigException(name);
336 
337 			return true;
338 		}
339 
ConfigLogFlush(XmlElement xmlElem, string name, ref TransactionConfig.LogFlush value, bool compulsory)340 		public static bool ConfigLogFlush(XmlElement xmlElem,
341 		    string name, ref TransactionConfig.LogFlush value,
342 		    bool compulsory)
343 		{
344 			XmlNode xmlNode;
345 			string logFlush;
346 
347 			xmlNode = XMLReader.GetNode(xmlElem, name);
348 			if (xmlNode == null && compulsory == false)
349 				return false;
350 			else if (xmlNode == null && compulsory == true)
351 				throw new ConfigNotFoundException(name);
352 
353 			logFlush = xmlNode.InnerText;
354 			if (logFlush == "DEFAULT")
355 				value = TransactionConfig.LogFlush.DEFAULT;
356 			else if (logFlush == "NOSYNC")
357 				value = TransactionConfig.LogFlush.NOSYNC;
358 			else if (logFlush == "WRITE_NOSYNC")
359 				value = TransactionConfig.LogFlush.WRITE_NOSYNC;
360 			else if (logFlush == "SYNC")
361 				value = TransactionConfig.LogFlush.SYNC;
362 			else
363 				throw new InvalidConfigException(name);
364 
365 			return true;
366 		}
367 
ConfigLong(XmlElement xmlElem, string name, ref long value, bool compulsory)368 		public static bool ConfigLong(XmlElement xmlElem,
369 		    string name, ref long value, bool compulsory)
370 		{
371 			XmlNode xmlNode;
372 
373 			xmlNode = XMLReader.GetNode(xmlElem, name);
374 			if (xmlNode == null && compulsory == false)
375 				return false;
376 			else if (xmlNode == null && compulsory == true)
377 				throw new ConfigNotFoundException(name);
378 
379 			value = long.Parse(xmlNode.InnerText);
380 			return true;
381 		}
382 
ConfigMaxSequentialWrites( XmlElement xmlElem, string name, MPoolConfig mpoolConfig, bool compulsory)383 		public static bool ConfigMaxSequentialWrites(
384 		    XmlElement xmlElem, string name,
385 		    MPoolConfig mpoolConfig, bool compulsory)
386 		{
387 			XmlNode xmlNode;
388 			uint pause;
389 			int writes;
390 
391 			xmlNode = XMLReader.GetNode(xmlElem, name);
392 			if (xmlNode == null && compulsory == false)
393 				return false;
394 			else if (xmlNode == null && compulsory == true)
395 				throw new ConfigNotFoundException(name);
396 
397 			pause = uint.Parse(XMLReader.GetNode(
398 			    (XmlElement)xmlNode, "pause").InnerText);
399 			writes = int.Parse(XMLReader.GetNode(
400 			    (XmlElement)xmlNode,"maxWrites").InnerText);
401 			mpoolConfig.SetMaxSequentialWrites(writes, pause);
402 			return true;
403 		}
404 
ConfigReplicationHostAddress( XmlElement xmlElem, string name, ref DbSiteConfig siteConfig, bool compulsory)405 		public static bool ConfigReplicationHostAddress(
406 		    XmlElement xmlElem, string name,
407 		    ref DbSiteConfig siteConfig, bool compulsory)
408 		{
409 			XmlNode xmlNode = XMLReader.GetNode(
410 			    xmlElem, name);
411 			if (xmlNode == null && compulsory == false)
412 				return false;
413 			else if (xmlNode == null && compulsory == true)
414 				throw new ConfigNotFoundException(name);
415 
416 			    siteConfig.Host = XMLReader.GetNode(
417 			    (XmlElement)xmlNode, "Host").InnerText;
418 			    siteConfig.Port = uint.Parse(XMLReader.GetNode(
419 			    (XmlElement)xmlNode, "Port").InnerText);
420 			return true;
421 		}
422 
ConfigString(XmlElement xmlElem, string name, ref string valChar, bool compulsory)423 		public static bool ConfigString(XmlElement xmlElem,
424 		    string name, ref string valChar, bool compulsory)
425 		{
426 			XmlNode xmlNode;
427 
428 			xmlNode = XMLReader.GetNode(xmlElem, name);
429 			if (xmlNode == null && compulsory == false)
430 				return false;
431 			else if (xmlNode == null && compulsory == true)
432 				throw new ConfigNotFoundException(name);
433 
434 			valChar = xmlNode.InnerText;
435 			return true;
436 		}
437 
ConfigStringList(XmlElement xmlElem, string name, ref List<string> strings, bool compulsory)438 		public static bool ConfigStringList(XmlElement xmlElem,
439 		    string name, ref List<string> strings, bool compulsory)
440 		{
441 			XmlNode xmlNode;
442 
443 			xmlNode = XMLReader.GetNode(xmlElem, name);
444 			if (xmlNode == null && compulsory == false)
445 				return false;
446 			else if (xmlNode == null && compulsory == true)
447 				throw new ConfigNotFoundException(name);
448 
449 			XmlNodeList list = xmlNode.ChildNodes;
450 			for (int i = 0; i < list.Count; i++)
451 				strings.Add(list[i].InnerText);
452 
453 			return true;
454 		}
455 
ConfigUint(XmlElement xmlElem, string name, ref uint value, bool compulsory)456 		public static bool ConfigUint(XmlElement xmlElem,
457 		    string name, ref uint value, bool compulsory)
458 		{
459 			XmlNode xmlNode;
460 
461 			xmlNode = XMLReader.GetNode(xmlElem, name);
462 			if (xmlNode == null && compulsory == false)
463 				return false;
464 			else if (xmlNode == null && compulsory == true)
465 				throw new ConfigNotFoundException(name);
466 
467 			value = uint.Parse(xmlNode.InnerText);
468 			return true;
469 		}
470 
ConfigVerboseMessages( XmlElement xmlElem, string name, ref VerboseMessages verbose, bool compulsory)471 		public static bool ConfigVerboseMessages(
472 		    XmlElement xmlElem, string name,
473 		    ref VerboseMessages verbose, bool compulsory)
474 		{
475 			XmlNode xmlNode = XMLReader.GetNode(xmlElem,
476 			    name);
477 			if (xmlNode == null && compulsory == false)
478 				return false;
479 			else if (xmlNode == null && compulsory == true)
480 				throw new ConfigNotFoundException(name);
481 
482 			ConfigBool((XmlElement)xmlNode, "AllFileOps",
483 			    ref verbose.AllFileOps, compulsory);
484 			ConfigBool((XmlElement)xmlNode, "Deadlock",
485 			    ref verbose.Deadlock, compulsory);
486 			ConfigBool((XmlElement)xmlNode, "FileOps",
487 			    ref verbose.FileOps, compulsory);
488 			ConfigBool((XmlElement)xmlNode, "Recovery",
489 			    ref verbose.Recovery, compulsory);
490 			ConfigBool((XmlElement)xmlNode, "Register",
491 			    ref verbose.Register, compulsory);
492 			ConfigBool((XmlElement)xmlNode, "Replication",
493 			    ref verbose.Replication, compulsory);
494 			ConfigBool((XmlElement)xmlNode, "ReplicationElection",
495 			    ref verbose.ReplicationElection, compulsory);
496 			ConfigBool((XmlElement)xmlNode, "ReplicationLease",
497 			    ref verbose.ReplicationLease, compulsory);
498 			ConfigBool((XmlElement)xmlNode, "ReplicationMessages",
499 			    ref verbose.ReplicationMessages, compulsory);
500 			ConfigBool((XmlElement)xmlNode, "ReplicationMisc",
501 			    ref verbose.ReplicationMisc, compulsory);
502 			ConfigBool((XmlElement)xmlNode, "ReplicationSync",
503 			    ref verbose.ReplicationSync, compulsory);
504 			ConfigBool((XmlElement)xmlNode, "RepMgrConnectionFailure",
505 			    ref verbose.RepMgrConnectionFailure, compulsory);
506 			ConfigBool((XmlElement)xmlNode, "RepMgrMisc",
507 			    ref verbose.RepMgrMisc, compulsory);
508 			ConfigBool((XmlElement)xmlNode, "WaitsForTable",
509 			    ref verbose.WaitsForTable, compulsory);
510 			return true;
511 		}
512 
513 		#endregion Config
514 
515 		/*
516 		 * Confirm that the given value is the same with that in
517 		 * xml. If there is no testing data in xml and it is
518 		 * compulsory, the ConfigNotFoundException will be thrown.
519 		 * If there is no testing data and it is optional, nothing
520 		 * will be done. If any testing data is provided, the value
521 		 * will be checked.
522 		 */
523 		#region Confirm
ConfirmAckPolicy(XmlElement xmlElem, string name, AckPolicy ackPolicy, bool compulsory)524 		public static void ConfirmAckPolicy(XmlElement xmlElem,
525 		    string name, AckPolicy ackPolicy, bool compulsory)
526 		{
527 			XmlNode xmlNode = XMLReader.GetNode(xmlElem,
528 			    name);
529 			if (xmlNode == null && compulsory == true)
530 				throw new ConfigNotFoundException(name);
531 			else if (xmlNode != null)
532 			{
533 				string policy = xmlNode.InnerText;
534 				if (policy == "ALL")
535 					Assert.AreEqual(AckPolicy.ALL,
536                                             ackPolicy);
537 				else if (policy == "ALL_PEERS")
538 					Assert.AreEqual(AckPolicy.ALL_PEERS,
539                                             ackPolicy);
540 				else if (policy == "NONE")
541 					Assert.AreEqual(AckPolicy.NONE,
542                                             ackPolicy);
543 				else if (policy == "ONE")
544 					Assert.AreEqual(AckPolicy.ONE,
545                                             ackPolicy);
546 				else if (policy == "ONE_PEER")
547 					Assert.AreEqual(AckPolicy.ONE_PEER,
548                                             ackPolicy);
549 				else if (policy == "QUORUM")
550 					Assert.AreEqual(AckPolicy.QUORUM,
551                                             ackPolicy);
552 				else
553 					throw new InvalidConfigException(name);
554 			}
555 		}
556 
ConfirmBool(XmlElement xmlElem, string name, bool value, bool compulsory)557 		public static void ConfirmBool(XmlElement xmlElem,
558 		    string name, bool value, bool compulsory)
559 		{
560 			XmlNode xmlNode;
561 			bool expected;
562 
563 			xmlNode = XMLReader.GetNode(xmlElem,
564 			    name);
565 			if (xmlNode == null && compulsory == true)
566 				throw new ConfigNotFoundException(name);
567 			else if (xmlNode != null)
568 			{
569 				if (xmlNode.ChildNodes.Count > 1)
570 				{
571 					expected = bool.Parse(
572 					    xmlNode.FirstChild.NextSibling.InnerText);
573 					Assert.AreEqual(expected, value);
574 				}
575 			}
576 		}
577 
578 		/*
579 		 * If configure MACHINE, the ByteOrder in database will
580 		 * switch to LITTLE_ENDIAN or BIG_ENDIAN according to the
581 		 * current machine.
582 		 */
ConfirmByteOrder(XmlElement xmlElem, string name, ByteOrder byteOrder, bool compulsory)583 		public static void ConfirmByteOrder(XmlElement xmlElem,
584 		    string name, ByteOrder byteOrder, bool compulsory)
585 		{
586 			XmlNode xmlNode;
587 			ByteOrder specOrder;
588 
589 			xmlNode = XMLReader.GetNode(xmlElem, name);
590 			if (xmlNode == null && compulsory == true)
591 				throw new ConfigNotFoundException(name);
592 			else if (xmlNode != null)
593 			{
594 				specOrder = ByteOrder.FromConst(int.Parse(
595 				    xmlNode.InnerText));
596 				if (specOrder == ByteOrder.MACHINE)
597 					Assert.AreNotEqual(specOrder, byteOrder);
598 				else
599 					Assert.AreEqual(specOrder, byteOrder);
600 			}
601 		}
602 
ConfirmByteMatrix(XmlElement xmlElem, string name, byte[,] byteMatrix, bool compulsory)603 		public static void ConfirmByteMatrix(XmlElement xmlElem,
604 		    string name, byte[,] byteMatrix, bool compulsory)
605 		{
606 			int i, j, matrixLen;
607 
608 			XmlNode xmlNode = XMLReader.GetNode(xmlElem, name);
609 			if (xmlNode == null && compulsory == true)
610 				throw new ConfigNotFoundException(name);
611 			else if (xmlNode != null)
612 			{
613 				/*
614 				 * If the length of the 2 matrixes are not
615 				 * the same, the matrixes are definately
616 				 * not equal.
617 				 */
618 				matrixLen = xmlNode.ChildNodes.Count;
619 				Assert.AreEqual(matrixLen * matrixLen,byteMatrix.Length);
620 
621 				/*
622 				 * Go over every element in the matrix to
623 				 * see if the same with the given xml data.
624 				 */
625 				for (i = 0; i < matrixLen; i++)
626 				{
627 					if (xmlNode.ChildNodes[i].ChildNodes.Count != matrixLen)
628 						throw new ConfigNotFoundException(name);
629 					for (j = 0; j < matrixLen; j++)
630 						Assert.AreEqual(
631 						    byte.Parse(xmlNode.ChildNodes[i].ChildNodes[j].InnerText),
632                                                     byteMatrix[i, j]);
633 				}
634 			}
635 		}
636 
ConfirmCachePriority(XmlElement xmlElem, string name, CachePriority priority, bool compulsory)637 		public static void ConfirmCachePriority(XmlElement xmlElem,
638 		    string name, CachePriority priority, bool compulsory)
639 		{
640 			XmlNode xmlNode;
641 
642 			xmlNode = XMLReader.GetNode(xmlElem, name);
643 			if (xmlNode == null && compulsory == true)
644 				throw new ConfigNotFoundException(name);
645 			else if (xmlNode != null)
646 			{
647 				if (xmlNode.InnerText == "DEFAULT")
648 					Assert.AreEqual(CachePriority.DEFAULT, priority);
649 				else if (xmlNode.InnerText == "HIGH")
650 					Assert.AreEqual(CachePriority.HIGH, priority);
651 				else if (xmlNode.InnerText == "LOW")
652 					Assert.AreEqual(CachePriority.LOW, priority);
653 				else if (xmlNode.InnerText == "VERY_HIGH")
654 					Assert.AreEqual(CachePriority.VERY_HIGH, priority);
655 				else if (xmlNode.InnerText == "VERY_LOW")
656 					Assert.AreEqual(CachePriority.VERY_LOW, priority);
657 			}
658 		}
659 
ConfirmCacheSize(XmlElement xmlElem, string name, CacheInfo cache, bool compulsory)660 		public static void ConfirmCacheSize(XmlElement xmlElem,
661 		    string name, CacheInfo cache, bool compulsory)
662 		{
663 			uint bytes;
664 			uint gigabytes;
665 			int nCaches;
666 			XmlNode xmlNode;
667 			XmlNode xmlChildNode;
668 
669 			xmlNode = XMLReader.GetNode(xmlElem, name);
670 			if (xmlNode == null && compulsory == true)
671 				throw new ConfigNotFoundException(name);
672 			else if (xmlNode != null)
673 			{
674 				if ((xmlChildNode = XMLReader.GetNode(
675 				    (XmlElement)xmlNode, "Bytes")) != null)
676 				{
677 					bytes = uint.Parse(xmlChildNode.InnerText);
678 					if ((xmlChildNode = XMLReader.GetNode(
679 					    (XmlElement)xmlNode, "Gigabytes")) != null)
680 					{
681 						gigabytes = uint.Parse(xmlChildNode.InnerText);
682 						if ((xmlChildNode = XMLReader.GetNode(
683 						    (XmlElement)xmlNode,
684 						    "NCaches")) != null)
685 						{
686 							nCaches = int.Parse(xmlChildNode.InnerText);
687 							Assert.LessOrEqual(bytes, cache.Bytes);
688 							Assert.AreEqual(gigabytes, cache.Gigabytes);
689 							Assert.AreEqual(nCaches, cache.NCaches);
690 						}
691 					}
692 				}
693 			}
694 		}
695 
696 		/*
697 		 * If bytes in CacheSize is assigned, the bytes in cachesize
698 		 * couldn't be the default one.
699 		 */
ConfirmCacheSize(XmlElement xmlElem, string name, CacheInfo cache, uint defaultCache, bool compulsory)700 		public static void ConfirmCacheSize(XmlElement xmlElem,
701 		    string name, CacheInfo cache, uint defaultCache,
702 		    bool compulsory)
703 		{
704 			uint bytes;
705 			uint gigabytes;
706 			int nCaches;
707 			XmlNode xmlNode;
708 			XmlNode xmlChildNode;
709 
710 			xmlNode = XMLReader.GetNode(xmlElem, name);
711 			if (xmlNode == null && compulsory == true)
712 				throw new ConfigNotFoundException(name);
713 			else if (xmlNode != null)
714 			{
715 				if ((xmlChildNode = XMLReader.GetNode(
716 				    (XmlElement)xmlNode, "Bytes")) != null)
717 				{
718 					bytes = defaultCache;
719 					if ((xmlChildNode = XMLReader.GetNode(
720 					    (XmlElement)xmlNode, "Gigabytes")) != null)
721 					{
722 						gigabytes = uint.Parse(xmlChildNode.InnerText);
723 						if ((xmlChildNode = XMLReader.GetNode(
724 						    (XmlElement)xmlNode, "NCaches")) != null)
725 						{
726 							nCaches = int.Parse(xmlChildNode.InnerText);
727 							Assert.AreNotEqual(bytes, cache.Bytes);
728 							Assert.AreEqual(gigabytes, cache.Gigabytes);
729 							Assert.AreEqual(nCaches, cache.NCaches);
730 						}
731 					}
732 				}
733 			}
734 		}
735 
ConfirmCreatePolicy(XmlElement xmlElem, string name, CreatePolicy createPolicy, bool compulsory)736 		public static void ConfirmCreatePolicy(XmlElement xmlElem,
737 		    string name, CreatePolicy createPolicy, bool compulsory)
738 		{
739 			XmlNode xmlNode;
740 
741 			xmlNode = XMLReader.GetNode(xmlElem, name);
742 			if (xmlNode == null && compulsory == true)
743 				throw new ConfigNotFoundException(name);
744 			else if (xmlNode != null)
745 			{
746 				if (xmlNode.InnerText == "ALWAYS")
747 					Assert.IsTrue(createPolicy.Equals(CreatePolicy.ALWAYS));
748 				else if (xmlNode.InnerText == "IF_NEEDED")
749 					Assert.IsTrue(createPolicy.Equals(CreatePolicy.IF_NEEDED));
750 				else if (xmlNode.InnerText == "NEVER")
751 					Assert.IsTrue(createPolicy.Equals(CreatePolicy.NEVER));
752 			}
753 		}
754 
ConfirmDataBaseType(XmlElement xmlElem, string name, DatabaseType dbType, bool compulsory)755 		public static void ConfirmDataBaseType(XmlElement xmlElem,
756 		    string name, DatabaseType dbType, bool compulsory)
757 		{
758 			XmlNode xmlNode;
759 			xmlNode = XMLReader.GetNode(xmlElem, name);
760 			if (xmlNode == null && compulsory == true)
761 				throw new ConfigNotFoundException(name);
762 			else if (xmlNode != null)
763 			{
764 				if (xmlNode.InnerText == "BTREE")
765 					Assert.AreEqual(dbType, DatabaseType.BTREE);
766 				else if (xmlNode.InnerText == "HASH")
767 					Assert.AreEqual(dbType, DatabaseType.HASH);
768 				else if (xmlNode.InnerText == "QUEUE")
769 					Assert.AreEqual(dbType, DatabaseType.QUEUE);
770 				else if (xmlNode.InnerText == "RECNO")
771 					Assert.AreEqual(dbType, DatabaseType.RECNO);
772 				else if (xmlNode.InnerText == "UNKNOWN")
773 					Assert.AreEqual(dbType, DatabaseType.UNKNOWN);
774 			}
775 		}
776 
ConfirmDateTime(XmlElement xmlElem, string name, DateTime time, bool compulsory)777 		public static void ConfirmDateTime(XmlElement xmlElem,
778 		    string name, DateTime time, bool compulsory)
779 		{
780 			XmlNode xmlNode;
781 
782 			xmlNode = XMLReader.GetNode(xmlElem, name);
783 			if (xmlNode == null && compulsory == true)
784 				throw new ConfigNotFoundException(name);
785 			else if (xmlNode != null)
786 				Assert.AreEqual(DateTime.Parse(
787 				    xmlNode.InnerText), time);
788 		}
789 
ConfirmDeadlockPolicy(XmlElement xmlElem, string name, DeadlockPolicy deadlockPolicy, bool compulsory)790 		public static void ConfirmDeadlockPolicy(XmlElement xmlElem,
791 		    string name, DeadlockPolicy deadlockPolicy, bool compulsory)
792 		{
793 			XmlNode xmlNode = XMLReader.GetNode(xmlElem, name);
794 			if (xmlNode == null && compulsory == true)
795 				throw new ConfigNotFoundException(name);
796 			else if (xmlNode != null)
797 			{
798 				string policy = xmlNode.InnerText;
799 				if (policy == "DEFAULT")
800 					Assert.AreEqual(DeadlockPolicy.DEFAULT, deadlockPolicy);
801 				else if (policy == "EXPIRE")
802 					Assert.AreEqual(DeadlockPolicy.EXPIRE, deadlockPolicy);
803 				else if (policy == "MAX_LOCKS")
804 					Assert.AreEqual(DeadlockPolicy.MAX_LOCKS, deadlockPolicy);
805 				else if (policy == "MAX_WRITE")
806 					Assert.AreEqual(DeadlockPolicy.MAX_WRITE, deadlockPolicy);
807 				else if (policy == "MIN_LOCKS")
808 					Assert.AreEqual(DeadlockPolicy.MIN_LOCKS, deadlockPolicy);
809 				else if (policy == "MIN_WRITE")
810 					Assert.AreEqual(DeadlockPolicy.MIN_WRITE, deadlockPolicy);
811 				else if (policy == "OLDEST")
812 					Assert.AreEqual(DeadlockPolicy.OLDEST, deadlockPolicy);
813 				else if (policy == "RANDOM")
814 					Assert.AreEqual(DeadlockPolicy.RANDOM, deadlockPolicy);
815 				else if (policy == "YOUNGEST")
816 					Assert.AreEqual(DeadlockPolicy.YOUNGEST, deadlockPolicy);
817 				else
818 					throw new InvalidConfigException(name);
819 			}
820 		}
821 
ConfirmDuplicatesPolicy( XmlElement xmlElem, string name, DuplicatesPolicy duplicatedPolicy, bool compulsory)822 		public static void ConfirmDuplicatesPolicy(
823 		    XmlElement xmlElem, string name,
824 		    DuplicatesPolicy duplicatedPolicy, bool compulsory)
825 		{
826 			XmlNode xmlNode;
827 			xmlNode = XMLReader.GetNode(xmlElem, name);
828 			if (xmlNode == null && compulsory == true)
829 				throw new ConfigNotFoundException(name);
830 			else if (xmlNode != null)
831 			{
832 				if (xmlNode.InnerText == "NONE")
833 					Assert.AreEqual(duplicatedPolicy, DuplicatesPolicy.NONE);
834 				else if (xmlNode.InnerText == "SORTED")
835 					Assert.AreEqual(duplicatedPolicy, DuplicatesPolicy.SORTED);
836 				else if (xmlNode.InnerText == "UNSORTED")
837 					Assert.AreEqual(duplicatedPolicy, DuplicatesPolicy.UNSORTED);
838 			}
839 		}
840 
ConfirmEncryption(XmlElement xmlElem, string name, string dPwd, EncryptionAlgorithm dAlg, bool compulsory)841 		public static void ConfirmEncryption(XmlElement xmlElem,
842 		    string name, string dPwd, EncryptionAlgorithm dAlg, bool compulsory)
843 		{
844             EncryptionAlgorithm alg;
845 			XmlNode xmlNode = XMLReader.GetNode(xmlElem,
846 			    name);
847 			if (xmlNode == null && compulsory == true)
848 				throw new ConfigNotFoundException(name);
849 			else if (xmlNode != null)
850 			{
851 				string password = XMLReader.GetNode(
852 				    (XmlElement)xmlNode, "password").InnerText;
853 				string tmp = XMLReader.GetNode(
854                     (XmlElement)xmlNode, "algorithm").InnerText;
855                 if (tmp == "AES")
856                     alg = EncryptionAlgorithm.AES;
857                 else
858                     alg = EncryptionAlgorithm.DEFAULT;
859 				Assert.AreEqual(dAlg, alg);
860 				Assert.AreEqual(dPwd, dPwd);
861 			}
862 		}
863 
ConfirmInt(XmlElement xmlElem, string name, int value, bool compulsory)864 		public static void ConfirmInt(XmlElement xmlElem,
865 		    string name, int value, bool compulsory)
866 		{
867 			XmlNode xmlNode;
868 			xmlNode = XMLReader.GetNode(xmlElem, name);
869 			if (xmlNode == null && compulsory == true)
870 				throw new ConfigNotFoundException(name);
871 			else if (xmlNode != null)
872 				Assert.AreEqual(int.Parse(xmlNode.InnerText), value);
873 		}
874 
ConfirmIsolation(XmlElement xmlElem, string name, Isolation value, bool compulsory)875 		public static void ConfirmIsolation(XmlElement xmlElem,
876 		    string name, Isolation value, bool compulsory)
877 		{
878 			XmlNode xmlNode;
879 			int isolationDegree;
880 
881 			xmlNode = XMLReader.GetNode(xmlElem, name);
882 			if (xmlNode == null && compulsory == true)
883 				throw new ConfigNotFoundException(name);
884 			else if (xmlNode != null)
885 			{
886 				isolationDegree = int.Parse(xmlNode.InnerText);
887 				if (isolationDegree == 1)
888 					Assert.AreEqual(Isolation.DEGREE_ONE, value);
889 				else if (isolationDegree == 2)
890 					Assert.AreEqual(Isolation.DEGREE_TWO, value);
891 				else if (isolationDegree == 3)
892 					Assert.AreEqual(Isolation.DEGREE_THREE, value);
893 				else
894 					throw new InvalidConfigException(name);
895 			}
896 		}
897 
ConfirmLogFlush(XmlElement xmlElem, string name, TransactionConfig.LogFlush value, bool compulsory)898 		public static void ConfirmLogFlush(XmlElement xmlElem,
899 		    string name, TransactionConfig.LogFlush value,
900 		    bool compulsory)
901 		{
902 			XmlNode xmlNode;
903 			string logFlush;
904 
905 			xmlNode = XMLReader.GetNode(xmlElem, name);
906 			if (xmlNode == null && compulsory == true)
907 				throw new ConfigNotFoundException(name);
908 			else if (xmlNode != null)
909 			{
910 				logFlush = xmlNode.InnerText;
911 				if (logFlush == "DEFAULT")
912 					Assert.AreEqual(TransactionConfig.LogFlush.DEFAULT, value);
913 				else if (logFlush == "NOSYNC")
914 					Assert.AreEqual(TransactionConfig.LogFlush.NOSYNC, value);
915 				else if (logFlush == "WRITE_NOSYNC")
916 					Assert.AreEqual(TransactionConfig.LogFlush.WRITE_NOSYNC, value);
917 				else if (logFlush == "SYNC")
918 					Assert.AreEqual(TransactionConfig.LogFlush.SYNC, value);
919 				else
920 					throw new InvalidConfigException(name);
921 			}
922 		}
923 
ConfirmLong(XmlElement xmlElem, string name, long value, bool compulsory)924 		public static void ConfirmLong(XmlElement xmlElem,
925 		    string name, long value, bool compulsory)
926 		{
927 			XmlNode xmlNode;
928 			xmlNode = XMLReader.GetNode(xmlElem, name);
929 			if (xmlNode == null && compulsory == true)
930 				throw new ConfigNotFoundException(name);
931 			else if (xmlNode != null)
932 				Assert.AreEqual(long.Parse(xmlNode.InnerText), value);
933 		}
934 
ConfirmMaxSequentialWrites( XmlElement xmlElem, string name, uint mPause, int mWrites, bool compulsory)935 		public static void ConfirmMaxSequentialWrites(
936 		    XmlElement xmlElem, string name,
937 		    uint mPause, int mWrites, bool compulsory)
938 		{
939 			XmlNode xmlNode;
940 			uint pause;
941 			int writes;
942 
943 			xmlNode = XMLReader.GetNode(xmlElem, name);
944 			if (xmlNode == null && compulsory == true)
945 				throw new ConfigNotFoundException(name);
946 			else if (xmlNode != null)
947 			{
948 				writes = int.Parse(XMLReader.GetNode(
949 				    (XmlElement)xmlNode, "maxWrites").InnerText);
950 				pause = uint.Parse(XMLReader.GetNode(
951 				    (XmlElement)xmlNode, "pause").InnerText);
952 
953 				Assert.AreEqual(mPause, pause);
954 				Assert.AreEqual(mWrites, writes);
955 			}
956 		}
957 
ConfirmReplicationHostAddress( XmlElement xmlElem, string name, DbSiteConfig siteConfig, bool compulsory)958 		public static void ConfirmReplicationHostAddress(
959 		    XmlElement xmlElem, string name,
960 		    DbSiteConfig siteConfig, bool compulsory)
961 		{
962 			XmlNode xmlNode = XMLReader.GetNode(xmlElem, name);
963 			if (xmlNode == null && compulsory == true)
964 				throw new ConfigNotFoundException(name);
965 			else if (xmlNode != null)
966 			{
967 				string host = XMLReader.GetNode(
968 				    (XmlElement)xmlNode, "Host").InnerText;
969 				uint port = uint.Parse(XMLReader.GetNode(
970 				    (XmlElement)xmlNode, "Port").InnerText);
971 
972 				Assert.AreEqual(host, siteConfig.Host);
973 				Assert.AreEqual(port, siteConfig.Port);
974 			}
975 		}
976 
ConfirmString(XmlElement xmlElem, string name, string str, bool compulsory)977 		public static void ConfirmString(XmlElement xmlElem,
978 		    string name, string str, bool compulsory)
979 		{
980 			XmlNode xmlNode;
981 
982 			if (str != null)
983 			{
984 				xmlNode = XMLReader.GetNode(xmlElem, name);
985 				if (xmlNode == null && compulsory == true)
986 					throw new ConfigNotFoundException(name);
987 				else if (xmlNode != null)
988 				{
989 					if (xmlNode.HasChildNodes)
990 						Assert.AreEqual(
991 						    xmlNode.FirstChild.InnerText, str);
992 				}
993 			}
994 		}
995 
ConfirmStringList(XmlElement xmlElem, string name, List<string> strings, bool compulsory)996 		public static void ConfirmStringList(XmlElement xmlElem,
997 		    string name, List<string> strings, bool compulsory)
998 		{
999 			XmlNode xmlNode;
1000 
1001 			if (strings != null)
1002 			{
1003 				xmlNode = XMLReader.GetNode(xmlElem, name);
1004 				if (xmlNode == null && compulsory == true)
1005 					throw new ConfigNotFoundException(name);
1006 				else if (xmlNode != null)
1007 				{
1008 					if (xmlNode.HasChildNodes)
1009 					{
1010 						XmlNodeList list = xmlNode.ChildNodes;
1011 						for (int i = 0; i < xmlNode.ChildNodes.Count;i++)
1012 							Assert.IsTrue(
1013 							    strings.Contains(list[i].InnerText));
1014 					}
1015 				}
1016 			}
1017 		}
1018 
ConfirmUint(XmlElement xmlElem, string name, uint value, bool compulsory)1019 		public static void ConfirmUint(XmlElement xmlElem,
1020 		    string name, uint value, bool compulsory)
1021 		{
1022 			XmlNode xmlNode;
1023 
1024 			xmlNode = XMLReader.GetNode(xmlElem, name);
1025 			if (xmlNode == null && compulsory == true)
1026 				throw new ConfigNotFoundException(name);
1027 			else if (xmlNode != null)
1028 				Assert.AreEqual(uint.Parse(xmlNode.InnerText), value);
1029 		}
1030 
ConfirmVerboseMessages( XmlElement xmlElem, string name, VerboseMessages verbose, bool compulsory)1031 		public static void ConfirmVerboseMessages(
1032 		    XmlElement xmlElem, string name,
1033 		    VerboseMessages verbose, bool compulsory)
1034 		{
1035 			XmlNode xmlNode = XMLReader.GetNode(xmlElem, name);
1036 			if (xmlNode == null && compulsory == true)
1037 				throw new ConfigNotFoundException(name);
1038 			else if (xmlNode != null)
1039 			{
1040 				ConfirmBool((XmlElement)xmlNode, "AllFileOps",
1041 				    verbose.AllFileOps, compulsory);
1042 				ConfirmBool((XmlElement)xmlNode, "Deadlock",
1043 				    verbose.Deadlock, compulsory);
1044 				ConfirmBool((XmlElement)xmlNode, "FileOps",
1045 				    verbose.FileOps, compulsory);
1046 				ConfirmBool((XmlElement)xmlNode, "Recovery",
1047 				    verbose.Recovery, compulsory);
1048 				ConfirmBool((XmlElement)xmlNode, "Register",
1049 				    verbose.Register, compulsory);
1050 				ConfirmBool((XmlElement)xmlNode, "Replication",
1051 				    verbose.Replication, compulsory);
1052 				ConfirmBool((XmlElement)xmlNode, "ReplicationElection",
1053 				    verbose.ReplicationElection, compulsory);
1054 				ConfirmBool((XmlElement)xmlNode, "ReplicationLease",
1055 				    verbose.ReplicationLease, compulsory);
1056 				ConfirmBool((XmlElement)xmlNode, "ReplicationMessages",
1057 				    verbose.ReplicationMessages, compulsory);
1058 				ConfirmBool((XmlElement)xmlNode, "ReplicationMisc",
1059 				    verbose.ReplicationMisc, compulsory);
1060 				ConfirmBool((XmlElement)xmlNode, "ReplicationSync",
1061 				    verbose.ReplicationSync, compulsory);
1062 				ConfirmBool((XmlElement)xmlNode, "RepMgrConnectionFailure",
1063 				    verbose.RepMgrConnectionFailure, compulsory);
1064 				ConfirmBool((XmlElement)xmlNode, "RepMgrMisc",
1065 				    verbose.RepMgrMisc, compulsory);
1066 				ConfirmBool((XmlElement)xmlNode,"WaitsForTable",
1067 				    verbose.WaitsForTable, compulsory);
1068 			}
1069 		}
1070 		#endregion Confirm
1071 
dbtFromString(DatabaseEntry dbt, string s)1072 		public static void dbtFromString(DatabaseEntry dbt, string s)
1073 		{
1074 			dbt.Data = System.Text.Encoding.ASCII.GetBytes(s);
1075 		}
1076 
strFromDBT(DatabaseEntry dbt)1077 		public static string strFromDBT(DatabaseEntry dbt)
1078 		{
1079 
1080 			System.Text.ASCIIEncoding decode = new ASCIIEncoding();
1081 			return decode.GetString(dbt.Data);
1082 		}
1083 
1084 		/*
1085 		 * Reading params successfully returns true. Unless returns
1086 		 * false. The retrieved Xml fragment is returning in xmlElem.
1087 		 */
TestSetUp(string testFixtureName, string testName)1088 		public static XmlElement TestSetUp(string testFixtureName, string testName)
1089 		{
1090 			XMLReader xmlReader = new XMLReader("../../../AllTestData.xml");
1091 			XmlElement xmlElem = xmlReader.GetXmlElement(testFixtureName, testName);
1092 			if (xmlElem == null)
1093 				throw new ConfigNotFoundException(testFixtureName + ":" + testName);
1094 			else
1095 				return xmlElem;
1096 		}
1097 
1098 		/*
1099 		 * Delete existing test output directory and its files,
1100 		 * then create a new one.
1101 		 */
ClearDir(string testDir)1102 		public static void ClearDir(string testDir)
1103 		{
1104 			if (Directory.Exists(testDir))
1105 				Directory.Delete(testDir, true);
1106 			Directory.CreateDirectory(testDir);
1107 		}
1108 
RandomString(int max)1109 		public static string RandomString(int max) {
1110 			string text = "";
1111 			int len = random.Next(max);
1112 
1113 			for (int i = 0; i < len; i++)
1114 				text += "a";
1115 
1116 			return text;
1117 		}
1118 	}
1119 }
1120