Skip to content

ut_kvp_profile: Key‐Value Pair Assertions for Unit Testing

Ulrond edited this page Jul 24, 2024 · 9 revisions

The ut_kvp_profile.h header is an extension of the ut_kvp framework, specifically designed for streamlined assertions within unit tests. It leverages the key-value pair (KVP) structure to simplify the validation of test results against expected outcomes.

Key Features

  • Simplified Assertions: Provides a concise syntax for common assertions (equality checks, string comparisons, etc.) using KVPs.
  • Test Case Configuration: Enables loading of expected test results from YAML/JSON files for easy management and maintenance.
  • Error Reporting: Integrates with the ut_log module to provide clear and informative error messages upon assertion failures.
  • Integration with ut-core: ut_kvp_profile support is provided by default when using ut-core via the -p switch.

Example Usage

  1. Create a Configuration File:
test_case_1:
  expected_result: true
test_case_2:
  expected_result: 12345
  1. Start the test and specify the profile file
  • Passing a profile into the testing suite, will automatically open the profile
./hdmi_cec -p hdmi_one_port_no_extendedEnums.yml
  1. Use Assertions:

Macro's are now active and available for use in the test suite.

bool result = my_function();
UT_ASSERT_EQUAL_KVP_PROFILE_BOOL(result, "test_case_1/expected_result");

Detail on how it works.

Integration with ut_log

The ut_kvp_profile module seamlessly integrates with the ut_log module to provide informative logging upon assertion failures. For example, the following code:

UT_ASSERT_EQUAL_KVP_PROFILE_BOOL(false, "test_case_1/expected_result");

would result in a log message similar to:

Assertion failed: test_case_1/expected_result (expected: true, actual: false)

Assertion Macros

The header defines several macros for common assertion types:

  • UT_ASSERT_EQUAL_KVP_PROFILE_BOOL(checkValue, key)
  • UT_ASSERT_EQUAL_KVP_PROFILE_UINT8(checkValue, key)
  • UT_ASSERT_EQUAL_KVP_PROFILE_UINT16(checkValue, key)
  • UT_ASSERT_EQUAL_KVP_PROFILE_UINT32(checkValue, key)
  • UT_ASSERT_EQUAL_KVP_PROFILE_UINT64(checkValue, key)
  • UT_ASSERT_EQUAL_KVP_PROFILE_STRING(checkValue, key)

These macros compare a given checkValue against the value associated with the specified key in the KVP data structure. If the values don't match, an assertion failure is triggered.

Get Field Marcos

The header defines several macros for common get types:

  • UT_KVP_PROFILE_GET_BOOL(key)
  • UT_KVP_PROFILE_GET_UINT8(key)
  • UT_KVP_PROFILE_GET_UINT16(key)
  • UT_KVP_PROFILE_GET_UINT32(key)
  • UT_KVP_PROFILE_GET_UINT64(key)
  • UT_KVP_PROFILE_GET_LIST_COUNT(key)
  • UT_KVP_PROFILE_GET_STRING(key, pszReturnedString )

For more detailed information of operation see the header file ut_kvp_profile.h

Clone this wiki locally