binary_serialize_endpoints.cpp
Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 #include <opc/ua/protocol/message_identifiers.h>
00012 #include <opc/ua/protocol/binary/stream.h>
00013 #include <opc/ua/protocol/endpoints.h>
00014 #include <opc/ua/protocol/types.h>
00015 
00016 #include <algorithm>
00017 #include <stdexcept>
00018 #include <gtest/gtest.h>
00019 
00020 #include "common.h"
00021 
00022 
00023 class EndpointsSerialization : public OpcUaBinarySerialization
00024 {
00025 };
00026 
00027 class EndpointsDeserialization : public OpcUaBinaryDeserialization
00028 {
00029 };
00030 
00031 //-------------------------------------------------------
00032 // GetEndpointsRequest
00033 //-------------------------------------------------------
00034 
00035 TEST_F(EndpointsSerialization, GetEndpointsRequest)
00036 {
00037 
00038   using namespace OpcUa;
00039   using namespace OpcUa::Binary;
00040 
00041   GetEndpointsRequest request;
00042 
00043   ASSERT_EQ(request.TypeId.Encoding, EV_FOUR_BYTE);
00044   ASSERT_EQ(request.TypeId.FourByteData.NamespaceIndex, 0);
00045   ASSERT_EQ(request.TypeId.FourByteData.Identifier, OpcUa::GET_ENDPOINTS_REQUEST);
00046 
00047   FILL_TEST_REQUEST_HEADER(request.Header);
00048   request.Parameters.EndpointUrl = "test";
00049   request.Parameters.LocaleIds.push_back("RU");
00050   request.Parameters.ProfileUris.push_back("pro");
00051 
00052 
00053   GetStream() << request << flush;
00054 
00055   const std::vector<char> expectedData = {
00056   1, 0, (char)0xac, 0x1, // TypeId
00057   // RequestHeader
00058   TEST_REQUEST_HEADER_BINARY_DATA,
00059   4,0,0,0, 't','e','s','t',
00060   1,0,0,0, 2,0,0,0, 'R','U',
00061   1,0,0,0, 3,0,0,0, 'p','r','o'
00062   };
00063 
00064   ASSERT_EQ(expectedData, GetChannel().SerializedData);
00065   ASSERT_EQ(expectedData.size(), RawSize(request));
00066 }
00067 
00068 TEST_F(EndpointsDeserialization, GetEndpointsRequest)
00069 {
00070   using namespace OpcUa;
00071   using namespace OpcUa::Binary;
00072 
00073   const std::vector<char> expectedData = {
00074   1, 0, (char)0xac, 0x1, // TypeId
00075   // RequestHeader
00076   TEST_REQUEST_HEADER_BINARY_DATA,
00077   4,0,0,0, 't','e','s','t',
00078   1,0,0,0, 2,0,0,0, 'R','U',
00079   1,0,0,0, 3,0,0,0, 'p','r','o'
00080   };
00081 
00082   GetChannel().SetData(expectedData);
00083 
00084   GetEndpointsRequest request;
00085   GetStream() >> request;
00086 
00087   ASSERT_EQ(request.TypeId.Encoding, EV_FOUR_BYTE);
00088   ASSERT_EQ(request.TypeId.FourByteData.NamespaceIndex, 0);
00089   ASSERT_EQ(request.TypeId.FourByteData.Identifier, OpcUa::GET_ENDPOINTS_REQUEST);
00090 
00091   ASSERT_REQUEST_HEADER_EQ(request.Header);
00092 
00093   ASSERT_EQ(request.Parameters.EndpointUrl, "test");
00094   ASSERT_EQ(request.Parameters.LocaleIds, std::vector<std::string>(1, "RU"));
00095   ASSERT_EQ(request.Parameters.ProfileUris, std::vector<std::string>(1, "pro"));
00096 }
00097 
00098 //----------------------------------------------------
00099 // GetEndpointsResponse
00100 //----------------------------------------------------
00101 
00102 TEST_F(EndpointsSerialization, GetEndpointsResponse)
00103 {
00104 
00105   using namespace OpcUa;
00106   using namespace OpcUa::Binary;
00107 
00108   GetEndpointsResponse response;
00109 
00110   ASSERT_EQ(response.TypeId.Encoding, EV_FOUR_BYTE);
00111   ASSERT_EQ(response.TypeId.FourByteData.NamespaceIndex, 0);
00112   ASSERT_EQ(response.TypeId.FourByteData.Identifier, OpcUa::GET_ENDPOINTS_RESPONSE);
00113 
00114   FILL_TEST_RESPONSE_HEADER(response.Header);
00115 
00116   EndpointDescription endpoint;
00117   FILL_TEST_ENDPOINT(endpoint);
00118   response.Endpoints.push_back(endpoint);
00119 
00120   GetStream() << response << flush;
00121 
00122   const std::vector<char> expectedData = {
00123   1, 0, (char)0xaf, 0x1, // TypeId
00124   // RequestHeader
00125   TEST_RESPONSE_HEADER_BINARY_DATA,
00126 
00127   1,0,0,0,
00128   TEST_ENDPOINT_BINARY_DATA
00129   };
00130 
00131   ASSERT_EQ(expectedData, GetChannel().SerializedData);
00132   ASSERT_EQ(expectedData.size(), RawSize(response));
00133 }
00134 
00135 TEST_F(EndpointsDeserialization, GetEndpointsResponse)
00136 {
00137   using namespace OpcUa;
00138   using namespace OpcUa::Binary;
00139 
00140   const std::vector<char> expectedData = {
00141   1, 0, (char)0xaf, 0x1, // TypeId
00142   // RequestHeader
00143   TEST_RESPONSE_HEADER_BINARY_DATA,
00144 
00145   1,0,0,0,
00146   TEST_ENDPOINT_BINARY_DATA
00147   };
00148 
00149   GetChannel().SetData(expectedData);
00150 
00151   GetEndpointsResponse response;
00152   GetStream() >> response;
00153 
00154   ASSERT_EQ(response.TypeId.Encoding, EV_FOUR_BYTE);
00155   ASSERT_EQ(response.TypeId.FourByteData.NamespaceIndex, 0);
00156   ASSERT_EQ(response.TypeId.FourByteData.Identifier, OpcUa::GET_ENDPOINTS_RESPONSE);
00157 
00158   ASSERT_RESPONSE_HEADER_EQ(response.Header);
00159 
00160   ASSERT_EQ(response.Endpoints.size(), 1);
00161   ASSERT_ENDPOINT_EQ(response.Endpoints[0]);
00162 
00163   ASSERT_TRUE(Channel->IsEmpty());
00164 }
00165 
00166 const std::vector<unsigned char> GetEndpointsResponseRealData = {
00167   0x4d, 0x53, 0x47, 0x46, 0xd2, 0x06, 0x00, 0x00, 0xfc, 0x4b, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,  // MSGF.....K......
00168   0x34, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0xaf, 0x01, 0xd8, 0xcd, 0x4e, 0x53,  // 4.............NS
00169   0x36, 0xda, 0xcd, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  // 6...............
00170   0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x6f, 0x70, 0x63, 0x2e,  // ............opc.
00171   0x74, 0x63, 0x70, 0x3a, 0x2f, 0x2f, 0x31, 0x39, 0x32, 0x2e, 0x31, 0x36, 0x38, 0x2e, 0x31, 0x2e,  // tcp://192.168.1.
00172   0x33, 0x36, 0x3a, 0x34, 0x39, 0x33, 0x32, 0x30, 0x34, 0x00, 0x00, 0x00, 0x75, 0x72, 0x6e, 0x3a,  // 36:493204...urn:
00173   0x74, 0x72, 0x65, 0x77, 0x77, 0x2d, 0x61, 0x35, 0x38, 0x35, 0x35, 0x35, 0x37, 0x31, 0x62, 0x3a,  // treww-a5855571b:
00174   0x4b, 0x65, 0x70, 0x77, 0x61, 0x72, 0x65, 0x2e, 0x4b, 0x45, 0x50, 0x53, 0x65, 0x72, 0x76, 0x65,  // Kepware.KEPServe
00175   0x72, 0x45, 0x58, 0x2e, 0x56, 0x35, 0x3a, 0x55, 0x41, 0x20, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72,  // rEX.V5:UA Server
00176   0x34, 0x00, 0x00, 0x00, 0x75, 0x72, 0x6e, 0x3a, 0x74, 0x72, 0x65, 0x77, 0x77, 0x2d, 0x61, 0x35,  // 4...urn:treww-a5
00177   0x38, 0x35, 0x35, 0x35, 0x37, 0x31, 0x62, 0x3a, 0x4b, 0x65, 0x70, 0x77, 0x61, 0x72, 0x65, 0x2e,  // 855571b:Kepware.
00178   0x4b, 0x45, 0x50, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x45, 0x58, 0x2e, 0x56, 0x35, 0x3a, 0x55,  // KEPServerEX.V5:U
00179   0x41, 0x20, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x03, 0x02, 0x00, 0x00, 0x00, 0x65, 0x6e, 0x1e,  // A Server.....en.
00180   0x00, 0x00, 0x00, 0x4b, 0x45, 0x50, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x45, 0x58, 0x2f, 0x55,  // ...KEPServerEX/U
00181   0x41, 0x40, 0x74, 0x72, 0x65, 0x77, 0x77, 0x2d, 0x61, 0x35, 0x38, 0x35, 0x35, 0x35, 0x37, 0x31,  // A@treww-a5855571
00182   0x62, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00,  // b...............
00183   0x00, 0x1c, 0x00, 0x00, 0x00, 0x6f, 0x70, 0x63, 0x2e, 0x74, 0x63, 0x70, 0x3a, 0x2f, 0x2f, 0x31,  // .....opc.tcp://1
00184   0x39, 0x32, 0x2e, 0x31, 0x36, 0x38, 0x2e, 0x31, 0x2e, 0x33, 0x36, 0x3a, 0x34, 0x39, 0x33, 0x32,  // 92.168.1.36:4932
00185   0x30, 0xf3, 0x03, 0x00, 0x00, 0x30, 0x82, 0x03, 0xef, 0x30, 0x82, 0x03, 0x58, 0xa0, 0x03, 0x02,  // 0....0...0..X...
00186   0x01, 0x02, 0x02, 0x04, 0x84, 0x79, 0x20, 0xf2, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,  // .....y .0...*.H.
00187   0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x60, 0x31, 0x1f, 0x30, 0x1d, 0x06, 0x0a, 0x09,  // .......0`1.0....
00188   0x92, 0x26, 0x89, 0x93, 0xf2, 0x2c, 0x64, 0x01, 0x19, 0x16, 0x0f, 0x74, 0x72, 0x65, 0x77, 0x77,  // .&...,d....treww
00189   0x2d, 0x61, 0x35, 0x38, 0x35, 0x35, 0x35, 0x37, 0x31, 0x62, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03,  // -a5855571b1.0...
00190   0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a,  // U....US1.0...U..
00191   0x13, 0x07, 0x55, 0x6e, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x31, 0x1e, 0x30, 0x1c, 0x06, 0x03, 0x55,  // ..Unknown1.0...U
00192   0x04, 0x03, 0x13, 0x15, 0x4b, 0x45, 0x50, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x45, 0x58, 0x2f,  // ....KEPServerEX/
00193   0x55, 0x41, 0x20, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x32, 0x31,  // UA Server0...121
00194   0x31, 0x30, 0x34, 0x30, 0x36, 0x33, 0x38, 0x34, 0x35, 0x5a, 0x17, 0x0d, 0x32, 0x32, 0x31, 0x31,  // 104063845Z..2211
00195   0x30, 0x32, 0x30, 0x36, 0x33, 0x38, 0x34, 0x35, 0x5a, 0x30, 0x60, 0x31, 0x1f, 0x30, 0x1d, 0x06,  // 02063845Z0`1.0..
00196   0x0a, 0x09, 0x92, 0x26, 0x89, 0x93, 0xf2, 0x2c, 0x64, 0x01, 0x19, 0x16, 0x0f, 0x74, 0x72, 0x65,  // ...&...,d....tre
00197   0x77, 0x77, 0x2d, 0x61, 0x35, 0x38, 0x35, 0x35, 0x35, 0x37, 0x31, 0x62, 0x31, 0x0b, 0x30, 0x09,  // ww-a5855571b1.0.
00198   0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55,  // ..U....US1.0...U
00199   0x04, 0x0a, 0x13, 0x07, 0x55, 0x6e, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x31, 0x1e, 0x30, 0x1c, 0x06,  // ....Unknown1.0..
00200   0x03, 0x55, 0x04, 0x03, 0x13, 0x15, 0x4b, 0x45, 0x50, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x45,  // .U....KEPServerE
00201   0x58, 0x2f, 0x55, 0x41, 0x20, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x30, 0x81, 0x9f, 0x30, 0x0d,  // X/UA Server0..0.
00202   0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x81, 0x8d,  // ..*.H...........
00203   0x00, 0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xb0, 0x1f, 0x2b, 0xd7, 0x13, 0x46, 0x0d, 0xd6,  // .0........+..F..
00204   0x52, 0xa9, 0x94, 0x38, 0xef, 0x30, 0xc2, 0xe8, 0xcf, 0x2e, 0x72, 0x8c, 0x4d, 0x95, 0x66, 0xbf,  // R..8.0....r.M.f.
00205   0x0d, 0x55, 0xa3, 0x03, 0x24, 0xf1, 0xc2, 0x94, 0x1c, 0xf0, 0x72, 0x4c, 0x7b, 0x3f, 0xf0, 0x13,  // .U..$.....rL{?..
00206   0x26, 0x97, 0x25, 0xb0, 0x26, 0x30, 0x3f, 0xe7, 0xa9, 0x4b, 0xb7, 0xbf, 0x29, 0x5a, 0x14, 0x42,  // &.%.&0?..K..)Z.B
00207   0x20, 0xe6, 0xc0, 0x2e, 0x71, 0xb6, 0xb2, 0xb9, 0xb4, 0x56, 0x2c, 0x28, 0xb9, 0x5c, 0x87, 0xd5,  //  ...q....V,(.\..
00208   0xab, 0x26, 0x6d, 0x7c, 0x19, 0x3a, 0x51, 0x33, 0x04, 0x13, 0xf8, 0x79, 0x2c, 0x36, 0xae, 0xff,  // .&m|.:Q3...y,6..
00209   0xce, 0x76, 0x2b, 0x21, 0xfb, 0xdb, 0xef, 0xe4, 0x0a, 0xe1, 0x8a, 0x48, 0x3f, 0x58, 0xfe, 0xd7,  // .v+!.......H?X..
00210   0xa0, 0xea, 0x6d, 0x75, 0x57, 0xf4, 0x71, 0x0e, 0x91, 0xc5, 0x29, 0xb3, 0x91, 0x93, 0x9e, 0x27,  // ..muW.q...)....'
00211   0xfc, 0xe8, 0x36, 0x79, 0xd7, 0x96, 0xa1, 0xef, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x82, 0x01,  // ..6y............
00212   0xb4, 0x30, 0x82, 0x01, 0xb0, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14,  // .0...0...U......
00213   0xcf, 0xfd, 0xaf, 0x08, 0x54, 0x3d, 0x74, 0x5a, 0xc8, 0x81, 0x4f, 0x80, 0xa0, 0x5e, 0xb8, 0xbe,  // ....T=tZ..O..^..
00214   0x16, 0x2d, 0x0f, 0xb1, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04,  // .-..0...U.......
00215   0x03, 0x02, 0x02, 0xf4, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04, 0x02,  // ....0...U.......
00216   0x30, 0x00, 0x30, 0x81, 0x8d, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x81, 0x85, 0x30, 0x81, 0x82,  // 0.0....U.#...0..
00217   0x80, 0x14, 0xcf, 0xfd, 0xaf, 0x08, 0x54, 0x3d, 0x74, 0x5a, 0xc8, 0x81, 0x4f, 0x80, 0xa0, 0x5e,  // ......T=tZ..O..^
00218   0xb8, 0xbe, 0x16, 0x2d, 0x0f, 0xb1, 0xa1, 0x64, 0xa4, 0x62, 0x30, 0x60, 0x31, 0x1f, 0x30, 0x1d,  // ...-...d.b0`1.0.
00219   0x06, 0x0a, 0x09, 0x92, 0x26, 0x89, 0x93, 0xf2, 0x2c, 0x64, 0x01, 0x19, 0x16, 0x0f, 0x74, 0x72,  // ....&...,d....tr
00220   0x65, 0x77, 0x77, 0x2d, 0x61, 0x35, 0x38, 0x35, 0x35, 0x35, 0x37, 0x31, 0x62, 0x31, 0x0b, 0x30,  // eww-a5855571b1.0
00221   0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03,  // ...U....US1.0...
00222   0x55, 0x04, 0x0a, 0x13, 0x07, 0x55, 0x6e, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x31, 0x1e, 0x30, 0x1c,  // U....Unknown1.0.
00223   0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x15, 0x4b, 0x45, 0x50, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72,  // ..U....KEPServer
00224   0x45, 0x58, 0x2f, 0x55, 0x41, 0x20, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x82, 0x04, 0x84, 0x79,  // EX/UA Server...y
00225   0x20, 0xf2, 0x30, 0x20, 0x06, 0x03, 0x55, 0x1d, 0x25, 0x01, 0x01, 0xff, 0x04, 0x16, 0x30, 0x14,  //  .0 ..U.%.....0.
00226   0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x01, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05,  // ..+.........+...
00227   0x05, 0x07, 0x03, 0x02, 0x30, 0x6d, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x86, 0xf8, 0x42, 0x01,  // ....0m..`.H...B.
00228   0x0d, 0x04, 0x60, 0x16, 0x5e, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x64, 0x20, 0x62,  // ..`.^Generated b
00229   0x79, 0x20, 0x53, 0x59, 0x53, 0x54, 0x45, 0x4d, 0x40, 0x74, 0x72, 0x65, 0x77, 0x77, 0x2d, 0x61,  // y SYSTEM@treww-a
00230   0x35, 0x38, 0x35, 0x35, 0x35, 0x37, 0x31, 0x62, 0x20, 0x6f, 0x6e, 0x20, 0x32, 0x30, 0x31, 0x32,  // 5855571b on 2012
00231   0x2d, 0x31, 0x31, 0x2d, 0x30, 0x34, 0x54, 0x30, 0x36, 0x3a, 0x33, 0x38, 0x3a, 0x34, 0x35, 0x2e,  // -11-04T06:38:45.
00232   0x32, 0x32, 0x39, 0x20, 0x75, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x4f, 0x70, 0x65, 0x6e, 0x53, 0x53,  // 229 using OpenSS
00233   0x4c, 0x20, 0x31, 0x2e, 0x30, 0x2e, 0x30, 0x64, 0x20, 0x38, 0x20, 0x46, 0x65, 0x62, 0x20, 0x32,  // L 1.0.0d 8 Feb 2
00234   0x30, 0x31, 0x31, 0x30, 0x50, 0x06, 0x03, 0x55, 0x1d, 0x11, 0x04, 0x49, 0x30, 0x47, 0x86, 0x34,  // 0110P..U...I0G.4
00235   0x75, 0x72, 0x6e, 0x3a, 0x74, 0x72, 0x65, 0x77, 0x77, 0x2d, 0x61, 0x35, 0x38, 0x35, 0x35, 0x35,  // urn:treww-a58555
00236   0x37, 0x31, 0x62, 0x3a, 0x4b, 0x65, 0x70, 0x77, 0x61, 0x72, 0x65, 0x2e, 0x4b, 0x45, 0x50, 0x53,  // 71b:Kepware.KEPS
00237   0x65, 0x72, 0x76, 0x65, 0x72, 0x45, 0x58, 0x2e, 0x56, 0x35, 0x3a, 0x55, 0x41, 0x20, 0x53, 0x65,  // erverEX.V5:UA Se
00238   0x72, 0x76, 0x65, 0x72, 0x82, 0x0f, 0x74, 0x72, 0x65, 0x77, 0x77, 0x2d, 0x61, 0x35, 0x38, 0x35,  // rver..treww-a585
00239   0x35, 0x35, 0x37, 0x31, 0x62, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01,  // 5571b0...*.H....
00240   0x01, 0x05, 0x05, 0x00, 0x03, 0x81, 0x81, 0x00, 0x36, 0x3d, 0x98, 0xdc, 0xc8, 0xa2, 0x48, 0xfe,  // ........6=....H.
00241   0xbd, 0xc1, 0xdb, 0xf9, 0xfb, 0x32, 0x3b, 0x3d, 0x43, 0x6c, 0xff, 0xd3, 0x9d, 0xa0, 0x96, 0x80,  // .....2;=Cl......
00242   0x8a, 0x99, 0x0b, 0x19, 0x2b, 0x77, 0xd0, 0xd7, 0x66, 0x26, 0x45, 0xe4, 0x72, 0x5b, 0x7b, 0x62,  // ....+w..f&E.r[{b
00243   0xb6, 0x16, 0x25, 0x8c, 0xdf, 0x06, 0x53, 0x89, 0xb4, 0x19, 0x5d, 0xb3, 0x85, 0x50, 0x83, 0x86,  // ..%...S...]..P..
00244   0x1f, 0xc5, 0xa3, 0xc7, 0x8d, 0xd7, 0x0b, 0x0b, 0xfe, 0xd3, 0xb2, 0x54, 0x88, 0x9c, 0x41, 0xfd,  // ...........T..A.
00245   0x31, 0x83, 0x16, 0x49, 0x1e, 0x21, 0x16, 0xc5, 0x30, 0xaf, 0x72, 0xf2, 0x9b, 0x63, 0xe2, 0x96,  // 1..I.!..0.r..c..
00246   0x70, 0x97, 0x3c, 0x79, 0x4a, 0x58, 0x56, 0x9f, 0x2b, 0xa7, 0x66, 0x83, 0xd8, 0x43, 0xcf, 0x2b,  // p.<yJXV.+.f..C.+
00247   0xfe, 0x9b, 0x04, 0xa6, 0x8f, 0xa3, 0x23, 0x83, 0xff, 0x4f, 0xc7, 0x91, 0xa0, 0x9e, 0xfb, 0x5b,  // ......#..O.....[
00248   0x6c, 0xfe, 0xb7, 0x56, 0xee, 0x87, 0x1e, 0x89, 0x01, 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00, 0x00,  // l..V......../...
00249   0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x6f, 0x70, 0x63, 0x66, 0x6f, 0x75, 0x6e, 0x64, 0x61,  // http://opcfounda
00250   0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x55, 0x41, 0x2f, 0x53, 0x65, 0x63, 0x75,  // tion.org/UA/Secu
00251   0x72, 0x69, 0x74, 0x79, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x23, 0x4e, 0x6f, 0x6e, 0x65, 0x02,  // rityPolicy#None.
00252   0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x41, 0x6e, 0x6f, 0x6e, 0x79, 0x6d, 0x6f, 0x75, 0x73,  // .......Anonymous
00253   0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,  // ................
00254   0x08, 0x00, 0x00, 0x00, 0x55, 0x73, 0x65, 0x72, 0x4e, 0x61, 0x6d, 0x65, 0x01, 0x00, 0x00, 0x00,  // ....UserName....
00255   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x38, 0x00, 0x00, 0x00, 0x68, 0x74, 0x74, 0x70,  // ........8...http
00256   0x3a, 0x2f, 0x2f, 0x6f, 0x70, 0x63, 0x66, 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e,  // ://opcfoundation
00257   0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x55, 0x41, 0x2f, 0x53, 0x65, 0x63, 0x75, 0x72, 0x69, 0x74, 0x79,  // .org/UA/Security
00258   0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x23, 0x42, 0x61, 0x73, 0x69, 0x63, 0x31, 0x32, 0x38, 0x52,  // Policy#Basic128R
00259   0x73, 0x61, 0x31, 0x35, 0x41, 0x00, 0x00, 0x00, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x6f,  // sa15A...http://o
00260   0x70, 0x63, 0x66, 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x6f, 0x72, 0x67,  // pcfoundation.org
00261   0x2f, 0x55, 0x41, 0x2d, 0x50, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x2f, 0x54, 0x72, 0x61, 0x6e,  // /UA-Profile/Tran
00262   0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x75, 0x61, 0x74, 0x63, 0x70, 0x2d, 0x75, 0x61, 0x73, 0x63,  // sport/uatcp-uasc
00263   0x2d, 0x75, 0x61, 0x62, 0x69, 0x6e, 0x61, 0x72, 0x79, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,  // -uabinary.......
00264   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff,  // ................
00265   0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff,  // ................
00266   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff,  // ................
00267   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff,  // ................
00268   0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00,  // ................
00269   0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff,  // ................
00270   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,  // ................
00271   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00,  // ................
00272   0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00,  // ................
00273   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,  // ................
00274   0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff,  // ................
00275   0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,  // ................
00276   0xff, 0x00 };                                                                       //  ..
00277 
00278 TEST_F(EndpointsDeserialization, GetEndpointsResponseReal)
00279 {
00280   using namespace OpcUa;
00281   using namespace OpcUa::Binary;
00282 
00283   GetChannel().SetData(std::vector<char>(GetEndpointsResponseRealData.begin(), GetEndpointsResponseRealData.end()));
00284 
00285   SecureHeader responseHeader;
00286   GetStream() >> responseHeader;
00287 
00288   SymmetricAlgorithmHeader responseAlgo;
00289   GetStream() >> responseAlgo;
00290 
00291   SequenceHeader responseSequence;
00292   GetStream() >> responseSequence; // TODO Check for request Number
00293 
00294   GetEndpointsResponse response;
00295   GetStream() >> response;
00296 
00297   ASSERT_EQ(response.TypeId.Encoding, EV_FOUR_BYTE);
00298   ASSERT_EQ(response.TypeId.FourByteData.NamespaceIndex, 0);
00299   ASSERT_EQ(response.TypeId.FourByteData.Identifier, OpcUa::GET_ENDPOINTS_RESPONSE);
00300 
00301   ASSERT_EQ(response.Endpoints.size(), 5);
00302 
00303   ASSERT_TRUE(Channel->IsEmpty());
00304 }
00305 
00306 
00307 //-------------------------------------------------------
00308 // FindServersParameters
00309 //-------------------------------------------------------
00310 
00311 TEST_F(EndpointsSerialization, FindServersParameters)
00312 {
00313 
00314   using namespace OpcUa;
00315   using namespace OpcUa::Binary;
00316 
00317   FindServersParameters params;
00318 
00319   params.EndpointUrl = "url";
00320   params.Locales.push_back("en");
00321   params.ServersToReturn.push_back("server");
00322 
00323   GetStream() << params << flush;
00324 
00325   const std::vector<char> expectedData = {
00326   3,0,0,0, 'u','r','l',
00327   1,0,0,0, 2,0,0,0, 'e','n',
00328   1,0,0,0, 6,0,0,0, 's','e','r','v','e','r'
00329   };
00330 
00331   ASSERT_EQ(expectedData, GetChannel().SerializedData);
00332   ASSERT_EQ(expectedData.size(), RawSize(params));
00333 }
00334 
00335 TEST_F(EndpointsDeserialization, FindServersParameters)
00336 {
00337 
00338   using namespace OpcUa;
00339   using namespace OpcUa::Binary;
00340 
00341   const std::vector<char> expectedData = {
00342   3,0,0,0, 'u','r','l',
00343   1,0,0,0, 2,0,0,0, 'e','n',
00344   1,0,0,0, 6,0,0,0, 's','e','r','v','e','r'
00345   };
00346 
00347   GetChannel().SetData(expectedData);
00348 
00349   FindServersParameters params;
00350   GetStream() >> params;
00351 
00352   ASSERT_EQ(params.EndpointUrl, "url");
00353   ASSERT_EQ(params.Locales.size(), 1);
00354   ASSERT_EQ(params.Locales[0], "en");
00355   ASSERT_EQ(params.ServersToReturn.size(), 1);
00356   ASSERT_EQ(params.ServersToReturn[0], "server");
00357 }
00358 
00359 //-------------------------------------------------------
00360 // FindServersRequest
00361 //-------------------------------------------------------
00362 
00363 TEST_F(EndpointsSerialization, FindServersRequest)
00364 {
00365 
00366   using namespace OpcUa;
00367   using namespace OpcUa::Binary;
00368 
00369   FindServersRequest request;
00370 
00371   ASSERT_EQ(request.TypeId.Encoding, EV_FOUR_BYTE);
00372   ASSERT_EQ(request.TypeId.FourByteData.NamespaceIndex, 0);
00373   ASSERT_EQ(request.TypeId.FourByteData.Identifier, OpcUa::FIND_ServerS_REQUEST);
00374 
00375   FILL_TEST_REQUEST_HEADER(request.Header);
00376   request.Parameters.EndpointUrl = "url";
00377   request.Parameters.Locales.push_back("en");
00378   request.Parameters.ServersToReturn.push_back("server");
00379 
00380 
00381   GetStream() << request << flush;
00382 
00383   const std::vector<char> expectedData = {
00384   1, 0, (char)0xa6, 0x1, // TypeId
00385   // RequestHeader
00386   TEST_REQUEST_HEADER_BINARY_DATA,
00387   3,0,0,0, 'u','r','l',
00388   1,0,0,0, 2,0,0,0, 'e','n',
00389   1,0,0,0, 6,0,0,0, 's','e','r','v','e','r'
00390   };
00391 
00392   ASSERT_EQ(expectedData, GetChannel().SerializedData);
00393   ASSERT_EQ(expectedData.size(), RawSize(request));
00394 }
00395 
00396 TEST_F(EndpointsDeserialization, FindServersRequest)
00397 {
00398   using namespace OpcUa;
00399   using namespace OpcUa::Binary;
00400 
00401   const std::vector<char> expectedData = {
00402   1, 0, (char)0xa6, 0x1, // TypeId
00403   // RequestHeader
00404   TEST_REQUEST_HEADER_BINARY_DATA,
00405   3,0,0,0, 'u','r','l',
00406   1,0,0,0, 2,0,0,0, 'e','n',
00407   1,0,0,0, 6,0,0,0, 's','e','r','v','e','r'
00408   };
00409 
00410   GetChannel().SetData(expectedData);
00411 
00412   FindServersRequest request;
00413   GetStream() >> request;
00414 
00415   ASSERT_EQ(request.TypeId.Encoding, EV_FOUR_BYTE);
00416   ASSERT_EQ(request.TypeId.FourByteData.NamespaceIndex, 0);
00417   ASSERT_EQ(request.TypeId.FourByteData.Identifier, OpcUa::FIND_ServerS_REQUEST);
00418 
00419   ASSERT_REQUEST_HEADER_EQ(request.Header);
00420 
00421   ASSERT_EQ(request.Parameters.EndpointUrl, "url");
00422   ASSERT_EQ(request.Parameters.Locales, std::vector<std::string>(1, "en"));
00423   ASSERT_EQ(request.Parameters.ServersToReturn, std::vector<std::string>(1, "server"));
00424 }
00425 
00426 //----------------------------------------------------
00427 // FindServersResponse
00428 //----------------------------------------------------
00429 
00430 TEST_F(EndpointsSerialization, FindServersResponse)
00431 {
00432 
00433   using namespace OpcUa;
00434   using namespace OpcUa::Binary;
00435 
00436   FindServersResponse response;
00437 
00438   ASSERT_EQ(response.TypeId.Encoding, EV_FOUR_BYTE);
00439   ASSERT_EQ(response.TypeId.FourByteData.NamespaceIndex, 0);
00440   ASSERT_EQ(response.TypeId.FourByteData.Identifier, OpcUa::FIND_ServerS_RESPONSE);
00441 
00442   FILL_TEST_RESPONSE_HEADER(response.Header);
00443 
00444   ApplicationDescription desc;
00445   FILL_APPLICATION_DESCRIPTION(desc);
00446   response.Data.Descriptions.push_back(desc);
00447 
00448   GetStream() << response << flush;
00449 
00450   const std::vector<char> expectedData = {
00451   1, 0, (char)0xa9, 0x1, // TypeId
00452   // RequestHeader
00453   TEST_RESPONSE_HEADER_BINARY_DATA,
00454 
00455   1,0,0,0,
00456   TEST_APPLICATION_DESCRIPTION_BINARY_DATA
00457   };
00458 
00459   ASSERT_EQ(expectedData, GetChannel().SerializedData);
00460   ASSERT_EQ(expectedData.size(), RawSize(response));
00461 }
00462 
00463 TEST_F(EndpointsDeserialization, FindServersResponse)
00464 {
00465   using namespace OpcUa;
00466   using namespace OpcUa::Binary;
00467 
00468   const std::vector<char> expectedData = {
00469   1, 0, (char)0xa9, 0x1, // TypeId
00470   // RequestHeader
00471   TEST_RESPONSE_HEADER_BINARY_DATA,
00472 
00473   1,0,0,0,
00474   TEST_APPLICATION_DESCRIPTION_BINARY_DATA
00475   };
00476 
00477   GetChannel().SetData(expectedData);
00478 
00479   FindServersResponse response;
00480   GetStream() >> response;
00481 
00482   ASSERT_EQ(response.TypeId.Encoding, EV_FOUR_BYTE);
00483   ASSERT_EQ(response.TypeId.FourByteData.NamespaceIndex, 0);
00484   ASSERT_EQ(response.TypeId.FourByteData.Identifier, OpcUa::FIND_ServerS_RESPONSE);
00485 
00486   ASSERT_RESPONSE_HEADER_EQ(response.Header);
00487 
00488   ASSERT_EQ(response.Data.Descriptions.size(), 1);
00489   ASSERT_APPLICATION_DESCRIPTION_EQ(response.Data.Descriptions[0]);
00490 
00491   ASSERT_TRUE(Channel->IsEmpty());
00492 }


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Sat Jun 8 2019 18:24:39