diff options
| author | jmmv <jmmv@NetBSD.org> | 2010-07-03 08:04:47 +0000 |
|---|---|---|
| committer | jmmv <jmmv@NetBSD.org> | 2010-07-03 08:04:47 +0000 |
| commit | edebbb8e6f8abcd6fefa7fb39b74d08d581cbece (patch) | |
| tree | 06057ac7f9bce3eb8f2d78e347cc5d2c97a65f8d /external/bsd/atf/dist/atf-c++/utils_test.cpp | |
| parent | 6c3fa23d545e3de776d657c73f1f19ab26c533b6 (diff) | |
Import atf 0.10:
Miscellaneous features
* Added expected failures support to test cases and atf-run. These
include, for example, expected clean exits, expected reception of fatal
signals, expected timeouts and expected errors in condition checks.
These statuses can be used to denote test cases that are known to fail
due to a bug in the code they are testing. atf-report reports these
tests separately but they do not count towards the failed test cases
amount.
* Added the ATF_CHECK_ERRNO and ATF_REQUIRE_ERRNO to the C library to
allow easy checking of call failures that update errno.
* Added the has.cleanup meta-data property to test caes that specifies
whether the test case has a cleanup routine or not; its value is
automatically set. This property is read by atf-run to know if it has to
run the cleanup routine; skipping this run for every test case
significantly speeds up the run time of test suites.
* Reversed the order of the ATF_CHECK_THROW macro in the C++ binding to
take the expected exception as the first argument and the statement to
execute as the second argument.
Changes in atf-check
* Changed atf-check to support negating the status and output checks by
prefixing them with not- and added support to specify multiple checkers
for stdout and stderr, not only one.
* Added the match output checker to atf-check to look for regular
expressions in the stdout and stderr of commands.
* Modified the exit checks in atf-check to support checking for the
reception of signals.
Code simplifications and cleanups
* Removed usage messages from test programs to simplify the
implementation of every binding by a significant amount. They just now
refer the user to the appropriate manual page and do not attempt to wrap
lines on terminal boundaries. Test programs are not supposed to be run
by users directly so this minor interface regression is not important.
* Removed the atf-format internal utility, which is unused after the
change documented above.
* Removed the atf-cleanup internal utility. It has been unused since the
test case isolation was moved to atf-run in 0.8
* Splitted the Makefile.am into smaller files for easier maintenance and
dropped the use of M4. Only affects users building from the repository
sources.
* Intermixed tests with the source files in the source tree to provide
them more visibility and easier access. The tests directory is gone from
the source tree and tests are now suffixed by _test, not prefixed by t_.
* Simplifications to the atf-c library: removed the io, tcr and ui
modules as they had become unnecessary after all simplifications
introduced since the 0.8 release.
* Removed the application/X-atf-tcr format introduced in 0.8 release.
Tests now print a much simplified format that is easy to parse and nicer
to read by end users. As a side effect, the default for test cases is
now to print their results to stdout unless otherwise stated by providing
the -r flag.
* Removed XML distribution documents and replaced them with plain-text
documents. They provided little value and introduced a lot of complexity
to the build system.
* Simplified the output of atf-version by not attempting to print a
revision number when building form a distfile. Makes the build system
easier to maintain.
Diffstat (limited to 'external/bsd/atf/dist/atf-c++/utils_test.cpp')
| -rw-r--r-- | external/bsd/atf/dist/atf-c++/utils_test.cpp | 308 |
1 files changed, 308 insertions, 0 deletions
diff --git a/external/bsd/atf/dist/atf-c++/utils_test.cpp b/external/bsd/atf/dist/atf-c++/utils_test.cpp new file mode 100644 index 00000000000..ec8f5ef47ab --- /dev/null +++ b/external/bsd/atf/dist/atf-c++/utils_test.cpp @@ -0,0 +1,308 @@ +// +// Automated Testing Framework (atf) +// +// Copyright (c) 2007, 2008, 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 +// documentation and/or other materials provided with the distribution. +// +// 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 <iostream> + +#include "atf-c++/macros.hpp" +#include "atf-c++/utils.hpp" + +#include "test_helpers.hpp" + +// ------------------------------------------------------------------------ +// Tests for the "auto_array" class. +// ------------------------------------------------------------------------ + +class test_array { +public: + int m_value; + + static ssize_t m_nblocks; + + static + atf::utils::auto_array< test_array > + do_copy(atf::utils::auto_array< test_array >& ta) + { + return atf::utils::auto_array< test_array >(ta); + } + + void* operator new(size_t size) + { + ATF_FAIL("New called but should have been new[]"); + return new int(5); + } + + void* operator new[](size_t size) + { + m_nblocks++; + void* mem = ::operator new(size); + std::cout << "Allocated 'test_array' object " << mem << std::endl; + return mem; + } + + void operator delete(void* mem) + { + ATF_FAIL("Delete called but should have been delete[]"); + } + + void operator delete[](void* mem) + { + std::cout << "Releasing 'test_array' object " << mem << std::endl; + if (m_nblocks == 0) + ATF_FAIL("Unbalanced delete[]"); + m_nblocks--; + ::operator delete(mem); + } +}; + +ssize_t test_array::m_nblocks = 0; + +ATF_TEST_CASE(auto_array_scope); +ATF_TEST_CASE_HEAD(auto_array_scope) +{ + set_md_var("descr", "Tests the automatic scope handling in the " + "auto_array smart pointer class"); +} +ATF_TEST_CASE_BODY(auto_array_scope) +{ + using atf::utils::auto_array; + + ATF_CHECK_EQUAL(test_array::m_nblocks, 0); + { + auto_array< test_array > t(new test_array[10]); + ATF_CHECK_EQUAL(test_array::m_nblocks, 1); + } + ATF_CHECK_EQUAL(test_array::m_nblocks, 0); +} + +ATF_TEST_CASE(auto_array_copy); +ATF_TEST_CASE_HEAD(auto_array_copy) +{ + set_md_var("descr", "Tests the auto_array smart pointer class' copy " + "constructor"); +} +ATF_TEST_CASE_BODY(auto_array_copy) +{ + using atf::utils::auto_array; + + ATF_CHECK_EQUAL(test_array::m_nblocks, 0); + { + auto_array< test_array > t1(new test_array[10]); + ATF_CHECK_EQUAL(test_array::m_nblocks, 1); + + { + auto_array< test_array > t2(t1); + ATF_CHECK_EQUAL(test_array::m_nblocks, 1); + } + ATF_CHECK_EQUAL(test_array::m_nblocks, 0); + } + ATF_CHECK_EQUAL(test_array::m_nblocks, 0); +} + +ATF_TEST_CASE(auto_array_copy_ref); +ATF_TEST_CASE_HEAD(auto_array_copy_ref) +{ + set_md_var("descr", "Tests the auto_array smart pointer class' copy " + "constructor through the auxiliary auto_array_ref object"); +} +ATF_TEST_CASE_BODY(auto_array_copy_ref) +{ + using atf::utils::auto_array; + + ATF_CHECK_EQUAL(test_array::m_nblocks, 0); + { + auto_array< test_array > t1(new test_array[10]); + ATF_CHECK_EQUAL(test_array::m_nblocks, 1); + + { + auto_array< test_array > t2 = test_array::do_copy(t1); + ATF_CHECK_EQUAL(test_array::m_nblocks, 1); + } + ATF_CHECK_EQUAL(test_array::m_nblocks, 0); + } + ATF_CHECK_EQUAL(test_array::m_nblocks, 0); +} + +ATF_TEST_CASE(auto_array_get); +ATF_TEST_CASE_HEAD(auto_array_get) +{ + set_md_var("descr", "Tests the auto_array smart pointer class' get " + "method"); +} +ATF_TEST_CASE_BODY(auto_array_get) +{ + using atf::utils::auto_array; + + test_array* ta = new test_array[10]; + auto_array< test_array > t(ta); + ATF_CHECK_EQUAL(t.get(), ta); +} + +ATF_TEST_CASE(auto_array_release); +ATF_TEST_CASE_HEAD(auto_array_release) +{ + set_md_var("descr", "Tests the auto_array smart pointer class' release " + "method"); +} +ATF_TEST_CASE_BODY(auto_array_release) +{ + using atf::utils::auto_array; + + test_array* ta1 = new test_array[10]; + { + auto_array< test_array > t(ta1); + ATF_CHECK_EQUAL(test_array::m_nblocks, 1); + test_array* ta2 = t.release(); + ATF_CHECK_EQUAL(ta2, ta1); + ATF_CHECK_EQUAL(test_array::m_nblocks, 1); + } + ATF_CHECK_EQUAL(test_array::m_nblocks, 1); + delete [] ta1; +} + +ATF_TEST_CASE(auto_array_reset); +ATF_TEST_CASE_HEAD(auto_array_reset) +{ + set_md_var("descr", "Tests the auto_array smart pointer class' reset " + "method"); +} +ATF_TEST_CASE_BODY(auto_array_reset) +{ + using atf::utils::auto_array; + + test_array* ta1 = new test_array[10]; + test_array* ta2 = new test_array[10]; + ATF_CHECK_EQUAL(test_array::m_nblocks, 2); + + { + auto_array< test_array > t(ta1); + ATF_CHECK_EQUAL(test_array::m_nblocks, 2); + t.reset(ta2); + ATF_CHECK_EQUAL(test_array::m_nblocks, 1); + t.reset(); + ATF_CHECK_EQUAL(test_array::m_nblocks, 0); + } + ATF_CHECK_EQUAL(test_array::m_nblocks, 0); +} + +ATF_TEST_CASE(auto_array_assign); +ATF_TEST_CASE_HEAD(auto_array_assign) +{ + set_md_var("descr", "Tests the auto_array smart pointer class' " + "assignment operator"); +} +ATF_TEST_CASE_BODY(auto_array_assign) +{ + using atf::utils::auto_array; + + ATF_CHECK_EQUAL(test_array::m_nblocks, 0); + { + auto_array< test_array > t1(new test_array[10]); + ATF_CHECK_EQUAL(test_array::m_nblocks, 1); + + { + auto_array< test_array > t2; + t2 = t1; + ATF_CHECK_EQUAL(test_array::m_nblocks, 1); + } + ATF_CHECK_EQUAL(test_array::m_nblocks, 0); + } + ATF_CHECK_EQUAL(test_array::m_nblocks, 0); +} + +ATF_TEST_CASE(auto_array_assign_ref); +ATF_TEST_CASE_HEAD(auto_array_assign_ref) +{ + set_md_var("descr", "Tests the auto_array smart pointer class' " + "assignment operator through the auxiliary auto_array_ref " + "object"); +} +ATF_TEST_CASE_BODY(auto_array_assign_ref) +{ + using atf::utils::auto_array; + + ATF_CHECK_EQUAL(test_array::m_nblocks, 0); + { + auto_array< test_array > t1(new test_array[10]); + ATF_CHECK_EQUAL(test_array::m_nblocks, 1); + + { + auto_array< test_array > t2; + t2 = test_array::do_copy(t1); + ATF_CHECK_EQUAL(test_array::m_nblocks, 1); + } + ATF_CHECK_EQUAL(test_array::m_nblocks, 0); + } + ATF_CHECK_EQUAL(test_array::m_nblocks, 0); +} + +ATF_TEST_CASE(auto_array_access); +ATF_TEST_CASE_HEAD(auto_array_access) +{ + set_md_var("descr", "Tests the auto_array smart pointer class' access " + "operator"); +} +ATF_TEST_CASE_BODY(auto_array_access) +{ + using atf::utils::auto_array; + + auto_array< test_array > t(new test_array[10]); + + for (int i = 0; i < 10; i++) + t[i].m_value = i * 2; + + for (int i = 0; i < 10; i++) + ATF_CHECK_EQUAL(t[i].m_value, i * 2); +} + +// ------------------------------------------------------------------------ +// Tests cases for the header file. +// ------------------------------------------------------------------------ + +HEADER_TC(include, "atf-c++/utils.hpp"); + +// ------------------------------------------------------------------------ +// Main. +// ------------------------------------------------------------------------ + +ATF_INIT_TEST_CASES(tcs) +{ + // Add the test for the "auto_array" class. + ATF_ADD_TEST_CASE(tcs, auto_array_scope); + ATF_ADD_TEST_CASE(tcs, auto_array_copy); + ATF_ADD_TEST_CASE(tcs, auto_array_copy_ref); + ATF_ADD_TEST_CASE(tcs, auto_array_get); + ATF_ADD_TEST_CASE(tcs, auto_array_release); + ATF_ADD_TEST_CASE(tcs, auto_array_reset); + ATF_ADD_TEST_CASE(tcs, auto_array_assign); + ATF_ADD_TEST_CASE(tcs, auto_array_assign_ref); + ATF_ADD_TEST_CASE(tcs, auto_array_access); + + // Add the test cases for the header file. + ATF_ADD_TEST_CASE(tcs, include); +} |
