X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Ftest%2Ftest-util.c;h=795f3a1b3d07d2e6c20803f37b6031b616942e76;hb=fb835651aff79a1e7fc5795086c9b26e59a8e6ca;hp=4d9b28f9c8e7b82aca0440a0b2c56c8d86b06789;hpb=684fc8927e0f83496d4384ac434e265f7cd7a87b;p=elogind.git diff --git a/src/test/test-util.c b/src/test/test-util.c index 4d9b28f9c..795f3a1b3 100644 --- a/src/test/test-util.c +++ b/src/test/test-util.c @@ -96,6 +96,24 @@ static void test_max(void) { assert_cc(MAXSIZE(char, long) == sizeof(long)); } +static void test_container_of(void) { + struct mytype { + uint8_t pad1[3]; + uint64_t v1; + uint8_t pad2[2]; + uint32_t v2; + } _packed_ myval = { }; + + assert_cc(sizeof(myval) == 17); + assert_se(container_of(&myval.v1, struct mytype, v1) == &myval); + assert_se(container_of(&myval.v2, struct mytype, v2) == &myval); + assert_se(container_of(&container_of(&myval.v2, + struct mytype, + v2)->v1, + struct mytype, + v1) == &myval); +} + static void test_first_word(void) { assert_se(first_word("Hello", "")); assert_se(first_word("Hello", "Hello")); @@ -1218,6 +1236,7 @@ int main(int argc, char *argv[]) { test_streq_ptr(); test_align_power2(); test_max(); + test_container_of(); test_first_word(); test_close_many(); test_parse_boolean();