Commit c08a5d5d authored by Adam Knapp's avatar Adam Knapp
Browse files

Hexstring RAW fix & RAW decoder overindex fix (issue #428 #430)


Signed-off-by: Adam Knapp's avatarAdam Knapp <adam.knapp@ericsson.com>
parent d07d7485
......@@ -259,6 +259,8 @@ HS16977_Test.control
IntX.control #ok! 6 pass
#RAW/Issue555
Issue555.control
#RAW/Issue557
Issue557.control
#RAW/Lengthto_Offset:
Lengthto_Offset
#RAW/RAW_bitstring_test:
......
/******************************************************************************
* Copyright (c) 2000-2021 Ericsson Telecom AB
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
*
* Contributors:
* Gabor, Szalai – initial implementation
*
******************************************************************************/
module Issue557 {
type record R4{
bitstring f1 length(4),
hexstring f2
} with {
variant (f2) "HEXORDER(high)"
variant "FIELDORDER(msb)"
}
type component CT{}
template bitstring t_expected_encoded:=oct2bit('F123456789'O)
template R4 t_expected_decoded:={'1111'B, '123456789'H }
testcase tc_issue557() runs on CT {
var R4 vl_pdu4:={'1111'B, '123456789'H }
var bitstring vl_encoded:=encvalue(vl_pdu4)
log(vl_pdu4, " encoded as ",bit2oct(vl_encoded), " expected as ", bit2oct(valueof(t_expected_encoded)))
if(match(vl_encoded,t_expected_encoded)){
setverdict(pass)
} else {
setverdict(fail, "wrong encoded value")
}
vl_encoded:=valueof(t_expected_encoded)
var integer vl_res:=decvalue(vl_encoded,vl_pdu4)
log("decode result: ", vl_res)
if(vl_res == 0) {
setverdict(pass)
log(bit2oct(valueof(t_expected_encoded)), " decoded as ",vl_pdu4, " expected as ", t_expected_decoded)
if(match(vl_pdu4,t_expected_decoded)){
setverdict(pass)
} else {
setverdict(fail, "wrong decoded value")
}
} else {
setverdict(fail, "Decoding failed")
}
}
control {
execute(tc_issue557());
}
} with {
encode "RAW"
}
###############################################################################
# Copyright (c) 2000-2021 Ericsson Telecom AB
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v2.0
# which accompanies this distribution, and is available at
# https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
#
# Contributors:
# Botond, Baranyi
#
###############################################################################
[LOGGING]
LogFile := "Issue557.log"
FileMask := LOG_ALL
ConsoleMask := TTCN_ERROR | TTCN_TESTCASE | TTCN_STATISTICS
LogSourceInfo := Yes
[EXECUTE]
Issue557.control
[TESTPORT_PARAMETERS]
......@@ -624,13 +624,10 @@ public final class TTCN_Buffer {
* Puts a bit string in the buffer. Use only this function if you use
* the buffer as bit buffer.
*
* @param len
* number of bits to write
* @param s
* char list
* @param coding_par
* @param align
* alignment length
* @param len number of bits to write
* @param s char list
* @param coding_par coding parameters
* @param align alignment length
*/
public void put_b(int len, byte[] s, final RAW_coding_par coding_par, int align) {
final int loc_align = align < 0 ? -align : align;
......@@ -706,7 +703,7 @@ public final class TTCN_Buffer {
if (coding_par.hexorder == raw_order_t.ORDER_MSB) {
final byte[] st2 = new byte[(len + 7) / 8];
if (bit_pos == 4) {
if (bit_pos == 4 && local_fieldorder == raw_order_t.ORDER_LSB) {
st2[0] = s[0];
for (int a = 1; a < (len + 7) / 8; a++) {
char ch = '\0';
......@@ -954,12 +951,11 @@ public final class TTCN_Buffer {
}
/** Reads a bit string from the buffer. Use only this function if you use the buffer as bit buffer.
* @param len
* @param s
* @param coding_par
* @param top_bit_order
* @param len number of bits to write
* @param s char list
* @param coding_par coding parameters
* @param top_bit_order bit order
* */
//TODO comment
public void get_b(final int len, final byte[] s, final RAW_coding_par coding_par,final raw_order_t top_bit_order) {
if (len == 0) {
return;
......@@ -1128,7 +1124,7 @@ public final class TTCN_Buffer {
}
if (coding_par.hexorder == raw_order_t.ORDER_MSB) {
if (bit_pos == 4) {
if (bit_pos == 4 && local_fieldorder == raw_order_t.ORDER_LSB) {
for (int a = 1; a < (len + 7) / 8; a++) {
char ch = '\0';
ch |= s[a - 1] >> 4;
......@@ -1476,7 +1472,7 @@ public final class TTCN_Buffer {
* @return
*/
private byte get_byte_align(final int len, final raw_order_t fieldorder, final raw_order_t req_align, final int index) {
if (index < 0 || index > (bit_pos + len) / 8 || data_ptr == null) {
if (index < 0 || index > (bit_pos + len) / 8 || (buf_pos + index) >= buf_len || data_ptr == null) {
return '\0';
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment