chiark / gitweb /
util: add hexdump() call to create pretty hexdumps of data
[elogind.git] / src / test / test-util.c
index 1de06dbda84e7c3ca0a2dcd34a47aba47041abd3..6297182e0bdb714c54b3e16ca4e244cc7cc319c4 100644 (file)
@@ -574,7 +574,6 @@ static void test_fstab_node_to_udev_node(void) {
         assert_se(streq(n, "/dev/disk/by-partuuid/037b9d94-148e-4ee4-8d38-67bfe15bb535"));
         free(n);
 
-
         n = fstab_node_to_udev_node("PONIES=awesome");
         puts(n);
         assert_se(streq(n, "PONIES=awesome"));
@@ -627,6 +626,25 @@ static void test_writing_tmpfile(void) {
         assert(streq(contents, "abc\n" ALPHANUMERICAL "\n"));
 }
 
+static void test_hexdump(void) {
+        uint8_t data[146];
+        unsigned i;
+
+        hexdump(stdout, NULL, 0);
+        hexdump(stdout, "", 0);
+        hexdump(stdout, "", 1);
+        hexdump(stdout, "x", 1);
+        hexdump(stdout, "x", 2);
+        hexdump(stdout, "foobar", 7);
+        hexdump(stdout, "f\nobar", 7);
+        hexdump(stdout, "xxxxxxxxxxxxxxxxxxxxyz", 23);
+
+        for (i = 0; i < ELEMENTSOF(data); i++)
+                data[i] = i*2;
+
+        hexdump(stdout, data, sizeof(data));
+}
+
 int main(int argc, char *argv[]) {
         log_parse_environment();
         log_open();
@@ -668,6 +686,7 @@ int main(int argc, char *argv[]) {
         test_get_files_in_directory();
         test_in_set();
         test_writing_tmpfile();
+        test_hexdump();
 
         return 0;
 }