YAC 3.20.0
Yet Another Coupler
Loading...
Searching...
No Matches
test_param.c File Reference

Unit tests for yac_param (interpolation method config param interface) More...

#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <stdint.h>
#include "parameter/param.h"
#include "parameter/param_int.h"
#include "parameter/param_bool.h"
#include "parameter/param_dble.h"
#include "parameter/param_angle.h"
#include "parameter/param_distance.h"
#include "parameter/param_oneof.h"
#include "parameter/param_list.h"
#include "parameter/param_str.h"
#include "parameter/param_struct.h"
#include "parameter/param_enum.h"
#include "parameter/param_internal.h"
#include "tests.h"
Include dependency graph for test_param.c:

Go to the source code of this file.

Data Structures

struct  dummy_config
 [icparam_example_struct] More...
 
struct  dummy_config::dummy_sub
 

Enumerations

enum  { dummy_option_types_size }
 

Functions

static int oneof_factory (const char *name, void **obj, struct yac_param **param, int *is_default)
 
static int oneof_failing_factory (const char *name, void **obj, struct yac_param **param, int *is_default)
 
static struct yac_paramget_sub_by_name (struct yac_param *param, char const *name)
 
static struct yac_paramget_sub_by_index (struct yac_param *param, size_t idx)
 
static int default_factory (void **element_ptr, struct yac_param **param_ptr)
 
static int failing_default_factory (void **element_ptr, struct yac_param **param_ptr)
 
static int list_existing_element_get_param (void *element, struct yac_param **param_ptr)
 
static struct yac_paramdummy_sub_build_param (struct dummy_sub *dummy_sub)
 [icparam_example_defaults]
 
static int dummy_sub_factory (const char *name, void **obj, struct yac_param **param, int *is_default)
 
static struct yac_paramdummy_config_get_param (struct dummy_config *cfg)
 

Variables

static double const tol = 1e-12
 
static char const * oneof_int_param_name = "int_sub"
 
static int oneof_int_val = 7
 
static int oneof_int_default = 42
 
static int oneof_int_min = 0
 
static int oneof_int_max = 100
 
static int oneof_has_default = 1
 
static int oneof_is_defined = 1
 
static char const * oneof_bool_param_name = "bool_sub"
 
static int oneof_bool_val = 1
 
static int oneof_bool_default = 0
 
static int oneof_bool_has_default = 1
 
static int oneof_bool_is_defined = 1
 
static char const * oneof_default_param_name = "int_sub"
 
static char const * list_param_name = "int_sub"
 
static int list_param_init_value = 4
 
static int list_param_default_value = 0
 
static int list_param_min = 0
 
static int list_param_max = 100
 
static int list_param_has_default = 1
 
static int list_param_is_defined = 1
 
static struct yac_name_type_pair const dummy_option_types []
 [icparam_example_struct]
 
int const DUMMY_COUNT_DEFAULT = 3
 [icparam_example_lookup]
 
double const DUMMY_DISTANCE_DEFAULT = 1.0 * M_PI / 180.0
 
static int const DUMMY_SUB_DEFAULT = (int)DUMMY_OPTION_A
 
double const DUMMY_SCALE_DEFAULT = 0.5
 
char const *const DUMMY_NAME_DEFAULT = "default_name"
 

Detailed Description

Unit tests for yac_param (interpolation method config param interface)

Test
Tests for yac_param.

Definition in file test_param.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
dummy_option_types_size 

Definition at line 2575 of file test_param.c.

Function Documentation

◆ default_factory()

static int default_factory ( void ** element_ptr,
struct yac_param ** param_ptr )
static

Definition at line 2329 of file test_param.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dummy_config_get_param()

static struct yac_param * dummy_config_get_param ( struct dummy_config * cfg)
static

Constructs the config param tree for dummy_config.

Parameters
[in]cfgPointer to the dummy_config struct that the config params will be backed by.
Returns
Pointer to the root config param struct for dummy_config.

Definition at line 2736 of file test_param.c.

Here is the call graph for this function:

◆ dummy_sub_build_param()

static struct yac_param * dummy_sub_build_param ( struct dummy_sub * dummy_sub)
static

[icparam_example_defaults]

Builds the parameter struct for a given dummy_sub struct, which is the "sub" parameter in dummy_config.

Parameters
[in]dummy_subThe dummy_sub struct for which to build the config param struct
Returns
Pointer to the config param struct for the given dummy_sub, or NULL it dummy_sub is NULL.

Definition at line 2599 of file test_param.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dummy_sub_factory()

static int dummy_sub_factory ( const char * name,
void ** obj,
struct yac_param ** param,
int * is_default )
static

Factory for the dummy_config "sub" parameter, which is a oneof with two variants:

  • DUMMY_OPTION_A: has a distance parameter "scale"
  • DUMMY_OPTION_B: has a string parameter "name" The factory populates the dummy_sub struct based on the option type and returns the corresponding config param struct for the active sub variant. The factory also sets is_default to true if the default sub variant (DUMMY_OPTION_A) is active.
Parameters
[in]nameThe name of the sub variant (e.g. "option_a" or "option_b"); NULL for default
[in,out]objPointer to the dummy_sub pointer in dummy_config; factory allocates and sets *obj to point to the dummy_sub struct for the active variant
[out]paramPointer to the config param struct for the active sub variant, which the factory allocates and populates with the appropriate sub-parameters (e.g. "scale" for option_a, "name" for option_b)
[out]is_defaultSet to true if the active sub variant is the default (DUMMY_OPTION_A), false otherwise
Returns
0 on success, non-zero on failure (e.g. unknown sub variant name)

Definition at line 2678 of file test_param.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ failing_default_factory()

static int failing_default_factory ( void ** element_ptr,
struct yac_param ** param_ptr )
static

Definition at line 2341 of file test_param.c.

◆ get_sub_by_index()

static struct yac_param * get_sub_by_index ( struct yac_param * param,
size_t idx )
static

Definition at line 2311 of file test_param.c.

Here is the call graph for this function:

◆ get_sub_by_name()

static struct yac_param * get_sub_by_name ( struct yac_param * param,
char const * name )
static

Definition at line 443 of file test_param.c.

Here is the call graph for this function:

◆ list_existing_element_get_param()

static int list_existing_element_get_param ( void * element,
struct yac_param ** param_ptr )
static

Definition at line 2348 of file test_param.c.

Here is the call graph for this function:

◆ oneof_factory()

static int oneof_factory ( const char * name,
void ** obj,
struct yac_param ** param,
int * is_default )
static

Definition at line 88 of file test_param.c.

Here is the call graph for this function:

◆ oneof_failing_factory()

static int oneof_failing_factory ( const char * name,
void ** obj,
struct yac_param ** param,
int * is_default )
static

Definition at line 149 of file test_param.c.

Variable Documentation

◆ DUMMY_COUNT_DEFAULT

int const DUMMY_COUNT_DEFAULT = 3

[icparam_example_lookup]

[icparam_example_defaults]

Definition at line 2583 of file test_param.c.

◆ DUMMY_DISTANCE_DEFAULT

double const DUMMY_DISTANCE_DEFAULT = 1.0 * M_PI / 180.0

Definition at line 2584 of file test_param.c.

◆ DUMMY_NAME_DEFAULT

char const* const DUMMY_NAME_DEFAULT = "default_name"

Definition at line 2587 of file test_param.c.

◆ dummy_option_types

struct yac_name_type_pair const dummy_option_types[]
static
Initial value:
= {
DEF_NAME_TYPE_PAIR(option_a, DUMMY_OPTION_A),
DEF_NAME_TYPE_PAIR(option_b, DUMMY_OPTION_B),
DEF_NAME_TYPE_PAIR(a, DUMMY_OPTION_A),
}
#define DEF_NAME_TYPE_PAIR(NAME, TYPE)

[icparam_example_struct]

[icparam_example_lookup]

Definition at line 2569 of file test_param.c.

◆ DUMMY_SCALE_DEFAULT

double const DUMMY_SCALE_DEFAULT = 0.5

Definition at line 2586 of file test_param.c.

◆ DUMMY_SUB_DEFAULT

int const DUMMY_SUB_DEFAULT = (int)DUMMY_OPTION_A
static

Definition at line 2585 of file test_param.c.

◆ list_param_default_value

int list_param_default_value = 0
static

Definition at line 2322 of file test_param.c.

◆ list_param_has_default

int list_param_has_default = 1
static

Definition at line 2325 of file test_param.c.

◆ list_param_init_value

int list_param_init_value = 4
static

Definition at line 2321 of file test_param.c.

◆ list_param_is_defined

int list_param_is_defined = 1
static

Definition at line 2326 of file test_param.c.

◆ list_param_max

int list_param_max = 100
static

Definition at line 2324 of file test_param.c.

◆ list_param_min

int list_param_min = 0
static

Definition at line 2323 of file test_param.c.

◆ list_param_name

char const* list_param_name = "int_sub"
static

Definition at line 2320 of file test_param.c.

◆ oneof_bool_default

int oneof_bool_default = 0
static

Definition at line 81 of file test_param.c.

◆ oneof_bool_has_default

int oneof_bool_has_default = 1
static

Definition at line 82 of file test_param.c.

◆ oneof_bool_is_defined

int oneof_bool_is_defined = 1
static

Definition at line 83 of file test_param.c.

◆ oneof_bool_param_name

char const* oneof_bool_param_name = "bool_sub"
static

Definition at line 79 of file test_param.c.

◆ oneof_bool_val

int oneof_bool_val = 1
static

Definition at line 80 of file test_param.c.

◆ oneof_default_param_name

char const* oneof_default_param_name = "int_sub"
static

Definition at line 85 of file test_param.c.

◆ oneof_has_default

int oneof_has_default = 1
static

Definition at line 76 of file test_param.c.

◆ oneof_int_default

int oneof_int_default = 42
static

Definition at line 73 of file test_param.c.

◆ oneof_int_max

int oneof_int_max = 100
static

Definition at line 75 of file test_param.c.

◆ oneof_int_min

int oneof_int_min = 0
static

Definition at line 74 of file test_param.c.

◆ oneof_int_param_name

char const* oneof_int_param_name = "int_sub"
static

Definition at line 71 of file test_param.c.

◆ oneof_int_val

int oneof_int_val = 7
static

Definition at line 72 of file test_param.c.

◆ oneof_is_defined

int oneof_is_defined = 1
static

Definition at line 77 of file test_param.c.

◆ tol

double const tol = 1e-12
static

Definition at line 49 of file test_param.c.