chiark / gitweb /
sd-bus: the attach_mask kernel module parameter is 64bit now, hence initialize it...
[elogind.git] / src / libsystemd / sd-bus / test-bus-error.c
index b78be5499c4dce188a8c51c296c1247d7335646c..ae894e39fd19d134339dbbf6b3045fba0c85b697 100644 (file)
@@ -23,8 +23,7 @@
 #include "bus-error.h"
 #include "bus-util.h"
 
-int main(int argc, char *argv[]) {
-
+static void test_error(void) {
         _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL, second = SD_BUS_ERROR_NULL;
         const sd_bus_error const_error = SD_BUS_ERROR_MAKE_CONST(SD_BUS_ERROR_FILE_EXISTS, "const error");
         const sd_bus_error temporarily_const_error = {
@@ -110,6 +109,44 @@ int main(int argc, char *argv[]) {
         assert_se(sd_bus_error_has_name(&error, SD_BUS_ERROR_IO_ERROR));
         assert_se(sd_bus_error_get_errno(&error) == EIO);
         assert_se(sd_bus_error_is_set(&error));
+}
+
+extern const sd_bus_name_error_mapping __start_sd_bus_errnomap[];
+extern const sd_bus_name_error_mapping __stop_sd_bus_errnomap[];
+
+static void dump_mapping_table(void) {
+        const sd_bus_name_error_mapping *m;
+
+        printf("----- errno mappings ------\n");
+        for (m = __start_sd_bus_errnomap; m < __stop_sd_bus_errnomap; m++)
+                printf("%s -> %d\n", m->name, m->code);
+        printf("---------------------------\n");
+}
+
+static void test_errno_mapping_standard(void) {
+        assert_se(sd_bus_error_set(NULL, "System.Error.EUCLEAN", NULL) == -EUCLEAN);
+        assert_se(sd_bus_error_set(NULL, "System.Error.EBUSY", NULL) == -EBUSY);
+        assert_se(sd_bus_error_set(NULL, "System.Error.EINVAL", NULL) == -EINVAL);
+        assert_se(sd_bus_error_set(NULL, "System.Error.WHATSIT", NULL) == -EIO);
+}
+
+SD_BUS_ERROR_MAPPING(test) = {
+        {"org.freedesktop.custom-dbus-error", 5},
+        {"org.freedesktop.custom-dbus-error-2", 52},
+};
+
+static void test_errno_mapping_custom(void) {
+        assert_se(sd_bus_error_set(NULL, "org.freedesktop.custom-dbus-error", NULL) == -5);
+        assert_se(sd_bus_error_set(NULL, "org.freedesktop.custom-dbus-error-2", NULL) == -52);
+        assert_se(sd_bus_error_set(NULL, "org.freedesktop.custom-dbus-error-x", NULL) == -EIO);
+}
+
+int main(int argc, char *argv[]) {
+        dump_mapping_table();
+
+        test_error();
+        test_errno_mapping_standard();
+        test_errno_mapping_custom();
 
         return 0;
 }