Skip to content

Commit

Permalink
Merge pull request #26 from RI-SE/fix_messageSizeInHeaders
Browse files Browse the repository at this point in the history
Tests for message size in headers
  • Loading branch information
LukasWikander authored Dec 12, 2022
2 parents 7241285 + e3cbc39 commit e26db59
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/osem.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#include "osem.h"
#include "defines.h"
#include "timeconversions.h"
#include "iso22133.h"

#include <errno.h>
#include <stdio.h>
#include <string.h>


/*!
* \brief encodeOSEMMessage Creates an OSEM message and writes it into a buffer based on supplied values. All values are passed as pointers and
* passing them as NULL causes the OSEM message to contain a default value for that field (a value representing "unavailable" or similar).
Expand Down Expand Up @@ -53,10 +55,11 @@ ssize_t encodeOSEMMessage(

// Build header, and account for the two values which are 48 bit in the message
uint32_t msgLen = sizeof (HeaderType) + sizeof(OSEMIDType) + sizeof(OSEMOriginType)
- 2 * SizeDifference64bitTo48bit + sizeof (OSEMDateTimeType)
+ sizeof(OSEMAccuracyRequirementsType) + 4*2*sizeof(uint16_t) + sizeof (FooterType)
+ timeServerUsed ? sizeof (OSEMTimeServerType) + 2*sizeof(uint16_t) : 0
+ idAssociationUsed ? sizeof(OSEMIDAssociationType) + 2*sizeof(uint16_t) : 0; // TODO handle id association
+ sizeof(OSEMDateTimeType) + sizeof(OSEMAccuracyRequirementsType)
+ 4*2*sizeof(uint16_t) + sizeof (FooterType);
msgLen -= 2 * SizeDifference64bitTo48bit;
msgLen += timeServerUsed ? sizeof (OSEMTimeServerType) + 2*sizeof(uint16_t) : 0;
msgLen += idAssociationUsed ? sizeof(OSEMIDAssociationType) + 2*sizeof(uint16_t) : 0; // TODO handle id association
OSEMData.header = buildISOHeader(MESSAGE_ID_OSEM, msgLen, debug);

// Fill the OSEM struct with relevant values
Expand Down
13 changes: 13 additions & 0 deletions tests/monr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ class EncodeMONR : public ::testing::Test {

};

TEST_F(EncodeMONR, MessageID)
{
EXPECT_EQ(encodeBuffer[16], '\x06');
EXPECT_EQ(encodeBuffer[17], '\x00');
}

TEST_F(EncodeMONR, MessageLength)
{
EXPECT_EQ(encodeBuffer[2], '\x28');
EXPECT_EQ(encodeBuffer[3], '\x00');
EXPECT_EQ(encodeBuffer[4], '\x00');
EXPECT_EQ(encodeBuffer[5], '\x00');
}

TEST_F(EncodeMONR, Preamble)
{
Expand Down
14 changes: 14 additions & 0 deletions tests/osem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ class EncodeOSEM : public ::testing::Test
char* timeServer = accReq + 22; // skip accuracy requirements
};

TEST_F(EncodeOSEM, MessageID)
{
EXPECT_EQ(encodeBuffer[16], '\x02');
EXPECT_EQ(encodeBuffer[17], '\x00');
}

TEST_F(EncodeOSEM, MessageLength)
{
EXPECT_EQ(encodeBuffer[2], '\x56');
EXPECT_EQ(encodeBuffer[3], '\x00');
EXPECT_EQ(encodeBuffer[4], '\x00');
EXPECT_EQ(encodeBuffer[5], '\x00');
}

TEST_F(EncodeOSEM, IdStructPreamble)
{
EXPECT_EQ(id[0], '\x20');
Expand Down
15 changes: 15 additions & 0 deletions tests/traj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ class EncodeTRAJHeader : public ::testing::Test
char* name = info + 5; // skip info
};

TEST_F(EncodeTRAJHeader, MessageID)
{
EXPECT_EQ(encodeBuffer[16], '\x01');
EXPECT_EQ(encodeBuffer[17], '\x00');
}

TEST_F(EncodeTRAJHeader, MessageLength)
{
// 68+6+5+21×(34)+5
EXPECT_EQ(encodeBuffer[2], '\x1E');
EXPECT_EQ(encodeBuffer[3], '\x03');
EXPECT_EQ(encodeBuffer[4], '\x00');
EXPECT_EQ(encodeBuffer[5], '\x00');
}

TEST_F(EncodeTRAJHeader, Id)
{
EXPECT_EQ(id[0], '\x01');
Expand Down

0 comments on commit e26db59

Please sign in to comment.