@@ -91,13 +91,25 @@ struct SGlobalFixture
91
91
92
92
static bool IsSFTP () { return type == SFTP; }
93
93
94
- static unique_ptr<iostream> CreateStream (const string& path)
94
+ static unique_ptr<iostream> CreateStream (const string& path, const string& file = {}, size_t offset = 0 , bool upload = false )
95
95
{
96
96
if (auto sftp_session = get_if<SFTP>(&session)) {
97
- return make_unique<CSFTP_Stream>(*sftp_session, path);
97
+ if (file.empty ()) {
98
+ return make_unique<CSFTP_Stream>(*sftp_session, path);
99
+ } else if (upload) {
100
+ return make_unique<CSFTP_UploadStream>(*sftp_session, file, offset, path);
101
+ } else {
102
+ return make_unique<CSFTP_DownloadStream>(*sftp_session, file, offset, path);
103
+ }
98
104
99
105
} else if (auto cred = get_if<FTP>(&session)) {
100
- return make_unique<CConn_FtpStream>(" ftp-private.ncbi.nlm.nih.gov" , cred->first , cred->second , path);
106
+ if (file.empty ()) {
107
+ return make_unique<CConn_FtpStream>(" ftp-private.ncbi.nlm.nih.gov" , cred->first , cred->second , path);
108
+ } else if (upload) {
109
+ return make_unique<CConn_FTPUploadStream>(" ftp-private.ncbi.nlm.nih.gov" , cred->first , cred->second , file, path, 0 , 0 , offset);
110
+ } else {
111
+ return make_unique<CConn_FTPDownloadStream>(" ftp-private.ncbi.nlm.nih.gov" , file, cred->first , cred->second , path, 0 , 0 , nullptr , offset);
112
+ }
101
113
102
114
} else {
103
115
BOOST_FAIL (" Unknown stream type requested" );
@@ -126,35 +138,49 @@ struct SDefaultDirFixture
126
138
}
127
139
128
140
template <class ... TArgs>
129
- void Test (string_view command, TArgs&&... args)
141
+ void Test (iostream& s, string_view command, TArgs&&... args)
130
142
{
131
143
BOOST_TEST_INFO_SCOPE (command);
132
- stream << command << endl;
133
- x_Test (std::forward<TArgs>(args)...);
134
- stream.clear ();
144
+ s << command << endl;
145
+ x_Test (s, std::forward<TArgs>(args)...);
146
+ s.clear ();
147
+ }
148
+
149
+ template <class ... TArgs>
150
+ void Test (string_view command, TArgs&&... args)
151
+ {
152
+ Test (stream, command, std::forward<TArgs>(args)...);
153
+ }
154
+
155
+ template <class ... TArgs>
156
+ void TestNoCommand (iostream& s, TArgs&&... args)
157
+ {
158
+ BOOST_TEST_INFO_SCOPE (" No command" );
159
+ x_Test (s, std::forward<TArgs>(args)...);
160
+ s.clear ();
135
161
}
136
162
137
163
private:
138
- void x_Test ()
164
+ void x_Test (iostream& s )
139
165
{
140
- BOOST_CHECK (!getline (stream , line));
141
- BOOST_CHECK_EQUAL (stream .rdstate (), ios_base::failbit | ios_base::eofbit);
166
+ BOOST_CHECK (!getline (s , line));
167
+ BOOST_CHECK_EQUAL (s .rdstate (), ios_base::failbit | ios_base::eofbit);
142
168
}
143
169
144
- void x_Test (string_view expected)
170
+ void x_Test (iostream& s, string_view expected)
145
171
{
146
172
BOOST_TEST_INFO_SCOPE (" With expected=" << expected);
147
- BOOST_CHECK (getline (stream , line));
173
+ BOOST_CHECK (getline (s , line));
148
174
BOOST_CHECK_EQUAL (line, expected);
149
- BOOST_CHECK (!getline (stream , line));
150
- BOOST_CHECK_EQUAL (stream .rdstate (), ios_base::failbit | ios_base::eofbit);
175
+ BOOST_CHECK (!getline (s , line));
176
+ BOOST_CHECK_EQUAL (s .rdstate (), ios_base::failbit | ios_base::eofbit);
151
177
}
152
178
153
- void x_Test (set<string> expected)
179
+ void x_Test (iostream& s, set<string> expected)
154
180
{
155
181
set<string> actual;
156
182
157
- while (getline (stream , line)) {
183
+ while (getline (s , line)) {
158
184
if (line.back () == ' \r ' ) {
159
185
line.replace (line.size () - 1 , 1 , " \\ r" sv);
160
186
}
@@ -163,20 +189,20 @@ struct SDefaultDirFixture
163
189
}
164
190
165
191
BOOST_CHECK_EQUAL_COLLECTIONS (actual.begin (), actual.end (), expected.begin (), expected.end ());
166
- BOOST_CHECK_EQUAL (stream .rdstate (), ios_base::failbit | ios_base::eofbit);
192
+ BOOST_CHECK_EQUAL (s .rdstate (), ios_base::failbit | ios_base::eofbit);
167
193
}
168
194
169
195
template <class TExpected >
170
- void x_Test (array<TExpected, 2 > expected)
196
+ void x_Test (iostream& s, array<TExpected, 2 > expected)
171
197
{
172
- x_Test (expected[SGlobalFixture::IsSFTP () ? 0 : 1 ]);
198
+ x_Test (s, expected[SGlobalFixture::IsSFTP () ? 0 : 1 ]);
173
199
}
174
200
175
- void x_Test (string_view data, string_view expected)
201
+ void x_Test (iostream& s, string_view data, string_view expected)
176
202
{
177
203
BOOST_TEST_INFO_SCOPE (" With data=" << data);
178
- stream << data;
179
- x_Test (expected);
204
+ s << data;
205
+ x_Test (s, expected);
180
206
}
181
207
};
182
208
@@ -229,9 +255,11 @@ BOOST_AUTO_TEST_CASE(FilesAndDirs)
229
255
Test (" RETR file1" , " 00000000000000000000" );
230
256
Test (" STOR file1" , " 111111111" , " 9" );
231
257
Test (" RETR file1" , " 111111111" );
232
- Test (" REST 4" , " 350" );
233
- Test (" STOR file1" , " 2222" , " 4" );
234
- Test (" RETR file1" , " 111122221" );
258
+
259
+ auto stor = SGlobalFixture::CreateStream (default_path, " file1" , 4 , true );
260
+ TestNoCommand (*stor, " 2222" , " 4" );
261
+ Test (*stor, " RETR file1" , " 111122221" );
262
+
235
263
Test (" REST 8" , " 350" );
236
264
Test (" STOR file1" , " 33" , " 2" );
237
265
Test (" RETR file1" , " 1111222233" );
@@ -243,8 +271,12 @@ BOOST_AUTO_TEST_CASE(FilesAndDirs)
243
271
Test (" RETR file2" , " 1111222233444" );
244
272
Test (" APPE file2" , " 5" , " 1" );
245
273
Test (" RETR file2" , " 11112222334445" );
246
- Test (" REST 5" , " 350" );
247
- Test (" APPE file2" , " 66" , " 2" );
274
+
275
+ auto retr = SGlobalFixture::CreateStream (default_path, " file2" , 8 , false );
276
+ TestNoCommand (*retr, " 334445" );
277
+ Test (*retr, " REST 5" , " 350" );
278
+ Test (*retr, " APPE file2" , " 66" , " 2" );
279
+
248
280
Test (" RETR file2" , " 11112662334445" );
249
281
Test (" REST 9" , " 350" );
250
282
Test (" APPE file2" , " 77" , " 2" );
0 commit comments