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
|
#!/bin/sh
exec smbscript "$0" ${1+"$@"}
/*
demonstrate access to ldb databases from ejs
*/
var ldb = ldb_init();
function basic_tests(ldb)
{
println("Running basic tests");
ok = ldb.add("
dn: cn=x,cn=test
objectClass: foo
x: 3
");
assert(ok);
println("Testing ldb.search");
var res = ldb.search("(objectClass=*)");
assert(res[0].objectClass[0] == "foo");
assert(res[0].dn == "cn=x,cn=test");
assert(res[0].x == 3);
ok = ldb.add("
dn: cn=x2,cn=test
objectClass: foo
x: 4
");
assert(ok);
var attrs = new Array("x");
res = ldb.search("x=4", NULL, ldb.SCOPE_DEFAULT, attrs);
assert(res[0].x == 4);
assert(res[0].objectClass == undefined);
assert(res[0].dn == "cn=x2,cn=test");
ok = ldb.del("cn=x,cn=test");
assert(ok);
ok = ldb.rename("cn=x2,cn=test", "cn=x3,cn=test");
assert(ok);
res = ldb.search("x=4", NULL, ldb.SCOPE_DEFAULT, attrs);
assert(res[0].dn == "cn=x3,cn=test");
ok = ldb.modify("
dn: cn=x3,cn=test
changetype: modify
add: x
x: 7
");
res = ldb.search("x=7");
assert(res.length == 1);
assert(res[0].x.length == 2);
}
sys_init(ldb);
var dbfile = "test.ldb";
ldb.unlink(dbfile);
var ok = ldb.connect("tdb://" + dbfile);
assert(ok);
basic_tests(ldb);
ldb.unlink(dbfile);
return 0;
|