Skip to content

Commit

Permalink
MT#58307 test: Do not print binary garbage to stdout
Browse files Browse the repository at this point in the history
Depending on the buffer contents, we might be printing binary garbage to
stdout, which can mess up with the terminal state if that happens to be
ANSI control codes.

Change-Id: Iee0059bccccb33bc47a6b066a353b0038a9679a2
  • Loading branch information
guillemj committed Sep 19, 2023
1 parent 97aaf60 commit f71a0c4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
19 changes: 13 additions & 6 deletions tests/basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ const char tcap[] = {
//const int tcap_len = sizeof(tcap) - 1;
const int tcap_len = sizeof(tcap);

static void print_outbuf(const char *desc, int ret, struct output_buffer *out)
{
printf("%s: returned %i, value: ", desc, ret);
for (int i = 0; i < out->used; i++)
printf("%#02x ", out->buf[i]);
printf("\n");
}

int main() {
int i;
Expand All @@ -23,27 +30,27 @@ int main() {

// OUTPUT_BUFFER_INIT(&out, buf);
// i = tcap_extract(tcap, tcap_len, "end.components.1.invoke.opCode.localValue", &out);
// printf("tcap_extract opcode: returned %i, value %.*s\n", i, (int) out.used, out.buf);
// print_outbuf("tcap_extract opcode", i, &out);
//
// OUTPUT_BUFFER_INIT(&out, buf);
// i = inap_extract(tcap, tcap_len, "ConnectArg", &out);
// printf("inap_extract ConnectArg: returned %i, value %.*s\n", i, (int) out.used, out.buf);
// print_outbuf("inap_extract ConnectArg", i, &out);
//
// OUTPUT_BUFFER_INIT(&out, buf);
// i = inap_extract(tcap, tcap_len, "ConnectArg.cutAndPaste", &out);
// printf("inap_extract ConnectArg.cutAndPaste: returned %i, value %.*s\n", i, (int) out.used, out.buf);
// print_outbuf("inap_extract ConnectArg.cutAndPaste", i, &out);
//
// OUTPUT_BUFFER_INIT(&out, buf);
// i = inap_extract(tcap, tcap_len, "ConnectArg.destinationRoutingAddress", &out);
// printf("inap_extract ConnectArg.destinationRoutingAddress: returned %i, value %.*s\n", i, (int) out.used, out.buf);
// print_outbuf("inap_extract ConnectArg.destinationRoutingAddress", i, &out);
//
OUTPUT_BUFFER_INIT(&out, buf);
i = inap_extract(tcap, tcap_len, "ConnectArg.destinationRoutingAddress.0", &out);
printf("inap_extract ConnectArg: returned %i, value %.*s\n", i, (int) out.used, out.buf);
print_outbuf("inap_extract ConnectArg", i, &out);

// OUTPUT_BUFFER_INIT(&out, buf);
// i = inap_extract(tcap, tcap_len, "InitialDPArg.calledPartyNumber", &out);
// printf("inap_extract InitialDPArg: returned %i, value %.*s\n", i, (int) out.used, out.buf);
// print_outbuf("inap_extract InitialDPArg", i, &out);

return 0;
}
5 changes: 4 additions & 1 deletion tests/encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ int main() {
if (ret < 0) {
fprintf(stderr, "failed to encode tcap\n");
} else {
fwrite(buf, ret, 1, stdout);
printf("buffer: ");
for (int i = 0; i < ret; i++)
printf("0x%02x ", (unsigned char)buf[i]);
printf("\n");
}

free(buf);
Expand Down

0 comments on commit f71a0c4

Please sign in to comment.