String hex escapes (\xXX) don't work for values > 127 in CAPL

296 Views Asked by At

I'm trying to define some test data using string literals in CAPL. Most of the data is ASCII, but occasionally I need raw bytes, which I encode using hex escape sequences. This worked until I tried to encode values above 127. Here's a test example:

variables 
{
    message 0x123 testmsg;
}
testcase TestHex(char hexdata[])
{
    testStep("Info", "First byte: 0x%X", hexdata[0]);
    testmsg.byte(0) = hexdata[0];
    output(testmsg);
}
void MainTest ()
{ 
    TestHex("\x00");
    TestHex("\x10");
    TestHex("\x20");
    TestHex("\x50");
    TestHex("\x7F");
    TestHex("\x80");
    TestHex("\xFF");
}

The output I get in the test report is:

First byte: 0x0
First byte: 0x10
First byte: 0x20
First byte: 0x50
First byte: 0x7F
First byte: 0x3F
First byte: 0x3F

I can also see the same bytes transmitted on the bus inside the testmsg message.

How could I encode such values in CAPL strings?

1

There are 1 best solutions below

10
On

If you want to use values greater than 127, you should use byte instead of char as datatype for your parameter to TestHex. I.e.:

testcase TestHex(byte hexdata[])
{
    testStep("Info", "First byte: 0x%X", hexdata[0]);
    testmsg.byte(0) = hexdata[0];
    output(testmsg);
}