summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test-bus-util.c43
-rw-r--r--src/test/test-fd-util.c4
-rw-r--r--src/test/test-string-util.c4
3 files changed, 47 insertions, 4 deletions
diff --git a/src/test/test-bus-util.c b/src/test/test-bus-util.c
index 608052be1..a320a0d78 100644
--- a/src/test/test-bus-util.c
+++ b/src/test/test-bus-util.c
@@ -35,6 +35,48 @@ static void test_name_async(unsigned n_messages) {
}
}
+static int callback(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) {
+ return 1;
+}
+
+static void destroy_callback(void *userdata) {
+ int *n_called = userdata;
+
+ (*n_called) ++;
+}
+
+static void test_destroy_callback(void) {
+ _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
+ sd_bus_slot *slot = NULL;
+ sd_bus_destroy_t t;
+
+ int r, n_called = 0;
+
+ log_info("/* %s */", __func__);
+
+ r = bus_open_system_watch_bind_with_description(&bus, "test-bus");
+ if (r < 0) {
+ log_error_errno(r, "Failed to connect to bus: %m");
+ return;
+ }
+
+ r = sd_bus_request_name_async(bus, &slot, "org.freedesktop.elogind.test-bus-util", 0, callback, &n_called);
+ assert(r == 1);
+
+ assert_se(sd_bus_slot_get_destroy_callback(slot, NULL) == 0);
+ assert_se(sd_bus_slot_get_destroy_callback(slot, &t) == 0);
+
+ assert_se(sd_bus_slot_set_destroy_callback(slot, destroy_callback) == 0);
+ assert_se(sd_bus_slot_get_destroy_callback(slot, NULL) == 1);
+ assert_se(sd_bus_slot_get_destroy_callback(slot, &t) == 1);
+ assert_se(t == destroy_callback);
+
+ /* Force cleanup so we can look at n_called */
+ assert(n_called == 0);
+ sd_bus_slot_unref(slot);
+ assert(n_called == 1);
+}
+
int main(int argc, char **argv) {
log_set_max_level(LOG_DEBUG);
log_parse_environment();
@@ -42,6 +84,7 @@ int main(int argc, char **argv) {
test_name_async(0);
test_name_async(20);
+ test_destroy_callback();
return 0;
}
diff --git a/src/test/test-fd-util.c b/src/test/test-fd-util.c
index 2b6cd0511..4328442ad 100644
--- a/src/test/test-fd-util.c
+++ b/src/test/test-fd-util.c
@@ -246,6 +246,7 @@ static void assert_equal_fd(int fd1, int fd2) {
}
}
+#if 0 /// UNNEEDED by elogind
static void test_fd_duplicate_data_fd(void) {
_cleanup_close_ int fd1 = -1, fd2 = -1;
_cleanup_(close_pairp) int sfd[2] = { -1, -1 };
@@ -311,6 +312,7 @@ static void test_fd_duplicate_data_fd(void) {
assert_se(read(fd2, &j, sizeof(j)) == 0);
}
+#endif // 0
static void test_read_nr_open(void) {
log_info("nr-open: %i", read_nr_open());
@@ -329,7 +331,9 @@ int main(int argc, char *argv[]) {
test_acquire_data_fd();
test_fd_move_above_stdio();
test_rearrange_stdio();
+#if 0 /// UNNEEDED by elogind
test_fd_duplicate_data_fd();
+#endif // 0
test_read_nr_open();
return 0;
diff --git a/src/test/test-string-util.c b/src/test/test-string-util.c
index 7860499b7..47032729e 100644
--- a/src/test/test-string-util.c
+++ b/src/test/test-string-util.c
@@ -431,7 +431,6 @@ static void test_delete_trailing_slashes(void) {
assert_se(streq(delete_trailing_chars(s4, "/"), ""));
}
-#if 0 /// UNNEEDED by elogind
static void test_skip_leading_chars(void) {
char input1[] = " \n \r k \n \r ",
input2[] = "kkkkthiskkkiskkkaktestkkk",
@@ -443,7 +442,6 @@ static void test_skip_leading_chars(void) {
assert_se(streq(skip_leading_chars(input3, WHITESPACE), "abcdef"));
assert_se(streq(skip_leading_chars(input3, "bcaef"), "def"));
}
-#endif // 0
static void test_in_charset(void) {
assert_se(in_charset("dddaaabbbcccc", "abcd"));
@@ -533,9 +531,7 @@ int main(int argc, char *argv[]) {
#endif // 0
test_delete_trailing_chars();
test_delete_trailing_slashes();
-#if 0 /// UNNEEDED by elogind
test_skip_leading_chars();
-#endif // 0
test_in_charset();
test_split_pair();
test_first_word();