/* Copyright (c) 2008 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. */
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <atf-c.h>
#include "atf-c/detail/test_helpers.h"
/* ---------------------------------------------------------------------
* Tests for the "atf_dynstr" type.
* --------------------------------------------------------------------- */
/*
* Constructors and destructors.
*/
{
}
{
}
static
void
{
}
{
"a va_list argument");
}
{
"large ", "string ", "aaaabbbbccccdddd");
"This should be a large string "
"aaaabbbbccccdddd") == 0);
}
{
"a variable list of parameters");
}
{
"be ", "a ", "large ", "string ",
"aaaabbbbccccdddd"));
"This should be a large string "
"aaaabbbbccccdddd") == 0);
}
{
"using a raw memory pointer");
}
{
{
}
}
{
"repeating characters");
}
{
size_t i;
buf[0] = '\0';
for (i = 0; i < maxlen; i++) {
atf_tc_fail("Failed to construct dynstr by repeating %zd "
"times the '%c' character", i, 'a');
}
}
{
}
}
{
"using a substring of another one");
}
{
}
{
}
{
}
{
"internal plain C string");
}
{
const char *cstr;
char *cstr2;
}
/*
* Getters.
*/
{
"string");
}
{
const char *cstr;
}
{
}
{
size_t i;
for (i = 0; i < 8192; i++) {
}
}
{
"occurrence of a character starting from the end");
}
{
}
/*
* Modifiers.
*/
static
void
{
size_t i;
printf("Appending with plain string\n");
buf[0] = '\0';
for (i = 0; i < maxlen; i++) {
atf_tc_fail("Failed to append character at iteration %zd", i);
}
}
printf("Appending with formatted string\n");
buf[0] = '\0';
for (i = 0; i < maxlen; i++) {
atf_tc_fail("Failed to append character at iteration %zd", i);
}
}
}
static
{
return err;
}
{
"another one works");
}
{
}
{
"another one works");
}
{
}
{
}
{
printf("Clear an empty string\n");
printf("Clear a non-empty string\n");
}
static
void
{
size_t i;
printf("Prepending with plain string\n");
buf[0] = '\0';
for (i = 0; i < maxlen; i++) {
atf_tc_fail("Failed to prepend character at iteration %zd", i);
}
if (i % 2 == 0) {
buf[0] = 'a';
} else {
buf[0] = 'b';
}
}
printf("Prepending with formatted string\n");
buf[0] = '\0';
for (i = 0; i < maxlen; i++) {
atf_tc_fail("Failed to prepend character at iteration %zd", i);
}
if (i % 2 == 0) {
buf[0] = 'a';
} else {
buf[0] = 'b';
}
}
}
static
{
return err;
}
{
"another one works");
}
{
}
{
"another one works");
}
{
}
/*
* Operators.
*/
{
"function");
}
{
}
{
"function");
}
{
}
/* ---------------------------------------------------------------------
* Main.
* --------------------------------------------------------------------- */
{
/* Constructors and destructors. */
/* Getters. */
/* Modifiers. */
/* Operators. */
return atf_no_error();
}