summaryrefslogtreecommitdiff
path: root/src/libsystemd/sd-bus/test-bus-error.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-10-30 20:31:48 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-10-30 20:31:48 -0400
commit4a0a74179fcfb85c456794fd91fa2ae5d4d3bc8f (patch)
tree7aa0256e5790c60df2bd945099550b60bd19435c /src/libsystemd/sd-bus/test-bus-error.c
parente1323fbfbe8a574f28b704f2df8ce7f99e3a28f5 (diff)
bus: add sd_bus_errnomap section
This allows custom "name" ↔ errno mappings to be registered. Tables from all compilation units are concatenated.
Diffstat (limited to 'src/libsystemd/sd-bus/test-bus-error.c')
-rw-r--r--src/libsystemd/sd-bus/test-bus-error.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/libsystemd/sd-bus/test-bus-error.c b/src/libsystemd/sd-bus/test-bus-error.c
index b78be5499c..dd0cca4ab8 100644
--- a/src/libsystemd/sd-bus/test-bus-error.c
+++ b/src/libsystemd/sd-bus/test-bus-error.c
@@ -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,31 @@ 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));
+}
+
+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 = {
+ {"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[]) {
+
+ test_error();
+ test_errno_mapping_standard();
+ test_errno_mapping_custom();
return 0;
}