io_test.cpp revision ef421f66f47224a42073deaf087378c5d0c9952e
//
// Automated Testing Framework (atf)
//
// Copyright (c) 2007, 2008, 2009, 2010 The NetBSD Foundation, Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
//
// THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
// CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
// IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
extern "C" {
#include <fcntl.h>
#include <unistd.h>
}
#include <cerrno>
#include <cstddef>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <istream>
#include <ostream>
#include "../atf-c++/detail/sanity.hpp"
#include "../atf-c++/macros.hpp"
#include "io.hpp"
#include "signals.hpp"
// ------------------------------------------------------------------------
// Auxiliary functions.
// ------------------------------------------------------------------------
static
void
{
if (ch == 'Z')
ch = 'A';
else
ch++;
cnt++;
}
}
static
void
{
char ch = 'A';
if (ch == 'Z')
ch = 'A';
else
ch++;
}
}
static
void
{
f.close();
::unlink("test_read.txt");
}
static
void
{
::unlink("test_write.txt");
}
// ------------------------------------------------------------------------
// Test cases for the "file_handle" class.
// ------------------------------------------------------------------------
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
int pfd[2];
{
char buf[17];
}
// Redo previous to ensure that remapping over the same descriptor
// has no side-effects.
{
char buf[17];
}
}
// ------------------------------------------------------------------------
// Test cases for the "systembuf" class.
// ------------------------------------------------------------------------
{
"internal buffer) works when using systembuf");
}
{
}
{
"the internal buffer) works when using systembuf");
}
{
}
{
"internal buffer) works when using systembuf");
}
{
}
{
"in the internal buffer) works when using systembuf");
}
{
}
// ------------------------------------------------------------------------
// Test cases for the "pistream" class.
// ------------------------------------------------------------------------
{
}
{
int fds[2];
// XXX This assumes that the pipe's buffer is big enough to accept
// the data written without blocking!
wend << "1Test 1message\n";
}
// ------------------------------------------------------------------------
// Tests for the "muxer" class.
// ------------------------------------------------------------------------
namespace {
static void
{
// If we receive a signal while writing to the stream, the bad bit gets set.
// Things seem to behave fine afterwards if we clear such error condition.
// However, I'm not sure if it's safe to query errno at this point.
}
{
// The following should be enabled but causes the output to be so big
// that it is annoying. Reenable at some point if we make atf store
// the output of the test cases in some other way (e.g. only if a test
// failes), because this message is the only help in seeing how the
// test fails.
//std::cout << "line_callback(" << index << ", " << line << ")\n";
switch (index) {
default: ATF_REQUIRE(false);
}
}
public:
};
static bool child_finished = false;
static void sigchld_handler(int signo)
{
child_finished = true;
}
static void
const size_t iterations)
{
for (size_t i = 0; i < iterations; i++) {
}
}
static void
{
if (pid == 0) {
}
int status;
for (size_t i = 0; i < iterations; i++) {
exp0 << "stdout " << i;
exp1 << "stderr " << i;
}
}
} // anonymous namespace
{
}
{
}
// ------------------------------------------------------------------------
// Main.
// ------------------------------------------------------------------------
{
// Add the tests for the "file_handle" class.
// Add the tests for the "systembuf" class.
// Add the tests for the "pistream" class.
// Add the tests for the "muxer" class.
}