test::Function
- Inherits: test::Test
public
Types
#
ExpectedErrorusing test::Function< return_type, args >::ExpectedError = arg::Argument<int, struct FunctionExpectedErrorTag>
Type: arg::Argument< int, struct FunctionExpectedErrorTag >
#
ExpectedReturnusing test::Function< return_type, args >::ExpectedReturn = arg::Argument<return_type, struct FunctionExpectedErrorTag>
Type: arg::Argument< return_type, struct FunctionExpectedErrorTag >
Functions
#
Function(const var::String &test_name, return_type(function)(args...), Test parent=0)inline
test::Function< return_type, args >::Function (const var::String &test_name, return_type(*function)(args...), Test *parent=0)
#
~Function()inline
test::Function< return_type, args >::~Function ()
#
execute_case_with_expected_return(const char *case_name, return_type expected_value, int expected_errno, args... arguments)inline
return_type test::Function< return_type, args >::execute_case_with_expected_return (const char *case_name, return_type expected_value, int expected_errno, args... arguments)
Type: return_type
Parameters:
const char *
case_name
return_type
expected_value
int
expected_errno
args...
arguments
#
DetailsExecutes a test case.
Returns:
The value that the tested function returns
#
execute_case_with_less_than_zero_on_error(const char *case_name, int expected_errno, args... arguments)inline
return_type test::Function< return_type, args >::execute_case_with_less_than_zero_on_error (const char *case_name, int expected_errno, args... arguments)
Type: return_type
Parameters:
const char *
case_name
int
expected_errno
args...
arguments
#
expect_error(int expected_errno, args... arguments)inline
return_type test::Function< return_type, args >::expect_error (int expected_errno, args... arguments)
Type: return_type
Parameters:
int
expected_errno
args...
arguments
#
expect_result(return_type expected_result, args... arguments)inline
return_type test::Function< return_type, args >::expect_result (return_type expected_result, args... arguments)
Type: return_type
Parameters:
Details
The Function template class is designed to test any arbitrary C or C++ function (not member methods, just regular functions).The following is an example that tests open() for various error conditions.
#include <sapi/test.hpp>
//because open() has variable arguments we wrap it to make it work with thisclass int test_open(const char * path, int o_flags, int o_mode){ returnopen(path, o_flags, o_mode);}
bool is_test_enabled = true;
Test::initilize("test name", "0.1");
if( is_test_enabled ){ //when test is constructed Function<int, const char *, int, int> open_function_test("open",test_open);
open_function_test.execute("NO EXIST Read only", -1, ENOENT,"/home/non-existing-file.txt", O_RDONLY, 0); open_function_test.execute("NOEXIST Read Write", -1, ENOENT, "/home/non-existing-file.txt", O_RDWR, 0); open_function_test.execute("NO EXIST Read Write", -1, ENAMETOOLONG,"/home/non-existing-file-too-long-too-long-too-long-too-long-too-long-too-long-too-long-too-long-too-long-too-long.txt",O_RDWR, 0);
//open_function_test will call the deconstructor here before[Test::finalize](classtest_1_1_test#classtest_1_1_test_1aff841db16eb845c2cc2b285b433538f1)()}
[Test::finalize](classtest_1_1_test#classtest_1_1_test_1aff841db16eb845c2cc2b285b433538f1)();