@@ -881,7 +881,7 @@ extension ProgressManager.Properties {
881
881
}
882
882
}
883
883
884
- @Suite ( " Progress Manager Image URL (Non-retaining) Properties " , . tags( . progressManager) ) struct ProgressManagerImageURLProperties {
884
+ @Suite ( " Progress Manager URL (Non-retaining) Properties " , . tags( . progressManager) ) struct ProgressManagerURLProperties {
885
885
func doSomething( subprogress: consuming Subprogress ) async {
886
886
let manager = subprogress. start ( totalCount: 1 )
887
887
@@ -946,3 +946,95 @@ extension ProgressManager.Properties {
946
946
}
947
947
}
948
948
949
+ extension ProgressManager . Properties {
950
+ var totalPixelCount : TotalPixelCount . Type { TotalPixelCount . self }
951
+ struct TotalPixelCount : Sendable , ProgressManager . Property {
952
+ typealias Value = UInt64
953
+
954
+ typealias Summary = [ UInt64 ]
955
+
956
+ static var key : String { " MyApp.TotalPixelCount " }
957
+
958
+ static var defaultValue : UInt64 { 0 }
959
+
960
+ static var defaultSummary : [ UInt64 ] { [ ] }
961
+
962
+ static func reduce( into summary: inout [ UInt64 ] , value: UInt64 ) {
963
+ summary. append ( value)
964
+ }
965
+
966
+ static func merge( _ summary1: [ UInt64 ] , _ summary2: [ UInt64 ] ) -> [ UInt64 ] {
967
+ summary1 + summary2
968
+ }
969
+
970
+ static func terminate( _ parentSummary: [ UInt64 ] , _ childSummary: [ UInt64 ] ) -> [ UInt64 ] {
971
+ parentSummary + childSummary
972
+ }
973
+ }
974
+ }
975
+
976
+ @Suite ( " Progress Manager UInt64 (Retaining) Properties " , . tags( . progressManager) ) struct ProgressManagerUInt64Properties {
977
+
978
+ func doSomething( subprogress: consuming Subprogress ) async {
979
+ let manager = subprogress. start ( totalCount: 1 )
980
+
981
+ manager. withProperties { properties in
982
+ properties. completedCount = 1
983
+ properties. totalPixelCount = 24
984
+ }
985
+
986
+ #expect( manager. summary ( of: ProgressManager . Properties. TotalPixelCount. self) == [ 24 ] )
987
+ }
988
+
989
+ func doSomethingTwoLevels( subprogress: consuming Subprogress ) async {
990
+ let manager = subprogress. start ( totalCount: 2 )
991
+
992
+ manager. withProperties { properties in
993
+ properties. completedCount = 1
994
+ properties. totalPixelCount = 26
995
+ }
996
+
997
+ await doSomething ( subprogress: manager. subprogress ( assigningCount: 1 ) )
998
+
999
+ #expect( manager. summary ( of: ProgressManager . Properties. TotalPixelCount. self) == [ 26 , 24 ] )
1000
+ }
1001
+
1002
+ @Test func discreteManager( ) async throws {
1003
+ let manager = ProgressManager ( totalCount: 1 )
1004
+
1005
+ manager. withProperties { properties in
1006
+ properties. totalPixelCount = 42
1007
+ }
1008
+
1009
+ #expect( manager. fractionCompleted == 0.0 )
1010
+ #expect( manager. summary ( of: ProgressManager . Properties. TotalPixelCount. self) == [ 42 ] )
1011
+ }
1012
+
1013
+ @Test func twoLevelsManager( ) async throws {
1014
+ let manager = ProgressManager ( totalCount: 2 )
1015
+
1016
+ manager. withProperties { properties in
1017
+ properties. completedCount = 1
1018
+ properties. totalPixelCount = 42
1019
+ }
1020
+
1021
+ await doSomething ( subprogress: manager. subprogress ( assigningCount: 1 ) )
1022
+
1023
+ #expect( manager. fractionCompleted == 1.0 )
1024
+ #expect( manager. summary ( of: ProgressManager . Properties. TotalPixelCount. self) == [ 42 , 24 ] )
1025
+ }
1026
+
1027
+ @Test func threeLevelsManager( ) async throws {
1028
+ let manager = ProgressManager ( totalCount: 2 )
1029
+
1030
+ manager. withProperties { properties in
1031
+ properties. completedCount = 1
1032
+ properties. totalPixelCount = 42
1033
+ }
1034
+
1035
+ await doSomethingTwoLevels ( subprogress: manager. subprogress ( assigningCount: 1 ) )
1036
+
1037
+ #expect( manager. fractionCompleted == 1.0 )
1038
+ #expect( manager. summary ( of: ProgressManager . Properties. TotalPixelCount. self) == [ 42 , 26 , 24 ] )
1039
+ }
1040
+ }
0 commit comments