Added 'automatic' test/check tool
[eblob.git] / example / eblob_open.cpp
blobc643d13bc777c3e9240a52a2bba8a9aa41c427d8
2 #include <sys/mman.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
6 #include <fcntl.h>
7 #include <stdio.h>
8 #include <string.h>
10 #include <iostream>
11 #include <string>
13 #include <boost/thread.hpp>
14 #include <boost/regex.hpp>
15 #include <boost/iostreams/device/mapped_file.hpp>
17 #include <eblob/eblob.hpp>
19 using namespace zbr;
21 int main(int argc, char *argv[])
23 if (argc < 2) {
24 std::cerr << "Usage: " << argv[0] << " eblob log log_mask" << std::endl;
25 exit(-1);
28 std::string input_blob_name = argv[1];
30 char *log_file = (char *)"/dev/stdout";
31 if (argc > 2)
32 log_file = argv[2];
34 int log_mask = EBLOB_LOG_INFO | EBLOB_LOG_ERROR;
35 if (argc > 3)
36 log_mask = ::strtoul(argv[3], NULL, 0);
38 try {
39 eblob eblob(log_file, log_mask, input_blob_name);
41 struct eblob_key ekey;
42 memset(&ekey, 0, sizeof(ekey));
43 snprintf((char *)ekey.id, sizeof(ekey.id), "test_key");
45 std::string data = "this is supposed to be compressed data";
46 eblob.write(ekey, data, 0, BLOB_DISK_CTL_COMPRESS);
48 std::cout << "read: " << eblob.read(ekey, 0, 0) << std::endl;
50 std::string key = "to-be-hashed-test-key";
52 data = "this is supposed to be compressed data";
53 eblob.write_hashed(key, data, 0, BLOB_DISK_CTL_COMPRESS);
54 std::cout << "read hashed: " << eblob.read_hashed(key, 0, 0) << std::endl;
56 memset(&ekey, 0, sizeof(ekey));
57 snprintf((char *)ekey.id, sizeof(ekey.id), "test_key1");
59 data = "this is a plain uncompressed data1 ";
60 eblob.write(ekey, data, 0, 0);
61 std::cout << "read1: " << eblob.read(ekey, 0, 0) << std::endl;
63 uint64_t offset = data.size();
64 data = "this is a plain uncompressed data2";
65 eblob.write(ekey, data, offset, 0);
66 std::cout << "read2: " << eblob.read(ekey, 5, 0) << std::endl;
68 } catch (const std::exception &e) {
69 std::cerr << e.what() << std::endl;
72 return 0;