updated
[psensor-pkg-ubuntu.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
32 test_fct(unsigned int type, int use_celsius, const char *ref)
33 {
34         const char *u;
35
36         u = psensor_type_to_unit_str(type, use_celsius);
37         if (strcmp(ref, u)) {
38                 fprintf(stderr, "returns: %s expected: %s\n", u, ref);
39                 return 0;
40         }
41
42         return 1;
43 }
44
45 static int test() {
46         int failures;
47
48         failures = 0;
49
50         if (!test_fct(SENSOR_TYPE_TEMP, 1, "\302\260C"))
51                 failures++;
52
53         if (!test_fct(SENSOR_TYPE_TEMP, 0, "\302\260F"))
54                 failures++;
55
56         if (!test_fct(SENSOR_TYPE_LMSENSOR | SENSOR_TYPE_TEMP, 1, "\302\260C"))
57                 failures++;
58
59         if (!test_fct(SENSOR_TYPE_LMSENSOR | SENSOR_TYPE_TEMP, 0, "\302\260F"))
60                 failures++;
61
62         if (!test_fct(SENSOR_TYPE_RPM, 0, _("RPM")))
63                 failures++;
64
65         return failures;
66 }
67
68 int main(int argc, char **argv)
69 {
70         int failures;
71
72         setlocale(LC_ALL, "");
73         bindtextdomain(PACKAGE, LOCALEDIR);
74         textdomain(PACKAGE);
75
76         failures = test();
77
78         if (failures) 
79                 exit(EXIT_FAILURE);
80         else
81                 exit(EXIT_SUCCESS);
82 }