Branch data Line data Source code
1 : : /*
2 : : * Copyright (c) 2020, 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 <stdarg.h>
32 : : #include <stddef.h>
33 : : #include <setjmp.h>
34 : : #include <cmocka.h>
35 : :
36 : : #include "libvhd.h"
37 : : #include "vhd-wrappers.h"
38 : :
39 : : static int cookie = 0;
40 : : static int close_count = 0;
41 : : static int *open_return_errs = NULL;
42 : : static int n_return_errs = 0;
43 : : static int open_call_count = 0;
44 : :
45 : 2 : void reset_flags()
46 : : {
47 : 2 : close_count = 0;
48 : 2 : cookie = 0;
49 : 2 : open_return_errs = NULL;
50 : 2 : n_return_errs = 0;
51 : 2 : open_call_count = 0;
52 : 2 : }
53 : :
54 : 5 : int get_close_count()
55 : : {
56 : 5 : return close_count;
57 : : }
58 : :
59 : 1 : void set_open_errors(int nerrs, int* errs)
60 : : {
61 : 1 : open_return_errs = errs;
62 : 1 : n_return_errs = nerrs;
63 : 1 : }
64 : :
65 : 2 : void set_cookie()
66 : : {
67 : 2 : cookie = 1;
68 : 2 : }
69 : :
70 : 5 : void __wrap_free(void* in)
71 : : {
72 : 5 : check_expected(in);
73 : 5 : }
74 : :
75 : 5 : char *__wrap_canonpath(const char *path, char *resolved_path)
76 : : {
77 : 5 : return (char*)mock();
78 : : }
79 : :
80 : 5 : int __wrap_vhd_snapshot(const char *snapshot, uint64_t bytes, const char *parent,
81 : : uint64_t mbytes, uint32_t flag)
82 : : {
83 : 5 : return (int)mock();
84 : : }
85 : :
86 : 6 : int __wrap_vhd_open(vhd_context_t *ctx, const char *file, int flags)
87 : : {
88 : : int ret;
89 [ + + ]: 6 : if(open_return_errs) {
90 : 2 : ret = open_return_errs[open_call_count];
91 : :
92 : : } else {
93 : 4 : ret = (int)mock();
94 : : }
95 : 6 : open_call_count++;
96 : 6 : return ret;
97 : : }
98 : :
99 : 3 : int __wrap_vhd_get_keyhash(vhd_context_t *ctx, struct vhd_keyhash* hash)
100 : : {
101 [ + + ]: 3 : if(cookie) {
102 : 2 : hash->cookie = 1;
103 : : }
104 : 3 : return (int)mock();
105 : : }
106 : :
107 : 4 : int __wrap_vhd_close(vhd_context_t *ctx)
108 : : {
109 : 4 : check_expected(ctx);
110 : 4 : close_count++;
111 : 4 : return (int)mock();
112 : : }
113 : :
114 : 1 : int __wrap_vhd_set_keyhash(vhd_context_t *ctx, struct vhd_keyhash* hash)
115 : : {
116 : 1 : return (int)mock();
117 : : }
|