//
// Automated Testing Framework (atf)
//
// Copyright (c) 2009 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 <algorithm>
#include <fstream>
#include <memory>
#include "atffile.hpp"
#include "exceptions.hpp"
#include "test_helpers.hpp"
// ------------------------------------------------------------------------
// Auxiliary functions.
// ------------------------------------------------------------------------
namespace {
static
new_atffile(void)
{
ATF_REQUIRE(*os);
(*os) << "Content-Type: application/X-atf-atffile; version=\"1\"\n\n";
return os;
}
static
void
{
}
static inline
bool
{
}
} // anonymous namespace
// ------------------------------------------------------------------------
// Tests cases for the "atffile" parser.
// ------------------------------------------------------------------------
void
{
}
void
{
}
void
{
+ ")");
}
void
got_eof(void)
{
}
public:
{
}
void
read(void)
{
}
};
{
const char* input =
"Content-Type: application/X-atf-atffile; version=\"1\"\n"
"\n"
;
const char* exp_calls[] = {
"got_eof()",
};
const char* exp_errors[] = {
};
}
{
const char* input =
"Content-Type: application/X-atf-atffile; version=\"1\"\n"
"\n"
"# This is a comment on a line of its own.\n"
"# And this is another one.\n"
"\n"
" # Another after some whitespace.\n"
"\n"
"# The last one after an empty line.\n"
;
const char* exp_calls[] = {
"got_eof()",
};
const char* exp_errors[] = {
};
}
{
const char* input =
"Content-Type: application/X-atf-atffile; version=\"1\"\n"
"\n"
"conf: var1=value1\n"
"conf: var2 = value2\n"
"conf: var3 = value3\n"
"conf: var4 = value4\n"
"\n"
"conf:var5=value5\n"
" conf:var6=value6\n"
"\n"
"conf: var7 = \"This is a long value.\"\n"
"conf: var8 = \"Single-word\"\n"
"conf: var9 = \" Single-word \"\n"
"conf: var10 = Single-word\n"
;
const char* exp_calls[] = {
"got_conf(var1, value1)",
"got_conf(var2, value2)",
"got_conf(var3, value3)",
"got_conf(var4, value4)",
"got_conf(var5, value5)",
"got_conf(var6, value6)",
"got_conf(var7, This is a long value.)",
"got_conf(var8, Single-word)",
"got_conf(var9, Single-word )",
"got_conf(var10, Single-word)",
"got_eof()",
};
const char* exp_errors[] = {
};
}
{
const char* input =
"Content-Type: application/X-atf-atffile; version=\"1\"\n"
"\n"
"prop: var1=value1\n"
"prop: var2 = value2\n"
"prop: var3 = value3\n"
"prop: var4 = value4\n"
"\n"
"prop:var5=value5\n"
" prop:var6=value6\n"
"\n"
"prop: var7 = \"This is a long value.\"\n"
"prop: var8 = \"Single-word\"\n"
"prop: var9 = \" Single-word \"\n"
"prop: var10 = Single-word\n"
;
const char* exp_calls[] = {
"got_prop(var1, value1)",
"got_prop(var2, value2)",
"got_prop(var3, value3)",
"got_prop(var4, value4)",
"got_prop(var5, value5)",
"got_prop(var6, value6)",
"got_prop(var7, This is a long value.)",
"got_prop(var8, Single-word)",
"got_prop(var9, Single-word )",
"got_prop(var10, Single-word)",
"got_eof()",
};
const char* exp_errors[] = {
};
}
{
const char* input =
"Content-Type: application/X-atf-atffile; version=\"1\"\n"
"\n"
"tp:foo\n"
"tp: foo\n"
"tp: foo\n"
"tp: foo\n"
"tp: foo\n"
"tp: \"name with spaces\"\n"
"tp: \"single-word\"\n"
"tp: single-word\n"
"\n"
"tp-glob:foo*?bar\n"
"tp-glob: foo*?bar\n"
"tp-glob: foo*?bar\n"
"tp-glob: foo*?bar\n"
"tp-glob: foo*?bar\n"
"tp-glob: \"glob * with ? spaces\"\n"
"tp-glob: \"single-*-word\"\n"
"tp-glob: single-*-word\n"
;
const char* exp_calls[] = {
"got_tp(foo, false)",
"got_tp(foo, false)",
"got_tp(foo, false)",
"got_tp(foo, false)",
"got_tp(foo, false)",
"got_tp(name with spaces, false)",
"got_tp(single-word, false)",
"got_tp(single-word, false)",
"got_tp(foo*?bar, true)",
"got_tp(foo*?bar, true)",
"got_tp(foo*?bar, true)",
"got_tp(foo*?bar, true)",
"got_tp(foo*?bar, true)",
"got_tp(glob * with ? spaces, true)",
"got_tp(single-*-word, true)",
"got_tp(single-*-word, true)",
"got_eof()",
};
const char* exp_errors[] = {
};
}
{
const char* input =
"Content-Type: application/X-atf-atffile; version=\"1\"\n"
"\n"
"prop: foo = bar # A comment.\n"
"conf: foo = bar # A comment.\n"
"tp: foo # A comment.\n"
"tp-glob: foo # A comment.\n"
;
const char* exp_calls[] = {
"got_prop(foo, bar)",
"got_conf(foo, bar)",
"got_tp(foo, false)",
"got_tp(foo, true)",
"got_eof()",
};
const char* exp_errors[] = {
};
}
{
const char* input =
"Content-Type: application/X-atf-atffile; version=\"1\"\n"
"\n"
"foo\n"
;
const char* exp_calls[] = {
};
// NO_CHECK_STYLE_BEGIN
const char* exp_errors[] = {
"3: Unexpected token `foo'; expected conf, #, prop, tp, tp-glob, a new line or eof",
};
// NO_CHECK_STYLE_END
}
{
const char* input =
"Content-Type: application/X-atf-atffile; version=\"1\"\n"
"\n"
"foo bar\n"
"baz\n"
;
const char* exp_calls[] = {
};
// NO_CHECK_STYLE_BEGIN
const char* exp_errors[] = {
"3: Unexpected token `foo'; expected conf, #, prop, tp, tp-glob, a new line or eof",
"4: Unexpected token `baz'; expected conf, #, prop, tp, tp-glob, a new line or eof",
};
// NO_CHECK_STYLE_END
}
{
const char* input =
"Content-Type: application/X-atf-atffile; version=\"1\"\n"
"\n"
"conf\n"
"conf:\n"
"conf: foo =\n"
"conf: bar = # A comment.\n"
"\n"
"prop\n"
"prop:\n"
"prop: foo =\n"
"prop: bar = # A comment.\n"
"\n"
"tp\n"
"tp:\n"
"tp: # A comment.\n"
"\n"
"tp-glob\n"
"tp-glob:\n"
"tp-glob: # A comment.\n"
;
const char* exp_calls[] = {
};
const char* exp_errors[] = {
"3: Unexpected token `<<NEWLINE>>'; expected `:'",
"4: Unexpected token `<<NEWLINE>>'; expected variable name",
"5: Unexpected token `<<NEWLINE>>'; expected word or quoted string",
"6: Unexpected token `#'; expected word or quoted string",
"8: Unexpected token `<<NEWLINE>>'; expected `:'",
"9: Unexpected token `<<NEWLINE>>'; expected property name",
"10: Unexpected token `<<NEWLINE>>'; expected word or quoted string",
"11: Unexpected token `#'; expected word or quoted string",
"13: Unexpected token `<<NEWLINE>>'; expected `:'",
"14: Unexpected token `<<NEWLINE>>'; expected word or quoted string",
"15: Unexpected token `#'; expected word or quoted string",
"17: Unexpected token `<<NEWLINE>>'; expected `:'",
"18: Unexpected token `<<NEWLINE>>'; expected word or quoted string",
"19: Unexpected token `#'; expected word or quoted string",
};
}
{
const char* input =
"Content-Type: application/X-atf-atffile; version=\"1\"\n"
"\n"
"prop: foo = \"Correct value\" # With comment.\n"
"\n"
"prop: bar = # A comment.\n"
"\n"
"prop: baz = \"Last variable\"\n"
"\n"
"# End of file.\n"
;
const char* exp_calls[] = {
"got_prop(foo, Correct value)",
};
const char* exp_errors[] = {
"5: Unexpected token `#'; expected word or quoted string",
};
}
{
const char* input =
"Content-Type: application/X-atf-atffile; version=\"1\"\n"
"\n"
"prop: foo = \"\n"
"prop: bar = \"text\n"
"prop: baz = \"te\\\"xt\n"
"prop: last = \"\\\"\n"
;
const char* exp_calls[] = {
};
const char* exp_errors[] = {
"3: Missing double quotes before end of line",
"4: Missing double quotes before end of line",
"5: Missing double quotes before end of line",
"6: Missing double quotes before end of line",
};
}
// ------------------------------------------------------------------------
// Tests cases for the "atffile" class.
// ------------------------------------------------------------------------
}
// ------------------------------------------------------------------------
// Tests cases for the free functions.
// ------------------------------------------------------------------------
(*os) << "prop: test-suite = foo\n";
(*os) << "tp: tp-1\n";
(*os) << "conf: var1 = value1\n";
(*os) << "tp: tp-2\n";
(*os) << "tp: tp-3\n";
(*os) << "prop: prop1 = propvalue1\n";
(*os) << "conf: var2 = value2\n";
touch_exec("tp-1");
touch_exec("tp-2");
touch_exec("tp-3");
}
(*os) << "prop: test-suite = foo\n";
(*os) << "tp: foo\n";
(*os) << "tp-glob: *K*\n";
(*os) << "tp: bar\n";
(*os) << "tp-glob: t_*\n";
touch_exec("foo");
touch_exec("bar");
touch_exec("aK");
touch_exec("KKKKK");
touch_exec("t_hello");
touch_exec("zzzt_hello");
}
try {
ATF_FAIL("Missing property 'test-suite' did not raise an error");
}
}
(*os) << "tp: foo\n";
(*os) << "tp: bar\n";
(*os) << "tp: baz\n";
touch_exec("foo");
touch_exec("baz");
try {
ATF_FAIL("Missing file 'bar' did not raise an error");
}
}
// ------------------------------------------------------------------------
// Main.
// ------------------------------------------------------------------------
{
// Add the test cases for the parser class.
// Add the test cases for the atffile class.
// Add the test cases for the free functions.
}