summaryrefslogtreecommitdiff
path: root/db-4.8.30/test/scr025
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2016-12-17 21:28:53 -0800
committerJesse Morgan <jesse@jesterpm.net>2016-12-17 21:28:53 -0800
commit54df2afaa61c6a03cbb4a33c9b90fa572b6d07b8 (patch)
tree18147b92b969d25ffbe61935fb63035cac820dd0 /db-4.8.30/test/scr025
Berkeley DB 4.8 with rust build script for linux.
Diffstat (limited to 'db-4.8.30/test/scr025')
-rw-r--r--db-4.8.30/test/scr025/TestMulti.cpp206
-rw-r--r--db-4.8.30/test/scr025/chk.cxxmulti69
-rw-r--r--db-4.8.30/test/scr025/ignore4
3 files changed, 279 insertions, 0 deletions
diff --git a/db-4.8.30/test/scr025/TestMulti.cpp b/db-4.8.30/test/scr025/TestMulti.cpp
new file mode 100644
index 0000000..045380c
--- /dev/null
+++ b/db-4.8.30/test/scr025/TestMulti.cpp
@@ -0,0 +1,206 @@
+/*-
+ * See the file LICENSE for redistribution information.
+ *
+ * Copyright (c) 2002-2009 Oracle. All rights reserved.
+ */
+
+#include "db_cxx.h"
+#include "stdlib.h"
+
+void test1()
+{
+ int numberOfKeysToWrite= 10000;
+ Db db(0,DB_CXX_NO_EXCEPTIONS);
+ db.set_pagesize(512);
+ int err= db.open(0, "test1.db", 0, DB_BTREE, DB_CREATE, 0);
+ {
+ int i= 0;
+ Dbt key(&i,sizeof(i));
+ Dbt data(&i,sizeof(i));
+ for(;i<numberOfKeysToWrite;++i)
+ {
+ db.put(0,&key,&data,0);
+ }
+ }
+
+ {
+ Dbc *dbc;
+ err= db.cursor(0,&dbc,0);
+
+ char *check= (char*)calloc(numberOfKeysToWrite,1);
+ char buffer[8192];
+ int numberOfKeysRead= 0;
+ Dbt multikey(&numberOfKeysRead,sizeof(numberOfKeysRead));
+ Dbt multidata(&buffer,sizeof(buffer));
+ multidata.set_flags(DB_DBT_USERMEM);
+ multidata.set_ulen(sizeof(buffer));
+ err= 0;
+ while(err==0)
+ {
+ err= dbc->get(&multikey,&multidata,DB_NEXT|DB_MULTIPLE_KEY);
+ if(err==0)
+ {
+ Dbt key, data;
+ DbMultipleKeyDataIterator i(multidata);
+ while(err==0 && i.next(key,data))
+ {
+ int actualKey= *((int*)key.get_data());
+ int actualData= *((int*)data.get_data());
+ if(actualKey!=actualData)
+ {
+ std::cout << "Error: key/data mismatch. " << actualKey << "!=" << actualData << std::endl;
+ err= -1;
+ }
+ else
+ {
+ check[actualKey]++;
+ }
+ numberOfKeysRead++;
+ }
+ } else if(err!=DB_NOTFOUND)
+ std::cout << "Error: dbc->get: " << db_strerror(err) << std::endl;
+ }
+ if(numberOfKeysRead!=numberOfKeysToWrite)
+ {
+ std::cout << "Error: key count mismatch. " << numberOfKeysRead << "!=" << numberOfKeysToWrite << std::endl;
+ }
+ for(int n=0;n<numberOfKeysToWrite;++n)
+ {
+ if(check[n]!=1)
+ {
+ std::cout << "Error: key " << n << " was written to the database, but not read back." << std::endl;
+ }
+ }
+ free(check);
+ dbc->close();
+ }
+
+ db.close(0);
+}
+
+void test2()
+{
+ int numberOfKeysToWrite= 10000;
+ Db db(0,DB_CXX_NO_EXCEPTIONS);
+ db.set_flags(DB_DUP);
+ db.set_pagesize(512);
+ int err= db.open(0, "test2.db", 0, DB_BTREE, DB_CREATE, 0);
+
+ {
+ int i= 0;
+ int k= 0;
+ Dbt key(&k,sizeof(k));
+ Dbt data(&i,sizeof(i));
+ for(;i<numberOfKeysToWrite;++i)
+ {
+ err= db.put(0,&key,&data,0);
+ }
+ }
+
+ {
+ Dbc *dbc;
+ err= db.cursor(0,&dbc,0);
+
+ char buffer[8192];
+ int numberOfKeysRead= 0;
+ Dbt multikey(&numberOfKeysRead,sizeof(numberOfKeysRead));
+ Dbt multidata(&buffer,sizeof(buffer));
+ multidata.set_flags(DB_DBT_USERMEM);
+ multidata.set_ulen(sizeof(buffer));
+ err= 0;
+ while(err==0)
+ {
+ err= dbc->get(&multikey,&multidata,DB_NEXT|DB_MULTIPLE);
+ if(err==0)
+ {
+ Dbt data;
+ DbMultipleDataIterator i(multidata);
+ while(err==0 && i.next(data))
+ {
+ int actualData= *((int*)data.get_data());
+ if(numberOfKeysRead!=actualData)
+ {
+ std::cout << "Error: key/data mismatch. " << numberOfKeysRead << "!=" << actualData << std::endl;
+ err= -1;
+ }
+ numberOfKeysRead++;
+ }
+ } else if(err!=DB_NOTFOUND)
+ std::cout << "Error: dbc->get: " << db_strerror(err) << std::endl;
+ }
+ if(numberOfKeysRead!=numberOfKeysToWrite)
+ {
+ std::cout << "Error: key count mismatch. " << numberOfKeysRead << "!=" << numberOfKeysToWrite << std::endl;
+ }
+ dbc->close();
+ }
+ db.close(0);
+}
+
+void test3()
+{
+ int numberOfKeysToWrite= 10000;
+ Db db(0,DB_CXX_NO_EXCEPTIONS);
+ db.set_pagesize(512);
+ int err= db.open(0, "test3.db", 0, DB_RECNO, DB_CREATE, 0);
+
+ {
+ int i= 0;
+ Dbt key;
+ Dbt data(&i,sizeof(i));
+ for(;i<numberOfKeysToWrite;++i)
+ {
+ err= db.put(0,&key,&data,DB_APPEND);
+ }
+ }
+
+ {
+ Dbc *dbc;
+ err= db.cursor(0,&dbc,0);
+
+ char buffer[8192];
+ int numberOfKeysRead= 0;
+ Dbt multikey(&numberOfKeysRead,sizeof(numberOfKeysRead));
+ Dbt multidata(&buffer,sizeof(buffer));
+ multidata.set_flags(DB_DBT_USERMEM);
+ multidata.set_ulen(sizeof(buffer));
+ err= 0;
+ while(err==0)
+ {
+ err= dbc->get(&multikey,&multidata,DB_NEXT|DB_MULTIPLE_KEY);
+ if(err==0)
+ {
+ u_int32_t recno= 0;
+ Dbt data;
+ DbMultipleRecnoDataIterator i(multidata);
+ while(err==0 && i.next(recno,data))
+ {
+ int actualData= *((int*)data.get_data());
+ if(recno!=actualData+1)
+ {
+ std::cout << "Error: recno/data mismatch. " << recno << "!=" << actualData << "+1" << std::endl;
+ err= -1;
+ }
+ numberOfKeysRead++;
+ }
+ } else if(err!=DB_NOTFOUND)
+ std::cout << "Error: dbc->get: " << db_strerror(err) << std::endl;
+ }
+ if(numberOfKeysRead!=numberOfKeysToWrite)
+ {
+ std::cout << "Error: key count mismatch. " << numberOfKeysRead << "!=" << numberOfKeysToWrite << std::endl;
+ }
+ dbc->close();
+ }
+
+ db.close(0);
+}
+
+int main()
+{
+ test1();
+ test2();
+ test3();
+ return (0);
+}
+
diff --git a/db-4.8.30/test/scr025/chk.cxxmulti b/db-4.8.30/test/scr025/chk.cxxmulti
new file mode 100644
index 0000000..26d9393
--- /dev/null
+++ b/db-4.8.30/test/scr025/chk.cxxmulti
@@ -0,0 +1,69 @@
+#!/bin/sh -
+#
+# $Id$
+#
+# Check to make sure that regression tests for C++ run.
+
+TEST_CXX_SRCDIR=../test/scr025 # must be a relative directory
+
+# All paths must be relative to a subdirectory of the build directory
+LIBS="-L.. -ldb -ldb_cxx"
+CXXFLAGS="-I.. -I../../dbinc"
+
+[ `uname` = "Linux" ] && LIBS="$LIBS -lpthread"
+
+# Test must be run from a local build directory, not from a test
+# directory.
+cd ..
+[ -f db_config.h ] || {
+ echo 'FAIL: chk.cxxtests must be run from a local build directory.'
+ exit 1
+}
+[ -f libdb.a ] || make libdb.a || {
+ echo 'FAIL: unable to build libdb.a'
+ exit 1
+}
+[ -f libdb_cxx.a ] || make libdb_cxx.a || {
+ echo 'FAIL: unable to build libdb_cxx.a'
+ exit 1
+}
+CXX=`sed -e '/^CXX=/!d' -e 's/^CXX=//' -e 's/.*mode=compile *//' Makefile`
+echo " ====== cxx tests using $CXX"
+testnames=`cd $TEST_CXX_SRCDIR; ls *.cpp | sed -e 's/\.cpp$//'`
+
+for testname in $testnames; do
+ if grep -x $testname $TEST_CXX_SRCDIR/ignore > /dev/null; then
+ echo " **** cxx test $testname ignored"
+ continue
+ fi
+
+ echo " ==== cxx test $testname"
+ rm -rf TESTCXX; mkdir TESTCXX
+ cd ./TESTCXX
+ testprefix=../$TEST_CXX_SRCDIR/$testname
+
+ ${CXX} ${CXXFLAGS} -o $testname $testprefix.cpp ${LIBS} > ../$testname.compileout 2>&1 || {
+ echo "FAIL: compilation of $testname failed, see ../$testname.compileout"
+ exit 1
+ }
+ rm -f ../$testname.compileout
+ infile=$testprefix.testin
+ [ -f $infile ] || infile=/dev/null
+ goodoutfile=$testprefix.testout
+ [ -f $goodoutfile ] || goodoutfile=/dev/null
+ gooderrfile=$testprefix.testerr
+ [ -f $gooderrfile ] || gooderrfile=/dev/null
+ ./$testname <$infile >../$testname.out 2>../$testname.err
+ cmp ../$testname.out $goodoutfile > /dev/null || {
+ echo "FAIL: $testname output differs: see ../$testname.out, $goodoutfile"
+ exit 1
+ }
+ cmp ../$testname.err $gooderrfile > /dev/null || {
+ echo "FAIL: $testname error differs: see ../$testname.err, $gooderrfile"
+ exit 1
+ }
+ cd ..
+ rm -f $testname.err $testname.out
+done
+rm -rf TESTCXX
+exit 0
diff --git a/db-4.8.30/test/scr025/ignore b/db-4.8.30/test/scr025/ignore
new file mode 100644
index 0000000..bcd98b5
--- /dev/null
+++ b/db-4.8.30/test/scr025/ignore
@@ -0,0 +1,4 @@
+#
+# $Id$
+#
+# A list of tests to ignore