added test of the psensor_type_to_unit_str function
[psensor.git] / tests / test_psensor_type_to_unit_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 <locale.h>
26 #include <libintl.h>
27 #define _(str) gettext(str)
28
29 #include "../src/lib/psensor.h"
30
31 static int test_psensor_type_to_unit_str()
32 {
33         const char *u;
34         int failures;
35
36         u = psensor_type_to_unit_str(SENSOR_TYPE_TEMP, 1);
37         if (strcmp("\302\260C", u))
38             failures++;
39
40         u = psensor_type_to_unit_str(SENSOR_TYPE_TEMP, 0);
41         if (strcmp("\302\260F", u))
42             failures++;
43
44         u = psensor_type_to_unit_str(SENSOR_TYPE_LMSENSOR_TEMP, 1);
45         if (strcmp("\302\260C", u))
46             failures++;
47
48         u = psensor_type_to_unit_str(SENSOR_TYPE_LMSENSOR_TEMP, 0);
49         if (strcmp("\302\260F", u))
50             failures++;
51
52         u = psensor_type_to_unit_str(SENSOR_TYPE_FAN, 0);
53         if (strcmp(_("RPM"), u))
54             failures++;
55
56         return failures;
57 }
58
59 int main(int argc, char **argv)
60 {
61         int failures;
62
63         setlocale(LC_ALL, "");
64         bindtextdomain(PACKAGE, LOCALEDIR);
65         textdomain(PACKAGE);
66
67         failures = 0;
68
69         failures += test_psensor_type_to_unit_str();
70
71         if (failures) 
72                 exit(EXIT_FAILURE);
73         else
74                 exit(EXIT_SUCCESS);
75 }