diff options
author | David Herrmann <dh.herrmann@gmail.com> | 2014-10-02 16:36:09 +0200 |
---|---|---|
committer | David Herrmann <dh.herrmann@gmail.com> | 2014-10-03 15:57:00 +0200 |
commit | f1f5b2a3bdc3178d57c4088a7cd7758afaeba9cb (patch) | |
tree | e173b2fadb2df9c814fe9a3185e9fb90be30f64f /src/libsystemd-terminal/test-term-parser.c | |
parent | db1a606610e5a528903a4380f30c9934a0c5a134 (diff) |
terminal: make utf8 decoder return length
Lets return the parsed length in term_utf8_decode() instead of a buffer
pointer. Store the pointer in the passed argument.
This makes it adhere to the systemd coding-style, were we always avoid
returning pointers, but store them in output arguments. In this case, the
storage is not allocated, so it doesn't fit 100% to this idiom, but still
looks much nicer.
Diffstat (limited to 'src/libsystemd-terminal/test-term-parser.c')
-rw-r--r-- | src/libsystemd-terminal/test-term-parser.c | 49 |
1 files changed, 25 insertions, 24 deletions
diff --git a/src/libsystemd-terminal/test-term-parser.c b/src/libsystemd-terminal/test-term-parser.c index ed16f5f276..e8d5dcfbf2 100644 --- a/src/libsystemd-terminal/test-term-parser.c +++ b/src/libsystemd-terminal/test-term-parser.c @@ -33,39 +33,40 @@ static void test_term_utf8_invalid(void) { term_utf8 p = { }; - const uint32_t *res; + uint32_t *res; size_t len; - res = term_utf8_decode(NULL, NULL, 0); - assert_se(res == NULL); + len = term_utf8_decode(NULL, NULL, 0); + assert_se(!len); - res = term_utf8_decode(&p, NULL, 0); - assert_se(res != NULL); - - len = 5; - res = term_utf8_decode(NULL, &len, 0); - assert_se(res == NULL); - assert_se(len == 0); + len = term_utf8_decode(&p, NULL, 0); + assert_se(len == 1); - len = 5; - res = term_utf8_decode(&p, &len, 0); + res = NULL; + len = term_utf8_decode(NULL, &res, 0); + assert_se(!len); assert_se(res != NULL); + assert_se(!*res); + + len = term_utf8_decode(&p, &res, 0); assert_se(len == 1); + assert_se(res != NULL); + assert_se(!*res); - len = 5; - res = term_utf8_decode(&p, &len, 0xCf); - assert_se(res == NULL); + len = term_utf8_decode(&p, &res, 0xCf); assert_se(len == 0); - - len = 5; - res = term_utf8_decode(&p, &len, 0x0); assert_se(res != NULL); + assert_se(!*res); + + len = term_utf8_decode(&p, &res, 0); assert_se(len == 2); + assert_se(res != NULL); + assert_se(res[0] == 0xCf && res[1] == 0); } static void test_term_utf8_range(void) { term_utf8 p = { }; - const uint32_t *res; + uint32_t *res; char u8[4]; uint32_t i, j; size_t ulen, len; @@ -78,8 +79,8 @@ static void test_term_utf8_range(void) { continue; for (j = 0; j < ulen; ++j) { - res = term_utf8_decode(&p, &len, u8[j]); - if (!res) { + len = term_utf8_decode(&p, &res, u8[j]); + if (len < 1) { assert_se(j + 1 != ulen); continue; } @@ -117,13 +118,13 @@ static void test_term_utf8_mix(void) { 0x00F0, 0x0080, 0x0080, 0x0001, }; term_utf8 p = { }; - const uint32_t *res; + uint32_t *res; unsigned int i, j; size_t len; for (i = 0, j = 0; i < sizeof(source); ++i) { - res = term_utf8_decode(&p, &len, source[i]); - if (!res) + len = term_utf8_decode(&p, &res, source[i]); + if (len < 1) continue; assert_se(j + len <= ELEMENTSOF(result)); |