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
|
/*
*
* Copyright 2003-2004 The Ant-Contrib project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.sf.antcontrib.cpptasks.gcc;
import java.io.File;
import java.util.Vector;
import junit.framework.TestCase;
import net.sf.antcontrib.cpptasks.CCTask;
import net.sf.antcontrib.cpptasks.CUtil;
import net.sf.antcontrib.cpptasks.OutputTypeEnum;
import net.sf.antcontrib.cpptasks.compiler.LinkType;
import net.sf.antcontrib.cpptasks.types.LibrarySet;
import net.sf.antcontrib.cpptasks.types.LibraryTypeEnum;
/**
* Test ld linker adapter abstract base class
*
* Override create to test concrete compiler implementions
*/
public class TestAbstractLdLinker extends TestCase {
private final String realOSName;
public TestAbstractLdLinker(String name) {
super(name);
realOSName = System.getProperty("os.name");
}
protected AbstractLdLinker getLinker() {
return GccLinker.getInstance();
}
protected void tearDown() throws java.lang.Exception {
System.setProperty("os.name", realOSName);
}
/**
* Checks for proper arguments for plugin generation on Darwin
*
* See [ 676276 ] Enhanced support for Mac OS X
*/
public void testAddImpliedArgsDarwinPlugin() {
System.setProperty("os.name", "Mac OS X");
AbstractLdLinker linker = getLinker();
Vector args = new Vector();
LinkType pluginType = new LinkType();
OutputTypeEnum pluginOutType = new OutputTypeEnum();
pluginOutType.setValue("plugin");
pluginType.setOutputType(pluginOutType);
linker.addImpliedArgs(false, pluginType, args);
assertEquals(1, args.size());
assertEquals("-bundle", args.elementAt(0));
}
/**
* Checks for proper arguments for shared generation on Darwin
*
* See [ 676276 ] Enhanced support for Mac OS X
*/
public void testAddImpliedArgsDarwinShared() {
System.setProperty("os.name", "Mac OS X");
AbstractLdLinker linker = getLinker();
Vector args = new Vector();
LinkType pluginType = new LinkType();
OutputTypeEnum pluginOutType = new OutputTypeEnum();
pluginOutType.setValue("shared");
pluginType.setOutputType(pluginOutType);
linker.addImpliedArgs(false, pluginType, args);
assertEquals(2, args.size());
assertEquals("-prebind", args.elementAt(0));
assertEquals("-dynamiclib", args.elementAt(1));
}
/**
* Checks for proper arguments for plugin generation on Darwin
*
* See [ 676276 ] Enhanced support for Mac OS X
*/
public void testAddImpliedArgsNonDarwinPlugin() {
System.setProperty("os.name", "VAX/VMS");
AbstractLdLinker linker = getLinker();
Vector args = new Vector();
LinkType pluginType = new LinkType();
OutputTypeEnum pluginOutType = new OutputTypeEnum();
pluginOutType.setValue("plugin");
pluginType.setOutputType(pluginOutType);
linker.addImpliedArgs(false, pluginType, args);
assertEquals(1, args.size());
assertEquals("-shared", args.elementAt(0));
}
/**
* Checks for proper arguments for shared generation on Darwin
*
* See [ 676276 ] Enhanced support for Mac OS X
*/
public void testAddImpliedArgsNonDarwinShared() {
System.setProperty("os.name", "VAX/VMS");
AbstractLdLinker linker = getLinker();
Vector args = new Vector();
LinkType pluginType = new LinkType();
OutputTypeEnum pluginOutType = new OutputTypeEnum();
pluginOutType.setValue("shared");
pluginType.setOutputType(pluginOutType);
linker.addImpliedArgs(false, pluginType, args);
assertEquals(1, args.size());
assertEquals("-shared", args.elementAt(0));
}
public void testAddLibrarySetDirSwitch() {
AbstractLdLinker linker = getLinker();
CCTask task = new CCTask();
LibrarySet[] sets = new LibrarySet[]{new LibrarySet()};
/* throws an Exception in setLibs otherwise */
sets[0].setProject(new org.apache.tools.ant.Project());
sets[0].setDir(new File("/foo"));
sets[0].setLibs(new CUtil.StringArrayBuilder("bart,cart,dart"));
Vector preargs = new Vector();
Vector midargs = new Vector();
Vector endargs = new Vector();
String[] rc = linker.addLibrarySets(task, sets, preargs, midargs,
endargs);
String libdirSwitch = (String) endargs.elementAt(0);
assertEquals(libdirSwitch.substring(0, 2), "-L");
//
// can't have space after -L or will break Mac OS X
//
assertTrue(!libdirSwitch.substring(2, 3).equals(" "));
assertEquals(libdirSwitch.substring(libdirSwitch.length() - 3), "foo");
}
public void testAddLibrarySetLibSwitch() {
AbstractLdLinker linker = getLinker();
CCTask task = new CCTask();
LibrarySet[] sets = new LibrarySet[]{new LibrarySet()};
/* throws an Exception in setLibs otherwise */
sets[0].setProject(new org.apache.tools.ant.Project());
sets[0].setDir(new File("/foo"));
sets[0].setLibs(new CUtil.StringArrayBuilder("bart,cart,dart"));
Vector preargs = new Vector();
Vector midargs = new Vector();
Vector endargs = new Vector();
String[] rc = linker.addLibrarySets(task, sets, preargs, midargs,
endargs);
assertEquals("-lbart", (String) endargs.elementAt(1));
assertEquals("-lcart", (String) endargs.elementAt(2));
assertEquals("-ldart", (String) endargs.elementAt(3));
assertEquals(endargs.size(), 4);
}
public void testAddLibrarySetLibFrameworkNonDarwin() {
System.setProperty("os.name", "VAX/VMS");
AbstractLdLinker linker = getLinker();
CCTask task = new CCTask();
LibrarySet[] sets = new LibrarySet[]{new LibrarySet()};
/* throws an Exception in setLibs otherwise */
sets[0].setProject(new org.apache.tools.ant.Project());
sets[0].setDir(new File("/foo"));
LibraryTypeEnum libType = new LibraryTypeEnum();
libType.setValue("framework");
sets[0].setType(libType);
sets[0].setLibs(new CUtil.StringArrayBuilder("bart,cart,dart"));
Vector preargs = new Vector();
Vector midargs = new Vector();
Vector endargs = new Vector();
String[] rc = linker.addLibrarySets(task, sets, preargs, midargs,
endargs);
assertEquals("-L", ((String) endargs.elementAt(0)).substring(0, 2));
assertEquals("-Bdynamic", (String) endargs.elementAt(1));
assertEquals("-lbart", (String) endargs.elementAt(2));
assertEquals("-lcart", (String) endargs.elementAt(3));
assertEquals("-ldart", (String) endargs.elementAt(4));
assertEquals(endargs.size(), 5);
}
public void testAddLibrarySetLibFrameworkDarwin() {
System.setProperty("os.name", "Mac OS X");
AbstractLdLinker linker = getLinker();
CCTask task = new CCTask();
LibrarySet[] sets = new LibrarySet[]{new LibrarySet()};
/* throws an Exception in setLibs otherwise */
sets[0].setProject(new org.apache.tools.ant.Project());
sets[0].setDir(new File("/foo"));
LibraryTypeEnum libType = new LibraryTypeEnum();
libType.setValue("framework");
sets[0].setType(libType);
sets[0].setLibs(new CUtil.StringArrayBuilder("bart,cart,dart"));
Vector preargs = new Vector();
Vector midargs = new Vector();
Vector endargs = new Vector();
String[] rc = linker.addLibrarySets(task, sets, preargs, midargs,
endargs);
assertEquals("-F", ((String) endargs.elementAt(0)).substring(0, 2));
assertEquals("-framework bart", (String) endargs.elementAt(1));
assertEquals("-framework cart", (String) endargs.elementAt(2));
assertEquals("-framework dart", (String) endargs.elementAt(3));
assertEquals(endargs.size(), 4);
}
public void testAddLibraryStatic() {
AbstractLdLinker linker = getLinker();
CCTask task = new CCTask();
LibrarySet[] sets = new LibrarySet[]{
new LibrarySet(),
new LibrarySet(),
new LibrarySet()};
/* throws an Exception in setLibs otherwise */
sets[0].setProject(new org.apache.tools.ant.Project());
sets[0].setLibs(new CUtil.StringArrayBuilder("bart"));
sets[1].setProject(new org.apache.tools.ant.Project());
sets[1].setLibs(new CUtil.StringArrayBuilder("cart"));
LibraryTypeEnum libType = new LibraryTypeEnum();
libType.setValue("static");
sets[1].setType(libType);
sets[2].setProject(new org.apache.tools.ant.Project());
sets[2].setLibs(new CUtil.StringArrayBuilder("dart"));
Vector preargs = new Vector();
Vector midargs = new Vector();
Vector endargs = new Vector();
String[] rc = linker.addLibrarySets(task, sets, preargs, midargs,
endargs);
assertEquals("-lbart", (String) endargs.elementAt(0));
assertEquals("-Bstatic", (String) endargs.elementAt(1));
assertEquals("-lcart", (String) endargs.elementAt(2));
assertEquals("-Bdynamic", (String) endargs.elementAt(3));
assertEquals("-ldart", (String) endargs.elementAt(4));
assertEquals(endargs.size(), 5);
}
public void testLibReturnValue() {
AbstractLdLinker linker = getLinker();
CCTask task = new CCTask();
LibrarySet[] sets = new LibrarySet[]{new LibrarySet()};
/* throws an Exception in setLibs otherwise */
sets[0].setProject(new org.apache.tools.ant.Project());
sets[0].setDir(new File("/foo"));
sets[0].setLibs(new CUtil.StringArrayBuilder("bart,cart,dart"));
Vector preargs = new Vector();
Vector midargs = new Vector();
Vector endargs = new Vector();
String[] rc = linker.addLibrarySets(task, sets, preargs, midargs,
endargs);
assertEquals(3, rc.length);
assertEquals("bart", rc[0]);
assertEquals("cart", rc[1]);
assertEquals("dart", rc[2]);
}
}
|