From cc0976cd518315aa7efcbc229c4b7513e87cac04 Mon Sep 17 00:00:00 2001 From: Naveed Jooma Date: Thu, 21 Nov 2024 13:01:44 -0500 Subject: [PATCH] Update resource name map in resource manager --- .../ios/Flutter/AppFrameworkInfo.plist | 2 +- .../ios/Runner.xcodeproj/project.pbxproj | 8 +-- .../xcshareddata/xcschemes/Runner.xcscheme | 2 +- .../ios/Runner/AppDelegate.swift | 2 +- lib/src/resource/base.dart | 4 +- lib/src/resource/manager.dart | 13 +++- test/unit_test/resource/base_test.dart | 30 +++++++++ test/unit_test/resource/manager_test.dart | 62 +++++++++++++++++++ 8 files changed, 114 insertions(+), 9 deletions(-) create mode 100644 test/unit_test/resource/base_test.dart create mode 100644 test/unit_test/resource/manager_test.dart diff --git a/example/viam_example_app/ios/Flutter/AppFrameworkInfo.plist b/example/viam_example_app/ios/Flutter/AppFrameworkInfo.plist index 9625e105df3..7c569640062 100644 --- a/example/viam_example_app/ios/Flutter/AppFrameworkInfo.plist +++ b/example/viam_example_app/ios/Flutter/AppFrameworkInfo.plist @@ -21,6 +21,6 @@ CFBundleVersion 1.0 MinimumOSVersion - 11.0 + 12.0 diff --git a/example/viam_example_app/ios/Runner.xcodeproj/project.pbxproj b/example/viam_example_app/ios/Runner.xcodeproj/project.pbxproj index f14dc1888f8..ded87b019f0 100644 --- a/example/viam_example_app/ios/Runner.xcodeproj/project.pbxproj +++ b/example/viam_example_app/ios/Runner.xcodeproj/project.pbxproj @@ -216,7 +216,7 @@ isa = PBXProject; attributes = { BuildIndependentTargetsInParallel = YES; - LastUpgradeCheck = 1430; + LastUpgradeCheck = 1510; ORGANIZATIONNAME = ""; TargetAttributes = { 331C8080294A63A400263BE5 = { @@ -453,7 +453,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; @@ -580,7 +580,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -629,7 +629,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; diff --git a/example/viam_example_app/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/example/viam_example_app/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index 87131a09bea..8e3ca5dfe19 100644 --- a/example/viam_example_app/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/example/viam_example_app/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ (ResourceName name) { - final resource = resources[name]; + Resource? resource; + if (resources.containsKey(name)) { + resource = resources[name]; + } else { + final resourcesWithoutRemotes = resources.map((rn, res) { + final rnWithoutRemote = rn + ..remotePath.clear() + ..name = rn.localName; + return MapEntry(rnWithoutRemote, res); + }); + resource = resourcesWithoutRemotes[name]; + } if (resource == null) throw Exception('Resource not found in manager'); return resource as T; } diff --git a/test/unit_test/resource/base_test.dart b/test/unit_test/resource/base_test.dart new file mode 100644 index 00000000000..bf50f67903e --- /dev/null +++ b/test/unit_test/resource/base_test.dart @@ -0,0 +1,30 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:viam_sdk/src/components/sensor/sensor.dart'; + +void main() { + group('Subtype Tests', () { + test('getResourceName', () { + // Local + final localName = 'my-sensor'; + final localRN = Sensor.subtype.getResourceName(localName); + expect(localRN.namespace, Sensor.subtype.namespace); + expect(localRN.type, Sensor.subtype.resourceType); + expect(localRN.subtype, Sensor.subtype.resourceSubtype); + expect(localRN.remotePath, []); + expect(localRN.name, localName); + expect(localRN.localName, localName); + + // Remote + final remoteName = 'my-sensor'; + final remotePath = 'remote2:remote1'; + final fullRemoteName = '$remotePath:$remoteName'; + final remoteRN = Sensor.subtype.getResourceName(fullRemoteName); + expect(remoteRN.namespace, Sensor.subtype.namespace); + expect(remoteRN.type, Sensor.subtype.resourceType); + expect(remoteRN.subtype, Sensor.subtype.resourceSubtype); + expect(remoteRN.remotePath, remotePath.split(':')); + expect(remoteRN.name, fullRemoteName); + expect(remoteRN.localName, remoteName); + }); + }); +} diff --git a/test/unit_test/resource/manager_test.dart b/test/unit_test/resource/manager_test.dart new file mode 100644 index 00000000000..7e233ca50df --- /dev/null +++ b/test/unit_test/resource/manager_test.dart @@ -0,0 +1,62 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:viam_sdk/src/components/sensor/sensor.dart'; +import 'package:viam_sdk/src/resource/manager.dart'; + +import '../components/sensor_test.dart'; + +void main() { + group('ResourceManager Tests', () { + group('getResource', () { + test('Local', () { + final localName = 'local-sensor'; + final localRN = Sensor.getResourceName(localName); + final localResource = FakeSensor(localName); + final manager = ResourceManager(); + manager.register(localRN, localResource); + + expect(manager.getResource(Sensor.getResourceName(localName)), localResource); + }); + + test('Remote', () { + final remoteName = 'remote-sensor'; + final remotePath = 'remote2:remote1'; + final fullRemoteName = '$remotePath:$remoteName'; + final remoteRN = Sensor.subtype.getResourceName(fullRemoteName); + final remoteResource = FakeSensor(fullRemoteName); + final manager = ResourceManager(); + manager.register(remoteRN, remoteResource); + + // Works with full name + expect(manager.getResource(Sensor.getResourceName(fullRemoteName)), remoteResource); + + // Works with short name -- no collisions + expect(manager.getResource(Sensor.getResourceName(remoteName)), remoteResource); + }); + + test('Local and Remote - Same Names', () { + final manager = ResourceManager(); + + final localName = 'my-sensor'; + final localRN = Sensor.getResourceName(localName); + final localResource = FakeSensor(localName); + + final remoteName = 'my-sensor'; + final remotePath = 'remote2:remote1'; + final fullRemoteName = '$remotePath:$remoteName'; + final remoteRN = Sensor.subtype.getResourceName(fullRemoteName); + final remoteResource = FakeSensor(fullRemoteName); + + manager.register(localRN, localResource); + manager.register(remoteRN, remoteResource); + + // When using fully qualified names, it should return appropriately + expect(manager.getResource(Sensor.getResourceName(localName)), localResource); + expect(manager.getResource(Sensor.getResourceName(fullRemoteName)), remoteResource); + + // When using just `my-sensor`, it should always return the local + expect(manager.getResource(Sensor.getResourceName(localName)), localResource); + expect(manager.getResource(Sensor.getResourceName(remoteName)), localResource); + }); + }); + }); +}