The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
pair_test_helpers.h
Go to the documentation of this file.
1 #pragma once
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16  */
17 
18 /** Helper functions for pair tests
19  *
20  * @file src/lib/util/pair_test_helpers.h
21  *
22  * @copyright 2021 The FreeRADIUS server project
23  */
24 RCSIDH(pair_test_h, "$Id: b50b623db01744969a67f8fa5066df95a1a99707 $")
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 #include <freeradius-devel/util/pair.h>
31 #include <freeradius-devel/util/dict_test.h>
32 
33 DIAG_OFF(unused-variable)
34 static char const *test_string = "We love testing!";
35 static size_t test_string_len = 16;
36 static uint8_t test_octets[] = {
37  0x53, 0x65, 0x20, 0x6c, 0x6f, 0x76, 0x65,
38  0x20, 0x74, 0x65, 0x69, 0x74, 0x20, 0x41,
39  0x63, 0x61, 0x64, 0x65, 0x6d, 0x79, 0x0a
40  };
41 DIAG_ON(unused-variable)
42 
43 static inline int fr_pair_test_list_alloc(TALLOC_CTX *ctx, fr_pair_list_t *out,
44  fr_dict_test_attr_t const *test_defs)
45 {
46  fr_dict_test_attr_t const *p;
47 
48  if (!test_defs) test_defs = fr_dict_test_attrs;
49 
51 
52  for (p = test_defs;
53  p->attr != -1;
54  p++) if (!fr_type_is_structural((*p->da)->type) && fr_pair_prepend_by_da(ctx, NULL, out, *p->da) < 0) return -1;
55 
57 
58  return 0;
59 }
60 
61 static inline int fr_pair_test_list_alloc_nested(TALLOC_CTX *ctx, fr_pair_list_t *out,
62  fr_dict_test_attr_t const *test_defs)
63 {
64  fr_dict_test_attr_t const *p;
65 
66  if (!test_defs) test_defs = fr_dict_test_attrs;
67 
69 
70  for (p = test_defs;
71  p->attr != -1;
72  p++) if (fr_pair_append_by_da_parent(ctx, NULL, out, *p->da) < 0) return -1;
73 
75 
76  return 0;
77 }
78 
79 #ifdef __cplusplus
80 }
81 #endif
#define DIAG_ON(_x)
Definition: build.h:419
#define RCSIDH(h, id)
Definition: build.h:445
#define DIAG_OFF(_x)
Definition: build.h:418
fr_dict_test_attr_t const fr_dict_test_attrs[]
Definition: dict_test.c:86
fr_dict_test_attr_number_t attr
Attribute number to create.
Definition: dict_test.h:100
fr_dict_attr_t const ** da
Where to write a pointer to this attribute.
Definition: dict_test.h:102
Test enumeration attributes.
Definition: dict_test.h:99
unsigned char uint8_t
Definition: merged_model.c:30
void fr_pair_list_init(fr_pair_list_t *list)
Initialise a pair list header.
Definition: pair.c:46
int fr_pair_append_by_da_parent(TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t *list, fr_dict_attr_t const *da)
Alloc a new fr_pair_t, adding the parent attributes if required.
Definition: pair.c:1518
int fr_pair_prepend_by_da(TALLOC_CTX *ctx, fr_pair_t **out, fr_pair_list_t *list, fr_dict_attr_t const *da)
Alloc a new fr_pair_t (and prepend)
Definition: pair.c:1488
static int fr_pair_test_list_alloc_nested(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_test_attr_t const *test_defs)
static uint8_t test_octets[]
static int fr_pair_test_list_alloc(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_test_attr_t const *test_defs)
static size_t test_string_len
static char const * test_string
#define PAIR_LIST_VERIFY(_x)
Definition: pair.h:193
#define fr_type_is_structural(_x)
Definition: types.h:371
static size_t char ** out
Definition: value.h:984