<commit_before>*** Settings ***
Test Setup        Setup protocol, UDP server, and client
Test teardown     Teardown rammbock and increment port numbers
Resource          ../Protocols.robot
Default Tags      Regression

*** Variables ***
${HEADER} =    0x0100aaaa000f0000

*** Test Cases ***
Receive dynamic message with structural length
    Client Sends hex    ${HEADER} 03 cafe babe d00d
    ${msg} =    Server Receives dynamic request with structural length
    Should be equal    ${msg.pairList[0].first.hex}     0xca
    Should be equal    ${msg.pairList[0].second.hex}    0xfe
    Should be equal    ${msg.pairList[2].first.hex}     0xd0

Encode dynamic message with structural length
    Populate dynamic message with structural length    2  0x01  0x02  0x11  0x22
    ${msg} =    Get message
    Should be equal    ${msg.pairList[0].first.hex}     0x01
    Should be equal    ${msg.pairList[0].second.hex}    0x02
    Should be equal    ${msg.pairList[1].first.hex}     0x11

Encoding dynamic list with structural length without defining fails
    Populate dynamic message with structural length    ${EMPTY}  0x01  0x02  0x11  0x22
    Run keyword and expect error   Value of numberOfPairs.value not set    Get message

Receive dynamic message
    Client Sends hex    ${HEADER} 03 cafe babe d00d
    ${msg} =    Server Receives dynamic request
    Should be equal    ${msg.pairList[0].first.hex}     0xca
    Should be equal    ${msg.pairList[0].second.hex}    0xfe
    Should be equal    ${msg.pairList[2].first.hex}     0xd0

Encode dynamic message
    Populate dynamic message  2  0x01  0x02  0x11  0x22
    ${msg} =    Get message
    Should be equal    ${msg.pairList[0].first.hex}     0x01
    Should be equal    ${msg.pairList[0].second.hex}    0x02
    Should be equal    ${msg.pairList[1].first.hex}     0x11

Encoding dynamic list without defined length fails
    # TODO: This should perhaps work?
    Populate dynamic message  ${EMPTY}  0x01  0x02  0x11  0x22
    Run keyword and expect error   Value of numberOfPairs not set    Get message

Encoding dynamic message with extra list entries fails
    Populate dynamic message  1  0x01  0x02  0x11  0x22
    Run keyword and expect error   Unknown fields in 'DynamicRequest.pairList': *   Get message

Encoding length in 2byte struct matches
    [Template]       2byte struct with given length
    #struct length    #length field value
    length_field
    length_field      2
    2                 2
    length_field-10   12

Encoding length in 2byte struct does not match
    [Template]       2byte struct with given length should fail
    #struct length   #length field value
    length_field     5
    length_field     1
    3                2
    1                2
    length_field-10  2
    length_field-10  13

Decoding length in 2byte struct matches
    [Template]       Decode 2byte struct with given length
    #struct length    #length field value
    length_field
    length_field      2
    2                 2
    length_field+1    1
    length_field-10   12

Decoding length in 2byte struct does not match
    [Template]       Decode 2byte struct with given length should fail
    #struct length   #length field value
    length_field     5
    length_field     1
    3                2
    1                2
    length_field-10  2
    length_field-10  13
    length_field+1   0
    length_field+50  0

Encoding dynamic length from value
    [Template]    Dynamic length fields with different parameters
    #static length field value     kw for dynamic content creation    kw to validate outcome and params
    ${none}                        static named chars field           get message and validate length field      ilmari        6
    8                              static named chars field           get message and validate length field      ilmari        8
    1                              static named chars field           get message and validate length field      ilmari        8    length_field:8
    1                              static named chars field           get message and validate length field      ilmari        6    length_field:6
    6                              static named chars field           get message and validate length field      ilmari        6

Encoding too short dynamic length fails
    [Template]    Dynamic length fields with different parameters
    #static length field value     kw for dynamic content creation    kw to validate outcome and params
    1                              static named chars field           should fail    get message        name:ilmari
    0                              static named chars field           should fail    get message        name:ilmari
    1                              static named chars field           should fail    get message        name:ilmari  length_field:2
    6                              static named chars field           should fail    get message        name:ilmari  length_field:2

Encoding variable length container with multiple fields
    Define variable length container    multiple fields
    ${msg}=    get message
    should be equal as integers    ${msg.length_field.int}    10

#TO-DO should make below testcases work
#Encoding variable length container with structural length and multiple fields
#    Define structural variable length container    multiple fields
#    ${msg}=    get message
#    should be equal as integers    ${msg.length_field.value.int}    10
#
#Encoding variable length container with dynamic length content and structural length
#    Define structural variable length container    Dynamic string
#    ${msg}=    get message    container.name:fobbabobba
#    should be equal as integers    ${msg.length_field.value.int}    11
#    should be equal as integers    ${msg.container.stringLen.int}   10

Encoding variable length container with dynamic length content
    Define variable length container    Dynamic string
    ${msg}=    get message    container.name:fobbabobba
    should be equal as integers    ${msg.length_field.int}    11
    should be equal as integers    ${msg.container.stringLen.int}   10<commit_msg>Removed regression tag for test failing issue #56<commit_after>*** Settings ***
Test Setup        Setup protocol, UDP server, and client
Test teardown     Teardown rammbock and increment port numbers
Resource          ../Protocols.robot
Default Tags      Regression

*** Variables ***
${HEADER} =    0x0100aaaa000f0000

*** Test Cases ***
Receive dynamic message with structural length
    Client Sends hex    ${HEADER} 03 cafe babe d00d
    ${msg} =    Server Receives dynamic request with structural length
    Should be equal    ${msg.pairList[0].first.hex}     0xca
    Should be equal    ${msg.pairList[0].second.hex}    0xfe
    Should be equal    ${msg.pairList[2].first.hex}     0xd0

Encode dynamic message with structural length
    Populate dynamic message with structural length    2  0x01  0x02  0x11  0x22
    ${msg} =    Get message
    Should be equal    ${msg.pairList[0].first.hex}     0x01
    Should be equal    ${msg.pairList[0].second.hex}    0x02
    Should be equal    ${msg.pairList[1].first.hex}     0x11

Encoding dynamic list with structural length without defining fails
    Populate dynamic message with structural length    ${EMPTY}  0x01  0x02  0x11  0x22
    Run keyword and expect error   Value of numberOfPairs.value not set    Get message

Receive dynamic message
    Client Sends hex    ${HEADER} 03 cafe babe d00d
    ${msg} =    Server Receives dynamic request
    Should be equal    ${msg.pairList[0].first.hex}     0xca
    Should be equal    ${msg.pairList[0].second.hex}    0xfe
    Should be equal    ${msg.pairList[2].first.hex}     0xd0

Encode dynamic message
    Populate dynamic message  2  0x01  0x02  0x11  0x22
    ${msg} =    Get message
    Should be equal    ${msg.pairList[0].first.hex}     0x01
    Should be equal    ${msg.pairList[0].second.hex}    0x02
    Should be equal    ${msg.pairList[1].first.hex}     0x11

Encoding dynamic list without defined length fails
    # TODO: This should perhaps work?
    Populate dynamic message  ${EMPTY}  0x01  0x02  0x11  0x22
    Run keyword and expect error   Value of numberOfPairs not set    Get message

Encoding dynamic message with extra list entries fails
    Populate dynamic message  1  0x01  0x02  0x11  0x22
    Run keyword and expect error   Unknown fields in 'DynamicRequest.pairList': *   Get message

Encoding length in 2byte struct matches
    [Template]       2byte struct with given length
    #struct length    #length field value
    length_field
    length_field      2
    2                 2
    length_field-10   12

Encoding length in 2byte struct does not match
    [Template]       2byte struct with given length should fail
    #struct length   #length field value
    length_field     5
    length_field     1
    3                2
    1                2
    length_field-10  2
    length_field-10  13

Decoding length in 2byte struct matches
    [Template]       Decode 2byte struct with given length
    #struct length    #length field value
    length_field
    length_field      2
    2                 2
    length_field+1    1
    length_field-10   12

Decoding length in 2byte struct does not match
    [Template]       Decode 2byte struct with given length should fail
    #struct length   #length field value
    length_field     5
    length_field     1
    3                2
    1                2
    length_field-10  2
    length_field-10  13
    length_field+1   0
    length_field+50  0

Encoding dynamic length from value
    [Template]    Dynamic length fields with different parameters
    #static length field value     kw for dynamic content creation    kw to validate outcome and params
    ${none}                        static named chars field           get message and validate length field      ilmari        6
    8                              static named chars field           get message and validate length field      ilmari        8
    1                              static named chars field           get message and validate length field      ilmari        8    length_field:8
    1                              static named chars field           get message and validate length field      ilmari        6    length_field:6
    6                              static named chars field           get message and validate length field      ilmari        6

Encoding too short dynamic length fails
    [Template]    Dynamic length fields with different parameters
    #static length field value     kw for dynamic content creation    kw to validate outcome and params
    1                              static named chars field           should fail    get message        name:ilmari
    0                              static named chars field           should fail    get message        name:ilmari
    1                              static named chars field           should fail    get message        name:ilmari  length_field:2
    6                              static named chars field           should fail    get message        name:ilmari  length_field:2

Encoding variable length container with multiple fields
    Define variable length container    multiple fields
    ${msg}=    get message
    should be equal as integers    ${msg.length_field.int}    10

#TO-DO should make below testcases work
Encoding variable length container with structural length and multiple fields
    [Tags]      None
    Define structural variable length container    multiple fields
    ${msg}=    get message
    should be equal as integers    ${msg.length_field.value.int}    10

Encoding variable length container with dynamic length content and structural length
    [Tags]      None
    Define structural variable length container    Dynamic string
    ${msg}=    get message    container.name:fobbabobba
    should be equal as integers    ${msg.length_field.value.int}    11
    should be equal as integers    ${msg.container.stringLen.int}   10

Encoding variable length container with dynamic length content
    Define variable length container    Dynamic string
    ${msg}=    get message    container.name:fobbabobba
    should be equal as integers    ${msg.length_field.int}    11
    should be equal as integers    ${msg.container.stringLen.int}   10
{'fraction_non_alphanumeric': 0.04357316087308003, 'fraction_numerical': 0.03330638641875505, 'mean_word_length': 2.1176915322580645, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4325326', 'n_tokens_mistral': 3308, 'n_tokens_neox': 3123, 'n_words': 1332}