Skip to content

Commit 36c308d

Browse files
committed
libutil/test: test stdlog encode/decode of non-ascii message
Problem: The stdlog unit tests do not verify that non-ascii content can be encoded and decoded. Add a test that ensures non-ascii content is preserved.
1 parent 1a1926a commit 36c308d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/common/libutil/test/stdlog.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,22 @@ int main(int argc, char** argv)
150150
&& strncmp (msg, "Hello whorl", msglen) == 0,
151151
"trailing cr/lf chars were truncated");
152152

153+
/* Check that valid UTF-8 non-ascii characters are preserved
154+
*/
155+
const char data[] = "jobid ƒ6LEmNENaf9 😄 😹";
156+
len = stdlog_encode (buf,
157+
sizeof (buf),
158+
&hdr,
159+
STDLOG_NILVALUE,
160+
data);
161+
ok (len >= 0,
162+
"stdlog_encode worked with %s", data);
163+
n = stdlog_decode (buf, len, &hdr, &sd, &sdlen, &msg, &msglen);
164+
ok (n == 0,
165+
"stdlog_decode worked");
166+
is (data, msg,
167+
"non-ascii characters were preserved");
168+
153169
int i = 0;
154170
while (valid[i] != NULL) {
155171
n = stdlog_decode (valid[i],

0 commit comments

Comments
 (0)