mirror of
https://github.com/OPCFoundation/UA-.NETStandard.git
synced 2026-10-16 21:02:51 +08:00
da7412c429
## 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
401 lines
15 KiB
C#
401 lines
15 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.OpenUsd.Scene.Conversion;
|
|
using Opc.Ua.OpenUsd.Scene;
|
|
|
|
namespace Opc.Ua.OpenUsd.Tests
|
|
{
|
|
/// <summary>
|
|
/// Tests for USD time-sample support in the conversion layer (spec §7.1 step 3, §7.2, §9):
|
|
/// the reader parses a <c>.timeSamples = { … }</c> block into an ordered map kept separate
|
|
/// from the authored default, the writer re-emits it, and the §7.4 signature preserves it.
|
|
/// </summary>
|
|
[TestFixture]
|
|
public class UsdTimeSampleTests
|
|
{
|
|
private static string Wrap(params string[] bodyLines)
|
|
{
|
|
var lines = new List<string>
|
|
{
|
|
"#usda 1.0",
|
|
"(",
|
|
" defaultPrim = \"P\"",
|
|
" metersPerUnit = 1.0",
|
|
" upAxis = \"Z\"",
|
|
")",
|
|
string.Empty,
|
|
"def Xform \"P\"",
|
|
"{",
|
|
};
|
|
lines.AddRange(bodyLines);
|
|
lines.Add("}");
|
|
lines.Add(string.Empty);
|
|
return string.Join("\n", lines);
|
|
}
|
|
|
|
private static UsdAttribute ParseSingleAttribute(string stageName, params string[] bodyLines)
|
|
{
|
|
UsdStage stage = UsdaReader.Parse(Wrap(bodyLines), stageName);
|
|
UsdPrim prim = stage.Find("/P")!;
|
|
return prim.Attributes[0];
|
|
}
|
|
|
|
private static void AssertRoundTripSignature(UsdStage expected)
|
|
{
|
|
string written = UsdaWriter.Write(expected);
|
|
UsdStage reparsed = UsdaReader.Parse(written, expected.StageName);
|
|
|
|
string? difference = UsdSceneSignature.FirstDifference(expected, reparsed);
|
|
Assert.That(
|
|
UsdSceneSignature.Compute(reparsed),
|
|
Is.EqualTo(UsdSceneSignature.Compute(expected)),
|
|
difference ?? "signatures are unexpectedly equal");
|
|
}
|
|
|
|
// ---- parsing ------------------------------------------------------------------
|
|
|
|
[Test]
|
|
public void MultiLineBlock_ParsesScalarSamples_SeparateFromDefault()
|
|
{
|
|
UsdAttribute attr = ParseSingleAttribute(
|
|
"TS",
|
|
" double xformOp:rotateZ.timeSamples = {",
|
|
" 0: 0.0,",
|
|
" 24: 90.0,",
|
|
" 48: 180.0,",
|
|
" }");
|
|
|
|
Assert.That(attr.Value.IsNull, Is.True, "no authored default was declared");
|
|
Assert.That(attr.TimeSamples.Keys, Is.EqualTo(s_doubleValues1));
|
|
Assert.That(attr.TimeSamples.Values, Is.EqualTo(new[]
|
|
{
|
|
UsdValue.From(0.0),
|
|
UsdValue.From(90.0),
|
|
UsdValue.From(180.0)
|
|
}));
|
|
}
|
|
|
|
[Test]
|
|
public void SingleLineBlock_ParsesSamples()
|
|
{
|
|
UsdAttribute attr = ParseSingleAttribute(
|
|
"TS",
|
|
" double a.timeSamples = { 0: 0.0, 24: 90.0 }");
|
|
|
|
Assert.That(attr.TimeSamples.Keys, Is.EqualTo(s_doubleValues2));
|
|
Assert.That(attr.TimeSamples.Values, Is.EqualTo(new[] { UsdValue.From(0.0), UsdValue.From(90.0) }));
|
|
}
|
|
|
|
[Test]
|
|
public void NegativeAndFractionalTimeCodes_AreParsed()
|
|
{
|
|
UsdAttribute attr = ParseSingleAttribute(
|
|
"TS",
|
|
" double a.timeSamples = {",
|
|
" -12: -1.0,",
|
|
" 0.5: 5.0,",
|
|
" 2.25: 7.5,",
|
|
" }");
|
|
|
|
Assert.That(attr.TimeSamples.Keys, Is.EqualTo(new[] { -12.0, 0.5, 2.25 }));
|
|
UsdTestHelpers.AssertDouble(attr.TimeSamples[-12.0], -1.0);
|
|
UsdTestHelpers.AssertDouble(attr.TimeSamples[0.5], 5.0);
|
|
}
|
|
|
|
[Test]
|
|
public void SamplesAreOrderedByTimeCode_EvenWhenAuthoredOutOfOrder()
|
|
{
|
|
UsdAttribute attr = ParseSingleAttribute(
|
|
"TS",
|
|
" double a.timeSamples = {",
|
|
" 48: 180.0,",
|
|
" 0: 0.0,",
|
|
" 24: 90.0,",
|
|
" }");
|
|
|
|
Assert.That(attr.TimeSamples.Keys, Is.EqualTo(s_doubleValues1));
|
|
}
|
|
|
|
[Test]
|
|
public void TupleValuedSamples_AreParsed()
|
|
{
|
|
UsdAttribute attr = ParseSingleAttribute(
|
|
"TS",
|
|
" float3 xformOp:translate.timeSamples = {",
|
|
" 0: (0, 0, 0),",
|
|
" 24: (1, 2, 3),",
|
|
" }");
|
|
|
|
UsdTestHelpers.AssertIntegerItems(attr.TimeSamples[0.0], 0L, 0L, 0L);
|
|
UsdTestHelpers.AssertIntegerItems(attr.TimeSamples[24.0], 1L, 2L, 3L);
|
|
}
|
|
|
|
[Test]
|
|
public void ArrayValuedSamples_AreParsed()
|
|
{
|
|
UsdAttribute attr = ParseSingleAttribute(
|
|
"TS",
|
|
" int[] a.timeSamples = {",
|
|
" 0: [1, 2, 3],",
|
|
" 24: [4, 5, 6],",
|
|
" }");
|
|
|
|
UsdTestHelpers.AssertIntegerItems(attr.TimeSamples[0.0], 1L, 2L, 3L);
|
|
UsdTestHelpers.AssertIntegerItems(attr.TimeSamples[24.0], 4L, 5L, 6L);
|
|
}
|
|
|
|
[Test]
|
|
public void AssetValuedSamples_AreUnwrapped()
|
|
{
|
|
UsdAttribute attr = ParseSingleAttribute(
|
|
"TS",
|
|
" asset a.timeSamples = {",
|
|
" 0: @./a.usda@,",
|
|
" 24: @./b.usda@,",
|
|
" }");
|
|
|
|
UsdTestHelpers.AssertAssetPath(attr.TimeSamples[0.0], "./a.usda");
|
|
UsdTestHelpers.AssertAssetPath(attr.TimeSamples[24.0], "./b.usda");
|
|
}
|
|
|
|
[Test]
|
|
public void TokenValuedSamples_AreUnwrapped()
|
|
{
|
|
UsdAttribute attr = ParseSingleAttribute(
|
|
"TS",
|
|
" token door:state.timeSamples = {",
|
|
" 0: \"open\",",
|
|
" 24: \"closed\",",
|
|
" }");
|
|
|
|
UsdTestHelpers.AssertString(attr.TimeSamples[0.0], "open");
|
|
UsdTestHelpers.AssertString(attr.TimeSamples[24.0], "closed");
|
|
}
|
|
|
|
[Test]
|
|
public void DefaultAndSamples_CoexistOnOneAttribute()
|
|
{
|
|
UsdAttribute attr = ParseSingleAttribute(
|
|
"TS",
|
|
" double a = 5.0",
|
|
" double a.timeSamples = {",
|
|
" 0: 0.0,",
|
|
" 24: 90.0,",
|
|
" }");
|
|
|
|
UsdTestHelpers.AssertDouble(attr.Value, 5.0);
|
|
Assert.That(attr.TimeSamples.Keys, Is.EqualTo(s_doubleValues2));
|
|
}
|
|
|
|
[Test]
|
|
public void SamplesOnlyAttribute_HasNoBareDefaultDeclaration()
|
|
{
|
|
// An attribute declared only through its .timeSamples must not also gain a spurious
|
|
// valueless declaration that would re-parse to a second attribute.
|
|
UsdStage stage = UsdaReader.Parse(
|
|
Wrap(
|
|
" double a.timeSamples = {",
|
|
" 0: 0.0,",
|
|
" }"),
|
|
"TS");
|
|
|
|
UsdPrim prim = stage.Find("/P")!;
|
|
Assert.That(prim.Attributes.Count(a => a.Name == "a"), Is.EqualTo(1));
|
|
}
|
|
|
|
// ---- round-trip ---------------------------------------------------------------
|
|
|
|
[Test]
|
|
public void ScalarSamples_RoundTripThroughWriteAndReparse()
|
|
{
|
|
UsdStage stage = UsdaReader.Parse(
|
|
Wrap(
|
|
" double xformOp:rotateZ.timeSamples = {",
|
|
" 0: 0.0,",
|
|
" 24: 90.0,",
|
|
" 48: 180.0,",
|
|
" }"),
|
|
"TS");
|
|
|
|
AssertRoundTripSignature(stage);
|
|
}
|
|
|
|
[Test]
|
|
public void DefaultPlusSamples_RoundTripThroughWriteAndReparse()
|
|
{
|
|
UsdStage stage = UsdaReader.Parse(
|
|
Wrap(
|
|
" double a = 5.0",
|
|
" double a.timeSamples = {",
|
|
" -6: -1.0,",
|
|
" 0.5: 0.0,",
|
|
" 24: 90.0,",
|
|
" }"),
|
|
"TS");
|
|
|
|
AssertRoundTripSignature(stage);
|
|
}
|
|
|
|
[TestCase("float3 xformOp:translate", "(0, 0, 0)", "(1, 2, 3)")]
|
|
[TestCase("int[] a", "[1, 2, 3]", "[4, 5, 6]")]
|
|
[TestCase("asset a", "@./a.usda@", "@./b.usda@")]
|
|
[TestCase("token a", "\"open\"", "\"closed\"")]
|
|
public void TypedSamples_RoundTripThroughWriteAndReparse(string decl, string v0, string v24)
|
|
{
|
|
UsdStage stage = UsdaReader.Parse(
|
|
Wrap(
|
|
" " + decl + ".timeSamples = {",
|
|
" 0: " + v0 + ",",
|
|
" 24: " + v24 + ",",
|
|
" }"),
|
|
"TS");
|
|
|
|
AssertRoundTripSignature(stage);
|
|
}
|
|
|
|
[Test]
|
|
public void WriterOutputIsAFixedPoint_ForTimeSamples()
|
|
{
|
|
UsdStage stage = UsdaReader.Parse(
|
|
Wrap(
|
|
" double a = 5.0",
|
|
" double a.timeSamples = {",
|
|
" 0: 0.0,",
|
|
" 24: 90.0,",
|
|
" }"),
|
|
"TS");
|
|
|
|
string firstWrite = UsdaWriter.Write(stage);
|
|
string secondWrite = UsdaWriter.Write(UsdaReader.Parse(firstWrite, stage.StageName));
|
|
|
|
Assert.That(secondWrite, Is.EqualTo(firstWrite));
|
|
}
|
|
|
|
[Test]
|
|
public void WriterEmitsTimeCodesWithoutRedundantDecimalPoint()
|
|
{
|
|
UsdStage stage = UsdaReader.Parse(
|
|
Wrap(
|
|
" double a.timeSamples = {",
|
|
" 0: 0.0,",
|
|
" 24: 90.0,",
|
|
" }"),
|
|
"TS");
|
|
|
|
string written = UsdaWriter.Write(stage);
|
|
|
|
Assert.That(written, Does.Contain(".timeSamples = {"));
|
|
Assert.That(written, Does.Contain(" 0: 0.0,"));
|
|
Assert.That(written, Does.Contain(" 24: 90.0,"));
|
|
}
|
|
|
|
// ---- signature ----------------------------------------------------------------
|
|
|
|
[Test]
|
|
public void Signature_DistinguishesDifferingSampleValues()
|
|
{
|
|
var a = new UsdStage("S");
|
|
UsdPrim pa = a.AddRootPrim(new UsdPrim("X", "Xform"));
|
|
var attrA = new UsdAttribute("v", "double");
|
|
attrA.TimeSamples[0.0] = UsdValue.From(0.0);
|
|
attrA.TimeSamples[24.0] = UsdValue.From(90.0);
|
|
pa.Attributes.Add(attrA);
|
|
|
|
var b = new UsdStage("S");
|
|
UsdPrim pb = b.AddRootPrim(new UsdPrim("X", "Xform"));
|
|
var attrB = new UsdAttribute("v", "double");
|
|
attrB.TimeSamples[0.0] = UsdValue.From(0.0);
|
|
attrB.TimeSamples[24.0] = UsdValue.From(91.0);
|
|
pb.Attributes.Add(attrB);
|
|
|
|
Assert.That(UsdSceneSignature.Compute(b), Is.Not.EqualTo(UsdSceneSignature.Compute(a)));
|
|
Assert.That(UsdSceneSignature.FirstDifference(a, b), Is.Not.Null);
|
|
}
|
|
|
|
[Test]
|
|
public void Signature_DistinguishesPresenceOfSamples()
|
|
{
|
|
var withSamples = new UsdStage("S");
|
|
UsdPrim ps = withSamples.AddRootPrim(new UsdPrim("X", "Xform"));
|
|
var sampled = new UsdAttribute("v", "double") { Value = UsdValue.From(1.0) };
|
|
sampled.TimeSamples[0.0] = UsdValue.From(0.0);
|
|
ps.Attributes.Add(sampled);
|
|
|
|
var withoutSamples = new UsdStage("S");
|
|
UsdPrim pn = withoutSamples.AddRootPrim(new UsdPrim("X", "Xform"));
|
|
pn.Attributes.Add(new UsdAttribute("v", "double") { Value = UsdValue.From(1.0) });
|
|
|
|
Assert.That(
|
|
UsdSceneSignature.Compute(withoutSamples),
|
|
Is.Not.EqualTo(UsdSceneSignature.Compute(withSamples)));
|
|
}
|
|
|
|
[Test]
|
|
public void Signature_EqualForIdenticalSamples()
|
|
{
|
|
var a = new UsdStage("S");
|
|
UsdPrim pa = a.AddRootPrim(new UsdPrim("X", "Xform"));
|
|
var attrA = new UsdAttribute("v", "double");
|
|
attrA.TimeSamples[0.0] = UsdValue.From(0.0);
|
|
attrA.TimeSamples[24.0] = UsdValue.From(90.0);
|
|
pa.Attributes.Add(attrA);
|
|
|
|
var b = new UsdStage("S");
|
|
UsdPrim pb = b.AddRootPrim(new UsdPrim("X", "Xform"));
|
|
var attrB = new UsdAttribute("v", "double");
|
|
attrB.TimeSamples[0.0] = UsdValue.From(0.0);
|
|
attrB.TimeSamples[24.0] = UsdValue.From(90.0);
|
|
pb.Attributes.Add(attrB);
|
|
|
|
Assert.That(UsdSceneSignature.Compute(b), Is.EqualTo(UsdSceneSignature.Compute(a)));
|
|
}
|
|
|
|
[Test]
|
|
public void Signature_OfSampleLessAttribute_IsUnchangedByTheFeature()
|
|
{
|
|
// A sample-less attribute's signature must be byte-for-byte what it was before time
|
|
// samples existed, so the existing round-trip corpus cannot be perturbed.
|
|
var stage = new UsdStage("S");
|
|
UsdPrim prim = stage.AddRootPrim(new UsdPrim("X", "Xform"));
|
|
prim.Attributes.Add(new UsdAttribute("v", "int") { Value = UsdValue.From(1L) });
|
|
|
|
string signature = UsdSceneSignature.Compute(stage);
|
|
|
|
Assert.That(signature, Does.Not.Contain("TS("));
|
|
}
|
|
|
|
private static readonly double[] s_doubleValues1 = [0.0, 24.0, 48.0];
|
|
private static readonly double[] s_doubleValues2 = [0.0, 24.0];
|
|
}
|
|
}
|