Heraia  0.1.8
tests.c
Go to the documentation of this file.
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /*
3  * tests.c
4  * tests for code coverage and bugs
5  *
6  * (C) Copyright 2010 - 2011 Olivier Delhomme
7  * e-mail : heraia@delhomme.org
8  * URL : http://heraia.tuxfamily.org
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 as published by
12  * the Free Software Foundation; either version 2, or (at your option)
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23  */
24 
25  /**
26  * @file tests.c
27  * tests (code coverage and bug tracking)
28  */
29 #include <libheraia.h>
30 
31 static gboolean test_one_function(DecodeFunc a_function, gchar *function_name, guchar *data, gpointer data_struct, gchar *expected_result);
32 
33 
34 /**
35  * test one decoding function from the decode.c module
36  * @param a_function : a decoding function that responds to the DecodeFunc template
37  * @param function_name : a gchar * representing the name of the function
38  * @param data : the data to be decoded
39  * @param data_struct : a structure related to the decoding function that may
40  * help to decode data correctly
41  * @param expected_result : the result that may give the decoding function with
42  * those specific parameters
43  */
44 static gboolean test_one_function(DecodeFunc a_function, gchar *function_name, guchar *data, gpointer data_struct, gchar *expected_result)
45 {
46  gchar *ret_code = NULL;
47 
48  ret_code = a_function(data, data_struct);
49 
50  if (g_strcmp0(ret_code, expected_result) == 0)
51  {
52  return TRUE;
53  }
54  else
55  {
56  fprintf(stderr, Q_("WARNING : expected result was not good with %s\n"), function_name);
57  return FALSE;
58  }
59 }
60 
61 
62 /**
63  * test decode functions
64  * No parameters
65  */
66 gboolean test_decode_functions(void)
67 {
68 
69  gboolean exit_value = TRUE;
70 
71  exit_value = exit_value && test_one_function(decode_8bits_signed, "decode_8bits_signed", NULL, NULL, NULL);
72  exit_value = exit_value && test_one_function(decode_8bits_unsigned, "decode_8bits_unsigned", NULL, NULL, NULL);
73 
74  exit_value = exit_value && test_one_function(decode_16bits_signed, "decode_16bits_signed", NULL, NULL, NULL);
75  exit_value = exit_value && test_one_function(decode_16bits_unsigned, "decode_16bits_unsigned", NULL, NULL, NULL);
76 
77  exit_value = exit_value && test_one_function(decode_32bits_signed, "decode_32bits_signed", NULL, NULL, NULL);
78  exit_value = exit_value && test_one_function(decode_32bits_unsigned, "decode_32bits_unsigned", NULL, NULL, NULL);
79 
80  exit_value = exit_value && test_one_function(decode_64bits_signed, "decode_64bits_signed", NULL, NULL, NULL);
81  exit_value = exit_value && test_one_function(decode_64bits_unsigned, "decode_64bits_unsigned", NULL, NULL, NULL);
82 
83  exit_value = exit_value && test_one_function(decode_float_normal, "decode_float_normal", NULL, NULL, NULL);
84  exit_value = exit_value && test_one_function(decode_float_scientific, "decode_float_scientific", NULL, NULL, NULL);
85 
86  exit_value = exit_value && test_one_function(decode_double_normal, "decode_double_normal", NULL, NULL, NULL);
87  exit_value = exit_value && test_one_function(decode_double_scientific, "decode_double_scientific", NULL, NULL, NULL);
88 
89  return exit_value;
90 }
91 
92 
93 /**
94  * functions to tests heraia's UI
95  * @param main_struct : the main structure (the whole one)
96  */
97 gboolean tests_ui(heraia_struct_t *main_struct)
98 {
99 
100  return TRUE;
101 }
gboolean tests_ui(heraia_struct_t *main_struct)
functions to tests heraia's UI
Definition: tests.c:97
This is the main structure.
Definition: libheraia.h:332
gchar * decode_16bits_unsigned(guchar *data, gpointer data_struct)
general purpose of this function is to take a 2 byte data stream and convert it as if it is a 16 bits...
Definition: decode.c:118
gchar * decode_double_scientific(guchar *data, gpointer data_struct)
general purpose of this function is to take a 8 byte data stream and convert it as if it is a float n...
Definition: decode.c:302
static gboolean test_one_function(DecodeFunc a_function, gchar *function_name, guchar *data, gpointer data_struct, gchar *expected_result)
test one decoding function from the decode.c module
Definition: tests.c:44
gchar * decode_32bits_unsigned(guchar *data, gpointer data_struct)
general purpose of this function is to take a 4 byte data stream and convert it as if it is a 32 bits...
Definition: decode.c:164
gchar * decode_float_scientific(guchar *data, gpointer data_struct)
general purpose of this function is to take a 4 byte data stream and convert it as if it is a float n...
Definition: decode.c:256
gchar * decode_8bits_unsigned(guchar *data, gpointer data_struct)
general purpose of this function is to take a 1 byte data stream and convert it as if it is an 8 bits...
Definition: decode.c:72
gchar * decode_32bits_signed(guchar *data, gpointer data_struct)
general purpose of this function is to take a 4 byte data stream and convert it as if it is a 32 bits...
Definition: decode.c:141
gchar * decode_8bits_signed(guchar *data, gpointer data_struct)
General purpose of this function is to take a 1 byte data stream and convert it as if it is an 8 bits...
Definition: decode.c:49
gboolean test_decode_functions(void)
test decode functions No parameters
Definition: tests.c:66
gchar * decode_double_normal(guchar *data, gpointer data_struct)
general purpose of this function is to take a 8 byte data stream and convert it as if it is a float n...
Definition: decode.c:279
gchar *(* DecodeFunc)(guchar *, gpointer)
Templates for the decoding functions.
Definition: libheraia.h:139
gchar * decode_64bits_signed(guchar *data, gpointer data_struct)
general purpose of this function is to take a 8 byte data stream and convert it as if it is a 64 bits...
Definition: decode.c:187
gchar * decode_float_normal(guchar *data, gpointer data_struct)
general purpose of this function is to take a 4 byte data stream and convert it as if it is a float n...
Definition: decode.c:233
This file contains all the definitions and includes all other .h files.
gchar * decode_64bits_unsigned(guchar *data, gpointer data_struct)
general purpose of this function is to take a 8 byte data stream and convert it as if it is a 64 bits...
Definition: decode.c:210
gchar * decode_16bits_signed(guchar *data, gpointer data_struct)
general purpose of this function is to take a 2 byte data stream and convert it as if it is a 16 bits...
Definition: decode.c:95