summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-07-21 17:57:57 +0200
committerLennart Poettering <lennart@poettering.net>2016-07-22 12:59:36 +0200
commit910fd145f46f0916adbc6035b0433eb586bd6ce0 (patch)
treeb341a8ec1ed60cdf1459fd8c77435b3d079901f7 /src/test
parent3bbaff3e08070f03487958818edbd161d439ce15 (diff)
sd-id128: split UUID file read/write code into new id128-util.[ch]
We currently have code to read and write files containing UUIDs at various places. Unify this in id128-util.[ch], and move some other stuff there too. The new files are located in src/libsystemd/sd-id128/ (instead of src/shared/), because they are actually the backend of sd_id128_get_machine() and sd_id128_get_boot(). In follow-up patches we can use this reduce the code in nspawn and machine-id-setup by adopted the common implementation.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test-id128.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/test/test-id128.c b/src/test/test-id128.c
index 96aa008c06..324c7a2019 100644
--- a/src/test/test-id128.c
+++ b/src/test/test-id128.c
@@ -26,6 +26,7 @@
#include "macro.h"
#include "string-util.h"
#include "util.h"
+#include "id128-util.h"
#define ID128_WALDI SD_ID128_MAKE(01, 02, 03, 04, 05, 06, 07, 08, 09, 0a, 0b, 0c, 0d, 0e, 0f, 10)
#define STR_WALDI "0102030405060708090a0b0c0d0e0f10"
@@ -33,7 +34,7 @@
int main(int argc, char *argv[]) {
sd_id128_t id, id2;
- char t[33];
+ char t[33], q[37];
_cleanup_free_ char *b = NULL;
assert_se(sd_id128_randomize(&id) == 0);
@@ -57,6 +58,17 @@ int main(int argc, char *argv[]) {
printf("waldi2: %s\n", b);
assert_se(streq(t, b));
+ printf("waldi3: %s\n", id128_to_uuid_string(ID128_WALDI, q));
+ assert_se(streq(q, UUID_WALDI));
+
+ b = mfree(b);
+ assert_se(asprintf(&b, ID128_UUID_FORMAT_STR, SD_ID128_FORMAT_VAL(ID128_WALDI)) == 36);
+ printf("waldi4: %s\n", b);
+ assert_se(streq(q, b));
+
+ assert_se(sd_id128_from_string(STR_WALDI, &id) >= 0);
+ assert_se(sd_id128_equal(id, ID128_WALDI));
+
assert_se(sd_id128_from_string(UUID_WALDI, &id) >= 0);
assert_se(sd_id128_equal(id, ID128_WALDI));