mirror of
https://github.com/opnsense/src.git
synced 2026-07-16 12:33:07 -04:00
- freebsd::FILE_up is a wrapper class for std::unique_ptr<> for FILE objects which uses a custom deleter that calls fclose(). - freebsd::malloc_up<T> is a wrapper class for std::unique_ptr<> which uses a custom deleter that calls free(). It is useful for pointers allocated by malloc() such as strdup(). - The freebsd::stringf() functions return a std::string constructed using a printf format string. The current implementation of freebsd::stringf() uses fwopen() where the write function appends to a std::string. Sponsored by: Chelsio Communications Pull Request: https://github.com/freebsd/freebsd-src/pull/1794
33 lines
633 B
C++
33 lines
633 B
C++
/*-
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*
|
|
* Copyright (c) 2025 Chelsio Communications, Inc.
|
|
* Written by: John Baldwin <jhb@FreeBSD.org>
|
|
*/
|
|
|
|
#include <atf-c++.hpp>
|
|
#include <libutil.h>
|
|
|
|
#include <libutil++.hh>
|
|
|
|
ATF_TEST_CASE_WITHOUT_HEAD(FILE_up);
|
|
ATF_TEST_CASE_BODY(FILE_up)
|
|
{
|
|
FILE *fp = fopen("/dev/null", "r");
|
|
ATF_REQUIRE(fp != NULL);
|
|
ATF_REQUIRE(fileno(fp) != -1);
|
|
|
|
freebsd::FILE_up f(fp);
|
|
ATF_REQUIRE_EQ(fileno(fp), fileno(f.get()));
|
|
|
|
f.reset();
|
|
ATF_REQUIRE_EQ(f.get(), nullptr);
|
|
|
|
ATF_REQUIRE_EQ(-1, fileno(fp));
|
|
ATF_REQUIRE_EQ(EBADF, errno);
|
|
}
|
|
|
|
ATF_INIT_TEST_CASES(tcs)
|
|
{
|
|
ATF_ADD_TEST_CASE(tcs, FILE_up);
|
|
}
|