Skip to content

Commit

Permalink
Added a unittest for issue cruppstahl#105
Browse files Browse the repository at this point in the history
Added unittests/issue105.cc as a slightly modified copy of the code
from the description of issue cruppstahl#105 of the upstream repo (the only
change is the correct exit status of the test program).

Also added issue101 and issue105 to the list of tests executed
by 'make test'
  • Loading branch information
veloman-yunkan committed Sep 5, 2018
1 parent 80d01b8 commit 68035f7
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 4 deletions.
11 changes: 9 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,20 @@ doc documentation/html:
VERSION=$(VERSION) ; \
export VERSION; \
doxygen documentation/Doxyfile


html-dist: doc
tar cvzf upscaledb-html-documentation.$(VERSION).tar.gz documentation/html

test:
cd unittests && make && ./test && ./issue32 -i && ./issue32 -r && ./issue43
cd unittests && \
make && \
./test && \
./issue32 -i && \
./issue32 -r && \
./issue43 && \
./issue101 && \
./issue105
if ENABLE_JAVA
cd java && make test
endif
Expand Down
2 changes: 2 additions & 0 deletions unittests/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
issue32
issue43
issue101
issue105
testdb*
*.o
*.lo
Expand Down
7 changes: 5 additions & 2 deletions unittests/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
noinst_PROGRAMS = test recovery issue32 issue43 issue101
noinst_BIN = test recovery issue32 issue43 issue101
noinst_PROGRAMS = test recovery issue32 issue43 issue101 issue105
noinst_BIN = test recovery issue32 issue43 issue101 issue105

EXTRA_DIST = recovery.pl valgrind.supp data/* plugin.cc

Expand Down Expand Up @@ -105,5 +105,8 @@ issue43_LDADD = $(top_builddir)/src/libupscaledb.la
issue101_SOURCES = issue101.cc
issue101_LDADD = $(top_builddir)/src/libupscaledb.la

issue105_SOURCES = issue105.cc
issue105_LDADD = $(top_builddir)/src/libupscaledb.la

plugin: plugin.cc
$(CXX) -fPIC -shared -o plugin.so plugin.cc $(AM_CPPFLAGS)
82 changes: 82 additions & 0 deletions unittests/issue105.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright (C) 2005-2016 Christoph Rupp ([email protected]).
* All Rights Reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* See the file COPYING for License information.
*/

#include <iostream>
#include <ups/upscaledb.hpp>

int main()
{
ups_env_t* env;
ups_env_create(&env, "test.db", UPS_ENABLE_TRANSACTIONS, 0664, 0);
//ups_env_create(&env, "test.db", 0, 0664, 0);

ups_parameter_t params[] = {
{UPS_PARAM_KEY_TYPE, UPS_TYPE_UINT32},
{0, }
};

ups_db_t* db;
ups_env_create_db(env, &db, 1, 0, &params[0]);

const int item_count = 50;

for (int i = 0; i < item_count; i++)
{
ups_key_t key = ups_make_key(&i, sizeof(i));
ups_record_t record = {0};

ups_db_insert(db, 0, &key, &record, 0);
}

for(int i = 0; i < item_count / 2; i++)
{
ups_key_t key = ups_make_key(&i, sizeof(i));

ups_db_erase(db, 0, &key, 0);
}

uint64_t count = 0;
ups_db_count(db,0, 0, &count);

size_t error_count = 0;
if(count != item_count / 2){
std::cerr << "Item count after delete: " << count << std::endl;
++error_count;
}

for(int i = 0; i < item_count / 2; i++)
{
ups_key_t key = ups_make_key(&i, sizeof(i));
ups_record_t record = {0};

ups_cursor_t* cursor;
ups_cursor_create(&cursor, db, 0, 0);
ups_status_t st = ups_cursor_find(cursor, &key, &record, UPS_FIND_GEQ_MATCH);
//ups_status_t st = ups_db_find(db, 0, &key, &record, UPS_FIND_GEQ_MATCH);

if(st == UPS_SUCCESS && *reinterpret_cast<int*>(key.data) == i){
std::cerr << "Found deleted item: " << i << std::endl;
++error_count;
}

ups_cursor_close(cursor);
}

ups_db_close(db, 0);

return error_count;
}

0 comments on commit 68035f7

Please sign in to comment.