Repository navigation
Expand file tree
/
Copy pathgroup.js
More file actions
350 lines (278 loc) · 11 KB
/
Copy pathgroup.js
File metadata and controls
350 lines (278 loc) · 11 KB
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
var pbx = require('../lib/pbxProject'),
project,
projectHash;
var findChildInGroup = function(obj, target) {
var found = false;
for (var i = 0, j = obj.children.length; i < j; i++) {
if (obj.children[i].value === target) {
found = true;
break;
}
}
return found;
}
var findFileByUUID = function(obj, target) {
var found = false;
for (var k = 0, l = obj.files.length; k < l; k++) {
if (obj.files[k].value === target) {
found = true;
break;
}
}
return found;
}
var findByFileRef = function(obj, target) {
var found = false;
for (var property in obj) {
if (!/comment/.test(property)) {
if (obj[property].fileRef === target) {
found = true;
break;
}
}
}
return found;
}
var findByName = function(obj, target) {
var found = false;
for (var property in obj) {
if (!/comment/.test(property)) {
var value = obj[property];
if (value.name === target) {
found = true;
}
}
}
return found;
}
exports.setUp = function(callback) {
project = new pbx('test/parser/projects/group.pbxproj');
projectHash = project.parseSync();
callback();
}
exports.getGroupByKey = {
'should return PBXGroup for Classes': function(test) {
var groupKey = project.findPBXGroupKey({name: 'Classes'});
var group = project.getPBXGroupByKey(groupKey);
test.ok(group.name === 'Classes');
test.done();
},
'should return PBXGroup for Plugins': function(test) {
var groupKey = project.findPBXGroupKey({name: 'Plugins'});
var group = project.getPBXGroupByKey(groupKey);
test.ok(group.name === 'Plugins');
test.done();
}
}
exports.createGroup = {
'should create a new Test Group': function(test) {
var found = false;
var groups = project.getPBXObject('PBXGroup');
var found = findByName(groups, 'Test');
test.ok(found === false);
var group = project.findPBXGroupKey({name:'Test'});
test.ok(group === undefined);
project.pbxCreateGroup('Test', 'Test');
groups = project.getPBXObject('PBXGroup');
found = findByName(groups, 'Test');
test.ok(found === true);
group = project.findPBXGroupKey({name:'Test'});
test.ok(typeof group === 'string');
test.done();
}
}
exports.findGroupKey = {
'should return a valid group key':function(test) {
var keyByName = project.findPBXGroupKey({ name: 'Classes'});
var keyByPath = project.findPBXGroupKey({ path: 'icons'});
var keyByPathName = project.findPBXGroupKey({ path: '"HelloCordova/Plugins"', name: 'Plugins'});
var nonExistingKey = project.findPBXGroupKey({ name: 'Foo'});
test.ok(keyByName === '080E96DDFE201D6D7F000001');
test.ok(keyByPath === '308D052D1370CCF300D202BF');
test.ok(keyByPathName === '307C750510C5A3420062BCA9');
test.ok(nonExistingKey === undefined);
test.done();
}
}
exports.addGroupToGroup = {
'should create a new test group then add group to Classes group': function(test) {
var testKey = project.pbxCreateGroup('Test', 'Test');
var classesKey = project.findPBXGroupKey({name: 'Classes'});
project.addToPbxGroup(testKey, classesKey);
var classesGroup = project.getPBXGroupByKey(classesKey);
var foundTestGroup = false;
for (var i = 0, j = classesGroup.children.length; i < j; i++) {
var child = classesGroup.children[i];
if (child.value === testKey && child.comment === 'Test') {
foundTestGroup = true;
}
}
test.ok(foundTestGroup);
test.done();
}
}
exports.addSourceFileToGroup = {
'should create group + add source file' : function(test) {
var testKey = project.pbxCreateGroup('Test', 'Test');
var file = project.addSourceFile('Notifications.m', {}, testKey);
var foundInGroup = findChildInGroup(project.getPBXGroupByKey(testKey),file.fileRef );
test.ok(foundInGroup);
var foundInBuildFileSection = findByFileRef(project.pbxBuildFileSection(), file.fileRef);
test.ok(foundInBuildFileSection);
var foundInBuildPhase = findFileByUUID(project.pbxSourcesBuildPhaseObj(), file.uuid);
test.ok(foundInBuildPhase);
test.done();
}
}
exports.removeSourceFileFromGroup = {
'should create group + add source file then remove source file' : function(test) {
var testKey = project.pbxCreateGroup('Test', 'Test');
var file = project.addSourceFile('Notifications.m', {}, testKey);
var foundInGroup = findChildInGroup(project.getPBXGroupByKey(testKey),file.fileRef );
test.ok(foundInGroup);
var foundInBuildFileSection = findByFileRef(project.pbxBuildFileSection(), file.fileRef);
test.ok(foundInBuildFileSection);
var foundInBuildPhase = findFileByUUID(project.pbxSourcesBuildPhaseObj(), file.uuid);
test.ok(foundInBuildPhase);
project.removeSourceFile('Notifications.m', {}, testKey);
var foundInGroup = findChildInGroup(project.getPBXGroupByKey(testKey),file.fileRef );
test.ok(!foundInGroup);
var foundInBuildFileSection = findByFileRef(project.pbxBuildFileSection(), file.fileRef);
test.ok(!foundInBuildFileSection);
var foundInBuildPhase = findFileByUUID(project.pbxSourcesBuildPhaseObj(), file.uuid);
test.ok(!foundInBuildPhase);
test.done();
}
}
exports.addHeaderFileToGroup = {
'should create group + add header file' : function(test) {
var testKey = project.pbxCreateGroup('Test', 'Test');
var file = project.addHeaderFile('Notifications.h', {}, testKey);
var foundInGroup = findChildInGroup(project.getPBXGroupByKey(testKey),file.fileRef );
test.ok(foundInGroup);
test.done();
}
}
exports.removeHeaderFileFromGroup = {
'should create group + add source file then remove header file' : function(test) {
var testKey = project.pbxCreateGroup('Test', 'Test');
var file = project.addHeaderFile('Notifications.h', {}, testKey);
var foundInGroup = findChildInGroup(project.getPBXGroupByKey(testKey),file.fileRef );
test.ok(foundInGroup);
project.removeHeaderFile('Notifications.h', {}, testKey);
var foundInGroup = findChildInGroup(project.getPBXGroupByKey(testKey),file.fileRef );
test.ok(!foundInGroup);
test.done();
}
}
exports.addResourceFileToGroup = {
'should add resource file (PNG) to the splash group' : function(test) {
var testKey = project.findPBXGroupKey({path:'splash'});
var file = project.addResourceFile('DefaultTest-667h.png', {}, testKey);
var foundInGroup = findChildInGroup(project.getPBXGroupByKey(testKey),file.fileRef );
test.ok(foundInGroup);
test.done();
}
}
exports.removeResourceFileFromGroup = {
'should add resource file (PNG) then remove resource file from splash group' : function(test) {
var testKey = project.findPBXGroupKey({path:'splash'});
var file = project.addResourceFile('DefaultTest-667h.png', {}, testKey);
var foundInGroup = findChildInGroup(project.getPBXGroupByKey(testKey),file.fileRef );
test.ok(foundInGroup);
project.removeResourceFile('DefaultTest-667h.png', {}, testKey);
var foundInGroup = findChildInGroup(project.getPBXGroupByKey(testKey),file.fileRef );
test.ok(!foundInGroup);
test.done();
}
}
exports.retrieveBuildPropertyForBuild = {
'should retrieve valid build property ':function(test) {
var releaseTargetedDeviceFamily = project.getBuildProperty('TARGETED_DEVICE_FAMILY', 'Release');
var debugTargetedDeviceFamily = project.getBuildProperty('TARGETED_DEVICE_FAMILY', 'Debug');
var nonExistingProperty = project.getBuildProperty('FOO', 'Debug');
var nonExistingBuild = project.getBuildProperty('TARGETED_DEVICE_FAMILY', 'Foo');
test.equal(releaseTargetedDeviceFamily, '"1,2"');
test.equal(debugTargetedDeviceFamily,'"1"');
test.equal(nonExistingProperty, undefined);
test.equal(nonExistingBuild, undefined);
test.done();
}
}
exports.retrieveBuildConfigByName = {
'should retrieve valid build config':function(test) {
var releaseBuildConfig = project.getBuildConfigByName('Release');
for (var property in releaseBuildConfig) {
var value = releaseBuildConfig[property];
test.ok(value.name === 'Release');
}
var debugBuildConfig = project.getBuildConfigByName('Debug');
for (var property in debugBuildConfig) {
var value = debugBuildConfig[property];
test.ok(value.name === 'Debug');
}
var nonExistingBuildConfig = project.getBuildConfigByName('Foo');
test.deepEqual(nonExistingBuildConfig, {});
test.done();
}
}
/* This proves the issue in 0.6.7
exports.validatePropReplaceException = {
'should throw TypeError for updateBuildProperty VALID_ARCHS when none existed' : function(test) {
test.throws(
function() {
project.updateBuildProperty('VALID_ARCHS', '"armv7 armv7s');
},
TypeError,
"Object object has no method 'hasOwnProperty'"
);
test.done();
}
}
*/
exports.validatePropReplaceFix = {
'should create build configuration for VALID_ARCHS when none existed' : function(test) {
project.updateBuildProperty('VALID_ARCHS', '"armv7 armv7s"', 'Debug');
test.done();
}
}
exports.validateHasFile = {
'should return true for has file MainViewController.m': function(test) {
var result = project.hasFile('MainViewController.m');
test.ok(result.path == "MainViewController.m");
test.done();
}
}
exports.testWritingPBXProject = {
'should successfully write to PBXProject TargetAttributes': function(test) {
var pbxProjectObj = project.getPBXObject('PBXProject');
var pbxProject;
for (var property in pbxProjectObj) {
if (!/comment/.test(property)) {
pbxProject = pbxProjectObj[property];
}
}
var target;
var projectTargets = pbxProject.targets;
for (var i = 0, j = pbxProject.targets.length; i < j; i++ ) {
target = pbxProject.targets[i].value;
}
pbxProject.attributes.TargetAttributes = {};
pbxProject.attributes.TargetAttributes[target] = {
DevelopmentTeam: 'N6X4RJZZ5D',
SystemCapabilities: {
"com.apple.BackgroundModes": {
enabled : 0
},
"com.apple.DataProtection" : {
enabled : 0
},
"com.apple.Keychain" : {
enabled: 1
}
}
};
var output = project.writeSync();
test.done();
}
}