-
-
Notifications
You must be signed in to change notification settings - Fork 162
/
objectivec_classes.go
357 lines (290 loc) · 11.3 KB
/
objectivec_classes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
package nskeyedarchiver
import (
"fmt"
"time"
"github.com/google/uuid"
log "github.com/sirupsen/logrus"
"howett.net/plist"
)
var decodableClasses map[string]func(map[string]interface{}, []interface{}) interface{}
var encodableClasses map[string]func(object interface{}, objects []interface{}) ([]interface{}, plist.UID)
func SetupDecoders() {
if decodableClasses == nil {
decodableClasses = map[string]func(map[string]interface{}, []interface{}) interface{}{
"DTActivityTraceTapMessage": NewDTActivityTraceTapMessage,
"NSError": NewNSError,
"NSNull": NewNSNullFromArchived,
"NSDate": NewNSDate,
"XCTestConfiguration": NewXCTestConfigurationFromBytes,
"DTTapHeartbeatMessage": NewDTTapHeartbeatMessage,
"XCTCapabilities": NewXCTCapabilities,
"NSUUID": NewNSUUIDFromBytes,
"XCActivityRecord": DecodeXCActivityRecord,
}
}
}
func SetupEncoders() {
if encodableClasses == nil {
encodableClasses = map[string]func(object interface{}, objects []interface{}) ([]interface{}, plist.UID){
"XCTestConfiguration": archiveXcTestConfiguration,
"NSUUID": archiveNSUUID,
"NSURL": archiveNSURL,
"NSNull": archiveNSNull,
"NSMutableDictionary": archiveNSMutableDictionary,
"XCTCapabilities": archiveXCTCapabilities,
}
}
}
type XCTestConfiguration struct {
contents map[string]interface{}
}
func NewXCTestConfiguration(
productModuleName string,
sessionIdentifier uuid.UUID,
targetApplicationBundleID string,
targetApplicationPath string,
testBundleURL string,
) XCTestConfiguration {
contents := map[string]interface{}{}
contents["aggregateStatisticsBeforeCrash"] = map[string]interface{}{"XCSuiteRecordsKey": map[string]interface{}{}}
contents["automationFrameworkPath"] = "/Developer/Library/PrivateFrameworks/XCTAutomationSupport.framework"
contents["baselineFileRelativePath"] = plist.UID(0)
contents["baselineFileURL"] = plist.UID(0)
contents["defaultTestExecutionTimeAllowance"] = plist.UID(0)
contents["disablePerformanceMetrics"] = false
contents["emitOSLogs"] = false
//contents["formatVersion"]= 2
contents["gatherLocalizableStringsData"] = false
contents["initializeForUITesting"] = true
contents["maximumTestExecutionTimeAllowance"] = plist.UID(0)
contents["productModuleName"] = productModuleName
contents["randomExecutionOrderingSeed"] = plist.UID(0)
contents["reportActivities"] = true
contents["reportResultsToIDE"] = true
contents["sessionIdentifier"] = NewNSUUID(sessionIdentifier)
contents["systemAttachmentLifetime"] = 2
//contents["targetApplicationArguments"] = []interface{}{} //TODO: triggers a bug
contents["targetApplicationBundleID"] = targetApplicationBundleID
//contents["targetApplicationEnvironment"] = //TODO: triggers a bug map[string]interface{}{}
contents["targetApplicationPath"] = targetApplicationPath
//testApplicationDependencies
contents["testApplicationUserOverrides"] = plist.UID(0)
contents["testBundleRelativePath"] = plist.UID(0)
contents["testBundleURL"] = NewNSURL(testBundleURL)
contents["testExecutionOrdering"] = 0
contents["testsDrivenByIDE"] = false
contents["testsMustRunOnMainThread"] = true
contents["testsToRun"] = plist.UID(0)
contents["testsToSkip"] = plist.UID(0)
contents["testTimeoutsEnabled"] = false
contents["treatMissingBaselinesAsFailures"] = false
contents["userAttachmentLifetime"] = 1
return XCTestConfiguration{contents}
}
func archiveXcTestConfiguration(xctestconfigInterface interface{}, objects []interface{}) ([]interface{}, plist.UID) {
xctestconfig := xctestconfigInterface.(XCTestConfiguration)
xcconfigRef := plist.UID(len(objects))
objects = append(objects, xctestconfig.contents)
classRef := plist.UID(len(objects))
objects = append(objects, buildClassDict("XCTestConfiguration", "NSObject"))
xctestconfig.contents["$class"] = classRef
for _, key := range []string{"aggregateStatisticsBeforeCrash", "automationFrameworkPath", "productModuleName", "sessionIdentifier",
"targetApplicationBundleID", "targetApplicationPath", "testBundleURL"} {
var ref plist.UID
objects, ref = archive(xctestconfig.contents[key], objects)
xctestconfig.contents[key] = ref
}
return objects, xcconfigRef
}
type NSUUID struct {
uuidbytes []byte
}
func (n NSUUID) String() string {
uid, err := uuid.FromBytes(n.uuidbytes)
if err != nil {
return fmt.Sprintf("Failed converting %x to uuid with %+v", n.uuidbytes, err)
}
return uid.String()
}
type XCActivityRecord struct {
/*
finish":<interface {}(howett.net/plist.UID)>)
"start":<interface {}(howett.net/plist.UID)>)
"title":<interface {}(howett.net/plist.UID)>)
"uuid":<interface {}(howett.net/plist.UID)>)
"activityType":<interface {}(howett.net/plist.UID)>)
"attachments":<interface {}(howett.net/plist.UID)>)
*/
Finish interface{}
Start interface{}
Title string
UUID NSUUID
ActivityType string
Attachments interface{}
}
func DecodeXCActivityRecord(object map[string]interface{}, objects []interface{}) interface{} {
finish_ref := object["finish"].(plist.UID)
finish := objects[finish_ref]
start_ref := object["start"].(plist.UID)
start := objects[start_ref]
uuid_ref := object["uuid"].(plist.UID)
uuid_raw := objects[uuid_ref].(map[string]interface{})
uuid := NewNSUUIDFromBytes(uuid_raw, objects).(NSUUID)
title_ref := object["title"].(plist.UID)
title := objects[title_ref].(string)
attachments_ref := object["attachments"].(plist.UID)
attachments := objects[attachments_ref]
activityType_ref := object["activityType"].(plist.UID)
activityType := objects[activityType_ref].(string)
log.Info(objects[9])
return XCActivityRecord{Finish: finish, Start: start, UUID: uuid, Title: title, Attachments: attachments, ActivityType: activityType}
}
func NewNSUUIDFromBytes(object map[string]interface{}, objects []interface{}) interface{} {
val := object["NS.uuidbytes"].([]byte)
return NSUUID{uuidbytes: val}
}
func NewNSUUID(id uuid.UUID) NSUUID {
bytes, err := id.MarshalBinary()
if err != nil {
panic(fmt.Sprintf("Unexpected Error: %v", err))
}
return NSUUID{bytes}
}
func archiveXCTCapabilities(capsIface interface{}, objects []interface{}) ([]interface{}, plist.UID) {
caps := capsIface.(XCTCapabilities)
object := map[string]interface{}{}
objects, dictRef := serializeMap(caps.CapabilitiesDictionary, objects, buildClassDict("NSDictionary", "NSObject"))
object["capabilities-dictionary"] = dictRef
capsReference := len(objects)
objects = append(objects, object)
classref := capsReference + 1
object[class] = plist.UID(classref)
objects = append(objects, buildClassDict("XCTCapabilities", "NSObject"))
return objects, plist.UID(capsReference)
}
func archiveNSUUID(uid interface{}, objects []interface{}) ([]interface{}, plist.UID) {
nsuuid := uid.(NSUUID)
object := map[string]interface{}{}
object["NS.uuidbytes"] = nsuuid.uuidbytes
uuidReference := len(objects)
objects = append(objects, object)
classref := uuidReference + 1
object[class] = plist.UID(classref)
objects = append(objects, buildClassDict("NSUUID", "NSObject"))
return objects, plist.UID(uuidReference)
}
type NSURL struct {
path string
}
func NewNSURL(path string) NSURL {
return NSURL{path}
}
func archiveNSURL(nsurlInterface interface{}, objects []interface{}) ([]interface{}, plist.UID) {
nsurl := nsurlInterface.(NSURL)
object := map[string]interface{}{}
object["NS.base"] = plist.UID(0)
urlReference := len(objects)
objects = append(objects, object)
classref := urlReference + 1
object[class] = plist.UID(classref)
objects = append(objects, buildClassDict("NSURL", "NSObject"))
pathRef := classref + 1
object["NS.relative"] = plist.UID(pathRef)
objects = append(objects, fmt.Sprintf("file://%s", nsurl.path))
return objects, plist.UID(urlReference)
}
type DTActivityTraceTapMessage struct {
DTTapMessagePlist map[string]interface{}
}
func NewDTActivityTraceTapMessage(object map[string]interface{}, objects []interface{}) interface{} {
ref := object["DTTapMessagePlist"].(plist.UID)
plist, _ := extractDictionary(objects[ref].(map[string]interface{}), objects)
return DTActivityTraceTapMessage{DTTapMessagePlist: plist}
}
//TODO: make this nice, partially extracting objects is not really cool
type PartiallyExtractedXcTestConfig struct {
values map[string]interface{}
}
func NewXCTestConfigurationFromBytes(object map[string]interface{}, objects []interface{}) interface{} {
config := make(map[string]interface{}, len(object))
for k, v := range object {
value := v
uid, ok := v.(plist.UID)
if ok {
value = objects[uid]
}
config[k] = value
}
return PartiallyExtractedXcTestConfig{config}
}
type NSError struct {
ErrorCode uint64
Domain string
UserInfo map[string]interface{}
}
func NewNSError(object map[string]interface{}, objects []interface{}) interface{} {
errorCode := object["NSCode"].(uint64)
userInfo_ref := object["NSUserInfo"].(plist.UID)
domain_ref := object["NSDomain"].(plist.UID)
domain := objects[domain_ref].(string)
userinfo, _ := extractDictionary(objects[userInfo_ref].(map[string]interface{}), objects)
return NSError{ErrorCode: errorCode, Domain: domain, UserInfo: userinfo}
}
//Apples Reference Date is Jan 1st 2001 00:00
const nsReferenceDate = 978307200000
type NSDate struct {
Timestamp time.Time
}
type DTTapHeartbeatMessage struct {
DTTapMessagePlist map[string]interface{}
}
type XCTCapabilities struct {
CapabilitiesDictionary map[string]interface{}
}
func NewXCTCapabilities(object map[string]interface{}, objects []interface{}) interface{} {
ref := object["capabilities-dictionary"].(plist.UID)
plist, _ := extractDictionary(objects[ref].(map[string]interface{}), objects)
return XCTCapabilities{CapabilitiesDictionary: plist}
}
func NewDTTapHeartbeatMessage(object map[string]interface{}, objects []interface{}) interface{} {
ref := object["DTTapMessagePlist"].(plist.UID)
plist, _ := extractDictionary(objects[ref].(map[string]interface{}), objects)
return DTTapHeartbeatMessage{DTTapMessagePlist: plist}
}
func NewNSDate(object map[string]interface{}, objects []interface{}) interface{} {
value := object["NS.time"].(float64)
milliesFloat := (1000*value + nsReferenceDate)
millies := int64(milliesFloat)
time := time.Unix(0, millies*int64(time.Millisecond))
return NSDate{time}
}
func (n NSDate) String() string {
return fmt.Sprintf("%s", n.Timestamp)
}
type NSNull struct {
class string
}
func NewNSNullFromArchived(object map[string]interface{}, objects []interface{}) interface{} {
return NewNSNull()
}
func NewNSNull() interface{} {
return NSNull{"NSNull"}
}
func archiveNSNull(object interface{}, objects []interface{}) ([]interface{}, plist.UID) {
nsnull := map[string]interface{}{}
nsnullReference := len(objects)
objects = append(objects, nsnull)
objects = append(objects, buildClassDict("NSNull", "NSObject"))
nsnull[class] = plist.UID(nsnullReference + 1)
return objects, plist.UID(nsnullReference)
}
type NSMutableDictionary struct {
internalDict map[string]interface{}
}
func NewNSMutableDictionary(internalDict map[string]interface{}) interface{} {
return NSMutableDictionary{internalDict}
}
func archiveNSMutableDictionary(object interface{}, objects []interface{}) ([]interface{}, plist.UID) {
mut := object.(NSMutableDictionary)
return serializeMap(mut.internalDict, objects, buildClassDict("NSMutableDictionary", "NSDictionary", "NSObject"))
}