Esempio n. 1
0
    Variable Object::CreateVariable(const NodeId& newVariableId, const QualifiedName& browseName, const Variant& value)
    {
      // Creating new node for object
      AddNodesItem newNodeRequest;
      newNodeRequest.BrowseName = browseName;
      newNodeRequest.RequestedNewNodeId = newVariableId;
      newNodeRequest.Class = NodeClass::Variable;
      newNodeRequest.ParentNodeId = GetId();
      newNodeRequest.ReferenceTypeId = ObjectId::HasProperty;
      newNodeRequest.TypeDefinition = NodeId();
      VariableAttributes attrs;
      attrs.Description = LocalizedText(browseName.Name);
      attrs.DisplayName = LocalizedText(browseName.Name);
      attrs.Value = value;
      attrs.Type = OpcUa::VariantTypeToDataType(value.Type());
      newNodeRequest.Attributes = attrs;

      NodeManagementServices::SharedPtr nodes = GetServices()->NodeManagement();
      std::vector<AddNodesResult> newNode = nodes->AddNodes({newNodeRequest});
      if (newNode.size() != 1)
      {
        throw std::runtime_error("opcua_model| Server returned wrong number new nodes results.");
      }

      OpcUa::CheckStatusCode(newNode[0].Status);
      Variable newVariable(GetServices());
      newVariable.Id = newNode[0].AddedNodeId;
      newVariable.BrowseName = browseName;
      newVariable.DisplayName = attrs.Description;
      newVariable.DataType = value.Type();
      newVariable.TypeId = newNodeRequest.TypeDefinition;
      return newVariable;
    }
TEST_F(OpcUaBinaryDeserialization, Variant_QUALIFIED_NAME_DIMENSIONS)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::QUALIFIED_NAME) | HAS_DIMENSIONS_MASK;

  const std::vector<char> expectedData = {
  encodingMask,
  1,0,  4,0,0,0,  'n','a','m','e',
  1,0,0,0,
  1,0,0,0,
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  ASSERT_EQ(var.Type(), VariantType::QUALIFIED_NAME);
  ASSERT_EQ(var.As<QualifiedName>(), QualifiedName(1, "name"));
  ASSERT_FALSE(var.IsNul());
  ASSERT_FALSE(var.IsArray());
  ASSERT_EQ(var.Dimensions.size(), 1);
  ASSERT_EQ(var.Dimensions[0], 1);
}
TEST_F(OpcUaBinaryDeserialization, Variant_GUId_DIMENSIONS)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::GUId) | HAS_DIMENSIONS_MASK;

  const std::vector<char> expectedData = {
  encodingMask,
  4,3,2,1, 6,5, 8,7, 1,2,3,4,5,6,7,8,
  1,0,0,0,
  1,0,0,0,
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  OpcUa::Guid guid = CreateTestGuid();

  ASSERT_EQ(var.Type(), VariantType::GUId);
  ASSERT_EQ(var.As<Guid>(), guid);
  ASSERT_FALSE(var.IsNul());
  ASSERT_FALSE(var.IsArray());
  ASSERT_EQ(var.Dimensions.size(), 1);
  ASSERT_EQ(var.Dimensions[0], 1);
}
TEST_F(OpcUaBinaryDeserialization, Variant_GUId_Array)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::GUId) | HAS_ARRAY_MASK;

  const std::vector<char> expectedData = {
  encodingMask,
  2,0,0,0,
  4,3,2,1, 6,5, 8,7, 1,2,3,4,5,6,7,8,
  4,3,2,1, 6,5, 8,7, 1,2,3,4,5,6,7,8
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  OpcUa::Guid guid = CreateTestGuid();

  ASSERT_EQ(var.Type(), VariantType::GUId);
  std::vector<Guid> vals;
  ASSERT_NO_THROW(vals = var.As<std::vector<Guid>>());
  ASSERT_EQ(vals.size(), 2);
  ASSERT_EQ(vals[0], guid);
  ASSERT_EQ(vals[1], guid);
  ASSERT_FALSE(var.IsNul());
  ASSERT_TRUE(var.IsArray());
  ASSERT_TRUE(var.Dimensions.empty());
}
TEST_F(OpcUaBinaryDeserialization, Variant_BOOLEAN_Array)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::BOOLEAN) | HAS_ARRAY_MASK;

  const std::vector<char> expectedData = {
  encodingMask,
  2,0,0,0,
  1,
  1
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  ASSERT_EQ(var.Type(), VariantType::BOOLEAN);
  std::vector<bool> vals;
  ASSERT_NO_THROW(vals = var.As<std::vector<bool>>());
  ASSERT_EQ(vals.size(), 2);
  ASSERT_EQ(vals[0], true);
  ASSERT_EQ(vals[1], true);
  ASSERT_FALSE(var.IsNul());
  ASSERT_TRUE(var.IsArray());
}
TEST_F(OpcUaBinaryDeserialization, Variant_BOOLEAN_DIMENSIONS)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::BOOLEAN) | HAS_DIMENSIONS_MASK;

  const std::vector<char> expectedData =
  {
    encodingMask,
    1,
    1, 0, 0, 0,
    1, 0, 0, 0,
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  ASSERT_EQ(var.Type(), VariantType::BOOLEAN);
  ASSERT_TRUE(var.As<bool>());
  ASSERT_FALSE(var.IsNul());
  ASSERT_FALSE(var.IsArray());
}
TEST_F(OpcUaBinaryDeserialization, Variant_BYTE_DIMENSIONS)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::BYTE) | HAS_DIMENSIONS_MASK;

  const std::vector<char> expectedData = {
  encodingMask,
  (char)200,
  2,0,0,0,
  2,0,0,0,
  3,0,0,0,
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  ASSERT_EQ(var.Type(), VariantType::BYTE);
  ASSERT_EQ(var.As<uint8_t>(), 200);
  ASSERT_FALSE(var.IsNul());
  ASSERT_FALSE(var.IsArray());
  ASSERT_EQ(var.Dimensions.size(), 2);
  ASSERT_EQ(var.Dimensions[0], 2);
  ASSERT_EQ(var.Dimensions[1], 3);
}
Esempio n. 8
0
ViewfinderImpl::ViewfinderImpl(Handle hSourceDevice, boost::asio::io_service& ioService, std::shared_ptr<LightweightMutex> spMtxLock)
:m_hSourceDevice(hSourceDevice),
m_ioService(ioService),
m_spMtxLock(spMtxLock),
m_evtTimerStopped(true, false) // manual-reset event
{
   // Get the output device for the live view image
   PropertyAccess p(hSourceDevice);

   Variant vDevice = p.Get(kEdsPropID_Evf_OutputDevice);
   ATLASSERT(vDevice.Type() == Variant::typeUInt32);

   unsigned int device = vDevice.Get<unsigned int>();

   // PC live view starts by setting the PC as the output device for the live view image.
   device |= kEdsEvfOutputDevice_PC;

   vDevice.Set(device);

   {
      LightweightMutex::LockType lock(*spMtxLock);
      p.Set(kEdsPropID_Evf_OutputDevice, vDevice);
   }

   // A property change event notification is issued from the camera if property settings are made successfully.
   // Start downloading of the live view image once the property change notification arrives.
}
TEST_F(OpcUaBinaryDeserialization, Variant_NODE_Id_Array)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::NODE_Id) | HAS_ARRAY_MASK;

  const std::vector<char> expectedData = {
  encodingMask,
  2,0,0,0,
  1, 0, (char)0xC1, 0x1,
  1, 0, (char)0xC1, 0x1
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  ASSERT_EQ(var.Type(), VariantType::NODE_Id);
  std::vector<NodeId> vals;
  ASSERT_NO_THROW(vals = var.As<std::vector<NodeId>>());
  ASSERT_EQ(vals.size(), 2);
  ASSERT_EQ(vals[0], OpcUa::FourByteNodeId(449));
  ASSERT_EQ(vals[1], OpcUa::FourByteNodeId(449));
  ASSERT_FALSE(var.IsNul());
  ASSERT_TRUE(var.IsArray());
  ASSERT_TRUE(var.Dimensions.empty());
}
TEST_F(OpcUaBinaryDeserialization, Variant_STRING_Array)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::STRING) | HAS_ARRAY_MASK;

  const std::vector<char> expectedData = {
  encodingMask,
  2,0,0,0,
  4,0,0,0, 'R','o','o','t',
  4,0,0,0, 'R','o','o','t'
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  OpcUa::Guid guid = CreateTestGuid();

  ASSERT_EQ(var.Type(), VariantType::STRING);
  std::vector<std::string> vals;
  ASSERT_NO_THROW(vals = var.As<std::vector<std::string>>());
  ASSERT_EQ(vals.size(), 2);
  ASSERT_EQ(vals[0], std::string("Root"));
  ASSERT_EQ(vals[1], std::string("Root"));
  ASSERT_FALSE(var.IsNul());
  ASSERT_TRUE(var.IsArray());
  ASSERT_TRUE(var.Dimensions.empty());
}
TEST_F(OpcUaBinaryDeserialization, Variant_DOUBLE_Array)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::DOUBLE) | HAS_ARRAY_MASK;

  const std::vector<char> expectedData = {
  encodingMask,
  2,0,0,0,
  0, 0, 0, 0, (char)0x80, (char)0x4f, (char)0x32, (char)0x41, // 1200000
  0, 0, 0, 0, (char)0x80, (char)0x4f, (char)0x32, (char)0x41  // 1200000
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  ASSERT_EQ(var.Type(), VariantType::DOUBLE);
  std::vector<double> vals;
  ASSERT_NO_THROW(vals = var.As<std::vector<double>>());
  ASSERT_EQ(vals.size(), 2);
  ASSERT_EQ(vals[0], 1200000);
  ASSERT_EQ(vals[1], 1200000);
  ASSERT_FALSE(var.IsNul());
  ASSERT_TRUE(var.IsArray());
  ASSERT_TRUE(var.Dimensions.empty());
}
TEST_F(OpcUaBinaryDeserialization, Variant_DOUBLE_DIMENSIONS)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::DOUBLE) | HAS_DIMENSIONS_MASK;

  const std::vector<char> expectedData = {
  encodingMask,
  0, 0, 0, 0, (char)0x80, (char)0x4f, (char)0x32, (char)0x41, // 1200000
  1,0,0,0,
  1,0,0,0,
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  ASSERT_EQ(var.Type(), VariantType::DOUBLE);
  ASSERT_EQ(var.As<double>(), 1200000);
  ASSERT_FALSE(var.IsNul());
  ASSERT_FALSE(var.IsArray());
  ASSERT_EQ(var.Dimensions.size(), 1);
  ASSERT_EQ(var.Dimensions[0], 1);
}
TEST_F(OpcUaBinaryDeserialization, Variant_LOCALIZED_TEXT_DIMENSIONS)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::LOCALIZED_TEXT) | HAS_DIMENSIONS_MASK;

  const std::vector<char> expectedData = {
  encodingMask,
  2, 4,0,0,0,'t','e','x','t',
  1,0,0,0,
  1,0,0,0,
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  ASSERT_EQ(var.Type(), VariantType::LOCALIZED_TEXT);
  ASSERT_EQ(var.As<LocalizedText>(), LocalizedText("text"));
  ASSERT_FALSE(var.IsNul());
  ASSERT_FALSE(var.IsArray());
  ASSERT_EQ(var.Dimensions.size(), 1);
  ASSERT_EQ(var.Dimensions[0], 1);
}
TEST_F(OpcUaBinaryDeserialization, Variant_FLOAT_Array)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::FLOAT) | HAS_ARRAY_MASK;

  const std::vector<char> expectedData = {
  encodingMask,
  2,0,0,0,
  0, 0, (char)0xD0, (char)0xC0, // -6.5
  0, 0, (char)0xD0, (char)0xC0 // -6.5
  //(char)0xC0, (char)0xD0, 0, 0, // -6.5
  //(char)0xC0, (char)0xD0, 0, 0 // -6.5
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  ASSERT_EQ(var.Type(), VariantType::FLOAT);
  std::vector<float> vals;
  ASSERT_NO_THROW(vals = var.As<std::vector<float>>());
  ASSERT_EQ(vals.size(), 2);
  ASSERT_EQ(vals[0], -6.5);
  ASSERT_EQ(vals[1], -6.5);
  ASSERT_FALSE(var.IsNul());
  ASSERT_TRUE(var.IsArray());
  ASSERT_TRUE(var.Dimensions.empty());
}
TEST_F(OpcUaBinaryDeserialization, Variant_DATE_TIME_DIMENSIONS)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::DATE_TIME) | HAS_DIMENSIONS_MASK;

  const std::vector<char> expectedData = {
  encodingMask,
  8, 7, 6, 5, 4, 3, 2, 1,
  1,0,0,0,
  1,0,0,0,
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  ASSERT_EQ(var.Type(), VariantType::DATE_TIME);
  ASSERT_EQ(var.As<DateTime>(), 0x0102030405060708);
  ASSERT_FALSE(var.IsNul());
  ASSERT_FALSE(var.IsArray());
  ASSERT_EQ(var.Dimensions.size(), 1);
  ASSERT_EQ(var.Dimensions[0], 1);
}
TEST_F(OpcUaBinaryDeserialization, Variant_LOCALIZED_TEXT_Array)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::LOCALIZED_TEXT) | HAS_ARRAY_MASK;

  const std::vector<char> expectedData = {
  encodingMask,
  2,0,0,0,
  2, 4,0,0,0,'t','e','x','t',
  2, 4,0,0,0,'t','e','x','t'
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  ASSERT_EQ(var.Type(), VariantType::LOCALIZED_TEXT);
  std::vector<LocalizedText> vals;
  ASSERT_NO_THROW(vals = var.As<std::vector<LocalizedText>>());
  ASSERT_EQ(vals.size(), 2);
  ASSERT_EQ(vals[0], LocalizedText("text"));
  ASSERT_EQ(vals[1], LocalizedText("text"));
  ASSERT_FALSE(var.IsNul());
  ASSERT_TRUE(var.IsArray());
  ASSERT_TRUE(var.Dimensions.empty());
}
TEST_F(OpcUaBinaryDeserialization, Variant_DATE_TIME_Array)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::DATE_TIME) | HAS_ARRAY_MASK;

  const std::vector<char> expectedData = {
  encodingMask,
  2,0,0,0,
  8, 7, 6, 5, 4, 3, 2, 1,
  8, 7, 6, 5, 4, 3, 2, 1
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  ASSERT_EQ(var.Type(), VariantType::DATE_TIME);
  std::vector<DateTime> vals;
  ASSERT_NO_THROW(vals = var.As<std::vector<DateTime>>());
  ASSERT_EQ(vals.size(), 2);
  ASSERT_EQ(vals[0], 0x0102030405060708);
  ASSERT_EQ(vals[1], 0x0102030405060708);
  ASSERT_FALSE(var.IsNul());
  ASSERT_TRUE(var.IsArray());
  ASSERT_TRUE(var.Dimensions.empty());
}
TEST_F(OpcUaBinaryDeserialization, Variant_BYTE_STRING_DIMENSIONS)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::BYTE_STRING) | HAS_DIMENSIONS_MASK;

  const std::vector<char> expectedData = {
  encodingMask,
  2,0,0,0, 1,2,
  1,0,0,0,
  1,0,0,0,
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  OpcUa::Guid guid = CreateTestGuid();

  ASSERT_EQ(var.Type(), VariantType::BYTE_STRING);
  ASSERT_EQ(var.As<ByteString>(), ByteString(std::vector<uint8_t>{1,2}));
  ASSERT_FALSE(var.IsNul());
  ASSERT_FALSE(var.IsArray());
  ASSERT_EQ(var.Dimensions.size(), 1);
  ASSERT_EQ(var.Dimensions[0], 1);
}
TEST_F(OpcUaBinaryDeserialization, Variant_BYTE_STRING_Array)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::BYTE_STRING) | HAS_ARRAY_MASK;

  const std::vector<char> expectedData = {
  encodingMask,
  2,0,0,0,
  2,0,0,0, 1,2,
  2,0,0,0, 1,2
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  ASSERT_EQ(var.Type(), VariantType::BYTE_STRING);
  std::vector<ByteString> vals;
  ASSERT_NO_THROW(vals = var.As<std::vector<ByteString>>());
  ASSERT_EQ(vals.size(), 2);
  ASSERT_EQ(vals[0], ByteString(std::vector<uint8_t>{1,2}));
  ASSERT_EQ(vals[1], ByteString(std::vector<uint8_t>{1,2}));
  ASSERT_FALSE(var.IsNul());
  ASSERT_TRUE(var.IsArray());
  ASSERT_TRUE(var.Dimensions.empty());
}
TEST_F(OpcUaBinaryDeserialization, Variant_UINT64_Array)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::UINT64) | HAS_ARRAY_MASK;

  const std::vector<char> expectedData = {
  encodingMask,
  2,0,0,0,
  0x00,0x20,0,0, 0,0,0,0, // 0x2000
  0x00,0x20,0,0, 0,0,0,0 // 0x2000
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  ASSERT_EQ(var.Type(), VariantType::UINT64);
  std::vector<uint64_t> vals;
  ASSERT_NO_THROW(vals = var.As<std::vector<uint64_t>>());
  ASSERT_EQ(vals.size(), 2);
  ASSERT_EQ(vals[0], 8192);
  ASSERT_EQ(vals[1], 8192);
  ASSERT_FALSE(var.IsNul());
  ASSERT_TRUE(var.IsArray());
  ASSERT_TRUE(var.Dimensions.empty());
}
TEST_F(OpcUaBinaryDeserialization, Variant_QUALIFIED_NAME_Array)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::QUALIFIED_NAME) | HAS_ARRAY_MASK;

  const std::vector<char> expectedData = {
  encodingMask,
  2,0,0,0,
  1,0,  4,0,0,0,  'n','a','m','e',
  1,0,  4,0,0,0,  'n','a','m','e'
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  ASSERT_EQ(var.Type(), VariantType::QUALIFIED_NAME);
  std::vector<QualifiedName> vals;
  ASSERT_NO_THROW(vals = var.As<std::vector<QualifiedName>>());
  ASSERT_EQ(vals.size(), 2);
  ASSERT_EQ(vals[0], QualifiedName(1, "name"));
  ASSERT_EQ(vals[1], QualifiedName(1, "name"));
  ASSERT_FALSE(var.IsNul());
  ASSERT_TRUE(var.IsArray());
  ASSERT_TRUE(var.Dimensions.empty());
}
TEST_F(OpcUaBinaryDeserialization, Variant_UINT64_DIMENSIONS)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::UINT64) | HAS_DIMENSIONS_MASK;

  const std::vector<char> expectedData = {
  encodingMask,
  0x00,0x20,0,0, 0,0,0,0, // 0x2000
  1,0,0,0,
  1,0,0,0,
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  ASSERT_EQ(var.Type(), VariantType::UINT64);
  ASSERT_EQ(var.As<uint64_t>(), 8192);
  ASSERT_FALSE(var.IsNul());
  ASSERT_FALSE(var.IsArray());
  ASSERT_EQ(var.Dimensions.size(), 1);
  ASSERT_EQ(var.Dimensions[0], 1);
}
///-----------------------------------------------------------------------------
TEST_F(OpcUaBinaryDeserialization, Variant_FLOAT)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<char>(VariantType::FLOAT);

  const std::vector<char> expectedData =
  {
    encodingMask,
    //(char)0xC0, (char)0xD0, 0, 0 // -6.5
    0, 0, (char)0xD0, (char)0xC0 // -6.5
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  ASSERT_EQ(var.Type(), VariantType::FLOAT);
  ASSERT_EQ(var.As<float>(), -6.5);
  ASSERT_FALSE(var.IsNul());
  ASSERT_FALSE(var.IsArray());
  ASSERT_TRUE(var.Dimensions.empty());
}
TEST_F(OpcUaBinaryDeserialization, Variant_FLOAT_DIMENSIONS)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::FLOAT) | HAS_DIMENSIONS_MASK;

  const std::vector<char> expectedData = {
  encodingMask,
  0, 0, (char)0xD0, (char)0xC0, // -6.5
  //(char)0xC0, (char)0xD0, 0, 0, // -6.5
  1,0,0,0,
  1,0,0,0,
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  ASSERT_EQ(var.Type(), VariantType::FLOAT);
  ASSERT_EQ(var.As<float>(), -6.5);
  ASSERT_FALSE(var.IsNul());
  ASSERT_FALSE(var.IsArray());
  ASSERT_EQ(var.Dimensions.size(), 1);
  ASSERT_EQ(var.Dimensions[0], 1);
}
TEST_F(OpcUaBinaryDeserialization, Variant_NODE_Id_DIMENSIONS)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<uint8_t>(VariantType::NODE_Id) | HAS_DIMENSIONS_MASK;

  const std::vector<char> expectedData = {
  encodingMask,
  1, 0, (char)0xC1, 0x1,
  1,0,0,0,
  1,0,0,0,
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  ASSERT_EQ(var.Type(), VariantType::NODE_Id);
  ASSERT_EQ(var.As<NodeId>(), OpcUa::FourByteNodeId(449));
  ASSERT_FALSE(var.IsNul());
  ASSERT_FALSE(var.IsArray());
  ASSERT_EQ(var.Dimensions.size(), 1);
  ASSERT_EQ(var.Dimensions[0], 1);
}
Esempio n. 26
0
unsigned int GetUnsignedIntValue(const Variant& value)
{
   unsigned int uiValue = 0;

   if (value.Type() == Variant::typeUInt8)
      uiValue = value.Get<unsigned char>();
   else
   if (value.Type() == Variant::typeUInt16)
      uiValue = value.Get<unsigned short>();
   else
   if (value.Type() == Variant::typeUInt32)
      uiValue = value.Get<unsigned int>();
   else
   if (value.Type() == Variant::typeInt32)
      uiValue = static_cast<unsigned int>(value.Get<int>());
   else
   if (value.Type() == Variant::typeInvalid)
      uiValue = 0;
   else
      ATLASSERT(false);

   return uiValue;
}
Esempio n. 27
0
void ViewfinderImpl::Close()
{
   // clear live view flag in property
   PropertyAccess p(m_hSourceDevice);

   Variant vDevice = p.Get(kEdsPropID_Evf_OutputDevice);
   ATLASSERT(vDevice.Type() == Variant::typeUInt32);

   unsigned int device = vDevice.Get<unsigned int>();
   device &= ~kEdsEvfOutputDevice_PC;

   vDevice.Set(device);

   p.Set(kEdsPropID_Evf_OutputDevice, vDevice);
}
TEST_F(OpcUaBinaryDeserialization, Variant_NUL)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  const std::vector<char> expectedData = {
  0
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  ASSERT_EQ(var.Type(), VariantType::NUL);
  ASSERT_TRUE(var.IsNul());
  ASSERT_FALSE(var.IsArray());
}
///-----------------------------------------------------------------------------
TEST_F(OpcUaBinaryDeserialization, Variant_SBYTE)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<char>(VariantType::SBYTE);

  const std::vector<char> expectedData = {
    encodingMask,
    (char)-5
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  ASSERT_EQ(var.Type(), VariantType::SBYTE);
  ASSERT_EQ(var.As<int8_t>(), -5);
  ASSERT_FALSE(var.IsNul());
  ASSERT_FALSE(var.IsArray());
}
///-----------------------------------------------------------------------------
TEST_F(OpcUaBinaryDeserialization, Variant_DOUBLE)
{
  using namespace OpcUa;
  using namespace OpcUa::Binary;

  char encodingMask = static_cast<char>(VariantType::DOUBLE);

  const std::vector<char> expectedData = {
    encodingMask,
    0, 0, 0, 0, (char)0x80, (char)0x4f, (char)0x32, (char)0x41 // 1200000
  };

  GetChannel().SetData(expectedData);

  Variant var;
  GetStream() >> var;

  ASSERT_EQ(var.Type(), VariantType::DOUBLE);
  ASSERT_EQ(var.As<double>(), 1200000);
  ASSERT_FALSE(var.IsNul());
  ASSERT_FALSE(var.IsArray());
  ASSERT_TRUE(var.Dimensions.empty());
}