diff options
author | Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com> | 2021-02-02 14:47:39 +0300 |
---|---|---|
committer | Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) <spamtrap@nedprod.com> | 2021-02-02 14:47:39 +0300 |
commit | 1d77bfa3867f98cf59beca149026a013668c06b7 (patch) | |
tree | 4cedea0e98e334ef441a33d5bb8515f3041029e3 /test-packaging | |
parent | 669e0b45bbc60cf4d46a72559710d428f2863740 (diff) |
Add LLFIO_ENABLE_DEPENDENCY_SMOKE_TEST option for vcpkg.
Diffstat (limited to 'test-packaging')
-rw-r--r-- | test-packaging/example.cpp | 53 |
1 files changed, 25 insertions, 28 deletions
diff --git a/test-packaging/example.cpp b/test-packaging/example.cpp index 5840d4df..b64a98d2 100644 --- a/test-packaging/example.cpp +++ b/test-packaging/example.cpp @@ -24,37 +24,34 @@ Distributed under the Boost Software License, Version 1.0. #include <llfio.hpp> -#include <vector> +#include <iostream> int main() { - //! [file_entire_file1] namespace llfio = LLFIO_V2_NAMESPACE; - // Open the file for read - llfio::file_handle fh = llfio::file( // - {}, // path_handle to base directory - "foo" // path_view to path fragment relative to base directory - // default mode is read only - // default creation is open existing - // default caching is all - // default flags is none - ).value(); // If failed, throw a filesystem_error exception - - // Make a vector sized the current maximum extent of the file - std::vector<llfio::byte> buffer(fh.maximum_extent().value()); - - // Synchronous scatter read from file - llfio::file_handle::size_type bytesread = llfio::read( - fh, // handle to read from - 0, // offset - {{ buffer.data(), buffer.size() }} // Single scatter buffer of the vector - // default deadline is infinite - ).value(); // If failed, throw a filesystem_error exception - - // In case of racy truncation of file by third party to new length, adjust buffer to - // bytes actually read - buffer.resize(bytesread); - //! [file_entire_file1] - return 0; + auto r = []() -> llfio::result<int> { + OUTCOME_TRY(auto fh, llfio::file_handle::temp_file()); + static const char *buffers[] = { "He", "llo", " world" }; + OUTCOME_TRY(fh.write(0, { { (const llfio::byte *) buffers[0], 2 }, { (const llfio::byte *) buffers[1], 3 }, { (const llfio::byte *) buffers[2], 6 } } )); + llfio::byte buffer[64]; + OUTCOME_TRY(auto read, fh.read(0, { {buffer, sizeof(buffer)} })); + if(read != 11) + { + std::cerr << "FAILURE: Did not read 11 bytes!" << std::endl; + return 1; + } + if(0 != memcmp(buffer, "Hello world", 11)) + { + std::cerr << "FAILURE: Did not read what was written!" << std::endl; + return 1; + } + return 0; + }(); + if(!r) + { + std::cerr << "ERROR: " << r.error().message().c_str() << std::endl; + return 1; + } + return r.value(); } |