diff options
| author | Enji Cooper <ngie@FreeBSD.org> | 2026-08-17 09:41:49 +0000 |
|---|---|---|
| committer | Enji Cooper <ngie@FreeBSD.org> | 2026-08-17 09:41:49 +0000 |
| commit | 0c9bf043d6892725fd76cd2026949405c9381663 (patch) | |
| tree | 076723db8845ca592088620dde4d293fedb9dbfe /atf-c++ | |
| parent | cd355e3667c67b15d9850bacb416b13486e22c24 (diff) | |
vendor/atf: import atf-0.24-rc1vendor/atf/atf-0.24-rc1
This release candidate will likely serve as the actual upstream
release tag for version 0.24, but for now it should be considered a
release-candidate worthy tag as this code has not gone through a full
FreeBSD test suite run or been built with `make tinderbox` yet on all
supported architectures.
Obtained from: https://github.com/freebsd/atf/releases/tag/atf-0.24-rc1
Diffstat (limited to 'atf-c++')
| -rw-r--r-- | atf-c++/Makefile.am.inc | 4 | ||||
| -rw-r--r-- | atf-c++/atf-c++.pc.in | 4 | ||||
| -rw-r--r-- | atf-c++/check.cpp | 5 | ||||
| -rw-r--r-- | atf-c++/check.hpp | 5 | ||||
| -rw-r--r-- | atf-c++/check_test.cpp | 22 | ||||
| -rw-r--r-- | atf-c++/detail/Kyuafile | 1 | ||||
| -rw-r--r-- | atf-c++/detail/Makefile.am.inc | 7 | ||||
| -rw-r--r-- | atf-c++/detail/application.cpp | 16 | ||||
| -rw-r--r-- | atf-c++/detail/application.hpp | 1 | ||||
| -rw-r--r-- | atf-c++/detail/auto_array.hpp | 175 | ||||
| -rw-r--r-- | atf-c++/detail/auto_array_test.cpp | 302 | ||||
| -rw-r--r-- | atf-c++/detail/fs.cpp | 1 | ||||
| -rw-r--r-- | atf-c++/detail/process.cpp | 22 | ||||
| -rw-r--r-- | atf-c++/detail/process.hpp | 3 | ||||
| -rw-r--r-- | atf-c++/detail/process_test.cpp | 32 | ||||
| -rw-r--r-- | atf-c++/detail/test_helpers.hpp | 4 | ||||
| -rw-r--r-- | atf-c++/detail/text.cpp | 8 | ||||
| -rw-r--r-- | atf-c++/detail/text.hpp | 8 | ||||
| -rw-r--r-- | atf-c++/detail/text_test.cpp | 21 | ||||
| -rw-r--r-- | atf-c++/tests.cpp | 48 |
20 files changed, 71 insertions, 618 deletions
diff --git a/atf-c++/Makefile.am.inc b/atf-c++/Makefile.am.inc index 9d982b0f8c8d..1373acb55f4c 100644 --- a/atf-c++/Makefile.am.inc +++ b/atf-c++/Makefile.am.inc @@ -23,6 +23,8 @@ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +CODE_COVERAGE_DIRS+= atf-c++ + ATF_CXX_LIBS = libatf-c++.la libatf-c.la lib_LTLIBRARIES += libatf-c++.la @@ -61,6 +63,8 @@ atf-c++/atf-c++.pc: $(srcdir)/atf-c++/atf-c++.pc.in Makefile -e 's#__CXX__#$(ATF_BUILD_CXX)#g' \ -e 's#__INCLUDEDIR__#$(includedir)#g' \ -e 's#__LIBDIR__#$(libdir)#g' \ + -e 's#__PC_CXXFLAGS__#$(pc_cxxflags)#g' \ + -e 's#__PC_LDFLAGS__#$(pc_ldflags)#g' \ <$(srcdir)/atf-c++/atf-c++.pc.in >atf-c++/atf-c++.pc.tmp; \ mv atf-c++/atf-c++.pc.tmp atf-c++/atf-c++.pc diff --git a/atf-c++/atf-c++.pc.in b/atf-c++/atf-c++.pc.in index f366bb016d04..1101c0552f89 100644 --- a/atf-c++/atf-c++.pc.in +++ b/atf-c++/atf-c++.pc.in @@ -7,5 +7,5 @@ libdir=__LIBDIR__ Name: atf-c++ Description: Automated Testing Framework (C++ binding) Version: __ATF_VERSION__ -Cflags: -I${includedir} -Libs: -L${libdir} -latf-c++ -latf-c +Cflags: -I${includedir} __PC_CXXFLAGS__ +Libs: -L${libdir} -latf-c++ -latf-c __PC_LDFLAGS__ diff --git a/atf-c++/check.cpp b/atf-c++/check.cpp index e4d7db4d49a6..78da33fa9620 100644 --- a/atf-c++/check.cpp +++ b/atf-c++/check.cpp @@ -141,7 +141,7 @@ impl::build_cxx_o(const std::string& sfile, const std::string& ofile, return success; } -std::auto_ptr< impl::check_result > +std::unique_ptr< impl::check_result > impl::exec(const atf::process::argv_array& argva) { atf_check_result_t result; @@ -150,5 +150,6 @@ impl::exec(const atf::process::argv_array& argva) if (atf_is_error(err)) throw_atf_error(err); - return std::auto_ptr< impl::check_result >(new impl::check_result(&result)); + return std::unique_ptr< impl::check_result >( + new impl::check_result(&result)); } diff --git a/atf-c++/check.hpp b/atf-c++/check.hpp index 0144dedb2841..bcf9cb647f29 100644 --- a/atf-c++/check.hpp +++ b/atf-c++/check.hpp @@ -71,7 +71,8 @@ class check_result { check_result(const atf_check_result_t* result); friend check_result test_constructor(const char* const*); - friend std::auto_ptr< check_result > exec(const atf::process::argv_array&); + friend std::unique_ptr< check_result > + exec(const atf::process::argv_array&); public: //! @@ -120,7 +121,7 @@ bool build_cpp(const std::string&, const std::string&, const atf::process::argv_array&); bool build_cxx_o(const std::string&, const std::string&, const atf::process::argv_array&); -std::auto_ptr< check_result > exec(const atf::process::argv_array&); +std::unique_ptr< check_result > exec(const atf::process::argv_array&); // Useful for testing only. check_result test_constructor(void); diff --git a/atf-c++/check_test.cpp b/atf-c++/check_test.cpp index 7baf3fa19692..ecb5a9380e8f 100644 --- a/atf-c++/check_test.cpp +++ b/atf-c++/check_test.cpp @@ -52,7 +52,7 @@ extern "C" { // ------------------------------------------------------------------------ static -std::auto_ptr< atf::check::check_result > +std::unique_ptr< atf::check::check_result > do_exec(const atf::tests::tc* tc, const char* helper_name) { std::vector< std::string > argv; @@ -65,7 +65,7 @@ do_exec(const atf::tests::tc* tc, const char* helper_name) } static -std::auto_ptr< atf::check::check_result > +std::unique_ptr< atf::check::check_result > do_exec(const atf::tests::tc* tc, const char* helper_name, const char *carg2) { std::vector< std::string > argv; @@ -248,11 +248,11 @@ ATF_TEST_CASE_HEAD(exec_cleanup) } ATF_TEST_CASE_BODY(exec_cleanup) { - std::auto_ptr< atf::fs::path > out; - std::auto_ptr< atf::fs::path > err; + std::unique_ptr< atf::fs::path > out; + std::unique_ptr< atf::fs::path > err; { - std::auto_ptr< atf::check::check_result > r = + std::unique_ptr< atf::check::check_result > r = do_exec(this, "exit-success"); out.reset(new atf::fs::path(r->stdout_path())); err.reset(new atf::fs::path(r->stderr_path())); @@ -272,7 +272,7 @@ ATF_TEST_CASE_HEAD(exec_exitstatus) ATF_TEST_CASE_BODY(exec_exitstatus) { { - std::auto_ptr< atf::check::check_result > r = + std::unique_ptr< atf::check::check_result > r = do_exec(this, "exit-success"); ATF_REQUIRE(r->exited()); ATF_REQUIRE(!r->signaled()); @@ -280,7 +280,7 @@ ATF_TEST_CASE_BODY(exec_exitstatus) } { - std::auto_ptr< atf::check::check_result > r = + std::unique_ptr< atf::check::check_result > r = do_exec(this, "exit-failure"); ATF_REQUIRE(r->exited()); ATF_REQUIRE(!r->signaled()); @@ -288,7 +288,7 @@ ATF_TEST_CASE_BODY(exec_exitstatus) } { - std::auto_ptr< atf::check::check_result > r = + std::unique_ptr< atf::check::check_result > r = do_exec(this, "exit-signal"); ATF_REQUIRE(!r->exited()); ATF_REQUIRE(r->signaled()); @@ -321,12 +321,12 @@ ATF_TEST_CASE_HEAD(exec_stdout_stderr) } ATF_TEST_CASE_BODY(exec_stdout_stderr) { - std::auto_ptr< atf::check::check_result > r1 = + std::unique_ptr< atf::check::check_result > r1 = do_exec(this, "stdout-stderr", "result1"); ATF_REQUIRE(r1->exited()); ATF_REQUIRE_EQ(r1->exitcode(), EXIT_SUCCESS); - std::auto_ptr< atf::check::check_result > r2 = + std::unique_ptr< atf::check::check_result > r2 = do_exec(this, "stdout-stderr", "result2"); ATF_REQUIRE(r2->exited()); ATF_REQUIRE_EQ(r2->exitcode(), EXIT_SUCCESS); @@ -372,7 +372,7 @@ ATF_TEST_CASE_BODY(exec_unknown) argv.push_back("/foo/bar/non-existent"); atf::process::argv_array argva(argv); - std::auto_ptr< atf::check::check_result > r = atf::check::exec(argva); + std::unique_ptr< atf::check::check_result > r = atf::check::exec(argva); ATF_REQUIRE(r->exited()); ATF_REQUIRE_EQ(r->exitcode(), 127); } diff --git a/atf-c++/detail/Kyuafile b/atf-c++/detail/Kyuafile index fc799e64df69..425595cef644 100644 --- a/atf-c++/detail/Kyuafile +++ b/atf-c++/detail/Kyuafile @@ -3,7 +3,6 @@ syntax("kyuafile", 1) test_suite("atf") atf_test_program{name="application_test"} -atf_test_program{name="auto_array_test"} atf_test_program{name="env_test"} atf_test_program{name="exceptions_test"} atf_test_program{name="fs_test"} diff --git a/atf-c++/detail/Makefile.am.inc b/atf-c++/detail/Makefile.am.inc index 08628d413376..6055df6bbc2f 100644 --- a/atf-c++/detail/Makefile.am.inc +++ b/atf-c++/detail/Makefile.am.inc @@ -23,9 +23,10 @@ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +CODE_COVERAGE_DIRS+= atf-c++/detail + libatf_c___la_SOURCES += atf-c++/detail/application.cpp \ atf-c++/detail/application.hpp \ - atf-c++/detail/auto_array.hpp \ atf-c++/detail/env.cpp \ atf-c++/detail/env.hpp \ atf-c++/detail/exceptions.cpp \ @@ -51,10 +52,6 @@ tests_atf_c___detail_PROGRAMS = atf-c++/detail/application_test atf_c___detail_application_test_SOURCES = atf-c++/detail/application_test.cpp atf_c___detail_application_test_LDADD = atf-c++/detail/libtest_helpers.la $(ATF_CXX_LIBS) -tests_atf_c___detail_PROGRAMS += atf-c++/detail/auto_array_test -atf_c___detail_auto_array_test_SOURCES = atf-c++/detail/auto_array_test.cpp -atf_c___detail_auto_array_test_LDADD = atf-c++/detail/libtest_helpers.la $(ATF_CXX_LIBS) - tests_atf_c___detail_PROGRAMS += atf-c++/detail/env_test atf_c___detail_env_test_SOURCES = atf-c++/detail/env_test.cpp atf_c___detail_env_test_LDADD = atf-c++/detail/libtest_helpers.la $(ATF_CXX_LIBS) diff --git a/atf-c++/detail/application.cpp b/atf-c++/detail/application.cpp index 37086eb3ae8c..3eeb8f966cf9 100644 --- a/atf-c++/detail/application.cpp +++ b/atf-c++/detail/application.cpp @@ -37,6 +37,7 @@ extern "C" { #include <cstdio> #include <cstdlib> #include <cstring> +#include <filesystem> #include <iostream> extern "C" { @@ -205,19 +206,8 @@ impl::app::run(int argc, char* const* argv) m_argc = argc; m_argv = argv; - m_argv0 = m_argv[0]; - - m_prog_name = std::strrchr(m_argv[0], '/'); - if (m_prog_name == NULL) - m_prog_name = m_argv[0]; - else - m_prog_name++; - - // Libtool workaround: if running from within the source tree (binaries - // that are not installed yet), skip the "lt-" prefix added to files in - // the ".libs" directory to show the real (not temporary) name. - if (std::strncmp(m_prog_name, "lt-", 3) == 0) - m_prog_name += 3; + auto m_prog_filename = std::filesystem::path(m_argv[0]).filename(); + m_prog_name = m_prog_filename.c_str(); const std::string bug = std::string("This is probably a bug in ") + m_prog_name + diff --git a/atf-c++/detail/application.hpp b/atf-c++/detail/application.hpp index cdb4073ad807..ad068467ac3a 100644 --- a/atf-c++/detail/application.hpp +++ b/atf-c++/detail/application.hpp @@ -81,7 +81,6 @@ protected: int m_argc; char* const* m_argv; - const char* m_argv0; const char* m_prog_name; std::string m_description; std::string m_manpage; diff --git a/atf-c++/detail/auto_array.hpp b/atf-c++/detail/auto_array.hpp deleted file mode 100644 index b434a5808235..000000000000 --- a/atf-c++/detail/auto_array.hpp +++ /dev/null @@ -1,175 +0,0 @@ -// Copyright (c) 2007 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. - -#if !defined(ATF_CXX_DETAIL_AUTO_ARRAY_HPP) -#define ATF_CXX_DETAIL_AUTO_ARRAY_HPP - -#include <cstddef> - -namespace atf { - -// ------------------------------------------------------------------------ -// The "auto_array" class. -// ------------------------------------------------------------------------ - -template< class T > -struct auto_array_ref { - T* m_ptr; - - explicit auto_array_ref(T*); -}; - -template< class T > -auto_array_ref< T >::auto_array_ref(T* ptr) : - m_ptr(ptr) -{ -} - -template< class T > -class auto_array { - T* m_ptr; - -public: - auto_array(T* = NULL) throw(); - auto_array(auto_array< T >&) throw(); - auto_array(auto_array_ref< T >) throw(); - ~auto_array(void) throw(); - - T* get(void) throw(); - const T* get(void) const throw(); - T* release(void) throw(); - void reset(T* = NULL) throw(); - - auto_array< T >& operator=(auto_array< T >&) throw(); - auto_array< T >& operator=(auto_array_ref< T >) throw(); - - T& operator[](int) throw(); - operator auto_array_ref< T >(void) throw(); -}; - -template< class T > -auto_array< T >::auto_array(T* ptr) - throw() : - m_ptr(ptr) -{ -} - -template< class T > -auto_array< T >::auto_array(auto_array< T >& ptr) - throw() : - m_ptr(ptr.release()) -{ -} - -template< class T > -auto_array< T >::auto_array(auto_array_ref< T > ref) - throw() : - m_ptr(ref.m_ptr) -{ -} - -template< class T > -auto_array< T >::~auto_array(void) - throw() -{ - if (m_ptr != NULL) - delete [] m_ptr; -} - -template< class T > -T* -auto_array< T >::get(void) - throw() -{ - return m_ptr; -} - -template< class T > -const T* -auto_array< T >::get(void) - const throw() -{ - return m_ptr; -} - -template< class T > -T* -auto_array< T >::release(void) - throw() -{ - T* ptr = m_ptr; - m_ptr = NULL; - return ptr; -} - -template< class T > -void -auto_array< T >::reset(T* ptr) - throw() -{ - if (m_ptr != NULL) - delete [] m_ptr; - m_ptr = ptr; -} - -template< class T > -auto_array< T >& -auto_array< T >::operator=(auto_array< T >& ptr) - throw() -{ - reset(ptr.release()); - return *this; -} - -template< class T > -auto_array< T >& -auto_array< T >::operator=(auto_array_ref< T > ref) - throw() -{ - if (m_ptr != ref.m_ptr) { - delete [] m_ptr; - m_ptr = ref.m_ptr; - } - return *this; -} - -template< class T > -T& -auto_array< T >::operator[](int pos) - throw() -{ - return m_ptr[pos]; -} - -template< class T > -auto_array< T >::operator auto_array_ref< T >(void) - throw() -{ - return auto_array_ref< T >(release()); -} - -} // namespace atf - -#endif // !defined(ATF_CXX_DETAIL_AUTO_ARRAY_HPP) diff --git a/atf-c++/detail/auto_array_test.cpp b/atf-c++/detail/auto_array_test.cpp deleted file mode 100644 index aaad90e15295..000000000000 --- a/atf-c++/detail/auto_array_test.cpp +++ /dev/null @@ -1,302 +0,0 @@ -// Copyright (c) 2007 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 "atf-c++/detail/auto_array.hpp" - -extern "C" { -#include <sys/types.h> -} - -#include <iostream> - -#include <atf-c++.hpp> - -extern "C" { -#include "atf-c/defs.h" -} - -// ------------------------------------------------------------------------ -// Tests for the "auto_array" class. -// ------------------------------------------------------------------------ - -class test_array { -public: - int m_value; - - static ssize_t m_nblocks; - - static - atf::auto_array< test_array > - do_copy(atf::auto_array< test_array >& ta) - { - return atf::auto_array< test_array >(ta); - } - - void* operator new(size_t size ATF_DEFS_ATTRIBUTE_UNUSED) - { - 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 << "\n"; - return mem; - } - - void operator delete(void* mem ATF_DEFS_ATTRIBUTE_UNUSED) - { - ATF_FAIL("Delete called but should have been delete[]"); - } - - void operator delete[](void* mem) - { - std::cout << "Releasing 'test_array' object " << mem << "\n"; - 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::auto_array; - - ATF_REQUIRE_EQ(test_array::m_nblocks, 0); - { - auto_array< test_array > t(new test_array[10]); - ATF_REQUIRE_EQ(test_array::m_nblocks, 1); - } - ATF_REQUIRE_EQ(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::auto_array; - - ATF_REQUIRE_EQ(test_array::m_nblocks, 0); - { - auto_array< test_array > t1(new test_array[10]); - ATF_REQUIRE_EQ(test_array::m_nblocks, 1); - - { - auto_array< test_array > t2(t1); - ATF_REQUIRE_EQ(test_array::m_nblocks, 1); - } - ATF_REQUIRE_EQ(test_array::m_nblocks, 0); - } - ATF_REQUIRE_EQ(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::auto_array; - - ATF_REQUIRE_EQ(test_array::m_nblocks, 0); - { - auto_array< test_array > t1(new test_array[10]); - ATF_REQUIRE_EQ(test_array::m_nblocks, 1); - - { - auto_array< test_array > t2 = test_array::do_copy(t1); - ATF_REQUIRE_EQ(test_array::m_nblocks, 1); - } - ATF_REQUIRE_EQ(test_array::m_nblocks, 0); - } - ATF_REQUIRE_EQ(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::auto_array; - - test_array* ta = new test_array[10]; - auto_array< test_array > t(ta); - ATF_REQUIRE_EQ(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::auto_array; - - test_array* ta1 = new test_array[10]; - { - auto_array< test_array > t(ta1); - ATF_REQUIRE_EQ(test_array::m_nblocks, 1); - test_array* ta2 = t.release(); - ATF_REQUIRE_EQ(ta2, ta1); - ATF_REQUIRE_EQ(test_array::m_nblocks, 1); - } - ATF_REQUIRE_EQ(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::auto_array; - - test_array* ta1 = new test_array[10]; - test_array* ta2 = new test_array[10]; - ATF_REQUIRE_EQ(test_array::m_nblocks, 2); - - { - auto_array< test_array > t(ta1); - ATF_REQUIRE_EQ(test_array::m_nblocks, 2); - t.reset(ta2); - ATF_REQUIRE_EQ(test_array::m_nblocks, 1); - t.reset(); - ATF_REQUIRE_EQ(test_array::m_nblocks, 0); - } - ATF_REQUIRE_EQ(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::auto_array; - - ATF_REQUIRE_EQ(test_array::m_nblocks, 0); - { - auto_array< test_array > t1(new test_array[10]); - ATF_REQUIRE_EQ(test_array::m_nblocks, 1); - - { - auto_array< test_array > t2; - t2 = t1; - ATF_REQUIRE_EQ(test_array::m_nblocks, 1); - } - ATF_REQUIRE_EQ(test_array::m_nblocks, 0); - } - ATF_REQUIRE_EQ(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::auto_array; - - ATF_REQUIRE_EQ(test_array::m_nblocks, 0); - { - auto_array< test_array > t1(new test_array[10]); - ATF_REQUIRE_EQ(test_array::m_nblocks, 1); - - { - auto_array< test_array > t2; - t2 = test_array::do_copy(t1); - ATF_REQUIRE_EQ(test_array::m_nblocks, 1); - } - ATF_REQUIRE_EQ(test_array::m_nblocks, 0); - } - ATF_REQUIRE_EQ(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::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_REQUIRE_EQ(t[i].m_value, i * 2); -} - -// ------------------------------------------------------------------------ -// 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); -} diff --git a/atf-c++/detail/fs.cpp b/atf-c++/detail/fs.cpp index bcef9204d129..74bacf26a421 100644 --- a/atf-c++/detail/fs.cpp +++ b/atf-c++/detail/fs.cpp @@ -32,7 +32,6 @@ extern "C" { #include <sys/param.h> #include <sys/types.h> -#include <sys/mount.h> #include <sys/stat.h> #include <sys/wait.h> #include <dirent.h> diff --git a/atf-c++/detail/process.cpp b/atf-c++/detail/process.cpp index 8139536d39e3..25516059c884 100644 --- a/atf-c++/detail/process.cpp +++ b/atf-c++/detail/process.cpp @@ -46,31 +46,29 @@ namespace impl = atf::process; // ------------------------------------------------------------------------ template< class C > -atf::auto_array< const char* > +std::vector<const char*> collection_to_argv(const C& c) { - atf::auto_array< const char* > argv(new const char*[c.size() + 1]); + std::vector<const char*> argv; + argv.reserve(c.size() + 1); - std::size_t pos = 0; - for (typename C::const_iterator iter = c.begin(); iter != c.end(); - iter++) { - argv[pos] = (*iter).c_str(); - pos++; + for (const auto& item : c) { + argv.push_back(item.c_str()); } - INV(pos == c.size()); - argv[pos] = NULL; + argv.push_back(nullptr); return argv; } -template< class C > +template<class C> C argv_to_collection(const char* const* argv) { C c; - for (const char* const* iter = argv; *iter != NULL; iter++) + for (const char* const* iter = argv; *iter != nullptr; iter++) { c.push_back(std::string(*iter)); + } return c; } @@ -123,7 +121,7 @@ const char* const* impl::argv_array::exec_argv(void) const { - return m_exec_argv.get(); + return m_exec_argv.data(); } impl::argv_array::size_type diff --git a/atf-c++/detail/process.hpp b/atf-c++/detail/process.hpp index 0d4989a4f40b..78bd55fd0f05 100644 --- a/atf-c++/detail/process.hpp +++ b/atf-c++/detail/process.hpp @@ -36,7 +36,6 @@ extern "C" { #include <string> #include <vector> -#include <atf-c++/detail/auto_array.hpp> #include <atf-c++/detail/exceptions.hpp> #include <atf-c++/detail/fs.hpp> @@ -58,7 +57,7 @@ class argv_array { // std::tr1::shared_array instead when it becomes widely available. // The reason would be to remove all copy constructors and assignment // operators from this class. - auto_array< const char* > m_exec_argv; + std::vector< const char* > m_exec_argv; void ctor_init_exec_argv(void); public: diff --git a/atf-c++/detail/process_test.cpp b/atf-c++/detail/process_test.cpp index 0686d2a1911c..69cd79d3f628 100644 --- a/atf-c++/detail/process_test.cpp +++ b/atf-c++/detail/process_test.cpp @@ -196,22 +196,19 @@ ATF_TEST_CASE_BODY(argv_array_assign) const char* const carray1[] = { "arg1", NULL }; const char* const carray2[] = { "arg1", "arg2", NULL }; - std::auto_ptr< argv_array > argv1(new argv_array(carray1)); - std::auto_ptr< argv_array > argv2(new argv_array(carray2)); + argv_array argv1 = argv_array(carray1); + argv_array argv2 = argv_array(carray2); - *argv2 = *argv1; - ATF_REQUIRE_EQ(argv2->size(), argv1->size()); - ATF_REQUIRE(std::strcmp((*argv2)[0], (*argv1)[0]) == 0); + argv2 = argv1; + ATF_REQUIRE_EQ(argv2.size(), argv1.size()); + ATF_REQUIRE(std::strcmp(argv2[0], argv1[0]) == 0); - ATF_REQUIRE(argv2->exec_argv() != argv1->exec_argv()); - argv1.release(); + ATF_REQUIRE(argv2.exec_argv() != argv1.exec_argv()); { - const char* const* eargv2 = argv2->exec_argv(); + const char* const* eargv2 = argv2.exec_argv(); ATF_REQUIRE(std::strcmp(eargv2[0], carray1[0]) == 0); ATF_REQUIRE_EQ(eargv2[1], static_cast< const char* >(NULL)); } - - argv2.release(); } ATF_TEST_CASE(argv_array_copy); @@ -226,21 +223,18 @@ ATF_TEST_CASE_BODY(argv_array_copy) const char* const carray[] = { "arg0", NULL }; - std::auto_ptr< argv_array > argv1(new argv_array(carray)); - std::auto_ptr< argv_array > argv2(new argv_array(*argv1)); + argv_array argv1 = argv_array(carray); + argv_array argv2 = argv1; - ATF_REQUIRE_EQ(argv2->size(), argv1->size()); - ATF_REQUIRE(std::strcmp((*argv2)[0], (*argv1)[0]) == 0); + ATF_REQUIRE_EQ(argv2.size(), argv1.size()); + ATF_REQUIRE(std::strcmp(argv2[0], argv1[0]) == 0); - ATF_REQUIRE(argv2->exec_argv() != argv1->exec_argv()); - argv1.release(); + ATF_REQUIRE(argv2.exec_argv() != argv1.exec_argv()); { - const char* const* eargv2 = argv2->exec_argv(); + const char* const* eargv2 = argv2.exec_argv(); ATF_REQUIRE(std::strcmp(eargv2[0], carray[0]) == 0); ATF_REQUIRE_EQ(eargv2[1], static_cast< const char* >(NULL)); } - - argv2.release(); } ATF_TEST_CASE(argv_array_exec_argv); diff --git a/atf-c++/detail/test_helpers.hpp b/atf-c++/detail/test_helpers.hpp index c1171801a3a7..1c4c316f4714 100644 --- a/atf-c++/detail/test_helpers.hpp +++ b/atf-c++/detail/test_helpers.hpp @@ -45,8 +45,6 @@ { \ set_md_var("descr", "Tests that the " hdrname " file can be " \ "included on its own, without any prerequisites"); \ - const std::string cxx = atf::env::get("ATF_BUILD_CXX", ATF_BUILD_CXX); \ - set_md_var("require.progs", cxx); \ } \ ATF_TEST_CASE_BODY(name) \ { \ @@ -58,8 +56,6 @@ ATF_TEST_CASE_HEAD(name) \ { \ set_md_var("descr", descr); \ - const std::string cxx = atf::env::get("ATF_BUILD_CXX", ATF_BUILD_CXX); \ - set_md_var("require.progs", cxx); \ } \ ATF_TEST_CASE_BODY(name) \ { \ diff --git a/atf-c++/detail/text.cpp b/atf-c++/detail/text.cpp index 35a0beca95b9..524788a41971 100644 --- a/atf-c++/detail/text.cpp +++ b/atf-c++/detail/text.cpp @@ -42,14 +42,6 @@ extern "C" { namespace impl = atf::text; #define IMPL_NAME "atf::text" -char* -impl::duplicate(const char* str) -{ - char* copy = new char[std::strlen(str) + 1]; - std::strcpy(copy, str); - return copy; -} - bool impl::match(const std::string& str, const std::string& regex) { diff --git a/atf-c++/detail/text.hpp b/atf-c++/detail/text.hpp index 63c3190a37c1..2e07df2cf4e9 100644 --- a/atf-c++/detail/text.hpp +++ b/atf-c++/detail/text.hpp @@ -39,14 +39,6 @@ namespace atf { namespace text { //! -//! \brief Duplicates a C string using the new[] allocator. -//! -//! Replaces the functionality of strdup by using the new[] allocator and -//! thus allowing the resulting memory to be managed by utils::auto_array. -//! -char* duplicate(const char*); - -//! //! \brief Joins multiple words into a string. //! //! Joins a list of words into a string, separating them using the provided diff --git a/atf-c++/detail/text_test.cpp b/atf-c++/detail/text_test.cpp index 49d37741b414..108241130f5d 100644 --- a/atf-c++/detail/text_test.cpp +++ b/atf-c++/detail/text_test.cpp @@ -35,26 +35,6 @@ // Test cases for the free functions. // ------------------------------------------------------------------------ -ATF_TEST_CASE(duplicate); -ATF_TEST_CASE_HEAD(duplicate) -{ - set_md_var("descr", "Tests the duplicate function"); -} -ATF_TEST_CASE_BODY(duplicate) -{ - using atf::text::duplicate; - - const char* orig = "foo"; - - char* copy = duplicate(orig); - ATF_REQUIRE_EQ(std::strlen(copy), 3); - ATF_REQUIRE(std::strcmp(copy, "foo") == 0); - - std::strcpy(copy, "bar"); - ATF_REQUIRE(std::strcmp(copy, "bar") == 0); - ATF_REQUIRE(std::strcmp(orig, "foo") == 0); -} - ATF_TEST_CASE(join); ATF_TEST_CASE_HEAD(join) { @@ -373,7 +353,6 @@ ATF_TEST_CASE_BODY(to_type) ATF_INIT_TEST_CASES(tcs) { // Add the test cases for the free functions. - ATF_ADD_TEST_CASE(tcs, duplicate); ATF_ADD_TEST_CASE(tcs, join); ATF_ADD_TEST_CASE(tcs, match); ATF_ADD_TEST_CASE(tcs, split); diff --git a/atf-c++/tests.cpp b/atf-c++/tests.cpp index ede9609e32d6..9edd89c69f02 100644 --- a/atf-c++/tests.cpp +++ b/atf-c++/tests.cpp @@ -58,7 +58,6 @@ extern "C" { } #include "atf-c++/detail/application.hpp" -#include "atf-c++/detail/auto_array.hpp" #include "atf-c++/detail/env.hpp" #include "atf-c++/detail/exceptions.hpp" #include "atf-c++/detail/fs.hpp" @@ -123,13 +122,7 @@ static void set_program_name(const char* argv0) { const std::string program_name = atf::fs::path(argv0).leaf_name(); - // Libtool workaround: if running from within the source tree (binaries - // that are not installed yet), skip the "lt-" prefix added to files in - // the ".libs" directory to show the real (not temporary) name. - if (program_name.substr(0, 3) == "lt-") - Program_Name = program_name.substr(3); - else - Program_Name = program_name; + Program_Name = program_name; } bool @@ -207,22 +200,22 @@ impl::tc::init(const vars_map& config) { atf_error_t err; - auto_array< const char * > array(new const char*[(config.size() * 2) + 1]); - const char **ptr = array.get(); + std::vector< const char * > array; + array.reserve((config.size() * 2) + 1); + for (vars_map::const_iterator iter = config.begin(); iter != config.end(); iter++) { - *ptr = (*iter).first.c_str(); - *(ptr + 1) = (*iter).second.c_str(); - ptr += 2; + array.push_back((*iter).first.c_str()); + array.push_back((*iter).second.c_str()); } - *ptr = NULL; + array.push_back(nullptr); wraps[&pimpl->m_tc] = this; cwraps[&pimpl->m_tc] = this; err = atf_tc_init(&pimpl->m_tc, pimpl->m_ident.c_str(), pimpl->wrap_head, pimpl->wrap_body, pimpl->m_has_cleanup ? pimpl->wrap_cleanup : NULL, - array.get()); + array.data()); if (atf_is_error(err)) throw_atf_error(err); } @@ -273,6 +266,7 @@ impl::tc::get_md_vars(void) char **ptr; for (ptr = array; *ptr != NULL; ptr += 2) vars[*ptr] = *(ptr + 1); + atf_utils_free_charpp(array); } catch (...) { atf_utils_free_charpp(array); throw; @@ -454,9 +448,7 @@ init_tcs(void (*add_tcs)(tc_vector&), tc_vector& tcs, const atf::tests::vars_map& vars) { add_tcs(tcs); - for (tc_vector::iterator iter = tcs.begin(); iter != tcs.end(); iter++) { - impl::tc* tc = *iter; - + for (auto& tc : tcs) { tc->init(vars); } } @@ -609,27 +601,25 @@ safe_main(int argc, char** argv, void (*add_tcs)(tc_vector&)) int errcode; - tc_vector tcs; if (lflag) { if (argc > 0) throw usage_error("Cannot provide test case names with -l"); - - init_tcs(add_tcs, tcs, vars); - errcode = list_tcs(tcs); } else { if (argc == 0) throw usage_error("Must provide a test case name"); else if (argc > 1) throw usage_error("Cannot provide more than one test case name"); INV(argc == 1); - - init_tcs(add_tcs, tcs, vars); - errcode = run_tc(tcs, argv[0], resfile); } - for (tc_vector::iterator iter = tcs.begin(); iter != tcs.end(); iter++) { - impl::tc* tc = *iter; - - delete tc; + tc_vector tcs; + try { + init_tcs(add_tcs, tcs, vars); + errcode = lflag ? list_tcs(tcs) : run_tc(tcs, argv[0], resfile); + } catch (...) { + for (auto& tc: tcs) { + delete tc; + } + throw; } return errcode; |
