expo-targets 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +2 -0
- package/README.md +244 -0
- package/android/build.gradle +22 -0
- package/android/src/main/java/expo/modules/targets/ExpoTargetsLogger.kt +98 -0
- package/android/src/main/java/expo/modules/targets/ExpoTargetsReceiver.kt +136 -0
- package/android/src/main/java/expo/modules/targets/ExpoTargetsRemoteViewsProvider.kt +72 -0
- package/android/src/main/java/expo/modules/targets/ExpoTargetsWidgetProvider.kt +47 -0
- package/android/src/main/java/expo/modules/targets/ExpoTargetsWidgetSync.kt +78 -0
- package/android/src/main/java/expo/modules/targets/ExpoTargetsWidgetUpdateReceiver.kt +30 -0
- package/android/src/main/java/expo/modules/targets/extension/ExpoTargetsExtensionModule.kt +27 -0
- package/android/src/main/java/expo/modules/targets/messages/ExpoTargetsMessagesModule.kt +40 -0
- package/android/src/main/java/expo/modules/targets/storage/ExpoTargetsStorageModule.kt +119 -0
- package/app.plugin.js +1 -0
- package/build/metro/src/index.d.ts +2 -0
- package/build/metro/src/index.d.ts.map +1 -0
- package/build/metro/src/index.js +6 -0
- package/build/metro/src/index.js.map +1 -0
- package/build/metro/src/withTargetsMetro.d.ts +6 -0
- package/build/metro/src/withTargetsMetro.d.ts.map +1 -0
- package/build/metro/src/withTargetsMetro.js +171 -0
- package/build/metro/src/withTargetsMetro.js.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidColors.d.ts +7 -0
- package/build/plugin/src/android/config-plugins/withAndroidColors.d.ts.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidColors.js +56 -0
- package/build/plugin/src/android/config-plugins/withAndroidColors.js.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidManifest.d.ts +7 -0
- package/build/plugin/src/android/config-plugins/withAndroidManifest.d.ts.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidManifest.js +70 -0
- package/build/plugin/src/android/config-plugins/withAndroidManifest.js.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidModule.d.ts +7 -0
- package/build/plugin/src/android/config-plugins/withAndroidModule.d.ts.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidModule.js +41 -0
- package/build/plugin/src/android/config-plugins/withAndroidModule.js.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidResources.d.ts +7 -0
- package/build/plugin/src/android/config-plugins/withAndroidResources.d.ts.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidResources.js +75 -0
- package/build/plugin/src/android/config-plugins/withAndroidResources.js.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidTarget.d.ts +28 -0
- package/build/plugin/src/android/config-plugins/withAndroidTarget.d.ts.map +1 -0
- package/build/plugin/src/android/config-plugins/withAndroidTarget.js +28 -0
- package/build/plugin/src/android/config-plugins/withAndroidTarget.js.map +1 -0
- package/build/plugin/src/android/config-plugins/withGradleModule.d.ts +7 -0
- package/build/plugin/src/android/config-plugins/withGradleModule.d.ts.map +1 -0
- package/build/plugin/src/android/config-plugins/withGradleModule.js +86 -0
- package/build/plugin/src/android/config-plugins/withGradleModule.js.map +1 -0
- package/build/plugin/src/android/config-plugins/withGradleSettings.d.ts +7 -0
- package/build/plugin/src/android/config-plugins/withGradleSettings.d.ts.map +1 -0
- package/build/plugin/src/android/config-plugins/withGradleSettings.js +23 -0
- package/build/plugin/src/android/config-plugins/withGradleSettings.js.map +1 -0
- package/build/plugin/src/android/withAndroidAppBuildGradle.d.ts +7 -0
- package/build/plugin/src/android/withAndroidAppBuildGradle.d.ts.map +1 -0
- package/build/plugin/src/android/withAndroidAppBuildGradle.js +31 -0
- package/build/plugin/src/android/withAndroidAppBuildGradle.js.map +1 -0
- package/build/plugin/src/android/withAndroidKotlinGradleProperty.d.ts +3 -0
- package/build/plugin/src/android/withAndroidKotlinGradleProperty.d.ts.map +1 -0
- package/build/plugin/src/android/withAndroidKotlinGradleProperty.js +24 -0
- package/build/plugin/src/android/withAndroidKotlinGradleProperty.js.map +1 -0
- package/build/plugin/src/android/withAndroidProjectKotlinVersion.d.ts +3 -0
- package/build/plugin/src/android/withAndroidProjectKotlinVersion.d.ts.map +1 -0
- package/build/plugin/src/android/withAndroidProjectKotlinVersion.js +27 -0
- package/build/plugin/src/android/withAndroidProjectKotlinVersion.js.map +1 -0
- package/build/plugin/src/android/withAndroidTarget.d.ts +10 -0
- package/build/plugin/src/android/withAndroidTarget.d.ts.map +1 -0
- package/build/plugin/src/android/withAndroidTarget.js +22 -0
- package/build/plugin/src/android/withAndroidTarget.js.map +1 -0
- package/build/plugin/src/android/withAndroidWidget.d.ts +13 -0
- package/build/plugin/src/android/withAndroidWidget.d.ts.map +1 -0
- package/build/plugin/src/android/withAndroidWidget.js +564 -0
- package/build/plugin/src/android/withAndroidWidget.js.map +1 -0
- package/build/plugin/src/config.d.ts +141 -0
- package/build/plugin/src/config.d.ts.map +1 -0
- package/build/plugin/src/config.js +54 -0
- package/build/plugin/src/config.js.map +1 -0
- package/build/plugin/src/index.d.ts +9 -0
- package/build/plugin/src/index.d.ts.map +1 -0
- package/build/plugin/src/index.js +11 -0
- package/build/plugin/src/index.js.map +1 -0
- package/build/plugin/src/ios/config-plugins/withEntitlements.d.ts +11 -0
- package/build/plugin/src/ios/config-plugins/withEntitlements.d.ts.map +1 -0
- package/build/plugin/src/ios/config-plugins/withEntitlements.js +49 -0
- package/build/plugin/src/ios/config-plugins/withEntitlements.js.map +1 -0
- package/build/plugin/src/ios/config-plugins/withIOSTarget.d.ts +17 -0
- package/build/plugin/src/ios/config-plugins/withIOSTarget.d.ts.map +1 -0
- package/build/plugin/src/ios/config-plugins/withIOSTarget.js +152 -0
- package/build/plugin/src/ios/config-plugins/withIOSTarget.js.map +1 -0
- package/build/plugin/src/ios/config-plugins/withIosColorset.d.ts +8 -0
- package/build/plugin/src/ios/config-plugins/withIosColorset.d.ts.map +1 -0
- package/build/plugin/src/ios/config-plugins/withIosColorset.js +25 -0
- package/build/plugin/src/ios/config-plugins/withIosColorset.js.map +1 -0
- package/build/plugin/src/ios/config-plugins/withIosStickerPack.d.ts +8 -0
- package/build/plugin/src/ios/config-plugins/withIosStickerPack.d.ts.map +1 -0
- package/build/plugin/src/ios/config-plugins/withIosStickerPack.js +52 -0
- package/build/plugin/src/ios/config-plugins/withIosStickerPack.js.map +1 -0
- package/build/plugin/src/ios/config-plugins/withPodfile.d.ts +12 -0
- package/build/plugin/src/ios/config-plugins/withPodfile.d.ts.map +1 -0
- package/build/plugin/src/ios/config-plugins/withPodfile.js +162 -0
- package/build/plugin/src/ios/config-plugins/withPodfile.js.map +1 -0
- package/build/plugin/src/ios/config-plugins/withXcodeChanges.d.ts +15 -0
- package/build/plugin/src/ios/config-plugins/withXcodeChanges.d.ts.map +1 -0
- package/build/plugin/src/ios/config-plugins/withXcodeChanges.js +646 -0
- package/build/plugin/src/ios/config-plugins/withXcodeChanges.js.map +1 -0
- package/build/plugin/src/ios/target.d.ts +41 -0
- package/build/plugin/src/ios/target.d.ts.map +1 -0
- package/build/plugin/src/ios/target.js +574 -0
- package/build/plugin/src/ios/target.js.map +1 -0
- package/build/plugin/src/ios/utils/asset.d.ts +60 -0
- package/build/plugin/src/ios/utils/asset.d.ts.map +1 -0
- package/build/plugin/src/ios/utils/asset.js +375 -0
- package/build/plugin/src/ios/utils/asset.js.map +1 -0
- package/build/plugin/src/ios/utils/file.d.ts +33 -0
- package/build/plugin/src/ios/utils/file.d.ts.map +1 -0
- package/build/plugin/src/ios/utils/file.js +88 -0
- package/build/plugin/src/ios/utils/file.js.map +1 -0
- package/build/plugin/src/ios/utils/index.d.ts +12 -0
- package/build/plugin/src/ios/utils/index.d.ts.map +1 -0
- package/build/plugin/src/ios/utils/index.js +38 -0
- package/build/plugin/src/ios/utils/index.js.map +1 -0
- package/build/plugin/src/ios/utils/paths.d.ts +128 -0
- package/build/plugin/src/ios/utils/paths.d.ts.map +1 -0
- package/build/plugin/src/ios/utils/paths.js +141 -0
- package/build/plugin/src/ios/utils/paths.js.map +1 -0
- package/build/plugin/src/ios/utils/plist.d.ts +29 -0
- package/build/plugin/src/ios/utils/plist.d.ts.map +1 -0
- package/build/plugin/src/ios/utils/plist.js +114 -0
- package/build/plugin/src/ios/utils/plist.js.map +1 -0
- package/build/plugin/src/ios/utils/podfile.d.ts +82 -0
- package/build/plugin/src/ios/utils/podfile.d.ts.map +1 -0
- package/build/plugin/src/ios/utils/podfile.js +408 -0
- package/build/plugin/src/ios/utils/podfile.js.map +1 -0
- package/build/plugin/src/ios/utils/reactNativeSwift.d.ts +11 -0
- package/build/plugin/src/ios/utils/reactNativeSwift.d.ts.map +1 -0
- package/build/plugin/src/ios/utils/reactNativeSwift.js +263 -0
- package/build/plugin/src/ios/utils/reactNativeSwift.js.map +1 -0
- package/build/plugin/src/ios/utils/xcode.d.ts +185 -0
- package/build/plugin/src/ios/utils/xcode.d.ts.map +1 -0
- package/build/plugin/src/ios/utils/xcode.js +706 -0
- package/build/plugin/src/ios/utils/xcode.js.map +1 -0
- package/build/plugin/src/logger.d.ts +10 -0
- package/build/plugin/src/logger.d.ts.map +1 -0
- package/build/plugin/src/logger.js +62 -0
- package/build/plugin/src/logger.js.map +1 -0
- package/build/plugin/src/parseTargetConfig.d.ts +3 -0
- package/build/plugin/src/parseTargetConfig.d.ts.map +1 -0
- package/build/plugin/src/parseTargetConfig.js +113 -0
- package/build/plugin/src/parseTargetConfig.js.map +1 -0
- package/build/plugin/src/withTargetsDir.d.ts +6 -0
- package/build/plugin/src/withTargetsDir.d.ts.map +1 -0
- package/build/plugin/src/withTargetsDir.js +90 -0
- package/build/plugin/src/withTargetsDir.js.map +1 -0
- package/build/src/Target.d.ts +43 -0
- package/build/src/Target.d.ts.map +1 -0
- package/build/src/Target.js +128 -0
- package/build/src/Target.js.map +1 -0
- package/build/src/index.d.ts +9 -0
- package/build/src/index.d.ts.map +1 -0
- package/build/src/index.js +27 -0
- package/build/src/index.js.map +1 -0
- package/build/src/modules/extension/index.d.ts +18 -0
- package/build/src/modules/extension/index.d.ts.map +1 -0
- package/build/src/modules/extension/index.js +44 -0
- package/build/src/modules/extension/index.js.map +1 -0
- package/build/src/modules/messages/index.d.ts +40 -0
- package/build/src/modules/messages/index.d.ts.map +1 -0
- package/build/src/modules/messages/index.js +94 -0
- package/build/src/modules/messages/index.js.map +1 -0
- package/build/src/modules/storage/index.d.ts +16 -0
- package/build/src/modules/storage/index.d.ts.map +1 -0
- package/build/src/modules/storage/index.js +122 -0
- package/build/src/modules/storage/index.js.map +1 -0
- package/expo-module.config.json +17 -0
- package/ios/ExpoTargetsExtension.podspec +23 -0
- package/ios/ExpoTargetsExtensionModule.swift +181 -0
- package/ios/ExpoTargetsMessages.podspec +23 -0
- package/ios/ExpoTargetsMessagesModule.swift +267 -0
- package/ios/ExpoTargetsStorage.podspec +23 -0
- package/ios/ExpoTargetsStorageModule.swift +91 -0
- package/ios/Tests/.swiftlint.yml +52 -0
- package/ios/Tests/Helpers/MockExtensionContext.swift +58 -0
- package/ios/Tests/Helpers/MockUserDefaults.swift +70 -0
- package/ios/Tests/Helpers/MockWidgetCenter.swift +71 -0
- package/ios/Tests/Helpers/TestHelpers.swift +90 -0
- package/ios/Tests/Integration/TargetIntegrationTests.swift +478 -0
- package/ios/Tests/Main/AllTests.swift +80 -0
- package/ios/Tests/Package.swift +66 -0
- package/ios/Tests/Performance/StoragePerformanceTests.swift +461 -0
- package/ios/Tests/Unit/Extension/ExpoTargetsExtensionModuleTests.swift +501 -0
- package/ios/Tests/Unit/Storage/ExpoTargetsStorageModuleTests.swift +578 -0
- package/ios/Tests/Unit/Template/ShareExtensionTemplateTests.swift +421 -0
- package/ios/Tests/XCTestPlan.xctestplan +87 -0
- package/metro/src/index.ts +1 -0
- package/metro/src/withTargetsMetro.ts +247 -0
- package/metro/tsconfig.build.json +9 -0
- package/package.json +74 -0
- package/plugin/src/android/withAndroidAppBuildGradle.ts +34 -0
- package/plugin/src/android/withAndroidTarget.ts +26 -0
- package/plugin/src/android/withAndroidWidget.ts +778 -0
- package/plugin/src/config.ts +255 -0
- package/plugin/src/index.ts +19 -0
- package/plugin/src/ios/config-plugins/withEntitlements.ts +69 -0
- package/plugin/src/ios/config-plugins/withIOSTarget.ts +179 -0
- package/plugin/src/ios/config-plugins/withIosColorset.ts +29 -0
- package/plugin/src/ios/config-plugins/withIosStickerPack.ts +65 -0
- package/plugin/src/ios/config-plugins/withPodfile.ts +238 -0
- package/plugin/src/ios/config-plugins/withXcodeChanges.ts +891 -0
- package/plugin/src/ios/target.ts +668 -0
- package/plugin/src/ios/templates/MessagesViewController.swift +120 -0
- package/plugin/src/ios/templates/ReactNativeViewController.swift +240 -0
- package/plugin/src/ios/templates/action-extension-data.swift +106 -0
- package/plugin/src/ios/templates/clip-extension-data.swift +28 -0
- package/plugin/src/ios/templates/messages-extension-data.swift +28 -0
- package/plugin/src/ios/templates/share-extension-data.swift +113 -0
- package/plugin/src/ios/utils/asset.ts +490 -0
- package/plugin/src/ios/utils/file.ts +80 -0
- package/plugin/src/ios/utils/index.ts +12 -0
- package/plugin/src/ios/utils/paths.ts +253 -0
- package/plugin/src/ios/utils/plist.ts +101 -0
- package/plugin/src/ios/utils/podfile.ts +534 -0
- package/plugin/src/ios/utils/reactNativeSwift.ts +283 -0
- package/plugin/src/ios/utils/xcode.ts +989 -0
- package/plugin/src/logger.ts +63 -0
- package/plugin/src/parseTargetConfig.ts +115 -0
- package/plugin/src/types/normalize-colors.d.ts +3 -0
- package/plugin/src/withTargetsDir.ts +120 -0
- package/plugin/tsconfig.build.json +9 -0
- package/plugin/tsconfig.json +9 -0
- package/src/Target.ts +239 -0
- package/src/index.ts +52 -0
- package/src/modules/extension/index.ts +54 -0
- package/src/modules/messages/index.ts +124 -0
- package/src/modules/storage/index.ts +126 -0
- package/tsconfig.json +8 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// swift-tools-version:5.7
|
|
2
|
+
import PackageDescription
|
|
3
|
+
|
|
4
|
+
let package = Package(
|
|
5
|
+
name: "ExpoTargetsTests",
|
|
6
|
+
platforms: [
|
|
7
|
+
.iOS(.v14)
|
|
8
|
+
],
|
|
9
|
+
products: [
|
|
10
|
+
.library(
|
|
11
|
+
name: "ExpoTargetsTests",
|
|
12
|
+
targets: ["ExpoTargetsTests"]
|
|
13
|
+
)
|
|
14
|
+
],
|
|
15
|
+
dependencies: [],
|
|
16
|
+
targets: [
|
|
17
|
+
.target(
|
|
18
|
+
name: "ExpoTargetsStorage",
|
|
19
|
+
dependencies: [],
|
|
20
|
+
path: "../",
|
|
21
|
+
sources: ["ExpoTargetsStorageModule.swift"]
|
|
22
|
+
),
|
|
23
|
+
.target(
|
|
24
|
+
name: "ExpoTargetsExtension",
|
|
25
|
+
dependencies: [],
|
|
26
|
+
path: "../",
|
|
27
|
+
sources: ["ExpoTargetsExtensionModule.swift"]
|
|
28
|
+
),
|
|
29
|
+
.target(
|
|
30
|
+
name: "ExpoTargetsTestHelpers",
|
|
31
|
+
dependencies: [],
|
|
32
|
+
path: "Helpers"
|
|
33
|
+
),
|
|
34
|
+
.testTarget(
|
|
35
|
+
name: "ExpoTargetsStorageModuleTests",
|
|
36
|
+
dependencies: ["ExpoTargetsTestHelpers", "ExpoTargetsStorage"],
|
|
37
|
+
path: "Unit/Storage"
|
|
38
|
+
),
|
|
39
|
+
.testTarget(
|
|
40
|
+
name: "ExpoTargetsExtensionModuleTests",
|
|
41
|
+
dependencies: ["ExpoTargetsTestHelpers", "ExpoTargetsExtension"],
|
|
42
|
+
path: "Unit/Extension"
|
|
43
|
+
),
|
|
44
|
+
.testTarget(
|
|
45
|
+
name: "ExpoTargetsIntegrationTests",
|
|
46
|
+
dependencies: ["ExpoTargetsTestHelpers", "ExpoTargetsStorage", "ExpoTargetsExtension"],
|
|
47
|
+
path: "Integration"
|
|
48
|
+
),
|
|
49
|
+
.testTarget(
|
|
50
|
+
name: "ExpoTargetsPerformanceTests",
|
|
51
|
+
dependencies: ["ExpoTargetsTestHelpers", "ExpoTargetsStorage"],
|
|
52
|
+
path: "Performance"
|
|
53
|
+
),
|
|
54
|
+
.testTarget(
|
|
55
|
+
name: "ExpoTargetsTests",
|
|
56
|
+
dependencies: [
|
|
57
|
+
"ExpoTargetsTestHelpers",
|
|
58
|
+
"ExpoTargetsStorageModuleTests",
|
|
59
|
+
"ExpoTargetsExtensionModuleTests",
|
|
60
|
+
"ExpoTargetsIntegrationTests",
|
|
61
|
+
"ExpoTargetsPerformanceTests"
|
|
62
|
+
],
|
|
63
|
+
path: "Main"
|
|
64
|
+
)
|
|
65
|
+
]
|
|
66
|
+
)
|
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
import XCTest
|
|
2
|
+
import Foundation
|
|
3
|
+
@testable import ExpoTargetsStorage
|
|
4
|
+
|
|
5
|
+
/// Performance benchmarks for storage operations
|
|
6
|
+
/// Measures throughput, latency, and resource usage
|
|
7
|
+
class StoragePerformanceTests: XCTestCase {
|
|
8
|
+
|
|
9
|
+
var storage: MockUserDefaults!
|
|
10
|
+
let testAppGroup = "group.com.test.performance"
|
|
11
|
+
|
|
12
|
+
// MARK: - Setup & Teardown
|
|
13
|
+
|
|
14
|
+
override func setUp() {
|
|
15
|
+
super.setUp()
|
|
16
|
+
storage = MockUserDefaults(suiteName: testAppGroup)
|
|
17
|
+
storage?.clearStorage()
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
override func tearDown() {
|
|
21
|
+
storage?.clearStorage()
|
|
22
|
+
storage = nil
|
|
23
|
+
super.tearDown()
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// MARK: - Write Performance Tests
|
|
27
|
+
|
|
28
|
+
func testPerformance_SmallStringWrites() {
|
|
29
|
+
// Baseline: 1000 small string writes
|
|
30
|
+
measure {
|
|
31
|
+
for i in 0..<1000 {
|
|
32
|
+
storage.set("value\(i)", forKey: "key\(i)")
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
func testPerformance_MediumStringWrites() {
|
|
38
|
+
// Medium strings (100 chars)
|
|
39
|
+
let mediumString = String(repeating: "x", count: 100)
|
|
40
|
+
|
|
41
|
+
measure {
|
|
42
|
+
for i in 0..<1000 {
|
|
43
|
+
storage.set(mediumString, forKey: "key\(i)")
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
func testPerformance_LargeStringWrites() {
|
|
49
|
+
// Large strings (10KB)
|
|
50
|
+
let largeString = String(repeating: "x", count: 10_000)
|
|
51
|
+
|
|
52
|
+
measure {
|
|
53
|
+
for i in 0..<100 {
|
|
54
|
+
storage.set(largeString, forKey: "key\(i)")
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
func testPerformance_IntegerWrites() {
|
|
60
|
+
measure {
|
|
61
|
+
for i in 0..<1000 {
|
|
62
|
+
storage.set(i, forKey: "key\(i)")
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
func testPerformance_ObjectWrites() {
|
|
68
|
+
let testObject: [String: Any] = [
|
|
69
|
+
"name": "Test",
|
|
70
|
+
"value": 42,
|
|
71
|
+
"active": true,
|
|
72
|
+
"items": ["a", "b", "c"]
|
|
73
|
+
]
|
|
74
|
+
|
|
75
|
+
measure {
|
|
76
|
+
for i in 0..<100 {
|
|
77
|
+
storage.set(testObject, forKey: "key\(i)")
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
func testPerformance_ComplexObjectWrites() {
|
|
83
|
+
let complexObject: [String: Any] = [
|
|
84
|
+
"user": [
|
|
85
|
+
"name": "Jane Doe",
|
|
86
|
+
"age": 28,
|
|
87
|
+
"preferences": [
|
|
88
|
+
"theme": "dark",
|
|
89
|
+
"notifications": true,
|
|
90
|
+
"language": "en"
|
|
91
|
+
]
|
|
92
|
+
],
|
|
93
|
+
"data": Array(0..<100).map { ["id": $0, "value": "item\($0)"] }
|
|
94
|
+
]
|
|
95
|
+
|
|
96
|
+
measure {
|
|
97
|
+
for i in 0..<50 {
|
|
98
|
+
storage.set(complexObject, forKey: "key\(i)")
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// MARK: - Read Performance Tests
|
|
104
|
+
|
|
105
|
+
func testPerformance_SmallStringReads() {
|
|
106
|
+
// Setup
|
|
107
|
+
for i in 0..<1000 {
|
|
108
|
+
storage.set("value\(i)", forKey: "key\(i)")
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
measure {
|
|
112
|
+
for i in 0..<1000 {
|
|
113
|
+
_ = storage.string(forKey: "key\(i)")
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
func testPerformance_RandomAccessReads() {
|
|
119
|
+
// Setup
|
|
120
|
+
for i in 0..<1000 {
|
|
121
|
+
storage.set("value\(i)", forKey: "key\(i)")
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
measure {
|
|
125
|
+
for _ in 0..<1000 {
|
|
126
|
+
let randomKey = Int.random(in: 0..<1000)
|
|
127
|
+
_ = storage.string(forKey: "key\(randomKey)")
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
func testPerformance_IntegerReads() {
|
|
133
|
+
// Setup
|
|
134
|
+
for i in 0..<1000 {
|
|
135
|
+
storage.set(i, forKey: "key\(i)")
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
measure {
|
|
139
|
+
for i in 0..<1000 {
|
|
140
|
+
_ = storage.integer(forKey: "key\(i)")
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
func testPerformance_ObjectReads() {
|
|
146
|
+
// Setup
|
|
147
|
+
let testObject: [String: Any] = ["name": "Test", "value": 42]
|
|
148
|
+
for i in 0..<100 {
|
|
149
|
+
storage.set(testObject, forKey: "key\(i)")
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
measure {
|
|
153
|
+
for i in 0..<100 {
|
|
154
|
+
_ = storage.object(forKey: "key\(i)") as? [String: Any]
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// MARK: - Mixed Operations Performance
|
|
160
|
+
|
|
161
|
+
func testPerformance_MixedReadWrite() {
|
|
162
|
+
measure {
|
|
163
|
+
for i in 0..<500 {
|
|
164
|
+
storage.set("value\(i)", forKey: "key\(i)")
|
|
165
|
+
_ = storage.string(forKey: "key\(i)")
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
func testPerformance_UpdateExistingValues() {
|
|
171
|
+
// Setup
|
|
172
|
+
for i in 0..<1000 {
|
|
173
|
+
storage.set("initial\(i)", forKey: "key\(i)")
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
measure {
|
|
177
|
+
for i in 0..<1000 {
|
|
178
|
+
storage.set("updated\(i)", forKey: "key\(i)")
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// MARK: - Bulk Operations Performance
|
|
184
|
+
|
|
185
|
+
func testPerformance_GetAllKeys() {
|
|
186
|
+
// Setup
|
|
187
|
+
for i in 0..<1000 {
|
|
188
|
+
storage.set("value\(i)", forKey: "key\(i)")
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
measure {
|
|
192
|
+
_ = Array(storage.dictionaryRepresentation().keys)
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
func testPerformance_GetAllData() {
|
|
197
|
+
// Setup
|
|
198
|
+
for i in 0..<1000 {
|
|
199
|
+
storage.set("value\(i)", forKey: "key\(i)")
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
measure {
|
|
203
|
+
_ = storage.dictionaryRepresentation()
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
func testPerformance_BulkDelete() {
|
|
208
|
+
// Setup
|
|
209
|
+
for i in 0..<1000 {
|
|
210
|
+
storage.set("value\(i)", forKey: "key\(i)")
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
measure {
|
|
214
|
+
for i in 0..<1000 {
|
|
215
|
+
storage.removeObject(forKey: "key\(i)")
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
func testPerformance_ClearAll() {
|
|
221
|
+
// Setup
|
|
222
|
+
for i in 0..<1000 {
|
|
223
|
+
storage.set("value\(i)", forKey: "key\(i)")
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
measure {
|
|
227
|
+
let dict = storage.dictionaryRepresentation()
|
|
228
|
+
for key in dict.keys {
|
|
229
|
+
storage.removeObject(forKey: key)
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// MARK: - Synchronization Performance
|
|
235
|
+
|
|
236
|
+
func testPerformance_SynchronizeCalls() {
|
|
237
|
+
measure {
|
|
238
|
+
for _ in 0..<1000 {
|
|
239
|
+
_ = storage.synchronize()
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
func testPerformance_WriteWithSync() {
|
|
245
|
+
measure {
|
|
246
|
+
for i in 0..<100 {
|
|
247
|
+
storage.set("value\(i)", forKey: "key\(i)")
|
|
248
|
+
_ = storage.synchronize()
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// MARK: - Concurrent Operations Performance
|
|
254
|
+
|
|
255
|
+
func testPerformance_ConcurrentWrites() {
|
|
256
|
+
measure {
|
|
257
|
+
let queue = DispatchQueue(label: "test.concurrent", attributes: .concurrent)
|
|
258
|
+
let group = DispatchGroup()
|
|
259
|
+
|
|
260
|
+
for i in 0..<100 {
|
|
261
|
+
group.enter()
|
|
262
|
+
queue.async {
|
|
263
|
+
self.storage.set("value\(i)", forKey: "key\(i)")
|
|
264
|
+
group.leave()
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
group.wait()
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
func testPerformance_ConcurrentReads() {
|
|
273
|
+
// Setup
|
|
274
|
+
for i in 0..<100 {
|
|
275
|
+
storage.set("value\(i)", forKey: "key\(i)")
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
measure {
|
|
279
|
+
let queue = DispatchQueue(label: "test.concurrent.read", attributes: .concurrent)
|
|
280
|
+
let group = DispatchGroup()
|
|
281
|
+
|
|
282
|
+
for i in 0..<100 {
|
|
283
|
+
group.enter()
|
|
284
|
+
queue.async {
|
|
285
|
+
_ = self.storage.string(forKey: "key\(i)")
|
|
286
|
+
group.leave()
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
group.wait()
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
func testPerformance_ConcurrentMixedOperations() {
|
|
295
|
+
measure {
|
|
296
|
+
let queue = DispatchQueue(label: "test.concurrent.mixed", attributes: .concurrent)
|
|
297
|
+
let group = DispatchGroup()
|
|
298
|
+
|
|
299
|
+
// 50 writes, 50 reads
|
|
300
|
+
for i in 0..<50 {
|
|
301
|
+
group.enter()
|
|
302
|
+
queue.async {
|
|
303
|
+
self.storage.set("value\(i)", forKey: "key\(i)")
|
|
304
|
+
group.leave()
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
group.enter()
|
|
308
|
+
queue.async {
|
|
309
|
+
_ = self.storage.string(forKey: "key\(i)")
|
|
310
|
+
group.leave()
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
group.wait()
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// MARK: - Memory Performance Tests
|
|
319
|
+
|
|
320
|
+
func testPerformance_LargeDatasetMemory() {
|
|
321
|
+
// Test memory efficiency with large dataset
|
|
322
|
+
measure {
|
|
323
|
+
// Store 10,000 small items
|
|
324
|
+
for i in 0..<10_000 {
|
|
325
|
+
storage.set("value\(i)", forKey: "key\(i)")
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// Read them all
|
|
329
|
+
for i in 0..<10_000 {
|
|
330
|
+
_ = storage.string(forKey: "key\(i)")
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// Clear them all
|
|
334
|
+
let dict = storage.dictionaryRepresentation()
|
|
335
|
+
for key in dict.keys {
|
|
336
|
+
storage.removeObject(forKey: key)
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// MARK: - Real-World Scenario Performance
|
|
342
|
+
|
|
343
|
+
func testPerformance_TypicalWidgetUpdateCycle() {
|
|
344
|
+
// Simulate typical widget update: read old data, write new data, sync
|
|
345
|
+
measure {
|
|
346
|
+
for i in 0..<100 {
|
|
347
|
+
// Read current data
|
|
348
|
+
_ = storage.string(forKey: "temperature")
|
|
349
|
+
_ = storage.string(forKey: "condition")
|
|
350
|
+
_ = storage.integer(forKey: "humidity")
|
|
351
|
+
|
|
352
|
+
// Write new data
|
|
353
|
+
storage.set("72", forKey: "temperature")
|
|
354
|
+
storage.set("Sunny", forKey: "condition")
|
|
355
|
+
storage.set(65, forKey: "humidity")
|
|
356
|
+
|
|
357
|
+
// Sync
|
|
358
|
+
_ = storage.synchronize()
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
func testPerformance_HighFrequencyUpdates() {
|
|
364
|
+
// Simulate high-frequency updates (e.g., live activity)
|
|
365
|
+
measure {
|
|
366
|
+
for i in 0..<1000 {
|
|
367
|
+
storage.set("Update \(i)", forKey: "liveData")
|
|
368
|
+
_ = storage.synchronize()
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// MARK: - Stress Tests
|
|
374
|
+
|
|
375
|
+
func testStress_MassiveWriteLoad() {
|
|
376
|
+
// Write 100,000 small items
|
|
377
|
+
let startTime = Date()
|
|
378
|
+
|
|
379
|
+
for i in 0..<100_000 {
|
|
380
|
+
storage.set("value\(i)", forKey: "key\(i)")
|
|
381
|
+
|
|
382
|
+
// Sync every 1000 items
|
|
383
|
+
if i % 1000 == 0 {
|
|
384
|
+
_ = storage.synchronize()
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
let duration = Date().timeIntervalSince(startTime)
|
|
389
|
+
let throughput = 100_000.0 / duration
|
|
390
|
+
|
|
391
|
+
print("Massive write throughput: \(Int(throughput)) writes/second")
|
|
392
|
+
XCTAssertLessThan(duration, 60.0, "Massive write took too long")
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
func testStress_RapidReadWrite() {
|
|
396
|
+
// Rapid alternating read/write operations
|
|
397
|
+
let startTime = Date()
|
|
398
|
+
|
|
399
|
+
for i in 0..<10_000 {
|
|
400
|
+
storage.set("value\(i)", forKey: "key")
|
|
401
|
+
_ = storage.string(forKey: "key")
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
let duration = Date().timeIntervalSince(startTime)
|
|
405
|
+
print("Rapid read/write duration: \(duration)s for 10,000 cycles")
|
|
406
|
+
XCTAssertLessThan(duration, 10.0, "Rapid read/write took too long")
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// MARK: - Latency Tests
|
|
410
|
+
|
|
411
|
+
func testLatency_SingleWrite() {
|
|
412
|
+
let iterations = 100
|
|
413
|
+
var totalTime: TimeInterval = 0
|
|
414
|
+
|
|
415
|
+
for i in 0..<iterations {
|
|
416
|
+
let start = Date()
|
|
417
|
+
storage.set("value", forKey: "key\(i)")
|
|
418
|
+
totalTime += Date().timeIntervalSince(start)
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
let averageLatency = (totalTime / Double(iterations)) * 1000 // Convert to ms
|
|
422
|
+
print("Average write latency: \(averageLatency)ms")
|
|
423
|
+
XCTAssertLessThan(averageLatency, 1.0, "Write latency too high")
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
func testLatency_SingleRead() {
|
|
427
|
+
// Setup
|
|
428
|
+
for i in 0..<100 {
|
|
429
|
+
storage.set("value\(i)", forKey: "key\(i)")
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
let iterations = 100
|
|
433
|
+
var totalTime: TimeInterval = 0
|
|
434
|
+
|
|
435
|
+
for i in 0..<iterations {
|
|
436
|
+
let start = Date()
|
|
437
|
+
_ = storage.string(forKey: "key\(i)")
|
|
438
|
+
totalTime += Date().timeIntervalSince(start)
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
let averageLatency = (totalTime / Double(iterations)) * 1000 // Convert to ms
|
|
442
|
+
print("Average read latency: \(averageLatency)ms")
|
|
443
|
+
XCTAssertLessThan(averageLatency, 0.5, "Read latency too high")
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
func testLatency_SynchronizeOperation() {
|
|
447
|
+
let iterations = 100
|
|
448
|
+
var totalTime: TimeInterval = 0
|
|
449
|
+
|
|
450
|
+
for _ in 0..<iterations {
|
|
451
|
+
storage.set("value", forKey: "key")
|
|
452
|
+
let start = Date()
|
|
453
|
+
_ = storage.synchronize()
|
|
454
|
+
totalTime += Date().timeIntervalSince(start)
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
let averageLatency = (totalTime / Double(iterations)) * 1000 // Convert to ms
|
|
458
|
+
print("Average synchronize latency: \(averageLatency)ms")
|
|
459
|
+
XCTAssertLessThan(averageLatency, 5.0, "Synchronize latency too high")
|
|
460
|
+
}
|
|
461
|
+
}
|