summaryrefslogtreecommitdiff
path: root/db-4.8.30/test/scr037/DatabaseTest.cs
blob: 07634a67eb25a627aff73c68462c5cd67a068d67 (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
/*-
 * See the file LICENSE for redistribution information.
 *
 * Copyright (c) 2009 Oracle.  All rights reserved.
 *
 */
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml;
using NUnit.Framework;
using BerkeleyDB;

namespace CsharpAPITest
{
	public class DatabaseTest
	{
		public static uint getDefaultCacheSizeBytes()
		{
			uint defaultCacheSizeBytes;

			string fixtureHome = "./TestOut/DatabaseTest";
			string dbName = fixtureHome + "/" + "getDefaultCacheSizeBytes" + ".db";

			Configuration.ClearDir(fixtureHome);

			BTreeDatabaseConfig cfg = new BTreeDatabaseConfig();
			cfg.Creation = CreatePolicy.ALWAYS;
			using (BTreeDatabase db = BTreeDatabase.Open(dbName, cfg))
			{
				defaultCacheSizeBytes = db.CacheSize.Bytes;
			}

			return defaultCacheSizeBytes;
		}

		public static ByteOrder getMachineByteOrder()
		{
			string fixtureHome = "./TestOut/DatabaseTest";
			string dbName = fixtureHome + "/" + "getMachineByteOrder" + ".db";

			Configuration.ClearDir(fixtureHome);

			ByteOrder byteOrder;

			BTreeDatabaseConfig dbConfig = new BTreeDatabaseConfig();
			dbConfig.ByteOrder = ByteOrder.MACHINE;
			dbConfig.Creation = CreatePolicy.ALWAYS;
			using (BTreeDatabase db = BTreeDatabase.Open(dbName, dbConfig))
			{
				byteOrder = db.Endianness;
			}
			return byteOrder;
		}

		public static void Confirm(XmlElement xmlElement, Database db, bool compulsory)
		{
			uint defaultBytes;
			defaultBytes = getDefaultCacheSizeBytes();

			Configuration.ConfirmBool(xmlElement, "AutoCommit",
			     db.AutoCommit, compulsory);
			Configuration.ConfirmCacheSize(xmlElement, "CacheSize",
			    db.CacheSize, defaultBytes, compulsory);
			Configuration.ConfirmCreatePolicy(xmlElement, "Creation",
			    db.Creation, compulsory);
			Configuration.ConfirmString(xmlElement, "DatabaseName",
			    db.DatabaseName, compulsory);
			Configuration.ConfirmBool(xmlElement, "DoChecksum",
			    db.DoChecksum, compulsory);
			// Encrypted and EncryptWithAES?
			Configuration.ConfirmByteOrder(xmlElement, "ByteOrder",
			    db.Endianness, compulsory);
			Configuration.ConfirmString(xmlElement, "ErrorPrefix",
			    db.ErrorPrefix, compulsory);
			// File name is confirmed in functiion, not here.
			Configuration.ConfirmBool(xmlElement, "FreeThreaded",
			    db.FreeThreaded, compulsory);
			Configuration.ConfirmBool(xmlElement, "HasMultiple",
			    db.HasMultiple, compulsory);
			if (db.Endianness == getMachineByteOrder())
				Assert.IsTrue(db.InHostOrder);
			else
				Assert.IsFalse(db.InHostOrder);
			Configuration.ConfirmBool(xmlElement, "NoMMap",
			    db.NoMMap, compulsory);
			Configuration.ConfirmBool(xmlElement, "NonDurableTxns",
			    db.NonDurableTxns, compulsory);
			Configuration.ConfirmUint(xmlElement, "PageSize",
			    db.Pagesize, compulsory);
			Configuration.ConfirmCachePriority(xmlElement,
			    "Priority", db.Priority, compulsory);
			Configuration.ConfirmBool(xmlElement, "ReadOnly",
			    db.ReadOnly, compulsory);
			Configuration.ConfirmBool(xmlElement, "ReadUncommitted",
			    db.ReadUncommitted, compulsory);
			/*
			 * Database.Truncated is the value set in
			 * DatabaseConfig.Truncate.
			 */
			Configuration.ConfirmBool(xmlElement, "Truncate",
			    db.Truncated, compulsory);
			Configuration.ConfirmBool(xmlElement, "UseMVCC",
			    db.UseMVCC, compulsory);
		}
	}

}