OpenVPN
mock_msg.c
Go to the documentation of this file.
1 /*
2  * OpenVPN -- An application to securely tunnel IP networks
3  * over a single UDP port, with support for SSL/TLS-based
4  * session authentication and key exchange,
5  * packet encryption, packet authentication, and
6  * packet compression.
7  *
8  * Copyright (C) 2016-2018 Fox Crypto B.V. <openvpn@fox-it.com>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License version 2
12  * as published by the Free Software Foundation.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23 
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #elif defined(_MSC_VER)
27 #include "config-msvc.h"
28 #endif
29 
30 #include <stdarg.h>
31 #include <stddef.h>
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <setjmp.h>
35 #include <cmocka.h>
36 
37 
38 #include "errlevel.h"
39 #include "error.h"
40 
41 unsigned int x_debug_level = 0; /* Default to (almost) no debugging output */
42 bool fatal_error_triggered = false;
43 
44 void
46 {
47  x_debug_level = level;
48 }
49 
50 void
51 x_msg_va(const unsigned int flags, const char *format,
52  va_list arglist)
53 {
54  if (flags & M_FATAL)
55  {
56  fatal_error_triggered = true;
57  printf("FATAL ERROR:");
58  }
59  vprintf(format, arglist);
60  printf("\n");
61 }
62 
63 void
64 x_msg(const unsigned int flags, const char *format, ...)
65 {
66  va_list arglist;
67  va_start(arglist, format);
68  x_msg_va(flags, format, arglist);
69  va_end(arglist);
70 }
71 
72 void
73 assert_failed(const char *filename, int line, const char *condition)
74 {
75  mock_assert(false, condition ? condition : "", filename, line);
76  /* Keep compiler happy. Should not happen, mock_assert() does not return */
77  exit(1);
78 }
79 
80 /*
81  * Fail memory allocation. Don't use msg() because it tries
82  * to allocate memory as part of its operation.
83  */
84 void
86 {
87  fprintf(stderr, "Out of Memory\n");
88  exit(1);
89 }
90 
91 bool
92 dont_mute(unsigned int flags)
93 {
94  return true;
95 }
void x_msg_va(const unsigned int flags, const char *format, va_list arglist)
Definition: mock_msg.c:51
unsigned int x_debug_level
Definition: mock_msg.c:41
void assert_failed(const char *filename, int line, const char *condition)
Definition: mock_msg.c:73
void mock_assert(const int result, const char *const expression, const char *const file, const int line)
Function to replace assert(3) in tested code.
Definition: cmocka.c:1520
list flags
bool fatal_error_triggered
Definition: mock_msg.c:42
void out_of_memory(void)
Definition: mock_msg.c:85
void mock_set_debug_level(int level)
Mock debug level defaults to 0, which gives clean(-ish) test reports.
Definition: mock_msg.c:45
#define M_FATAL
Definition: error.h:94
bool dont_mute(unsigned int flags)
Check muting filter.
Definition: mock_msg.c:92
void x_msg(const unsigned int flags, const char *format,...)
Definition: mock_msg.c:64