60 std::string one_line =
"Hello World, this is a test and I like it. Exactly 100 characters long. 0123456780 abcdefghjklmnop..";
63 REQUIRE( ofs.
good() ==
true );
64 REQUIRE( ofs.
is_open() ==
true );
66 for(
size_t i=0; i < 1024_uz * 10_uz; i+=one_line.size()) {
67 REQUIRE( one_line.size() == ofs.
write(one_line.data(), one_line.size()) );
71 int res = std::system(
"killall mini_httpd");
74 const std::string cmd = std::string(
mini_httpd_exe)+
" -p 8080 -l "+cwd+
"/mini_httpd.log";
76 res = std::system(cmd.c_str());
83 int res = std::system(
"killall mini_httpd");
93 REQUIRE( 0 < protos.size() );
95 REQUIRE( 0 == protos.size() );
106 const std::string url =
"https://localhost:8080/" +
basename_10kiB;
116 const std::string url =
"lala://localhost:8080/" +
basename_10kiB;
122 const std::string url =
"lala://localhost:8080/" +
basename_10kiB;
124 size_t consumed_calls = 0;
125 uint64_t consumed_total_bytes = 0;
129 consumed_total_bytes += data.size();
133 REQUIRE( 0 == http_total_bytes );
134 REQUIRE( consumed_total_bytes == http_total_bytes );
135 REQUIRE( 0 == consumed_calls );
139 const std::string url =
"lala://localhost:8080/" +
basename_10kiB;
148 std::unique_ptr<std::thread> http_thread =
jau::io::read_url_stream(url, rb, url_header_sync, url_has_content_length, url_content_length, url_total_read, result);
149 REQUIRE(
nullptr == http_thread );
150 REQUIRE( url_header_sync.
completed() ==
true );
151 REQUIRE( url_has_content_length ==
false );
152 REQUIRE( url_content_length == 0 );
153 REQUIRE( url_content_length == url_total_read );
164 const size_t file_size = in_stats.
size();
168 REQUIRE( outfile.
good() );
172 size_t consumed_calls = 0;
173 uint64_t consumed_total_bytes = 0;
176 if( data.size() != outfile.
write(data.data(), data.size()) ) {
179 consumed_total_bytes += data.size();
180 jau::PLAIN_PRINT(
true,
"test01_sync_ok #%zu: consumed size %zu, total %" PRIu64
", capacity %zu, final %d",
181 consumed_calls, data.size(), consumed_total_bytes, data.capacity(), is_final );
185 const uint64_t out_bytes_total = outfile.
tellp();
186 jau::PLAIN_PRINT(
true,
"test01_sync_ok Done: total %" PRIu64
", capacity %zu", consumed_total_bytes, buffer.capacity());
188 REQUIRE( file_size == http_total_bytes );
189 REQUIRE( consumed_total_bytes == http_total_bytes );
190 REQUIRE( consumed_total_bytes == out_bytes_total );
198 const std::string url_input =
url_input_root +
"doesnt_exists.txt";
201 REQUIRE( outfile.
good() );
205 size_t consumed_calls = 0;
206 uint64_t consumed_total_bytes = 0;
209 if( data.size() != outfile.
write(data.data(), data.size()) ) {
212 consumed_total_bytes += data.size();
213 jau::PLAIN_PRINT(
true,
"test02_sync_404 #%zu: consumed size %zu, total %" PRIu64
", capacity %zu, final %d",
214 consumed_calls, data.size(), consumed_total_bytes, data.capacity(), is_final );
218 const uint64_t out_bytes_total = outfile.
tellp();
219 jau::PLAIN_PRINT(
true,
"test02_sync_404 Done: total %" PRIu64
", capacity %zu", consumed_total_bytes, buffer.capacity());
221 REQUIRE( 0 == http_total_bytes );
222 REQUIRE( consumed_total_bytes == http_total_bytes );
223 REQUIRE( consumed_total_bytes == out_bytes_total );
232 const size_t file_size = in_stats.
size();
236 REQUIRE( outfile.
good() );
239 constexpr const size_t buffer_size = 4096;
247 std::unique_ptr<std::thread> http_thread =
jau::io::read_url_stream(url_input, rb, url_header_sync, url_has_content_length, url_content_length, url_total_read, result);
248 REQUIRE(
nullptr != http_thread );
251 size_t consumed_loops = 0;
252 uint64_t consumed_total_bytes = 0;
257 const size_t consumed_bytes = rb.
getBlocking(buffer.data(), buffer_size, 1, 500_ms);
258 consumed_total_bytes += consumed_bytes;
259 jau::PLAIN_PRINT(
true,
"test11_async_ok.0 #%zu: consumed[this %zu, total %" PRIu64
", result %d, rb %s",
260 consumed_loops, consumed_bytes, consumed_total_bytes, result.
load(), rb.
toString().c_str() );
261 if( consumed_bytes != outfile.
write(buffer.data(), consumed_bytes) ) {
265 const uint64_t out_bytes_total = outfile.
tellp();
266 jau::PLAIN_PRINT(
true,
"test11_async_ok.X Done: total %" PRIu64
", result %d, rb %s",
267 consumed_total_bytes, (
int)result.
load(), rb.
toString().c_str() );
271 REQUIRE( url_header_sync.
completed() ==
true );
272 REQUIRE( url_has_content_length ==
true );
273 REQUIRE( url_content_length == file_size );
274 REQUIRE( url_content_length == consumed_total_bytes );
275 REQUIRE( url_content_length == url_total_read );
276 REQUIRE( url_content_length == out_bytes_total );
285 const std::string url_input =
url_input_root +
"doesnt_exists.txt";
288 REQUIRE( outfile.
good() );
291 constexpr const size_t buffer_size = 4096;
299 std::unique_ptr<std::thread> http_thread =
jau::io::read_url_stream(url_input, rb, url_header_sync, url_has_content_length, url_content_length, url_total_read, result);
300 REQUIRE(
nullptr != http_thread );
303 size_t consumed_loops = 0;
304 uint64_t consumed_total_bytes = 0;
309 const size_t consumed_bytes = rb.
getBlocking(buffer.data(), buffer_size, 1, 500_ms);
310 consumed_total_bytes += consumed_bytes;
311 jau::PLAIN_PRINT(
true,
"test12_async_404.0 #%zu: consumed[this %zu, total %" PRIu64
", result %d, rb %s",
312 consumed_loops, consumed_bytes, consumed_total_bytes, result.
load(), rb.
toString().c_str() );
313 if( consumed_bytes != outfile.
write(
reinterpret_cast<char*
>(buffer.data()), consumed_bytes) ) {
317 const uint64_t out_bytes_total = outfile.
tellp();
318 jau::PLAIN_PRINT(
true,
"test12_async_404.X Done: total %" PRIu64
", result %d, rb %s",
319 consumed_total_bytes, (
int)result.
load(), rb.
toString().c_str() );
323 REQUIRE( url_header_sync.
completed() ==
true );
324 REQUIRE( url_has_content_length ==
false );
325 REQUIRE( url_content_length == 0 );
326 REQUIRE( url_content_length == consumed_total_bytes );
327 REQUIRE( url_content_length == url_total_read );
328 REQUIRE( url_content_length == out_bytes_total );
const std::string basename_10kiB
const std::string url_input_root
Platform agnostic representation of POSIX ::lstat() and ::stat() for a given pathname.
uint64_t size() const noexcept
Returns the size in bytes of this element if is_file(), otherwise zero.
Class template jau::function is a general-purpose static-polymorphic function wrapper.
File based byte output stream, including named file descriptor.
size_t write(const void *, size_t) noexcept override
Write to the data sink.
uint64_t tellp() const noexcept override
Returns the output position indicator.
bool is_open() const noexcept override
Checks if the stream has an associated file.
bool good() const noexcept
Checks if no error nor eof() has occurred i.e.
bool getBlocking(Value_type &result, const fraction_i64 &timeout, bool &timeout_occurred) noexcept
Dequeues the oldest enqueued element.
bool isEmpty() const noexcept
Returns true if this ring buffer is empty, otherwise false.
std::string toString() const noexcept
Returns a short string representation incl.
std::string to_string(const endian_t v) noexcept
Return std::string representation of the given endian.
std::string get_cwd() noexcept
Return the current working directory or empty on failure.
bool remove(const std::string &path, const traverse_options topts=traverse_options::none) noexcept
Remove the given path.
std::vector< T, jau::callocator_sec< T > > secure_vector
bool is_local_file_protocol(const std::string_view &uri) noexcept
Returns true if the uri-scheme of given uri matches the local file protocol, i.e.
uint64_t read_url_stream(const std::string &url, secure_vector< uint8_t > &buffer, const StreamConsumerFunc &consumer_fn) noexcept
Synchronous URL stream reader using the given StreamConsumerFunc consumer_fn.
std::vector< std::string_view > supported_protocols() noexcept
Returns a list of supported protocol supported by libcurl network protocols, queried at runtime.
const size_t BEST_URLSTREAM_RINGBUFFER_SIZE
bool protocol_supported(const std::string_view &uri) noexcept
Returns true if the uri-scheme of given uri matches a supported by libcurl network protocols otherwis...
@ NONE
Operation still in progress.
@ FAILED
Operation failed.
@ SUCCESS
Operation succeeded.
void PLAIN_PRINT(const bool printPrefix, const char *format,...) noexcept
Use for unconditional plain messages, prefix '[elapsed_time] ' if printPrefix == true.
CXX_ALWAYS_INLINE _Tp load() const noexcept
constexpr std::string_view mini_httpd_exe
METHOD_AS_TEST_CASE(TestIOStream01::test00_protocols, "TestIOStream01 - test00_protocols")