forked from estraier/tkrzw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tkrzw_file_std_test.cc
119 lines (98 loc) · 3.12 KB
/
tkrzw_file_std_test.cc
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*************************************************************************************************
* Tests for tkrzw_file_std.h
*
* Copyright 2020 Google LLC
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of the License at
* https://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*************************************************************************************************/
#include "tkrzw_sys_config.h"
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "tkrzw_file.h"
#include "tkrzw_file_std.h"
#include "tkrzw_file_test_common.h"
#include "tkrzw_file_util.h"
#include "tkrzw_lib_common.h"
using namespace testing;
// Main routine
int main(int argc, char** argv) {
InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
class StdFileTest : public CommonFileTest {};
TEST_F(StdFileTest, Attributes) {
tkrzw::StdFile file;
EXPECT_FALSE(file.IsMemoryMapping());
EXPECT_TRUE(file.IsAtomic());
}
TEST_F(StdFileTest, EmptyFile) {
tkrzw::StdFile file;
EmptyFileTest(&file);
}
TEST_F(StdFileTest, SimpleRead) {
tkrzw::StdFile file;
SimpleReadTest(&file);
}
TEST_F(StdFileTest, SimpleWrite) {
tkrzw::StdFile file;
SimpleWriteTest(&file);
}
TEST_F(StdFileTest, ReallocWrite) {
tkrzw::StdFile file;
ReallocWriteTest(&file);
}
TEST_F(StdFileTest, Truncate) {
tkrzw::StdFile file;
TruncateTest(&file);
}
TEST_F(StdFileTest, ImplicitClose) {
tkrzw::StdFile file;
ImplicitCloseTest(&file);
}
TEST_F(StdFileTest, OpenOptions) {
tkrzw::StdFile file;
OpenOptionsTest(&file);
}
TEST_F(StdFileTest, OrderedThread) {
tkrzw::StdFile file;
OrderedThreadTest(&file);
}
TEST_F(StdFileTest, RandomThread) {
tkrzw::StdFile file;
RandomThreadTest(&file);
}
TEST_F(StdFileTest, FileReader) {
tkrzw::StdFile file;
FileReaderTest(&file);
}
TEST_F(StdFileTest, FlatRecord) {
tkrzw::StdFile file;
FlatRecordTest(&file);
}
TEST_F(StdFileTest, Rename) {
tkrzw::StdFile file;
RenameTest(&file);
}
TEST_F(StdFileTest, CriticalSection) {
tkrzw::TemporaryDirectory tmp_dir(true, "tkrzw-");
const std::string file_path = tmp_dir.MakeUniquePath();
tkrzw::StdFile file;
EXPECT_EQ(-1, file.Lock());
EXPECT_EQ(-1, file.Unlock());
EXPECT_EQ(tkrzw::Status::SUCCESS, file.Open(file_path, true, tkrzw::File::OPEN_TRUNCATE));
EXPECT_EQ(tkrzw::Status::SUCCESS, file.Write(0, "abc", 3));
EXPECT_EQ(3, file.Lock());
EXPECT_EQ(tkrzw::Status::SUCCESS, file.WriteInCriticalSection(2, "xyz", 3));
EXPECT_EQ(tkrzw::Status::SUCCESS, file.WriteInCriticalSection(5, "123", 3));
char buf[8];
EXPECT_EQ(tkrzw::Status::SUCCESS, file.ReadInCriticalSection(0, buf, 8));
EXPECT_EQ("abxyz123", std::string(buf, 8));
EXPECT_EQ(8, file.Unlock());
EXPECT_EQ(tkrzw::Status::SUCCESS, file.Close());
}
// END OF FILE