File: igtlStringMessageTest.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 (67 lines) | stat: -rw-r--r-- 2,282 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
/*=========================================================================
 
  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 "igtlStringMessage.h"
#include "igtlutil/igtl_test_data_string.h"
#include "igtl_string.h"
#include "igtl_header.h"
#include "igtlTestConfig.h"
#include "string.h"

#define IGTL_STRING_TEST_STRING "Welcome to OpenIGTLink"
#define IGTL_STRING_TEST_STRING_LEN 22

igtl::StringMessage::Pointer stringSendMsg = igtl::StringMessage::New();
igtl::StringMessage::Pointer stringReceiveMsg = igtl::StringMessage::New();

TEST(StringMessageTest, Pack)
{
  stringSendMsg->SetHeaderVersion(IGTL_HEADER_VERSION_1);
  stringSendMsg->SetString(IGTL_STRING_TEST_STRING);
  stringSendMsg->AllocatePack();
  stringSendMsg->SetTimeStamp(0, 1234567892);
  stringSendMsg->SetDeviceName("DeviceName");
  stringSendMsg->SetEncoding(3);
  stringSendMsg->Pack();
  int r = memcmp((const void*)stringSendMsg->GetPackPointer(), (const void*)test_string_message,
                 (size_t)(IGTL_HEADER_SIZE));
  EXPECT_EQ(r, 0);
  r = memcmp((const void*)stringSendMsg->GetPackBodyPointer(), (const void*)(test_string_message+IGTL_HEADER_SIZE),stringSendMsg->GetPackBodySize());
  EXPECT_EQ(r, 0);
}


TEST(StringMessageTest, Unpack)
{
  igtl::MessageHeader::Pointer headerMsg = igtl::MessageHeader::New();
  headerMsg->AllocatePack();
  memcpy(headerMsg->GetPackPointer(), (const void*)test_string_message, IGTL_HEADER_SIZE);
  headerMsg->Unpack();
  stringReceiveMsg->SetMessageHeader(headerMsg);
  stringReceiveMsg->AllocatePack();
  
  memcpy(stringReceiveMsg->GetPackBodyPointer(), stringSendMsg->GetPackBodyPointer(), stringSendMsg->GetPackBodySize());
  stringReceiveMsg->Unpack();
  
  EXPECT_EQ(stringReceiveMsg->GetEncoding(),3);
  EXPECT_STREQ(stringReceiveMsg->GetString(),IGTL_STRING_TEST_STRING);
  
}


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