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
|
/*-
* 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
{
[TestFixture]
public class RecnoDatabaseConfigTest : DatabaseConfigTest
{
private string testFixtureHome;
private string testFixtureName;
private string testName;
private string testHome;
[TestFixtureSetUp]
public void RunBeforeTests()
{
testFixtureName = "RecnoDatabaseConfigTest";
testFixtureHome = "./TestOut/" + testFixtureName;
Configuration.ClearDir(testFixtureHome);
}
[Test]
override public void TestConfigWithoutEnv()
{
testName = "TestConfigWithoutEnv";
XmlElement xmlElem = Configuration.TestSetUp(
testFixtureName, testName);
RecnoDatabaseConfig recnoDBConfig =
new RecnoDatabaseConfig();
Config(xmlElem, ref recnoDBConfig, true);
Confirm(xmlElem, recnoDBConfig, true);
}
[Test]
public void TestAppend()
{
uint recno;
testName = "TestAppend";
testHome = testFixtureHome + "/" + testName;
string dbFileName = testHome + "/" + testName + ".db";
Configuration.ClearDir(testHome);
RecnoDatabaseConfig recnoConfig =
new RecnoDatabaseConfig();
recnoConfig.Creation = CreatePolicy.IF_NEEDED;
recnoConfig.Append = new AppendRecordDelegate(
AppendRecord);
RecnoDatabase recnoDB = RecnoDatabase.Open(
dbFileName, recnoConfig);
recno = recnoDB.Append(new DatabaseEntry(
ASCIIEncoding.ASCII.GetBytes("data")));
KeyValuePair<DatabaseEntry, DatabaseEntry> pair;
pair = recnoDB.Get(
new DatabaseEntry(BitConverter.GetBytes(recno)));
Assert.AreEqual(ASCIIEncoding.ASCII.GetBytes("data"),
pair.Value.Data);
recnoDB.Close();
}
public void AppendRecord(DatabaseEntry data, uint recno)
{
data.Data = BitConverter.GetBytes(recno);
}
public static void Confirm(XmlElement xmlElement,
RecnoDatabaseConfig recnoDBConfig, bool compulsory)
{
DatabaseConfig dbConfig = recnoDBConfig;
Confirm(xmlElement, dbConfig, compulsory);
// Confirm Recno database specific configuration
Configuration.ConfirmString(xmlElement, "BackingFile",
recnoDBConfig.BackingFile, compulsory);
Configuration.ConfirmCreatePolicy(xmlElement,
"Creation", recnoDBConfig.Creation, compulsory);
Configuration.ConfirmInt(xmlElement, "Delimiter",
recnoDBConfig.Delimiter, compulsory);
Configuration.ConfirmUint(xmlElement, "Length",
recnoDBConfig.Length, compulsory);
Configuration.ConfirmInt(xmlElement, "PadByte",
recnoDBConfig.PadByte, compulsory);
Configuration.ConfirmBool(xmlElement, "Renumber",
recnoDBConfig.Renumber, compulsory);
Configuration.ConfirmBool(xmlElement, "Snapshot",
recnoDBConfig.Snapshot, compulsory);
}
public static void Config(XmlElement xmlElement,
ref RecnoDatabaseConfig recnoDBConfig, bool compulsory)
{
int intValue = new int();
uint uintValue = new uint();
DatabaseConfig dbConfig = recnoDBConfig;
Config(xmlElement, ref dbConfig, compulsory);
// Configure specific fields/properties of Recno database
Configuration.ConfigCreatePolicy(xmlElement, "Creation",
ref recnoDBConfig.Creation, compulsory);
if (Configuration.ConfigInt(xmlElement, "Delimiter",
ref intValue, compulsory))
recnoDBConfig.Delimiter = intValue;
if (Configuration.ConfigUint(xmlElement, "Length",
ref uintValue, compulsory))
recnoDBConfig.Length = uintValue;
if (Configuration.ConfigInt(xmlElement, "PadByte",
ref intValue, compulsory))
recnoDBConfig.PadByte = intValue;
Configuration.ConfigBool(xmlElement, "Renumber",
ref recnoDBConfig.Renumber, compulsory);
Configuration.ConfigBool(xmlElement, "Snapshot",
ref recnoDBConfig.Snapshot, compulsory);
}
}
}
|