forked from cruppstahl/upscaledb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a unittest for issue cruppstahl#105
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
1 parent
80d01b8
commit 68035f7
Showing
4 changed files
with
98 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
issue32 | ||
issue43 | ||
issue101 | ||
issue105 | ||
testdb* | ||
*.o | ||
*.lo | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, ¶ms[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; | ||
} |