From 8d327cb1d25681586005610ecfef4d262f61a410 Mon Sep 17 00:00:00 2001 From: Bob Polis Date: Fri, 24 Apr 2020 10:06:01 +0200 Subject: [PATCH] added 5th test --- sciotest/main.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/sciotest/main.cpp b/sciotest/main.cpp index 9c30ca1..817a151 100644 --- a/sciotest/main.cpp +++ b/sciotest/main.cpp @@ -51,6 +51,7 @@ void test2() { client << "ready to echo...\n"; string line; while (getline(client, line)) { + cerr << "received: " << line << '\n'; client << line << '\n'; } } @@ -59,7 +60,9 @@ void test2() { void test3() { string passwd {sc::file_get_contents("/etc/passwd")}; int fd = -1; - throw_if_min1(fd = ::open("passwd", O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR, S_IWUSR)); + int perm = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; + int mode = O_WRONLY | O_CREAT | O_TRUNC; + throw_if_min1(fd = ::open("passwd", mode, perm)); sc::io::fdostream os {fd}; os << passwd; throw_if_min1(::close(fd)); @@ -76,6 +79,20 @@ void test4() { throw_if_min1(::close(fd)); } +void test5() { + int fd = -1; + int perm = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; + int mode = O_RDWR | O_CREAT | O_TRUNC; + throw_if_min1(fd = ::open("test5", mode, perm)); + sc::io::fdstream file {fd}; + file << "A line of text\n"; + file.seekg(0); + string line; + file >> line; + cout << line; + throw_if_min1(::close(fd)); +} + int main(int argc, const char * argv[]) { try { struct option long_options[] = { @@ -122,6 +139,7 @@ int main(int argc, const char * argv[]) { case 2: test2(); break; case 3: test3(); break; case 4: test4(); break; + case 5: test5(); break; default: throw std::runtime_error("no such test"); }