libamxo  4.3.4
Object Definition Language (ODL) parsing
test_resolvers.c File Reference
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <inttypes.h>
#include <limits.h>
#include <unistd.h>
#include <fcntl.h>
#include <cmocka.h>
#include <amxc/amxc.h>
#include <amxp/amxp_signal.h>
#include <amxd/amxd_dm.h>
#include <amxd/amxd_object.h>
#include <amxd/amxd_parameter.h>
#include <amxo/amxo.h>
#include <amxo/amxo_hooks.h>
#include "test_resolvers.h"
#include <amxc/amxc_macros.h>

Go to the source code of this file.

Functions

static void test_resolver_get (amxo_parser_t *parser, void *priv)
 
static amxo_fn_ptr_t test_resolver_resolve (amxo_parser_t *parser, UNUSED const char *fn_name, UNUSED amxo_fn_type_t type, UNUSED const char *data, void *priv)
 
static void test_resolver_clean (amxo_parser_t *parser, void *priv)
 
void test_register_resolver (UNUSED void **state)
 
void test_invalid_resolver_names (UNUSED void **state)
 
void test_auto_resolver_order_no_any (UNUSED void **state)
 

Variables

static const char * priv_data = "PRIVATE"
 
static amxo_resolver_t test_resolver
 
static amxo_resolver_t invalid_resolver
 

Function Documentation

◆ test_auto_resolver_order_no_any()

void test_auto_resolver_order_no_any ( UNUSED void **  state)

Definition at line 184 of file test_resolvers.c.

184  {
185  amxd_dm_t dm;
186  amxo_parser_t parser;
187  amxc_var_t order;
188  const char* odls[] = {
189  "%define { object Test { void Func(); } }",
190  "%define { object Test { void Func()<!test:data!>; } }",
191  "%config { resolver = 'test'; } %define { object Test { void Func()<!${resolver}:data!>; } }",
192  NULL
193  };
194 
195  assert_int_equal(amxo_register_resolver("test", &test_resolver), 0);
196 
197  amxd_dm_init(&dm);
198  amxo_parser_init(&parser);
199  amxc_var_init(&order);
200  amxc_var_set_type(&order, AMXC_VAR_ID_LIST);
201  amxo_parser_set_config(&parser, "auto-resolver-order", &order);
202  amxc_var_clean(&order);
203 
204  for(int i = 0; odls[i] != NULL; i++) {
205  assert_int_equal(amxo_parser_parse_string(&parser, odls[i], amxd_dm_get_root(&dm)), 0);
206  assert_int_equal(amxo_parser_get_status(&parser), amxd_status_ok);
207  amxd_dm_clean(&dm);
208  }
209 
210  assert_int_equal(amxo_unregister_resolver("test"), 0);
211 
212  amxo_parser_clean(&parser);
213  amxd_dm_clean(&dm);
214 }
int amxo_parser_set_config(amxo_parser_t *parser, const char *path, amxc_var_t *value)
Sets a configuration option.
int amxo_parser_parse_string(amxo_parser_t *parser, const char *text, amxd_object_t *object)
Parses a string containing a valid ODL part.
void amxo_parser_clean(amxo_parser_t *parser)
Cleans up the odl parser instance.
static amxd_status_t amxo_parser_get_status(amxo_parser_t *parser)
Get the status of the odl parser.
Definition: amxo.h:414
int amxo_parser_init(amxo_parser_t *parser)
Initializes a new odl parser instance.
int amxo_unregister_resolver(const char *name)
Unregisters a function resolver.
int amxo_register_resolver(const char *name, amxo_resolver_t *resolver)
Registers a function resolver.
The ODL parser structure.
Definition: amxo_types.h:245
static amxo_resolver_t test_resolver

◆ test_invalid_resolver_names()

void test_invalid_resolver_names ( UNUSED void **  state)

Definition at line 160 of file test_resolvers.c.

160  {
161  amxd_dm_t dm;
162  amxo_parser_t parser;
163  const char* odls[] = {
164  "%define { object Test { void Func()<!!>; } }",
165  "%define { object Test { void Func()<!:data!>; } }",
166  "%define { object Test { void Func()<! :data!>; } }",
167  "%define { object Test { void Func()<!invalid-resolver:data!>; } }",
168  NULL
169  };
170 
171  amxd_dm_init(&dm);
172  amxo_parser_init(&parser);
173 
174  for(int i = 0; odls[i] != NULL; i++) {
175  assert_int_not_equal(amxo_parser_parse_string(&parser, odls[i], amxd_dm_get_root(&dm)), 0);
176  assert_int_equal(amxo_parser_get_status(&parser), amxd_status_invalid_name);
177  amxd_dm_clean(&dm);
178  }
179 
180  amxo_parser_clean(&parser);
181  amxd_dm_clean(&dm);
182 }

◆ test_register_resolver()

void test_register_resolver ( UNUSED void **  state)

Definition at line 126 of file test_resolvers.c.

126  {
127  amxd_dm_t dm;
128  amxo_parser_t parser;
129  const char* odls[] = {
130  "%define { object Test { void Func(); } }",
131  "%define { object Test { void Func()<!test:data!>; } }",
132  NULL
133  };
134 
135  amxd_dm_init(&dm);
136 
137  assert_int_not_equal(amxo_register_resolver("ftab", &test_resolver), 0);
138  assert_int_not_equal(amxo_register_resolver("auto", &test_resolver), 0);
139  assert_int_not_equal(amxo_register_resolver("import", &test_resolver), 0);
140  assert_int_not_equal(amxo_register_resolver("import2", NULL), 0);
141  assert_int_not_equal(amxo_register_resolver("My.Resolver", &test_resolver), 0);
142  assert_int_not_equal(amxo_register_resolver("test", &invalid_resolver), 0);
143  assert_int_equal(amxo_register_resolver("test", &test_resolver), 0);
144 
145  amxo_parser_init(&parser);
146 
147  for(int i = 0; odls[i] != NULL; i++) {
148  assert_int_equal(amxo_parser_parse_string(&parser, odls[i], amxd_dm_get_root(&dm)), 0);
149  assert_int_equal(amxo_parser_get_status(&parser), amxd_status_ok);
150  amxd_dm_clean(&dm);
151  }
152 
153  assert_int_equal(amxo_unregister_resolver("test"), 0);
154  assert_int_not_equal(amxo_unregister_resolver("test"), 0);
155 
156  amxo_parser_clean(&parser);
157  amxd_dm_clean(&dm);
158 }
static amxo_resolver_t invalid_resolver

◆ test_resolver_clean()

static void test_resolver_clean ( amxo_parser_t parser,
void *  priv 
)
static

Definition at line 104 of file test_resolvers.c.

105  {
106  amxc_var_t* config = amxo_parser_get_config(parser, "test-data");
107  assert_ptr_not_equal(config, NULL);
108  assert_int_equal(amxc_var_constcast(int32_t, config), 666);
109  assert_ptr_equal(priv, &priv_data);
110 }
config
amxc_var_t * amxo_parser_get_config(amxo_parser_t *parser, const char *path)
Gets a configuration option.
static const char * priv_data

◆ test_resolver_get()

static void test_resolver_get ( amxo_parser_t parser,
void *  priv 
)
static

Definition at line 83 of file test_resolvers.c.

84  {
85  amxc_var_t* config = amxo_parser_claim_config(parser, "test-data");
86  assert_ptr_not_equal(config, NULL);
87  amxc_var_set(int32_t, config, 666);
88  assert_ptr_equal(priv, &priv_data);
89 }
amxc_var_t * amxo_parser_claim_config(amxo_parser_t *parser, const char *path)
Gets or creates a configuration option.

◆ test_resolver_resolve()

static amxo_fn_ptr_t test_resolver_resolve ( amxo_parser_t parser,
UNUSED const char *  fn_name,
UNUSED amxo_fn_type_t  type,
UNUSED const char *  data,
void *  priv 
)
static

Definition at line 91 of file test_resolvers.c.

95  {
96  amxc_var_t* config = amxo_parser_get_config(parser, "test-data");
97  assert_ptr_not_equal(config, NULL);
98  assert_int_equal(amxc_var_constcast(int32_t, config), 666);
99  assert_ptr_equal(priv, &priv_data);
100 
101  return NULL;
102 }

Variable Documentation

◆ invalid_resolver

amxo_resolver_t invalid_resolver
static
Initial value:
= {
.resolve = NULL,
.priv = &priv_data
}
static void test_resolver_clean(amxo_parser_t *parser, void *priv)
static void test_resolver_get(amxo_parser_t *parser, void *priv)

Definition at line 119 of file test_resolvers.c.

◆ priv_data

const char* priv_data = "PRIVATE"
static

Definition at line 81 of file test_resolvers.c.

◆ test_resolver

amxo_resolver_t test_resolver
static
Initial value:
= {
.priv = &priv_data
}
static amxo_fn_ptr_t test_resolver_resolve(amxo_parser_t *parser, UNUSED const char *fn_name, UNUSED amxo_fn_type_t type, UNUSED const char *data, void *priv)

Definition at line 112 of file test_resolvers.c.