File: igtlStatusMessageTest.cxx

package info (click to toggle)
openigtlink 3.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,080 kB
  • sloc: cpp: 20,076; ansic: 6,704; sh: 227; perl: 74; makefile: 46
file content (73 lines) | stat: -rw-r--r-- 2,744 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*=========================================================================
 
  Program:   OpenIGTLink Library
  Language:  C++
 
  Copyright (c) Insight Software Consortium. All rights reserved.
 
  This software is distributed WITHOUT ANY WARRANTY; without even
  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  PURPOSE.  See the above copyright notices for more information.
 
  =========================================================================*/

#include "igtlStatusMessage.h"
#include "igtlutil/igtl_test_data_status.h"
#include "string.h"
#include "igtl_status.h"
#include "igtl_header.h"
#include "igtlTestConfig.h"
#include "string.h"


igtl::StatusMessage::Pointer statusSendMsg = igtl::StatusMessage::New();
igtl::StatusMessage::Pointer statusReceiveMsg = igtl::StatusMessage::New();

#define STR_ERROR_NAME     "ACTUATOR_DISABLED" /* within 20 characters */
#define STR_ERROR_MESSAGE  "Actuator A is disabled."

TEST(StatusMessageTest, Pack)
{
  std::string statusString = "randomstringrandomstring";
  statusSendMsg->SetHeaderVersion(IGTL_HEADER_VERSION_1);
  statusSendMsg->SetStatusString(statusString.c_str());// pass an empty string with size 54,just to initialize the memory
  statusSendMsg->AllocatePack();
  statusSendMsg->SetTimeStamp(0, 1234567892);
  statusSendMsg->SetDeviceName("DeviceName");
  statusSendMsg->SetCode(IGTL_STATUS_DISABLED);
  statusSendMsg->SetSubCode(0x0A);
  statusSendMsg->SetErrorName(STR_ERROR_NAME);
  statusSendMsg->SetStatusString(STR_ERROR_MESSAGE);
  statusSendMsg->Pack();
  int r = memcmp((const void*)statusSendMsg->GetPackPointer(), (const void*)test_status_message,
                 (size_t)(IGTL_HEADER_SIZE));
  EXPECT_EQ(r, 0);
  r = memcmp((const void*)statusSendMsg->GetPackBodyPointer(), (const void*)(test_status_message+IGTL_HEADER_SIZE),statusSendMsg->GetPackBodySize());
  EXPECT_EQ(r, 0);
}


TEST(StatusMessageTest, Unpack)
{
  igtl::MessageHeader::Pointer headerMsg = igtl::MessageHeader::New();
  headerMsg->AllocatePack();
  memcpy(headerMsg->GetPackPointer(), statusSendMsg->GetPackPointer(), IGTL_HEADER_SIZE);
  headerMsg->Unpack();
  statusReceiveMsg->SetMessageHeader(headerMsg);
  statusReceiveMsg->AllocatePack();
  memcpy(statusReceiveMsg->GetPackBodyPointer(), statusSendMsg->GetPackBodyPointer(), statusSendMsg->GetPackBodySize());
  statusReceiveMsg->Unpack();
  
  EXPECT_EQ(statusReceiveMsg->GetCode(),IGTL_STATUS_DISABLED);
  EXPECT_EQ(statusReceiveMsg->GetSubCode(),(igtlInt64)0x0A);
  EXPECT_STREQ(statusReceiveMsg->GetErrorName(),STR_ERROR_NAME);
  EXPECT_STREQ(statusReceiveMsg->GetStatusString(),STR_ERROR_MESSAGE);
}


int main(int argc, char **argv)
{
  testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}