2 This file is part of systemd
4 Copyright 2014 Ronny Chevalier
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 #include "condition-util.h"
24 #include "architecture.h"
25 #include "systemd/sd-id128.h"
27 static void test_condition_test_ac_power(void) {
30 condition = condition_new(CONDITION_AC_POWER, "true", false, false);
31 assert_se(condition_test_ac_power(condition) == on_ac_power());
32 condition_free(condition);
34 condition = condition_new(CONDITION_AC_POWER, "false", false, false);
35 assert_se(condition_test_ac_power(condition) != on_ac_power());
36 condition_free(condition);
38 condition = condition_new(CONDITION_AC_POWER, "false", false, true);
39 assert_se(condition_test_ac_power(condition) == on_ac_power());
40 condition_free(condition);
43 static void test_condition_test_host(void) {
47 char sid[SD_ID128_STRING_MAX];
48 _cleanup_free_ char *hostname = NULL;
50 r = sd_id128_get_machine(&id);
52 assert_se(sd_id128_to_string(id, sid));
54 condition = condition_new(CONDITION_HOST, sid, false, false);
55 assert_se(condition_test_host(condition));
56 condition_free(condition);
58 condition = condition_new(CONDITION_HOST, "garbage value jjjjjjjjjjjjjj", false, false);
59 assert_se(!condition_test_host(condition));
60 condition_free(condition);
62 condition = condition_new(CONDITION_HOST, sid, false, true);
63 assert_se(!condition_test_host(condition));
64 condition_free(condition);
66 hostname = gethostname_malloc();
69 condition = condition_new(CONDITION_HOST, hostname, false, false);
70 assert_se(condition_test_host(condition));
71 condition_free(condition);
74 static void test_condition_test_architecture(void) {
79 a = uname_architecture();
82 sa = architecture_to_string(a);
85 condition = condition_new(CONDITION_ARCHITECTURE, sa, false, false);
86 assert_se(condition_test_architecture(condition));
87 condition_free(condition);
89 condition = condition_new(CONDITION_ARCHITECTURE, "garbage value", false, false);
90 assert_se(!condition_test_architecture(condition));
91 condition_free(condition);
93 condition = condition_new(CONDITION_ARCHITECTURE, sa, false, true);
94 assert_se(!condition_test_architecture(condition));
95 condition_free(condition);
98 int main(int argc, char *argv[]) {
99 log_parse_environment();
102 test_condition_test_ac_power();
103 test_condition_test_host();
104 test_condition_test_architecture();