Files
UA-.NETStandard/tests/Opc.Ua.OpenUsd.Tests/UsdaReaderCellTests.cs
Marc Schier da7412c429 Add native xRegistry events and distinct Resource versions (#4396)
## Summary

- support the xRegistry 0.6.0 distinct Resource/Version hierarchy:
  `Registry -> Group -> Resource -> Versions -> Version`
- instantiate stable logical Resource nodes separately from exact
Version nodes
  while preserving existing Version NodeIds
- delegate logical Resource FileType operations and Version-view
metadata to the
selected default Version with handle pinning and shared writer
reservations
- make Resource and Version delete behavior role-stable and use
`MetaEpoch` /
  `Epoch` respectively
- use stable Resource SourceNodes, exact Version SourceNodes and the
  `Server -> Registry -> Group -> Resource -> Version` notifier chain
- keep a model-metadata-gated client fallback for 0.5 flat Servers; 0.6
Servers
  expose no legacy aliases
- target `HasWoTProjection` at the real stable logical Resource node
- use `AsyncCustomNodeManager` for the registration, fast-path, and
federation managers,
  with awaited lifecycle, node mutations, event delivery, and cleanup
- handle startup rollback, reentrant deletion callbacks, undisclosed
file handles,
  and retryable cleanup without blocking unrelated file operations

## Authoritative dependencies

- companion specification: OPCF-Members/spec-drafts#32 at
  `d3399fca025025a73e5a6b599f850a81d985c060`
- OPC UA binding: xregistry/spec#568
- xRegistry event semantics: xregistry/spec#563, merged as
  `66ee31e47fbadff6ab982ae1516f7d9065e46b64`
- companion NodeSet SHA-256:
  `369f5f3f1814b333e4eeb52bfb4b6a730cdff372505a5f91a54c94f0016ac4cf`

## Review feedback

- keep the WoT Connectivity information-model designation at `1.1`;
draft revisions update the publication date without changing the model
version
- eliminate all 198 unique CA1861 diagnostics across 54 files and remove
seven obsolete project suppressions
- fix the analyzer-clean touched-path CA1307 and the hierarchy follow-up
CA1846/CA1851 diagnostics without dropping legacy-TFM compatibility

- recover the reconcile queue after callback faults/cancellation and
continue accepted pending changes
- remove migration guidance for the xRegistry managers, which are new in
2.0

## Compatibility

- public WoT Connectivity model designation remains `1.1`
- generated event-record ABI, constructors, options, NodeIds, and stored
documents remain compatible
- the generic xRegistry managers are new in 2.0 and implement
`IAsyncNodeManager`;
use `IAsyncNodeManagerFactory` and the async lifecycle hooks (see
`docs\XRegistry.md`)
- persistence schema and document blobs remain compatible unless noted
below

## Validation

- merge validation at `980422f76` with upstream `e8bec27d5`: 454
targeted WoT/materialization/model/registry cases and all 327 XRegistry
cases passed on both net10.0 and net48; all 29 net10 aggregation sample
cases passed
- feedback regressions at `308e8ba74`: 55 targeted queue and live
registry event/projection/lifecycle cases passed on each of net10.0 and
net48
- prior CI: all 266 checks passed at `6489a0908`; the unchanged Ubuntu
Core certificate-counter test and dependent jobs passed on the one-time
retry ([run 34117304035, attempt
2](https://github.com/OPCFoundation/UA-.NETStandard/actions/runs/34117304035/attempts/2))
- `Opc.Ua.XRegistry.Tests` — 327 passed on net10.0 and net48 for
migration commit `32c914aaf`
- `Opc.Ua.WotCon.Tests` net10.0 — 1348 passed
- `Opc.Ua.WotCon.Bindings.Tests` net10.0 — 683 passed
- `Opc.Ua.SourceGeneration.Core.Tests` net10.0 — 3807 passed, 8 skipped
- `Opc.Ua.SourceGeneration.Tests` net10.0 — 145 passed
- `Opc.Ua.SourceGeneration.Stack.Tests` net10.0 — 94 passed
- affected XRegistry and WoT client/server projects build successfully
- xRegistry NodeSet is byte-identical to the companion artifact
- repository-wide CA1861 inventory — 198 unique diagnostics across 54
files reduced to zero
- targeted changed-fixture validation — 1,098 passed, 3 skipped, 0
failed
- constrained full `UA.slnx` net10.0 Release build — CA1861 = 0
- `Opc.Ua.XRegistry.Client` net472 and netstandard2.1 builds — 0
warnings, 0 errors
- independent shared-array safety review — no significant issues
- `git diff --check`

The final review regressions cover concurrent reconcile/open, synthetic
logical
handle collisions across default switches, cross-session Close
isolation,
shared writer reservations, logical FileType property/change
propagation,
logical Labels delegation, role-fixed deletion, event sources,
model-version
gating, and stable `HasWoTProjection` targets.

The companion specification and protocol binding are reviewed in the
linked PRs above.

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 5c79a1ed-6dab-4522-a9fc-6548caa78ad5
Copilot-Session: b605797f-a97a-4cd0-8f12-016d33c2fd88
Copilot-Session: 7ef369a5-2307-4f71-8a11-15af0e72f240
Copilot-Session: e716d455-8397-4d22-9c5a-398847ab7317
2026-09-08 04:46:40 +00:00

211 lines
9.3 KiB
C#

/* ========================================================================
* Copyright (c) 2005-2026 The OPC Foundation, Inc. All rights reserved.
*
* OPC Foundation MIT License 1.00
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* The complete license agreement can be found here:
* http://opcfoundation.org/License/MIT/1.00/
* ======================================================================*/
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using Opc.Ua;
using Opc.Ua.OpenUsd.Scene;
namespace Opc.Ua.OpenUsd.Tests
{
[TestFixture]
public class UsdaReaderCellTests
{
private const string R1 = "/Cell/Robots/R1";
private const string R2 = "/Cell/Robots/R2";
private const string R1Flange = "/Cell/Robots/R1/Base/J1/J2/J3/J4/J5/J6/Flange";
private UsdStage _stage = null!;
[OneTimeSetUp]
public void LoadStage()
{
_stage = TestAssets.Load("Cell.usda");
}
[Test]
public void StageMetadata_IsParsed()
{
Assert.That(_stage.DefaultPrim, Is.EqualTo("Cell"));
Assert.That(_stage.UpAxis, Is.EqualTo("Z"));
Assert.That(_stage.MetersPerUnit, Is.EqualTo(1.0));
Assert.That(_stage.RootLayerIdentifier, Is.EqualTo("Cell.usda"));
}
[Test]
public void ComposedPrimCount_MatchesReference()
{
Assert.That(_stage.AllPrims().Count(), Is.EqualTo(53));
}
[Test]
public void CellRoot_HasCustomOverrideAttribute()
{
UsdPrim cell = UsdTestHelpers.RequirePrim(_stage, "/Cell");
UsdAttribute over = UsdTestHelpers.RequireAttribute(cell, "inputs:speedOverride");
Assert.That(over.Custom, Is.True);
Assert.That(over.TypeName, Is.EqualTo("double"));
UsdTestHelpers.AssertInteger(over.Value, 100L);
}
[Test]
public void SafetyBeacon_TokenAndColorValues()
{
UsdPrim beacon = UsdTestHelpers.RequirePrim(_stage, "/Cell/SafetyBeacon");
Assert.That(beacon.TypeName, Is.EqualTo("Sphere"));
UsdAttribute visibility = UsdTestHelpers.RequireAttribute(beacon, "visibility");
Assert.That(visibility.TypeName, Is.EqualTo("token"));
UsdTestHelpers.AssertText(visibility.Value, "invisible");
UsdAttribute color = UsdTestHelpers.RequireAttribute(beacon, "primvars:displayColor");
Assert.That(color.Value.TryGetArray(out ArrayOf<UsdValue> outer), Is.True);
Assert.That(outer.Count, Is.EqualTo(1));
Assert.That(outer[0].TryGetTuple(out ArrayOf<UsdValue> tuple), Is.True);
Assert.That(tuple.ToArray()!.Select(v => v.TryGetInteger(out long integer) ? integer : -1L).ToArray(),
Is.EqualTo(s_longValues1));
}
[Test]
public void KeyLight_NumericAndTupleValues()
{
UsdPrim key = UsdTestHelpers.RequirePrim(_stage, "/Cell/KeyLight");
Assert.That(key.TypeName, Is.EqualTo("DistantLight"));
UsdAttribute intensity = UsdTestHelpers.RequireAttribute(key, "intensity");
Assert.That(intensity.TypeName, Is.EqualTo("float"));
UsdTestHelpers.AssertInteger(intensity.Value, 650L);
UsdAttribute rotate = UsdTestHelpers.RequireAttribute(key, "xformOp:rotateXYZ");
Assert.That(rotate.TypeName, Is.EqualTo("double3"));
Assert.That(rotate.Value.TryGetTuple(out ArrayOf<UsdValue> rotateValues), Is.True);
Assert.That(rotateValues.ToArray()!.Select(v => v.TryGetInteger(out long integer) ? integer : 0L).ToArray(),
Is.EqualTo(new[] { -45L, 0L, 35L }));
}
[TestCase(R1)]
[TestCase(R2)]
public void RobotMount_IsComponentWithReferenceAndInstanceArcs(string mountPath)
{
UsdPrim mount = UsdTestHelpers.RequirePrim(_stage, mountPath);
Assert.That(mount.TypeName, Is.EqualTo("Xform"));
Assert.That(mount.Kind, Is.EqualTo(UsdPrimKindEnum.Component));
Assert.That(mount.Composition, Has.Count.EqualTo(2));
Assert.That(mount.Composition[0].ArcKind, Is.EqualTo(UsdArcKindEnum.Reference));
Assert.That(mount.Composition[0].AssetPath, Is.EqualTo("robot.usda"));
Assert.That(mount.Composition[0].PrimPath, Is.EqualTo("/Robot"));
Assert.That(mount.Composition[0].ListPosition, Is.EqualTo(UsdListOpTypeEnum.Append));
Assert.That(mount.Composition[1].ArcKind, Is.EqualTo(UsdArcKindEnum.Instance));
Assert.That(mount.Composition[1].AssetPath, Is.EqualTo("robot.usda"));
Assert.That(mount.Composition[1].PrimPath, Is.EqualTo("/Robot"));
}
[TestCase(R1)]
[TestCase(R2)]
public void MergedRobotSubtree_IsPresentUnderMount(string mountPath)
{
Assert.That(_stage.Find(mountPath + "/Base"), Is.Not.Null);
Assert.That(_stage.Find(mountPath + "/Warning"), Is.Not.Null);
Assert.That(_stage.Find(mountPath + "/Materials/BaseGreen/Surface"), Is.Not.Null);
Assert.That(_stage.Find(mountPath + "/Base/J1/J2/J3/J4/J5/J6/Flange"), Is.Not.Null);
}
[Test]
public void MergedBase_HasCollectionApiAndRemappedBinding()
{
UsdPrim basePrim = UsdTestHelpers.RequirePrim(_stage, R1 + "/Base");
List<string> schemas = basePrim.ApiSchemas.Select(s => s.SchemaName).ToList();
Assert.That(schemas, Is.EqualTo(s_stringValues1));
UsdApiSchema collection = basePrim.ApiSchemas.First(s => s.SchemaName == "CollectionAPI");
Assert.That(collection.ExpansionRule, Is.EqualTo("expandPrims"));
UsdRelationship binding = UsdTestHelpers.RequireRelationship(basePrim, "material:binding");
Assert.That(binding.Targets, Is.EqualTo(new[] { R1 + "/Materials/BaseGreen" }));
}
[Test]
public void MergedMaterial_ConnectionIsRemappedToMount()
{
UsdPrim green = UsdTestHelpers.RequirePrim(_stage, R1 + "/Materials/BaseGreen");
UsdAttribute surface = UsdTestHelpers.RequireAttribute(green, "outputs:surface");
Assert.That(surface.Connections, Is.EqualTo(new[]
{
R1 + "/Materials/BaseGreen/Surface.outputs:surface",
}));
}
[Test]
public void MergedJoint_RotateAttributeIsLive()
{
UsdPrim j1 = UsdTestHelpers.RequirePrim(_stage, R1 + "/Base/J1");
UsdAttribute rotateZ = UsdTestHelpers.RequireAttribute(j1, "xformOp:rotateZ");
Assert.That(rotateZ.Live, Is.True);
UsdPrim j2 = UsdTestHelpers.RequirePrim(_stage, R1 + "/Base/J1/J2");
UsdAttribute rotateY = UsdTestHelpers.RequireAttribute(j2, "xformOp:rotateY");
Assert.That(rotateY.Live, Is.True);
UsdTestHelpers.AssertInteger(rotateY.Value, -30L);
}
[Test]
public void Tool_IsReferencedOnR1FlangeOnly()
{
UsdPrim tool = UsdTestHelpers.RequirePrim(_stage, R1Flange + "/Tool");
Assert.That(tool.TypeName, Is.EqualTo("Xform"));
Assert.That(tool.Kind, Is.EqualTo(UsdPrimKindEnum.Component));
Assert.That(tool.Composition, Has.Count.EqualTo(1));
Assert.That(tool.Composition[0].ArcKind, Is.EqualTo(UsdArcKindEnum.Reference));
Assert.That(tool.Composition[0].AssetPath, Is.EqualTo("tool.usda"));
Assert.That(tool.Composition[0].PrimPath, Is.EqualTo("/Gripper"));
Assert.That(_stage.Find(R1Flange + "/Tool/Body"), Is.Not.Null);
Assert.That(_stage.Find(R1Flange + "/Tool/JawUpper"), Is.Not.Null);
Assert.That(_stage.Find(R1Flange + "/Tool/JawLower"), Is.Not.Null);
// The tool is only attached to R1, never to R2.
Assert.That(_stage.Find(R2 + "/Base/J1/J2/J3/J4/J5/J6/Flange/Tool"), Is.Null);
}
[Test]
public void Tool_IsNotInstanceable()
{
UsdPrim tool = UsdTestHelpers.RequirePrim(_stage, R1Flange + "/Tool");
Assert.That(tool.Composition.Any(a => a.ArcKind == UsdArcKindEnum.Instance), Is.False);
}
private static readonly long[] s_longValues1 = [1L, 0L, 0L];
private static readonly string[] s_stringValues1 = ["MaterialBindingAPI", "CollectionAPI"];
}
}