Branch data Line data Source code
1 : : /*
2 : : * Copyright (c) 2017, Citrix Systems, Inc.
3 : : *
4 : : * All rights reserved.
5 : : *
6 : : * Redistribution and use in source and binary forms, with or without
7 : : * modification, are permitted provided that the following conditions are met:
8 : : *
9 : : * 1. Redistributions of source code must retain the above copyright
10 : : * notice, this list of conditions and the following disclaimer.
11 : : * 2. Redistributions in binary form must reproduce the above copyright
12 : : * notice, this list of conditions and the following disclaimer in the
13 : : * documentation and/or other materials provided with the distribution.
14 : : * 3. Neither the name of the copyright holder nor the names of its
15 : : * contributors may be used to endorse or promote products derived from
16 : : * this software without specific prior written permission.
17 : : *
18 : : * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 : : * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 : : * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 : : * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
22 : : * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 : : * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 : : * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25 : : * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26 : : * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 : : * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 : : * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 : : */
30 : :
31 : : #include <stddef.h>
32 : : #include <stdarg.h>
33 : : #include <setjmp.h>
34 : : #include <cmocka.h>
35 : :
36 : : #include <cbt-util-priv.h>
37 : : #include <wrappers.h>
38 : : #include "test-suites.h"
39 : :
40 : : void
41 : 1 : test_get_command_create(void **state)
42 : : {
43 : : struct command *cmd;
44 : :
45 : 1 : char* requested_command = { "create" };
46 : :
47 : 1 : cmd = get_command(requested_command);
48 : :
49 : 1 : assert_string_equal(cmd->name, "create");
50 : 1 : assert_ptr_equal(cmd->func, cbt_util_create);
51 : 1 : }
52 : :
53 : : void
54 : 1 : test_get_command_set(void **state)
55 : : {
56 : : struct command *cmd;
57 : :
58 : 1 : char* requested_command = { "set" };
59 : :
60 : 1 : cmd = get_command(requested_command);
61 : :
62 : 1 : assert_string_equal(cmd->name, "set");
63 : 1 : assert_ptr_equal(cmd->func, cbt_util_set);
64 : 1 : }
65 : :
66 : : void
67 : 1 : test_get_command_get(void **state)
68 : : {
69 : : struct command *cmd;
70 : :
71 : 1 : char* requested_command = { "get" };
72 : :
73 : 1 : cmd = get_command(requested_command);
74 : :
75 : 1 : assert_string_equal(cmd->name, "get");
76 : 1 : assert_ptr_equal(cmd->func, cbt_util_get);
77 : 1 : }
78 : :
79 : : void
80 : 1 : test_get_command_coalesce(void **state)
81 : : {
82 : : struct command *cmd;
83 : :
84 : 1 : char* requested_command = { "coalesce" };
85 : :
86 : 1 : cmd = get_command(requested_command);
87 : :
88 : 1 : assert_string_equal(cmd->name, "coalesce");
89 : 1 : assert_ptr_equal(cmd->func, cbt_util_coalesce);
90 : 1 : }
91 : :
92 : : void
93 : 1 : test_get_command_bad_command(void **state)
94 : : {
95 : : struct command *cmd;
96 : :
97 : 1 : char* requested_command = { "breakme" };
98 : :
99 : 1 : cmd = get_command(requested_command);
100 : :
101 : 1 : assert_null(cmd);
102 : 1 : }
103 : :
104 : : void
105 : 1 : test_get_command_over_long_command(void **state)
106 : : {
107 : : struct command *cmd;
108 : :
109 : 1 : char* requested_command = { "im_a_really_really_long_command" };
110 : :
111 : 1 : cmd = get_command(requested_command);
112 : :
113 : 1 : assert_null(cmd);
114 : 1 : }
115 : :
116 : : void
117 : 1 : test_help_success(void ** state)
118 : : {
119 : : struct printf_data *output;
120 : :
121 : 1 : output = setup_vprintf_mock(1024);
122 : :
123 : 1 : help();
124 : :
125 : 1 : assert_in_range(output->offset, 10, 1024);
126 : :
127 : 1 : free_printf_data(output);
128 : 1 : }
|