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
|
#include "../../testing/testing.hpp"
#include "../internal/file_data.hpp"
#include "../writer.hpp"
#include "../../base/logging.hpp"
namespace
{
string const name1 = "test1.file";
string const name2 = "test2.file";
void MakeFile(string const & name)
{
my::FileData f(name, my::FileData::OP_WRITE_TRUNCATE);
f.Write(name.c_str(), name.size());
}
void CheckFileOK(string const & name)
{
my::FileData f(name, my::FileData::OP_READ);
uint64_t const size = f.Size();
TEST_EQUAL ( size, name.size(), () );
vector<char> buffer(size);
f.Read(0, &buffer[0], size);
TEST ( equal(name.begin(), name.end(), buffer.begin()), () );
}
}
UNIT_TEST(FileData_ApiSmoke)
{
MakeFile(name1);
uint64_t const size = name1.size();
uint64_t sz;
TEST(my::GetFileSize(name1, sz), ());
TEST_EQUAL(sz, size, ());
TEST(my::RenameFileX(name1, name2), ());
TEST(!my::GetFileSize(name1, sz), ());
TEST(my::GetFileSize(name2, sz), ());
TEST_EQUAL(sz, size, ());
TEST(my::DeleteFileX(name2), ());
TEST(!my::GetFileSize(name2, sz), ());
}
/*
UNIT_TEST(FileData_NoDiskSpace)
{
char const * name = "/Volumes/KINDLE/file.bin";
vector<uint8_t> bytes(100000000);
try
{
my::FileData f(name, my::FileData::OP_WRITE_TRUNCATE);
for (size_t i = 0; i < 100; ++i)
f.Write(&bytes[0], bytes.size());
}
catch (Writer::Exception const & ex)
{
LOG(LINFO, ("Writer exception catched"));
}
(void)my::DeleteFileX(name);
}
*/
#ifdef OMIM_OS_WINDOWS
UNIT_TEST(FileData_SharingAV_Windows)
{
{
MakeFile(name1);
// lock file, will check sharing access
my::FileData f1(name1, my::FileData::OP_READ);
// try rename or delete locked file
TEST(!my::RenameFileX(name1, name2), ());
TEST(!my::DeleteFileX(name1), ());
MakeFile(name2);
// try rename or copy to locked file
TEST(!my::RenameFileX(name2, name1), ());
TEST(!my::CopyFile(name2, name1), ());
// files should be unchanged
CheckFileOK(name1);
CheckFileOK(name2);
//TEST(my::CopyFile(name1, name2), ());
}
// renaming to existing file is not allowed
TEST(!my::RenameFileX(name1, name2), ());
TEST(!my::RenameFileX(name2, name1), ());
TEST(my::DeleteFileX(name1), ());
TEST(my::DeleteFileX(name2), ());
}
#endif
|