Porównaj commity

...

1 Commity

Autor SHA1 Wiadomość Data
  Arcueid 0b3316e485 append basic io test for baseline 2 tygodni temu
3 zmienionych plików z 80 dodań i 7 usunięć
  1. +0
    -7
      .idea/misc.xml
  2. +5
    -0
      CMakeLists.txt
  3. +75
    -0
      test/test_basicio.cc

+ 0
- 7
.idea/misc.xml Wyświetl plik

@ -1,12 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="BackendCodeEditorMiscSettings">
<option name="/Default/RiderDebugger/RiderRestoreDecompile/RestoreDecompileSetting/@EntryValue" value="false" type="bool" />
<option name="/Default/Housekeeping/GlobalSettingsUpgraded/IsUpgraded/@EntryValue" value="true" type="bool" />
<option name="/Default/Housekeeping/FeatureSuggestion/FeatureSuggestionManager/DisabledSuggesters/=SwitchToGoToActionSuggester/@EntryIndexedValue" value="true" type="bool" />
<option name="/Default/Housekeeping/FeatureSuggestion/FeatureSuggestionManager/DisabledSuggesters/=SwitchToGoToActionSuggester/@EntryIndexRemoved" />
<option name="/Default/Environment/Hierarchy/GeneratedFilesCacheKey/Timestamp/@EntryValue" value="5" type="long" />
</component>
<component name="CMakePythonSetting">
<option name="pythonIntegrationState" value="YES" />
</component>

+ 5
- 0
CMakeLists.txt Wyświetl plik

@ -524,3 +524,8 @@ add_executable(test_fields
"${PROJECT_SOURCE_DIR}/test/test_fields.cc"
)
target_link_libraries(test_fields PRIVATE leveldb gtest)
add_executable(test_basicio
"${PROJECT_SOURCE_DIR}/test/test_basicio.cc"
)
target_link_libraries(test_basicio PRIVATE leveldb gtest)

+ 75
- 0
test/test_basicio.cc Wyświetl plik

@ -0,0 +1,75 @@
#include "gtest/gtest.h"
#include "leveldb/env.h"
#include "leveldb/db.h"
using namespace leveldb;
constexpr int value_size = 2048;
constexpr int data_size = 128 << 20;
std::map<std::string, std::string> data;
Status OpenDB(std::string dbName, DB **db) {
Options options;
options.create_if_missing = true;
return DB::Open(options, dbName, db);
}
void InsertData(DB *db) {
WriteOptions writeOptions;
int key_num = data_size / value_size;
srand(0);
for (int i = 0; i < key_num; i++) {
int key_ = rand() % key_num+1;
std::string key = std::to_string(key_);
std::string value(value_size, 'a');
db->Put(writeOptions, key, value);
data[key] = value;
}
}
TEST(TestBasicIO, PointGet) {
DB *db;
if(OpenDB("testdb", &db).ok() == false) {
std::cerr << "open db failed" << std::endl;
abort();
}
data.clear();
InsertData(db);
ReadOptions readOptions;
for (auto iter = data.begin(); iter != data.end(); ++iter) {
std::string value;
db->Get(readOptions, iter->first, &value);
ASSERT_TRUE(value == iter->second);
}
delete db;
}
TEST(TestBasicIO, RangeQuery) {
DB *db;
if(OpenDB("testdb", &db).ok() == false) {
std::cerr << "open db failed" << std::endl;
abort();
}
data.clear();
InsertData(db);
ReadOptions readOptions;
auto iter = db->NewIterator(readOptions);
iter->SeekToFirst();
while (iter->Valid()) {
ASSERT_TRUE(data[iter->key().ToString()] == iter->fields()["1"]);
iter->Next();
}
}
int main(int argc, char **argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

Ładowanie…
Anuluj
Zapisz