Skip to content

Commit

Permalink
ut
Browse files Browse the repository at this point in the history
  • Loading branch information
qicosmos committed Jul 4, 2024
1 parent ec736a5 commit d024ecb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
15 changes: 8 additions & 7 deletions include/cinatra/ylt/coro_io/coro_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,22 @@ enum class read_mode { seq, random };
enum class async_mode { native_async, thread_pool };

constexpr flags to_flags(std::ios::ios_base::openmode mode) {
flags access = flags::read_write;
int access = flags::read_write;

if ((mode & (std::ios::app)) != 0)
access = flags::append;

if ((mode & (std::ios::trunc)) != 0)
access = flags::truncate;
access |= flags::truncate;

if ((mode & (std::ios::in | std::ios::out)) != 0)
access = read_write;
access |= read_write;
else if ((mode & std::ios::out) != 0)
access = flags::create_write;
access |= flags::create_write;
else if ((mode & std::ios::in) != 0)
access = flags::read_only;
access |= flags::read_only;

return access;
return (flags)access;
}

#if defined(ENABLE_FILE_IO_URING) || defined(ASIO_WINDOWS)
Expand Down Expand Up @@ -329,11 +329,12 @@ class basic_seq_coro_file {
return true;
}
auto coro_func = coro_io::post(
[this, flags, filepath] {
[this, flags, filepath]() mutable {
frw_seq_file_.open(filepath.data(), flags);
if (!frw_seq_file_.is_open()) {
std::cout << "line " << __LINE__ << " coro_file open failed "
<< filepath << "\n";
std::cerr << "Error: " << strerror(errno);
return false;
}
return true;
Expand Down
14 changes: 7 additions & 7 deletions tests/test_corofile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ TEST_CASE("multithread for balance") {
int index) mutable -> async_simple::coro::Lazy<void> {
coro_io::coro_file0 file(coro_io::get_global_block_executor<
coro_io::multithread_context_pool>());
file.open(filename, std::ios::out);
file.open(filename, std::ios::out | std::ios::trunc);
CHECK(file.is_open());

size_t id = index % write_str_vec.size();
Expand Down Expand Up @@ -368,7 +368,7 @@ TEST_CASE("read write 100 small files") {
std::string filename,
int index) mutable -> async_simple::coro::Lazy<void> {
coro_io::coro_file0 file(pool.get_executor());
file.open(filename, std::ios::out);
file.open(filename, std::ios::trunc | std::ios::out);
CHECK(file.is_open());

size_t id = index % write_str_vec.size();
Expand Down Expand Up @@ -626,7 +626,7 @@ TEST_CASE("small_file_write_test") {
std::string file_content_0 = "small_file_write_test_0";

coro_io::coro_file0 file(ioc.get_executor());
file.open(filename, std::ios::out);
file.open(filename, std::ios::trunc | std::ios::out);
CHECK(file.is_open());
async_simple::coro::syncAwait(file.async_write(file_content_0));

Expand Down Expand Up @@ -690,7 +690,7 @@ TEST_CASE("large_file_write_test") {
});

coro_io::coro_file0 file(ioc.get_executor());
file.open(filename, std::ios::out);
file.open(filename, std::ios::trunc | std::ios::out);
CHECK(file.is_open());

auto block_vec = create_filled_vec("large_file_write_test");
Expand Down Expand Up @@ -736,7 +736,7 @@ TEST_CASE("empty_file_write_test") {
});

coro_io::coro_file0 file(ioc.get_executor());
file.open(filename, std::ios::out);
file.open(filename, std::ios::trunc | std::ios::out);
CHECK(file.is_open());

char buf[512]{};
Expand Down Expand Up @@ -767,7 +767,7 @@ TEST_CASE("small_file_write_with_pool_test") {
});

coro_io::coro_file0 file(pool.get_executor());
file.open(filename, std::ios::out);
file.open(filename, std::ios::trunc | std::ios::out);
CHECK(file.is_open());

char buf[512]{};
Expand Down Expand Up @@ -838,7 +838,7 @@ TEST_CASE("large_file_write_with_pool_test") {
});

coro_io::coro_file0 file(pool.get_executor());
file.open(filename, std::ios::out);
file.open(filename, std::ios::trunc | std::ios::out);
CHECK(file.is_open());

auto block_vec = create_filled_vec("large_file_write_with_pool_test");
Expand Down

0 comments on commit d024ecb

Please sign in to comment.