11 #ifndef __OPC_UA_TESTS_COMMON_H__ 12 #define __OPC_UA_TESTS_COMMON_H__ 15 #include <gtest/gtest.h> 31 std::stringstream stream;
33 for (std::size_t i = 0; i < vec.size(); ++i)
35 stream <<
"0x" << std::setfill(
'0') << std::setw(2) <<
std::hex << ((int)vec[i] & 0xff) <<
' ';
42 if ((i + 1) % 32 == 0)
53 if (
const char * host = getenv(
"OPCUA_HOST"))
63 if (
char * port = getenv(
"OPCUA_PORT"))
73 if (
char * endpoint = getenv(
"OPCUA_ENDPOINT"))
78 return "opc.tcp://localhost:4841";
84 virtual void Send(
const char * data, std::size_t size)
143 virtual std::size_t
Receive(
char * data, std::size_t size)
150 const std::size_t dist =
static_cast<std::size_t
>(std::distance(CurPos,
SerializedData.end()));
151 const std::size_t minSize = std::min(size, dist);
152 std::copy(CurPos, CurPos + minSize, data);
212 #define TEST_RESPONSE_HEADER_BINARY_DATA \ 216 static_cast<DiagnosticInfoMask>(DIM_LOCALIZED_TEXT | DIM_INNER_DIAGNOSTIC_INFO), 4,0,0,0, \ 217 DIM_ADDITIONAL_INFO, 3, 0, 0, 0, 'a', 'd', 'd', \ 218 2,0,0,0, 3,0,0,0, 's','t','r', 3,0,0,0, 's','t','r', \ 222 #define FILL_TEST_RESPONSE_HEADER(header) \ 223 header.Timestamp.Value = 1; \ 224 header.RequestHandle = 2; \ 225 header.ServiceResult = static_cast<StatusCode>(3); \ 226 header.InnerDiagnostics.EncodingMask = static_cast<DiagnosticInfoMask>(DIM_LOCALIZED_TEXT | DIM_INNER_DIAGNOSTIC_INFO); \ 227 header.InnerDiagnostics.LocalizedText = 4; \ 228 header.InnerDiagnostics.InnerDiagnostics.reset(new DiagnosticInfo()); \ 229 header.InnerDiagnostics.InnerDiagnostics->EncodingMask = DIM_ADDITIONAL_INFO; \ 230 header.InnerDiagnostics.InnerDiagnostics->AdditionalInfo = "add"; \ 231 header.StringTable = std::vector<std::string>(2, std::string("str")); \ 232 header.Additional.TypeId.Encoding = EV_TWO_BYTE; \ 233 header.Additional.TypeId.TwoByteData.Identifier = 7; \ 234 header.Additional.Encoding = 8; 236 #define ASSERT_RESPONSE_HEADER_EQ(header) \ 237 ASSERT_EQ(header.Timestamp.Value, 1); \ 238 ASSERT_EQ(header.RequestHandle, 2); \ 239 ASSERT_EQ(header.ServiceResult, static_cast<StatusCode>(3)); \ 240 ASSERT_EQ(header.InnerDiagnostics.EncodingMask, static_cast<DiagnosticInfoMask>(DIM_LOCALIZED_TEXT | DIM_INNER_DIAGNOSTIC_INFO)); \ 241 ASSERT_EQ(header.InnerDiagnostics.LocalizedText, 4); \ 242 ASSERT_TRUE(static_cast<bool>(header.InnerDiagnostics.InnerDiagnostics)); \ 243 ASSERT_EQ(header.InnerDiagnostics.InnerDiagnostics->EncodingMask, DIM_ADDITIONAL_INFO); \ 244 ASSERT_EQ(header.InnerDiagnostics.InnerDiagnostics->AdditionalInfo, "add"); \ 245 ASSERT_EQ(header.StringTable, std::vector<std::string>(2, std::string("str"))); \ 246 ASSERT_EQ(header.Additional.TypeId.Encoding, EV_TWO_BYTE); \ 247 ASSERT_EQ(header.Additional.TypeId.TwoByteData.Identifier, 7); \ 248 ASSERT_EQ(header.Additional.Encoding, 8); 251 #define TEST_REQUEST_HEADER_BINARY_DATA \ 253 2, 0, 0, 0, 0, 0, 0, 0, \ 257 'a', 'u', 'd', 'i', 't', \ 263 #define FILL_TEST_REQUEST_HEADER(header) \ 264 header.SessionAuthenticationToken.Encoding = EV_TWO_BYTE; \ 265 header.SessionAuthenticationToken.TwoByteData.Identifier = 1; \ 266 header.UtcTime.Value = 2; \ 267 header.RequestHandle = 3; \ 268 header.ReturnDiagnostics = 4; \ 269 header.AuditEntryId = "audit"; \ 270 header.Timeout = 5; \ 271 header.Additional.TypeId.Encoding = EV_TWO_BYTE; \ 272 header.Additional.TypeId.TwoByteData.Identifier = 6; \ 273 header.Additional.Encoding = 8; 275 #define ASSERT_REQUEST_HEADER_EQ(header) \ 276 ASSERT_EQ(header.SessionAuthenticationToken.Encoding, EV_TWO_BYTE); \ 277 ASSERT_EQ(header.SessionAuthenticationToken.TwoByteData.Identifier, 1); \ 278 ASSERT_EQ(header.UtcTime.Value, 2); \ 279 ASSERT_EQ(header.RequestHandle, 3); \ 280 ASSERT_EQ(header.ReturnDiagnostics, 4); \ 281 ASSERT_EQ(header.AuditEntryId, "audit"); \ 282 ASSERT_EQ(header.Timeout, 5); \ 283 ASSERT_EQ(header.Additional.TypeId.Encoding, EV_TWO_BYTE); \ 284 ASSERT_EQ(header.Additional.TypeId.TwoByteData.Identifier, 6); \ 285 ASSERT_EQ(header.Additional.Encoding, 8); 288 #define FILL_APPLICATION_DESCRIPTION(desc) \ 289 desc.ApplicationUri = "u"; \ 290 desc.ProductUri = "pu"; \ 291 desc.ApplicationName.Encoding = HAS_LOCALE | HAS_TEXT; \ 292 desc.ApplicationName.Locale = "RU"; \ 293 desc.ApplicationName.Text = "text"; \ 294 desc.ApplicationType = ApplicationType::Client; \ 295 desc.GatewayServerUri = "gw"; \ 296 desc.DiscoveryProfileUri = "dpu"; \ 297 desc.DiscoveryUrls.push_back("du"); 299 #define TEST_APPLICATION_DESCRIPTION_BINARY_DATA \ 304 4,0,0,0, 't','e','x','t', \ 307 3,0,0,0, 'd','p','u', \ 308 1,0,0,0, 2,0,0,0, 'd','u' 310 #define ASSERT_APPLICATION_DESCRIPTION_EQ(desc) \ 311 ASSERT_EQ(desc.ApplicationUri, "u"); \ 312 ASSERT_EQ(desc.ProductUri, "pu"); \ 313 ASSERT_EQ(desc.ApplicationName.Encoding, HAS_LOCALE | HAS_TEXT); \ 314 ASSERT_EQ(desc.ApplicationName.Locale, "RU"); \ 315 ASSERT_EQ(desc.ApplicationName.Text, "text"); \ 316 ASSERT_EQ(desc.ApplicationType, ApplicationType::Client); \ 317 ASSERT_EQ(desc.GatewayServerUri, "gw"); \ 318 ASSERT_EQ(desc.DiscoveryProfileUri, "dpu"); \ 319 ASSERT_EQ(desc.DiscoveryUrls, std::vector<std::string>(1,"du")); 321 #define FILL_TEST_ENDPOINT(endpoint) \ 322 endpoint.EndpointUrl = "eu"; \ 323 FILL_APPLICATION_DESCRIPTION(endpoint.Server); \ 324 endpoint.ServerCertificate = ByteString(std::vector<uint8_t>{1,2,3,4}); \ 325 endpoint.SecurityMode = MessageSecurityMode::None; \ 326 endpoint.SecurityPolicyUri = "spu"; \ 327 UserTokenPolicy token; \ 328 token.PolicyId = "pi"; \ 329 token.TokenType = UserTokenType::UserName; \ 330 token.IssuedTokenType = "itt"; \ 331 token.IssuerEndpointUrl = "ieu"; \ 332 token.SecurityPolicyUri = "spu"; \ 333 endpoint.UserIdentityTokens.push_back(token); \ 334 endpoint.TransportProfileUri = "tpu"; \ 335 endpoint.SecurityLevel = 3; 337 #define TEST_ENDPOINT_BINARY_DATA \ 339 TEST_APPLICATION_DESCRIPTION_BINARY_DATA, \ 342 3,0,0,0, 's','p','u', \ 346 3,0,0,0, 'i','t','t', \ 347 3,0,0,0, 'i','e','u', \ 348 3,0,0,0, 's','p','u', \ 349 3,0,0,0, 't','p','u', \ 352 #define ASSERT_ENDPOINT_EQ(e) \ 353 ASSERT_EQ(e.EndpointUrl, "eu"); \ 354 ASSERT_APPLICATION_DESCRIPTION_EQ(e.Server); \ 355 const ByteString certificate = ByteString(std::vector<uint8_t>{1,2,3,4}); \ 356 ASSERT_EQ(e.ServerCertificate, certificate); \ 357 ASSERT_EQ(e.SecurityMode, MessageSecurityMode::None); \ 358 ASSERT_EQ(e.SecurityPolicyUri, "spu"); \ 359 ASSERT_EQ(e.UserIdentityTokens.size(), 1); \ 360 ASSERT_EQ(e.UserIdentityTokens[0].PolicyId, "pi"); \ 361 ASSERT_EQ(e.UserIdentityTokens[0].TokenType, UserTokenType::UserName); \ 362 ASSERT_EQ(e.UserIdentityTokens[0].IssuedTokenType, "itt"); \ 363 ASSERT_EQ(e.UserIdentityTokens[0].IssuerEndpointUrl, "ieu"); \ 364 ASSERT_EQ(e.UserIdentityTokens[0].SecurityPolicyUri, "spu"); \ 365 ASSERT_EQ(e.TransportProfileUri, "tpu"); \ 366 ASSERT_EQ(e.SecurityLevel, 3); 368 #endif // __OPC_UA_TESTS_COMMON_H__
IntFormatSpec< int, TypeSpec<'x'> > hex(int value)
std::string PrintData(const std::vector< char > &vec)
Test of opc ua binary handshake. GNU LGPL.
OpcUaBinarySerialization()
OpcUa::Binary::IStream< InputChannel > BinaryIStream
InputChannel & GetChannel()
virtual void Send(const char *data, std::size_t size)
std::unique_ptr< BinaryOStream > Stream
OpcUa::Binary::OStream< OutputChannel > BinaryOStream
BinaryIStream & GetStream()
std::shared_ptr< OutputChannel > Channel
OutputChannel & GetChannel()
BinaryOStream & GetStream()
std::shared_ptr< InputChannel > Channel
std::vector< char > SerializedData
std::string GetEndpoint()
std::unique_ptr< BinaryIStream > Stream
OpcUaBinaryDeserialization()