switched to 3.9.7 defaults
[psensor-pkg-ubuntu.git] / tests / test_psensor_value_to_str.c
1 /*
2  * Copyright (C) 2010-2011 jeanfi@gmail.com
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301 USA
18  */
19
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <string.h>
23 #include <sys/stat.h>
24
25 #include "../src/lib/psensor.h"
26
27 #define CELSIUS "\302\260C"
28 #define FAHRENHEIT "\302\260F"
29
30 static int
31 test_psensor_value_to_str(unsigned int type,
32                           double value,
33                           int celsius,
34                           const char *ref)
35 {
36         char *str;
37
38         str = psensor_value_to_str(type, value, celsius);
39         if (strcmp(ref, str)) {
40                 fprintf(stderr, "returns: %s expected: %s\n", str, ref);
41                 return 1;
42         } else {
43                 return 0;
44         }
45 }
46
47 int main(int argc, char **argv)
48 {
49         int errs;
50
51         errs = test_psensor_value_to_str(SENSOR_TYPE_TEMP, 13, 1,
52                                          "13"CELSIUS);
53         errs += test_psensor_value_to_str(SENSOR_TYPE_TEMP, 13, 0,
54                                           "55"FAHRENHEIT);
55         errs += test_psensor_value_to_str(SENSOR_TYPE_TEMP, 13.4, 1,
56                                           "13"CELSIUS);
57         errs += test_psensor_value_to_str(SENSOR_TYPE_TEMP, 13.5, 1,
58                                           "14"CELSIUS);
59
60         if (errs) 
61                 exit(EXIT_FAILURE);
62         else
63                 exit(EXIT_SUCCESS);
64 }