libamxp  1.4.0
Patterns C Implementation
test_siginfo_variant.c
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** SPDX-License-Identifier: BSD-2-Clause-Patent
4 **
5 ** SPDX-FileCopyrightText: Copyright (c) 2023 SoftAtHome
6 **
7 ** Redistribution and use in source and binary forms, with or without modification,
8 ** are permitted provided that the following conditions are met:
9 **
10 ** 1. Redistributions of source code must retain the above copyright notice,
11 ** this list of conditions and the following disclaimer.
12 **
13 ** 2. Redistributions in binary form must reproduce the above copyright notice,
14 ** this list of conditions and the following disclaimer in the documentation
15 ** and/or other materials provided with the distribution.
16 **
17 ** Subject to the terms and conditions of this license, each copyright holder
18 ** and contributor hereby grants to those receiving rights under this license
19 ** a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable
20 ** (except for failure to satisfy the conditions of this license) patent license
21 ** to make, have made, use, offer to sell, sell, import, and otherwise transfer
22 ** this software, where such license applies only to those patent claims, already
23 ** acquired or hereafter acquired, licensable by such copyright holder or contributor
24 ** that are necessarily infringed by:
25 **
26 ** (a) their Contribution(s) (the licensed copyrights of copyright holders and
27 ** non-copyrightable additions of contributors, in source or binary form) alone;
28 ** or
29 **
30 ** (b) combination of their Contribution(s) with the work of authorship to which
31 ** such Contribution(s) was added by such copyright holder or contributor, if,
32 ** at the time the Contribution is added, such addition causes such combination
33 ** to be necessarily infringed. The patent license shall not apply to any other
34 ** combinations which include the Contribution.
35 **
36 ** Except as expressly stated above, no rights or licenses from any copyright
37 ** holder or contributor is granted under this license, whether expressly, by
38 ** implication, estoppel or otherwise.
39 **
40 ** DISCLAIMER
41 **
42 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
43 ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
45 ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
46 ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
47 ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
48 ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
49 ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
50 ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
51 ** USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
52 **
53 ****************************************************************************/
54 #include <sys/time.h>
55 #include <sys/resource.h>
56 
57 #include <string.h>
58 #include <stdlib.h>
59 #include <stdio.h>
60 #include <stdarg.h>
61 #include <stddef.h>
62 #include <setjmp.h>
63 #include <inttypes.h>
64 #include <limits.h>
65 #include <unistd.h>
66 #include <fcntl.h>
67 #include <cmocka.h>
68 
69 #include <amxc/amxc_variant_type.h>
70 #include <amxp/variant_siginfo.h>
71 #include <amxp_signal_priv.h>
72 
73 #include "test_siginfo_variant.h"
74 
75 
76 #include <amxc/amxc_macros.h>
77 void test_var_siginfo_new(UNUSED void** state) {
78  amxc_var_t var;
79  const amxp_siginfo_t* siginfo = NULL;
80 
81  amxc_var_init(&var);
82  assert_int_equal(amxc_var_set_type(&var, AMXC_VAR_ID_SIGINFO), 0);
83  assert_int_equal(amxc_var_type_of(&var), AMXC_VAR_ID_SIGINFO);
84  assert_string_equal(amxc_var_type_name_of(&var), AMXC_VAR_NAME_SIGINFO);
85 
86  assert_ptr_not_equal(var.data.data, NULL);
87  siginfo = amxc_var_constcast(amxp_siginfo_t, &var);
88  assert_ptr_not_equal(siginfo, NULL);
89 
90  amxc_var_clean(&var);
91 }
92 
93 void test_var_siginfo_delete(UNUSED void** state) {
94  amxc_var_t var;
95 
96  amxc_var_init(&var);
97  assert_int_equal(amxc_var_set_type(&var, AMXC_VAR_ID_SIGINFO), 0);
98  assert_ptr_not_equal(var.data.data, NULL);
99  amxc_var_clean(&var);
100  assert_ptr_equal(var.data.data, NULL);
101 }
102 
103 void test_var_siginfo_set_copy(UNUSED void** state) {
104  amxc_var_t var;
105  amxc_var_t var_copy;
106  amxp_siginfo_t siginfo = {
107  .ssi_signo = SIGCHLD,
108  .ssi_errno = 0,
109  .ssi_code = 123,
110  .ssi_pid = 5012,
111  .ssi_uid = 100
112  };
113  const amxp_siginfo_t* copy = NULL;
114 
115  amxc_var_init(&var);
116  amxc_var_init(&var_copy);
117  assert_int_not_equal(amxc_var_set(amxp_siginfo_t, NULL, &siginfo), 0);
118  assert_int_not_equal(amxc_var_set(amxp_siginfo_t, &var, NULL), 0);
119  assert_int_equal(amxc_var_set(amxp_siginfo_t, &var, &siginfo), 0);
120  assert_ptr_not_equal(var.data.data, NULL);
121  assert_ptr_not_equal(var.data.data, &siginfo);
122 
123  copy = amxc_var_constcast(amxp_siginfo_t, &var_copy);
124  assert_ptr_equal(copy, NULL);
125 
126  assert_int_equal(amxc_var_copy(&var_copy, &var), 0);
127  assert_ptr_not_equal(var_copy.data.data, NULL);
128 
129  copy = amxc_var_constcast(amxp_siginfo_t, NULL);
130  assert_ptr_equal(copy, NULL);
131  copy = amxc_var_constcast(amxp_siginfo_t, &var_copy);
132  assert_ptr_not_equal(copy, NULL);
133  assert_int_equal(copy->ssi_signo, siginfo.ssi_signo);
134  assert_int_equal(copy->ssi_errno, siginfo.ssi_errno);
135  assert_int_equal(copy->ssi_code, siginfo.ssi_code);
136  assert_int_equal(copy->ssi_pid, siginfo.ssi_pid);
137  assert_int_equal(copy->ssi_uid, siginfo.ssi_uid);
138 
139  amxc_var_clean(&var);
140  amxc_var_clean(&var_copy);
141 }
142 
#define UNUSED
Definition: main.c:68
void test_var_siginfo_set_copy(UNUSED void **state)
void test_var_siginfo_delete(UNUSED void **state)
void test_var_siginfo_new(UNUSED void **state)
struct signalfd_siginfo amxp_siginfo_t
#define AMXC_VAR_NAME_SIGINFO
#define AMXC_VAR_ID_SIGINFO