binary_serialize_session.cpp
Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 #include "common.h"
00012 
00013 #include <opc/ua/protocol/extension_identifiers.h>
00014 #include <opc/ua/protocol/message_identifiers.h>
00015 #include <opc/ua/protocol/binary/stream.h>
00016 #include <opc/ua/protocol/types.h>
00017 #include <opc/ua/protocol/session.h>
00018 
00019 #include <algorithm>
00020 #include <stdexcept>
00021 
00022 
00023 
00024 //-------------------------------------------------------
00025 // CreateSessionRequest
00026 //-------------------------------------------------------
00027 
00028 TEST_F(OpcUaBinarySerialization, CreateSessionRequest)
00029 {
00030 
00031   using namespace OpcUa;
00032   using namespace OpcUa::Binary;
00033 
00034   CreateSessionRequest request;
00035 
00036   ASSERT_EQ(request.TypeId.Encoding, EV_FOUR_BYTE);
00037   ASSERT_EQ(request.TypeId.FourByteData.NamespaceIndex, 0);
00038   ASSERT_EQ(request.TypeId.FourByteData.Identifier, OpcUa::CREATE_SESSION_REQUEST);
00039 
00040   FILL_TEST_REQUEST_HEADER(request.Header);
00041 
00042   FILL_APPLICATION_DESCRIPTION(request.Parameters.ClientDescription);
00043 
00044   request.Parameters.ServerUri = "su";
00045   request.Parameters.EndpointUrl = "eu";
00046   request.Parameters.SessionName = "sn";
00047   request.Parameters.ClientNonce =  ByteString(std::vector<uint8_t>{1,2,3,4});
00048   request.Parameters.ClientCertificate = ByteString(std::vector<uint8_t>{5,6,7,8});
00049   request.Parameters.RequestedSessionTimeout = 1200000;
00050   request.Parameters.MaxResponseMessageSize = 2;
00051 
00052   GetStream() << request << flush;
00053 
00054   const std::vector<char> expectedData = {
00055   1, 0, (char)0xcd, 0x1, // TypeId
00056   // RequestHeader
00057   TEST_REQUEST_HEADER_BINARY_DATA,
00058   TEST_APPLICATION_DESCRIPTION_BINARY_DATA,
00059   2,0,0,0, 's','u',
00060   2,0,0,0, 'e','u',
00061   2,0,0,0, 's','n',
00062   4,0,0,0, 1,2,3,4,
00063   4,0,0,0, 5,6,7,8,
00064   0, 0, 0, 0, (char)0x80, (char)0x4f, (char)0x32, (char)0x41,
00065   2,0,0,0
00066   };
00067 
00068   ASSERT_EQ(expectedData, GetChannel().SerializedData) << PrintData(GetChannel().SerializedData) << std::endl << PrintData(expectedData);
00069   ASSERT_EQ(expectedData.size(), RawSize(request));
00070 }
00071 
00072 TEST_F(OpcUaBinaryDeserialization, CreateSessionRequest)
00073 {
00074   using namespace OpcUa;
00075   using namespace OpcUa::Binary;
00076 
00077   const std::vector<char> expectedData = {
00078   1, 0, (char)0xcd, 0x1, // TypeId
00079   // RequestHeader
00080   TEST_REQUEST_HEADER_BINARY_DATA,
00081   TEST_APPLICATION_DESCRIPTION_BINARY_DATA,
00082   2,0,0,0, 's','u',
00083   2,0,0,0, 'e','u',
00084   2,0,0,0, 's','n',
00085   4,0,0,0, 1,2,3,4,
00086   4,0,0,0, 5,6,7,8,
00087   0, 0, 0, 0, (char)0x80, (char)0x4f, (char)0x32, (char)0x41,
00088   2,0,0,0
00089   };
00090 
00091   GetChannel().SetData(expectedData);
00092 
00093   CreateSessionRequest request;
00094   GetStream() >> request;
00095 
00096   ASSERT_EQ(request.TypeId.Encoding, EV_FOUR_BYTE);
00097   ASSERT_EQ(request.TypeId.FourByteData.NamespaceIndex, 0);
00098   ASSERT_EQ(request.TypeId.FourByteData.Identifier, OpcUa::CREATE_SESSION_REQUEST);
00099 
00100   ASSERT_REQUEST_HEADER_EQ(request.Header);
00101   ASSERT_APPLICATION_DESCRIPTION_EQ(request.Parameters.ClientDescription);
00102 
00103   ASSERT_EQ(request.Parameters.ServerUri, "su");
00104   ASSERT_EQ(request.Parameters.EndpointUrl, "eu");
00105   ASSERT_EQ(request.Parameters.SessionName, "sn");
00106   ByteString clientNonce = ByteString(std::vector<uint8_t>{1,2,3,4});
00107   ASSERT_EQ(request.Parameters.ClientNonce, clientNonce);
00108   ByteString cert = ByteString(std::vector<uint8_t>{5,6,7,8});
00109   ASSERT_EQ(request.Parameters.ClientCertificate, cert);
00110   ASSERT_EQ(request.Parameters.RequestedSessionTimeout, 1200000);
00111   ASSERT_EQ(request.Parameters.MaxResponseMessageSize, 2);
00112 }
00113 
00114 
00115 //----------------------------------------------------
00116 // CreateSessionResponse
00117 //----------------------------------------------------
00118 
00119 // TEST_F(OpcUaBinarySerialization, CreateSessionResponse)
00120 // {
00121 //
00122 //   using namespace OpcUa;
00123 //   using namespace OpcUa::Binary;
00124 //
00125 //   CreateSessionResponse response;
00126 //
00127 //   ASSERT_EQ(response.TypeId.Encoding, EV_FOUR_BYTE);
00128 //   ASSERT_EQ(response.TypeId.FourByteData.NamespaceIndex, 0);
00129 //   ASSERT_EQ(response.TypeId.FourByteData.Identifier, OpcUa::CREATE_SESSION_RESPONSE);
00130 //
00131 //   FILL_TEST_RESPONSE_HEADER(response.Header);
00132 //
00133 //   response.Parameters.SessionId.Encoding = EV_FOUR_BYTE;
00134 //   response.Parameters.SessionId.FourByteData.NamespaceIndex = 1;
00135 //   response.Parameters.SessionId.FourByteData.Identifier = 2;
00136 //
00137 //   response.Parameters.AuthenticationToken.Encoding = EV_FOUR_BYTE;
00138 //   response.Parameters.AuthenticationToken.FourByteData.NamespaceIndex = 1;
00139 //   response.Parameters.AuthenticationToken.FourByteData.Identifier = 2;
00140 //
00141 //   response.Parameters.RevisedSessionTimeout = 1200000;
00142 //   response.Parameters.ServerNonce = ByteString(std::vector<uint8_t>{1,2,3,4});
00143 //   response.Parameters.ServerCertificate = ByteString(std::vector<uint8_t>{5,6,7,8});
00144 //   EndpointDescription e;
00145 //   FILL_TEST_ENDPOINT(e);
00146 //   response.Parameters.ServerEndpoints.push_back(e);
00147 //   SignedSoftwareCertificate cert;
00148 //   cert.CertificateData = ByteString(std::vector<uint8_t>{4,3,2,1});
00149 //   cert.Signature = ByteString(std::vector<uint8_t>{8,7,6,5});
00150 //   response.Parameters.ServerSoftwareCertificates.push_back(cert);
00151 //   response.Parameters.ServerSignature.Signature = ByteString(std::vector<uint8_t>{7,6,5,4});
00152 //   response.Parameters.ServerSignature.Algorithm = "aes";
00153 //
00154 //   response.Parameters.MaxRequestMessageSize = 0x1000;
00155 //
00156 //   GetStream() << response << flush;
00157 //
00158 //
00159 //   const std::vector<char> expectedData = {
00160 //   1, 0, (char)0xd0, 0x1, // TypeId
00161 //   // ResponseHeader
00162 //   TEST_RESPONSE_HEADER_BINARY_DATA,
00163 //   1,1,2,0,
00164 //   1,1,2,0,
00165 //   0, 0, 0, 0, (char)0x80, (char)0x4f, (char)0x32, (char)0x41,
00166 //   4,0,0,0, 1,2,3,4,
00167 //   4,0,0,0, 5,6,7,8,
00168 //   1,0,0,0,
00169 //   TEST_ENDPOINT_BINARY_DATA,
00170 //   1,0,0,0, 4,0,0,0, 4,3,2,1, 4,0,0,0, 8,7,6,5,
00171 //   4,0,0,0, 7,6,5,4,
00172 //   3,0,0,0, 'a','e','s',
00173 //   0,0x10,0,0
00174 //   };
00175 //
00176 //   ASSERT_EQ(expectedData, GetChannel().SerializedData);
00177 //   ASSERT_EQ(expectedData.size(), RawSize(response));
00178 // }
00179 //
00180 // TEST_F(OpcUaBinaryDeserialization, CreateSessionResponse)
00181 // {
00182 //   using namespace OpcUa;
00183 //   using namespace OpcUa::Binary;
00184 //
00185 //   const std::vector<char> expectedData = {
00186 //   1, 0, (char)0xd0, 0x1, // TypeId
00187 //   // RequestHeader
00188 //   TEST_RESPONSE_HEADER_BINARY_DATA,
00189 //   1,1,2,0,
00190 //   1,1,2,0,
00191 //   0, 0, 0, 0, (char)0x80, (char)0x4f, (char)0x32, (char)0x41,
00192 //   4,0,0,0, 1,2,3,4,
00193 //   4,0,0,0, 5,6,7,8,
00194 //   1,0,0,0,
00195 //   TEST_ENDPOINT_BINARY_DATA,
00196 //   1,0,0,0, 4,0,0,0, 4,3,2,1, 4,0,0,0, 8,7,6,5,
00197 //   4,0,0,0, 7,6,5,4,
00198 //   3,0,0,0, 'a','e','s',
00199 //   0,0x10,0,0
00200 //   };
00201 //
00202 //   GetChannel().SetData(expectedData);
00203 //
00204 //   CreateSessionResponse response;
00205 //   GetStream() >> response;
00206 //
00207 //   ASSERT_EQ(response.TypeId.Encoding, EV_FOUR_BYTE);
00208 //   ASSERT_EQ(response.TypeId.FourByteData.NamespaceIndex, 0);
00209 //   ASSERT_EQ(response.TypeId.FourByteData.Identifier, OpcUa::CREATE_SESSION_RESPONSE);
00210 //
00211 //   ASSERT_RESPONSE_HEADER_EQ(response.Header);
00212 //
00213 //   ASSERT_EQ(response.Parameters.SessionId.Encoding, EV_FOUR_BYTE);
00214 //   ASSERT_EQ(response.Parameters.SessionId.FourByteData.NamespaceIndex, 1);
00215 //   ASSERT_EQ(response.Parameters.SessionId.FourByteData.Identifier, 2);
00216 //
00217 //   ASSERT_EQ(response.Parameters.AuthenticationToken.Encoding, EV_FOUR_BYTE);
00218 //   ASSERT_EQ(response.Parameters.AuthenticationToken.FourByteData.NamespaceIndex, 1);
00219 //   ASSERT_EQ(response.Parameters.AuthenticationToken.FourByteData.Identifier, 2);
00220 //
00221 //   ASSERT_EQ(response.Parameters.RevisedSessionTimeout, 1200000);
00222 //
00223 //   ByteString serverNonce = ByteString(std::vector<uint8_t>{1,2,3,4});
00224 //   ASSERT_EQ(response.Parameters.ServerNonce, serverNonce);
00225 //
00226 //   ByteString serverCert = ByteString(std::vector<uint8_t>{5,6,7,8});
00227 //   ASSERT_EQ(response.Parameters.ServerCertificate, serverCert);
00228 //
00229 //   ASSERT_EQ(response.Parameters.ServerEndpoints.size(), 1);
00230 //   ASSERT_ENDPOINT_EQ(response.Parameters.ServerEndpoints[0]);
00231 //
00232 //   SignedSoftwareCertificate cert;
00233 //   cert.CertificateData = ByteString(std::vector<uint8_t>{4,3,2,1});
00234 //   cert.Signature = ByteString(std::vector<uint8_t>{8,7,6,5});
00235 //   std::vector<SignedSoftwareCertificate> certs = {cert};
00236 // //   ASSERT_EQ(response.Parameters.ServerSoftwareCertificates, certs);
00237 //
00238 //   ByteString signature = ByteString(std::vector<uint8_t>{7,6,5,4});
00239 //   ASSERT_EQ(response.Parameters.ServerSignature.Signature, signature);
00240 //   ASSERT_EQ(response.Parameters.ServerSignature.Algorithm, "aes");
00241 //
00242 //   ASSERT_EQ(response.Parameters.MaxRequestMessageSize, 0x1000);
00243 // }
00244 
00245 //-------------------------------------------------------------------
00246 // ExtensionObjectHeader
00247 //-------------------------------------------------------------------
00248 
00249 TEST_F(OpcUaBinarySerialization, UserIdentifyToken_Anonymous)
00250 {
00251   using namespace OpcUa;
00252   using namespace OpcUa::Binary;
00253 
00254   UserIdentifyToken token;
00255   token.setPolicyId("0");
00256 /*
00257   ASSERT_EQ(token.Header.TypeId.Encoding, EV_FOUR_BYTE);
00258   ASSERT_EQ(token.Header.TypeId.FourByteData.NamespaceIndex, 0);
00259   ASSERT_EQ(token.Hader.TypeId.FourByteData.Identifier, USER_IdENTIFY_TOKEN_ANONYMOUS);
00260   ASSERT_EQ(token.Header.Encoding, HAS_BINARY_BODY);
00261   ASSERT_EQ(token.Anonymous.Data, std::vector{});
00262 */
00263   GetStream() << token << flush;
00264 
00265   const std::vector<char> expectedData = {
00266   1, 0, (char)0x41, 0x1, // TypeId
00267   HAS_BINARY_BODY,
00268   0x5,0,0,0, 1,0,0,0,'0'
00269   };
00270 
00271   ASSERT_EQ(expectedData, GetChannel().SerializedData);
00272   ASSERT_EQ(expectedData.size(), RawSize(token));
00273 }
00274 
00275 TEST_F(OpcUaBinaryDeserialization, UserIdentifyToken_Anonymous)
00276 {
00277   using namespace OpcUa;
00278   using namespace OpcUa::Binary;
00279   const std::vector<char> expectedData = {
00280   1, 0, (char)0x41, 0x1, // TypeId
00281   HAS_BINARY_BODY,
00282   0x5,0,0,0, 1,0,0,0,'0'
00283   };
00284 
00285   GetChannel().SetData(expectedData);
00286 
00287   UserIdentifyToken token;
00288   GetStream() >> token;
00289 
00290   ASSERT_EQ(token.Header.TypeId.Encoding, EV_FOUR_BYTE);
00291   ASSERT_EQ(token.Header.TypeId.FourByteData.NamespaceIndex, 0);
00292   ASSERT_EQ(token.Header.TypeId.FourByteData.Identifier, OpcUa::USER_IdENTIFY_TOKEN_ANONYMOUS);
00293   ASSERT_EQ(token.Header.Encoding, HAS_BINARY_BODY);
00294   std::vector<uint8_t> policy_id = {'0'};
00295   ASSERT_EQ(token.PolicyId, policy_id);
00296 }
00297 
00298 
00299 //-------------------------------------------------------
00300 // ActivateSessionRequest
00301 //-------------------------------------------------------
00302 
00303 // TEST_F(OpcUaBinarySerialization, ActivateSessionRequest)
00304 // {
00305 //
00306 //   using namespace OpcUa;
00307 //   using namespace OpcUa::Binary;
00308 //
00309 //   ActivateSessionRequest request;
00310 //   request.Parameters.UserIdentityToken.setPolicyId("0");
00311 //
00312 //   ASSERT_EQ(request.TypeId.Encoding, EV_FOUR_BYTE);
00313 //   ASSERT_EQ(request.TypeId.FourByteData.NamespaceIndex, 0);
00314 //   ASSERT_EQ(request.TypeId.FourByteData.Identifier, OpcUa::ACTIVATE_SESSION_REQUEST);
00315 //
00316 //   FILL_TEST_REQUEST_HEADER(request.Header);
00317 //
00318 //   ASSERT_EQ(request.Parameters.UserIdentityToken.Header.TypeId.Encoding, EV_FOUR_BYTE);
00319 //   ASSERT_EQ(request.Parameters.UserIdentityToken.Header.TypeId.FourByteData.NamespaceIndex, 0);
00320 //   ASSERT_EQ(request.Parameters.UserIdentityToken.Header.TypeId.FourByteData.Identifier, OpcUa::USER_IdENTIFY_TOKEN_ANONYMOUS);
00321 //   ASSERT_EQ(request.Parameters.UserIdentityToken.Header.Encoding, HAS_BINARY_BODY);
00322 //   std::vector<uint8_t> policy_id = {1,0,0,0,'0'};
00323 //   ASSERT_EQ(request.Parameters.UserIdentityToken.PolicyId, policy_id);
00324 //
00325 //   GetStream() << request << flush;
00326 //
00327 //   const std::vector<char> expectedData = {
00328 //   1, 0, (char)0xd3, 0x1, // TypeId
00329 //   // RequestHeader
00330 //   TEST_REQUEST_HEADER_BINARY_DATA,
00331 //   -1,-1,-1,-1,
00332 //   -1,-1,-1,-1,
00333 //
00334 //   0,0,0,0,
00335 //   0,0,0,0,
00336 //
00337 //   1, 0, (char)0x41, 0x1, // TypeId
00338 //   1,
00339 //   0x5,0,0,0, 1,0,0,0,'0',
00340 //   -1,-1,-1,-1,
00341 //   -1,-1,-1,-1
00342 //   };
00343 //
00344 //   ASSERT_EQ(expectedData, GetChannel().SerializedData) << PrintData(GetChannel().SerializedData) << std::endl << PrintData(expectedData);
00345 //   ASSERT_EQ(expectedData.size(), RawSize(request));
00346 // }
00347 //
00348 // TEST_F(OpcUaBinaryDeserialization, ActivateSessionRequest)
00349 // {
00350 //
00351 //   using namespace OpcUa;
00352 //   using namespace OpcUa::Binary;
00353 //
00354 //   const std::vector<char> expectedData = {
00355 //   1, 0, (char)0xd3, 0x1, // TypeId
00356 //   // RequestHeader
00357 //   TEST_REQUEST_HEADER_BINARY_DATA,
00358 //   -1,-1,-1,-1,
00359 //   -1,-1,-1,-1,
00360 //
00361 //   1,0,0,0, 1,0,0,0, 1,
00362 //   0,0,0,0,
00363 //
00364 //   1, 0, (char)0x41, 0x1, // TypeId
00365 //   1,
00366 //   0x5,0,0,0, 1,0,0,0,'0',
00367 //   -1,-1,-1,-1,
00368 //   -1,-1,-1,-1
00369 //   };
00370 //
00371 //   GetChannel().SetData(expectedData);
00372 //
00373 //   ActivateSessionRequest request;
00374 //   GetStream() >> request;
00375 //
00376 //   ASSERT_EQ(request.TypeId.Encoding, EV_FOUR_BYTE);
00377 //   ASSERT_EQ(request.TypeId.FourByteData.NamespaceIndex, 0);
00378 //   ASSERT_EQ(request.TypeId.FourByteData.Identifier, OpcUa::ACTIVATE_SESSION_REQUEST);
00379 //
00380 //   ASSERT_REQUEST_HEADER_EQ(request.Header);
00381 //
00382 //   ASSERT_EQ(request.Parameters.ClientSoftwareCertificates.size(), 1);
00383 //   ASSERT_EQ(request.Parameters.ClientSoftwareCertificates[0].CertificateData, ByteString(std::vector<uint8_t>{1}));
00384 //
00385 //   ASSERT_EQ(request.Parameters.UserIdentityToken.Header.TypeId.Encoding, EV_FOUR_BYTE);
00386 //   ASSERT_EQ(request.Parameters.UserIdentityToken.Header.TypeId.FourByteData.NamespaceIndex, 0);
00387 //   ASSERT_EQ(request.Parameters.UserIdentityToken.Header.TypeId.FourByteData.Identifier, OpcUa::USER_IdENTIFY_TOKEN_ANONYMOUS);
00388 //   ASSERT_EQ(request.Parameters.UserIdentityToken.Header.Encoding, HAS_BINARY_BODY);
00389 //   std::vector<uint8_t> policy_id = {1,0,0,0,'0'};
00390 //   ASSERT_EQ(request.Parameters.UserIdentityToken.PolicyId, policy_id);
00391 // }
00392 
00393 //-------------------------------------------------------
00394 // ActivateSessionResponse
00395 //-------------------------------------------------------
00396 
00397 // TEST_F(OpcUaBinarySerialization, ActivateSessionResponse)
00398 // {
00399 //
00400 //   using namespace OpcUa;
00401 //   using namespace OpcUa::Binary;
00402 //
00403 //   ActivateSessionResponse response;
00404 //
00405 //   ASSERT_EQ(response.TypeId.Encoding, EV_FOUR_BYTE);
00406 //   ASSERT_EQ(response.TypeId.FourByteData.NamespaceIndex, 0);
00407 //   ASSERT_EQ(response.TypeId.FourByteData.Identifier, OpcUa::ACTIVATE_SESSION_RESPONSE);
00408 //
00409 //   FILL_TEST_RESPONSE_HEADER(response.Header);
00410 //   response.Parameters.ServerNonce = ByteString(std::vector<uint8_t>{1,1});
00411 //   std::vector<StatusCode> results;
00412 //   results.push_back(StatusCode(1));
00413 //   results.push_back(StatusCode(2));
00414 //   response.Parameters.Results = results;
00415 //
00416 //   GetStream() << response << flush;
00417 //
00418 //   const std::vector<char> expectedData = {
00419 //   1, 0, (char)0xd6, 0x1, // TypeId
00420 //   // RequestHeader
00421 //   TEST_RESPONSE_HEADER_BINARY_DATA,
00422 //   1,0,0,0, 1,
00423 //   2,0,0,0, 1,0,0,0, 1,0,0,0,
00424 //   0,0,0,0,
00425 //   };
00426 //
00427 //   ASSERT_EQ(expectedData.size(), RawSize(response));
00428 //   ASSERT_EQ(expectedData, GetChannel().SerializedData) << PrintData(GetChannel().SerializedData) << std::endl << PrintData(expectedData);
00429 // }
00430 //
00431 // TEST_F(OpcUaBinaryDeserialization, ActivateSessionResponse)
00432 // {
00433 //   using namespace OpcUa;
00434 //   using namespace OpcUa::Binary;
00435 //
00436 //   const std::vector<char> expectedData = {
00437 //   1, 0, (char)0xd6, 0x1, // TypeId
00438 //   // RequestHeader
00439 //   TEST_RESPONSE_HEADER_BINARY_DATA,
00440 //   1,0,0,0, 1,
00441 //   2,0,0,0, 1,0,0,0, 1,0,0,0,
00442 //   0,0,0,0,
00443 //   };
00444 //
00445 //   GetChannel().SetData(expectedData);
00446 //
00447 //   ActivateSessionResponse response;
00448 //   GetStream() >> response;
00449 //
00450 //   ASSERT_EQ(response.TypeId.Encoding, EV_FOUR_BYTE);
00451 //   ASSERT_EQ(response.TypeId.FourByteData.NamespaceIndex, 0);
00452 //   ASSERT_EQ(response.TypeId.FourByteData.Identifier, OpcUa::ACTIVATE_SESSION_RESPONSE);
00453 //
00454 //   ASSERT_RESPONSE_HEADER_EQ(response.Header);
00455 //
00456 //   ASSERT_EQ(response.Parameters.ServerNonce, ByteString(std::vector<uint8_t>{1,1}));
00457 //   std::vector<StatusCode> results;
00458 //   results.push_back(StatusCode(1));
00459 //   results.push_back(StatusCode(2));
00460 //   ASSERT_EQ(response.Parameters.Results, results);
00461 //   ASSERT_TRUE(response.Parameters.DiagnosticInfos.empty());
00462 // }
00463 
00464 //-------------------------------------------------------
00465 // CloseSessionRequest
00466 //-------------------------------------------------------
00467 
00468 TEST_F(OpcUaBinarySerialization, CloseSessionRequest)
00469 {
00470 
00471   using namespace OpcUa;
00472   using namespace OpcUa::Binary;
00473 
00474   CloseSessionRequest request;
00475 
00476   ASSERT_EQ(request.TypeId.Encoding, EV_FOUR_BYTE);
00477   ASSERT_EQ(request.TypeId.FourByteData.NamespaceIndex, 0);
00478   ASSERT_EQ(request.TypeId.FourByteData.Identifier, OpcUa::CLOSE_SESSION_REQUEST);
00479 
00480   FILL_TEST_REQUEST_HEADER(request.Header);
00481 
00482   GetStream() << request << flush;
00483 
00484   const std::vector<char> expectedData = {
00485   1, 0, (char)0xd9, 0x1, // TypeId
00486   // RequestHeader
00487   TEST_REQUEST_HEADER_BINARY_DATA,
00488   1
00489   };
00490 
00491   ASSERT_EQ(expectedData, GetChannel().SerializedData) << PrintData(GetChannel().SerializedData) << std::endl << PrintData(expectedData);
00492   ASSERT_EQ(expectedData.size(), RawSize(request));
00493 }
00494 
00495 TEST_F(OpcUaBinaryDeserialization, CloseSessionRequest)
00496 {
00497 
00498   using namespace OpcUa;
00499   using namespace OpcUa::Binary;
00500 
00501   const std::vector<char> expectedData = {
00502   1, 0, (char)0xd9, 0x1, // TypeId
00503   // RequestHeader
00504   TEST_REQUEST_HEADER_BINARY_DATA,
00505   1,
00506   };
00507 
00508   GetChannel().SetData(expectedData);
00509 
00510   CloseSessionRequest request;
00511   GetStream() >> request;
00512 
00513   ASSERT_EQ(request.TypeId.Encoding, EV_FOUR_BYTE);
00514   ASSERT_EQ(request.TypeId.FourByteData.NamespaceIndex, 0);
00515   ASSERT_EQ(request.TypeId.FourByteData.Identifier, OpcUa::CLOSE_SESSION_REQUEST);
00516 
00517   ASSERT_REQUEST_HEADER_EQ(request.Header);
00518 
00519   ASSERT_EQ(request.DeleteSubscriptions, true);
00520 }
00521 
00522 //-------------------------------------------------------
00523 // CloseSessionResponse
00524 //-------------------------------------------------------
00525 
00526 TEST_F(OpcUaBinarySerialization, CloseSessionResponse)
00527 {
00528 
00529   using namespace OpcUa;
00530   using namespace OpcUa::Binary;
00531 
00532   CloseSessionResponse response;
00533 
00534   ASSERT_EQ(response.TypeId.Encoding, EV_FOUR_BYTE);
00535   ASSERT_EQ(response.TypeId.FourByteData.NamespaceIndex, 0);
00536   ASSERT_EQ(response.TypeId.FourByteData.Identifier, OpcUa::CLOSE_SESSION_RESPONSE);
00537 
00538   FILL_TEST_RESPONSE_HEADER(response.Header);
00539 
00540   GetStream() << response << flush;
00541 
00542   const std::vector<char> expectedData = {
00543   1, 0, (char)0xdc, 0x1, // TypeId
00544   // RequestHeader
00545   TEST_RESPONSE_HEADER_BINARY_DATA,
00546   };
00547 
00548   ASSERT_EQ(expectedData.size(), RawSize(response));
00549   ASSERT_EQ(expectedData, GetChannel().SerializedData) << PrintData(GetChannel().SerializedData) << std::endl << PrintData(expectedData);
00550 }
00551 
00552 TEST_F(OpcUaBinaryDeserialization, CloseSessionResponse)
00553 {
00554 
00555   using namespace OpcUa;
00556   using namespace OpcUa::Binary;
00557 
00558   const std::vector<char> expectedData = {
00559   1, 0, (char)0xdc, 0x1, // TypeId
00560   // RequestHeader
00561   TEST_RESPONSE_HEADER_BINARY_DATA,
00562   1,
00563   };
00564 
00565   GetChannel().SetData(expectedData);
00566 
00567   CloseSessionResponse response;
00568   GetStream() >> response;
00569 
00570   ASSERT_EQ(response.TypeId.Encoding, EV_FOUR_BYTE);
00571   ASSERT_EQ(response.TypeId.FourByteData.NamespaceIndex, 0);
00572   ASSERT_EQ(response.TypeId.FourByteData.Identifier, OpcUa::CLOSE_SESSION_RESPONSE);
00573 
00574   ASSERT_RESPONSE_HEADER_EQ(response.Header);
00575 }
00576 
00577 


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