forked from baidu/braft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_protobuf_file.cpp
59 lines (48 loc) · 1.34 KB
/
test_protobuf_file.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* =====================================================================================
*
* Filename: test_protobuf_file.cpp
*
* Description:
*
* Version: 1.0
* Created: 2015/09/22 19:48:31
* Revision: none
* Compiler: gcc
*
* Author: WangYao (fisherman), [email protected]
* Company: Baidu, Inc
*
* =====================================================================================
*/
#include <gtest/gtest.h>
#include "braft/local_storage.pb.h"
#include "braft/protobuf_file.h"
class TestUsageSuits : public testing::Test {
protected:
void SetUp() {}
void TearDown() {}
};
TEST_F(TestUsageSuits, protobuf_file) {
int ret = 0;
braft::ProtoBufFile pb_file("./log.meta");
braft::LogPBMeta meta;
meta.set_first_log_index(1234);
ret = pb_file.save(static_cast<google::protobuf::Message*>(&meta), false);
ASSERT_EQ(ret, 0);
{
braft::LogPBMeta new_meta;
ret = pb_file.load(&new_meta);
ASSERT_EQ(ret, 0);
ASSERT_EQ(new_meta.first_log_index(), 1234);
}
ret = pb_file.save(&meta, true);
ASSERT_EQ(ret, 0);
{
braft::LogPBMeta new_meta;
ret = pb_file.load(&new_meta);
ASSERT_EQ(ret, 0);
ASSERT_EQ(new_meta.first_log_index(), 1234);
new_meta.PrintDebugString();
}
}