BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bslfmt_formattertestutil

Detailed Description

Provide utilities for testing custom formatters.

Outline

Purpose

Provide utilities for testing custom formatters

Classes

Description

This component provides a utility to facilitate testing of bsl::formatter partial specializations where, due to hierarchical reasons, the testing cannot be performed using bslfmt::format.

This component is for use within bslfmt only.

Usage

This section illustrates intended usage of this component.

Example: Testing an integer formatter

Suppose we want to test bsl::formatter specialization for int.

First, to test parse function, we can use testParseVFormat function, that accepts pointer to bsl::string in which to store an error message if any, a flag indicating our desire to see the result of the standard implementation and accordingly the format string itself:

typedef bslfmt::FormatterTestUtil<char> TestUtilChar;
bsl::string message;
bool rv = TestUtilChar::testParseVFormat<int>(&message, true, "{0:}");
Definition bslstl_string.h:1252
Definition bslfmt_formattertestutil.h:481

Since the input data is correct, we get a positive result and the error message is empty:

assert(true == rv);
assert(message.empty());
bool empty() const BSLS_KEYWORD_NOEXCEPT
Return true if this string has length 0, and false otherwise.
Definition bslstl_string.h:7331

Then, we try to parse invalid format string and get the expected error message at the output:

rv = TestUtilChar::testParseVFormat<int>(&message, true, "{0");
assert(false == rv);
assert(bsl::string("Format string too short") == message);
message.clear();
void clear() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_string.h:6043

Now we check format formatter's method using testEvaluateVFormat function, that in addition to the parameters already mentioned, accepts a string with the expected formatting result and a value for formatting:

rv = TestUtilChar::testEvaluateVFormat<int>(&message, // message
"5", // expected result
true, // oracle required
"{0:}", // format string
5); // value
assert(true == rv);
assert(message.empty());

Finally verify that this function returns a false value if the expected and actual results do not match:

rv = TestUtilChar::testEvaluateVFormat<int>(&message, // message
"7", // incorrect result
true, // oracle required
"{0:}", // format string
5); // value
assert(false == rv);
assert(message.starts_with("bslfmt result does not match"));
bool starts_with(basic_string_view< CHAR_TYPE, CHAR_TRAITS > characterString) const BSLS_KEYWORD_NOEXCEPT
Definition bslstl_string.h:7918

Macro Definition Documentation

◆ BSLFMT_FORMATTER_TEST_CONSTEVAL

#define BSLFMT_FORMATTER_TEST_CONSTEVAL

◆ BSLFMT_FORMATTER_TEST_UTIL_BASIC_FORMAT_STRING

#define BSLFMT_FORMATTER_TEST_UTIL_BASIC_FORMAT_STRING    bslfmt::basic_format_string<t_CHAR>

◆ BSLFMT_FORMATTER_TEST_UTIL_BASIC_FORMAT_STRING_GETTER

#define BSLFMT_FORMATTER_TEST_UTIL_BASIC_FORMAT_STRING_GETTER (   ARG)     ARG.get()

◆ BSLFMT_FORMATTER_TEST_UTIL_BASIC_FORMAT_STRING_ONE_ARG

#define BSLFMT_FORMATTER_TEST_UTIL_BASIC_FORMAT_STRING_ONE_ARG    bslfmt::basic_format_string<t_CHAR>

◆ BSLFMT_FORMATTER_TEST_UTIL_BASIC_FORMAT_STRING_P

#define BSLFMT_FORMATTER_TEST_UTIL_BASIC_FORMAT_STRING_P    bslfmt::basic_format_string<t_CHAR>

◆ BSLFMT_FORMATTER_TEST_UTIL_BASIC_FORMAT_STRING_TWO_ARGS

#define BSLFMT_FORMATTER_TEST_UTIL_BASIC_FORMAT_STRING_TWO_ARGS    bslfmt::basic_format_string<t_CHAR>

◆ BSLFMT_FORMATTER_TEST_UTIL_FORMAT_STRING

#define BSLFMT_FORMATTER_TEST_UTIL_FORMAT_STRING    bslfmt::basic_format_string<char>

◆ BSLFMT_FORMATTER_TEST_UTIL_FORMAT_STRING_ONE_ARG

#define BSLFMT_FORMATTER_TEST_UTIL_FORMAT_STRING_ONE_ARG    bslfmt::basic_format_string<char>

◆ BSLFMT_FORMATTER_TEST_UTIL_FORMAT_STRING_P

#define BSLFMT_FORMATTER_TEST_UTIL_FORMAT_STRING_P    bslfmt::basic_format_string<char>

◆ BSLFMT_FORMATTER_TEST_UTIL_FORMAT_STRING_TWO_ARGS

#define BSLFMT_FORMATTER_TEST_UTIL_FORMAT_STRING_TWO_ARGS    bslfmt::basic_format_string<char>

◆ BSLFMT_FORMATTER_TEST_UTIL_WFORMAT_STRING

#define BSLFMT_FORMATTER_TEST_UTIL_WFORMAT_STRING    bslfmt::basic_format_string<wchar_t>

◆ BSLFMT_FORMATTER_TEST_UTIL_WFORMAT_STRING_ONE_ARG

#define BSLFMT_FORMATTER_TEST_UTIL_WFORMAT_STRING_ONE_ARG    bslfmt::basic_format_string<wchar_t>

◆ BSLFMT_FORMATTER_TEST_UTIL_WFORMAT_STRING_P

#define BSLFMT_FORMATTER_TEST_UTIL_WFORMAT_STRING_P    bslfmt::basic_format_string<wchar_t>

◆ BSLFMT_FORMATTER_TEST_UTIL_WFORMAT_STRING_TWO_ARGS

#define BSLFMT_FORMATTER_TEST_UTIL_WFORMAT_STRING_TWO_ARGS    bslfmt::basic_format_string<wchar_t>