|
| 1 | +var fullProject = require('./fixtures/full-project') |
| 2 | + fullProjectStr = JSON.stringify(fullProject), |
| 3 | + pbx = require('../lib/pbxProject'), |
| 4 | + pbxFile = require('../lib/pbxFile'), |
| 5 | + proj = new pbx('.'); |
| 6 | + |
| 7 | +function cleanHash() { |
| 8 | + return JSON.parse(fullProjectStr); |
| 9 | +} |
| 10 | + |
| 11 | +function nonComments(obj) { |
| 12 | + var keys = Object.keys(obj), |
| 13 | + newObj = {}, i = 0; |
| 14 | + |
| 15 | + for (i; i < keys.length; i++) { |
| 16 | + if (!/_comment$/.test(keys[i])) { |
| 17 | + newObj[keys[i]] = obj[keys[i]]; |
| 18 | + } |
| 19 | + } |
| 20 | + |
| 21 | + return newObj; |
| 22 | +} |
| 23 | + |
| 24 | +exports.setUp = function (callback) { |
| 25 | + proj.hash = cleanHash(); |
| 26 | + callback(); |
| 27 | +} |
| 28 | + |
| 29 | +exports.addStaticLibrary = { |
| 30 | + 'should return a pbxFile': function (test) { |
| 31 | + var newFile = proj.addStaticLibrary('libGoogleAnalytics.a'); |
| 32 | + |
| 33 | + test.equal(newFile.constructor, pbxFile); |
| 34 | + test.done() |
| 35 | + }, |
| 36 | + 'should set a fileRef on the pbxFile': function (test) { |
| 37 | + var newFile = proj.addStaticLibrary('libGoogleAnalytics.a'); |
| 38 | + |
| 39 | + test.ok(newFile.fileRef); |
| 40 | + test.done() |
| 41 | + }, |
| 42 | + 'should populate the PBXBuildFile section with 2 fields': function (test) { |
| 43 | + var newFile = proj.addStaticLibrary('libGoogleAnalytics.a'); |
| 44 | + buildFileSection = proj.pbxBuildFileSection(), |
| 45 | + bfsLength = Object.keys(buildFileSection).length; |
| 46 | + |
| 47 | + test.equal(60, bfsLength); |
| 48 | + test.ok(buildFileSection[newFile.uuid]); |
| 49 | + test.ok(buildFileSection[newFile.uuid + '_comment']); |
| 50 | + |
| 51 | + test.done(); |
| 52 | + }, |
| 53 | + 'should add the PBXBuildFile comment correctly': function (test) { |
| 54 | + var newFile = proj.addStaticLibrary('libGoogleAnalytics.a'); |
| 55 | + commentKey = newFile.uuid + '_comment', |
| 56 | + buildFileSection = proj.pbxBuildFileSection(); |
| 57 | + |
| 58 | + test.equal(buildFileSection[commentKey], 'libGoogleAnalytics.a in Frameworks'); |
| 59 | + test.done(); |
| 60 | + }, |
| 61 | + 'should add the PBXBuildFile object correctly': function (test) { |
| 62 | + var newFile = proj.addStaticLibrary('libGoogleAnalytics.a'); |
| 63 | + buildFileSection = proj.pbxBuildFileSection(), |
| 64 | + buildFileEntry = buildFileSection[newFile.uuid]; |
| 65 | + |
| 66 | + test.equal(buildFileEntry.isa, 'PBXBuildFile'); |
| 67 | + test.equal(buildFileEntry.fileRef, newFile.fileRef); |
| 68 | + test.equal(buildFileEntry.fileRef_comment, 'libGoogleAnalytics.a'); |
| 69 | + |
| 70 | + test.done(); |
| 71 | + }, |
| 72 | + 'should populate the PBXFileReference section with 2 fields': function (test) { |
| 73 | + var newFile = proj.addStaticLibrary('libGoogleAnalytics.a'); |
| 74 | + fileRefSection = proj.pbxFileReferenceSection(), |
| 75 | + frsLength = Object.keys(fileRefSection).length; |
| 76 | + |
| 77 | + test.equal(68, frsLength); |
| 78 | + test.ok(fileRefSection[newFile.fileRef]); |
| 79 | + test.ok(fileRefSection[newFile.fileRef + '_comment']); |
| 80 | + |
| 81 | + test.done(); |
| 82 | + }, |
| 83 | + 'should populate the PBXFileReference comment correctly': function (test) { |
| 84 | + var newFile = proj.addStaticLibrary('libGoogleAnalytics.a'); |
| 85 | + fileRefSection = proj.pbxFileReferenceSection(), |
| 86 | + commentKey = newFile.fileRef + '_comment'; |
| 87 | + |
| 88 | + test.equal(fileRefSection[commentKey], 'libGoogleAnalytics.a'); |
| 89 | + test.done(); |
| 90 | + }, |
| 91 | + 'should add the PBXFileReference object correctly': function (test) { |
| 92 | + var newFile = proj.addStaticLibrary('libGoogleAnalytics.a'), |
| 93 | + fileRefSection = proj.pbxFileReferenceSection(), |
| 94 | + fileRefEntry = fileRefSection[newFile.fileRef]; |
| 95 | + |
| 96 | + test.equal(fileRefEntry.isa, 'PBXFileReference'); |
| 97 | + test.equal(fileRefEntry.lastKnownFileType, 'archive.ar'); |
| 98 | + test.equal(fileRefEntry.name, 'libGoogleAnalytics.a'); |
| 99 | + test.equal(fileRefEntry.path, 'libGoogleAnalytics.a'); |
| 100 | + test.equal(fileRefEntry.sourceTree, '"<group>"'); |
| 101 | + |
| 102 | + test.done(); |
| 103 | + }, |
| 104 | + 'should add to the PBXFrameworksBuildPhase': function (test) { |
| 105 | + var newFile = proj.addStaticLibrary('libGoogleAnalytics.a'), |
| 106 | + frameworks = proj.pbxFrameworksBuildPhaseObj(); |
| 107 | + |
| 108 | + test.equal(frameworks.files.length, 16); |
| 109 | + test.done(); |
| 110 | + }, |
| 111 | + 'should have the right values for the Sources entry': function (test) { |
| 112 | + var newFile = proj.addStaticLibrary('libGoogleAnalytics.a'), |
| 113 | + frameworks = proj.pbxFrameworksBuildPhaseObj(), |
| 114 | + framework = frameworks.files[15]; |
| 115 | + |
| 116 | + test.equal(framework.comment, 'libGoogleAnalytics.a in Frameworks'); |
| 117 | + test.equal(framework.value, newFile.uuid); |
| 118 | + test.done(); |
| 119 | + }, |
| 120 | + 'should set LIBRARY_SEARCH_PATHS for appropriate build configurations': function (test) { |
| 121 | + var newFile = proj.addStaticLibrary('libGoogleAnalytics.a'), |
| 122 | + configs = nonComments(proj.pbxXCBuildConfigurationSection()), |
| 123 | + ids = Object.keys(configs), i, buildSettings; |
| 124 | + |
| 125 | + for (i = 0; i< ids.length; i++) { |
| 126 | + buildSettings = configs[ids[i]].buildSettings; |
| 127 | + |
| 128 | + if (buildSettings['PRODUCT_NAME'] == '"KitchenSinktablet"') { |
| 129 | + test.ok(buildSettings['LIBRARY_SEARCH_PATHS']); |
| 130 | + } |
| 131 | + } |
| 132 | + |
| 133 | + test.done(); |
| 134 | + }, |
| 135 | + 'should ensure LIBRARY_SEARCH_PATHS inherits defaults correctly': function (test) { |
| 136 | + var newFile = proj.addStaticLibrary('libGoogleAnalytics.a'), |
| 137 | + configs = nonComments(proj.pbxXCBuildConfigurationSection()), |
| 138 | + ids = Object.keys(configs), i, current, buildSettings; |
| 139 | + |
| 140 | + for (i = 0; i< ids.length; i++) { |
| 141 | + buildSettings = configs[ids[i]].buildSettings; |
| 142 | + |
| 143 | + if (buildSettings['PRODUCT_NAME'] == '"KitchenSinktablet"') { |
| 144 | + current = buildSettings['LIBRARY_SEARCH_PATHS']; |
| 145 | + |
| 146 | + test.ok(current.indexOf('"$(inherited)"') >= 0) |
| 147 | + } |
| 148 | + } |
| 149 | + |
| 150 | + test.done(); |
| 151 | + }, |
| 152 | + 'should ensure the new library is in LIBRARY_SEARCH_PATHS': function (test) { |
| 153 | + var newFile = proj.addStaticLibrary('libGoogleAnalytics.a'), |
| 154 | + configs = nonComments(proj.pbxXCBuildConfigurationSection()), |
| 155 | + expectedPath = '"\\"$(SRCROOT)/KitchenSinktablet\\""', |
| 156 | + ids = Object.keys(configs), i, current, buildSettings; |
| 157 | + |
| 158 | + for (i = 0; i< ids.length; i++) { |
| 159 | + buildSettings = configs[ids[i]].buildSettings; |
| 160 | + |
| 161 | + if (buildSettings['PRODUCT_NAME'] == '"KitchenSinktablet"') { |
| 162 | + current = buildSettings['LIBRARY_SEARCH_PATHS']; |
| 163 | + |
| 164 | + test.ok(current.indexOf(expectedPath) >= 0) |
| 165 | + } |
| 166 | + } |
| 167 | + |
| 168 | + test.done(); |
| 169 | + } |
| 170 | +} |
0 commit comments