added 5th test

This commit is contained in:
Bob Polis 2020-04-24 10:06:01 +02:00
parent c6994e6983
commit 8d327cb1d2

View File

@ -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");
}