Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/openlaunchd
Path: blob/master/liblaunch/test/liblaunch_test.c
374 views
1
/*
2
* Copyright (c) 2013 R. Tyler Croy, All rights reserved.
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*
16
*/
17
18
#include <stdio.h>
19
#include "liblaunch_test.h"
20
21
22
#include "launch_priv.h"
23
#include "launch_internal.h"
24
/* Verify _launch_init_globals() properly sets up a given launch_globals_t */
25
void test_launch_init_globals(void **s) {
26
struct launch_globals_s data;
27
void *prev_ptr = data.lc_mtx;
28
_launch_init_globals(&data);
29
assert_true(data.lc_mtx == prev_ptr);
30
};
31
32
void setup_empty(void **s) {
33
};
34
35
void teardown_launch_data(void **state) {
36
launch_data_free((launch_data_t)(*state));
37
};
38
39
void test_launch_data_alloc(void **s) {
40
launch_data_t data = launch_data_alloc(LAUNCH_DATA_INTEGER);
41
*s = (void *)(data);
42
assert_false(NULL == data);
43
assert_true(data->type == LAUNCH_DATA_INTEGER);
44
};
45
46
void test_launch_data_alloc_array(void **s) {
47
launch_data_t data = launch_data_alloc(LAUNCH_DATA_ARRAY);
48
*s = (void *)(data);
49
assert_false(NULL == data);
50
assert_true(data->type == LAUNCH_DATA_ARRAY);
51
assert_false(NULL == data->_array);
52
};
53
54
int main(void) {
55
const UnitTest tests[] = {
56
unit_test(test_host2wire_64),
57
unit_test(test_host2wire_32),
58
unit_test(test_host2wire_16),
59
unit_test(test_host2wire_8),
60
unit_test(test_wire2host_64),
61
unit_test(test_wire2host_32),
62
unit_test(test_wire2host_16),
63
unit_test(test_wire2host_8),
64
unit_test(test_launch_data_get_errno_null),
65
unit_test(test_launch_data_get_errno),
66
unit_test(test_launch_data_get_fd_null),
67
unit_test(test_launch_data_get_integer_null),
68
unit_test(test_launch_data_get_integer),
69
unit_test(test_launch_data_get_bool_default),
70
unit_test(test_launch_data_get_bool_false),
71
unit_test(test_launch_init_globals),
72
unit_test_setup_teardown(test_launch_data_alloc, setup_empty, teardown_launch_data),
73
unit_test_setup_teardown(test_launch_data_alloc_array, setup_empty, teardown_launch_data),
74
};
75
76
return run_tests(tests);
77
}
78
79