View Javadoc

1   /*
2    * #%L
3    * Native ARchive plugin for Maven
4    * %%
5    * Copyright (C) 2002 - 2014 NAR Maven Plugin developers.
6    * %%
7    * Licensed under the Apache License, Version 2.0 (the "License");
8    * you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   * 
11   * http://www.apache.org/licenses/LICENSE-2.0
12   * 
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   * #L%
19   */
20  package com.github.maven_nar.cpptasks.gcc;
21  
22  import junit.framework.TestCase;
23  
24  import com.github.maven_nar.cpptasks.OutputTypeEnum;
25  import com.github.maven_nar.cpptasks.compiler.LinkType;
26  import com.github.maven_nar.cpptasks.compiler.Linker;
27  
28  /**
29   * @author CurtA
30   */
31  public class TestGccLinker extends TestCase {
32    private final String realOSName;
33  
34    /**
35     * Constructor
36     * 
37     * @param name
38     *          test name
39     */
40    public TestGccLinker(final String name) {
41      super(name);
42      this.realOSName = System.getProperty("os.name");
43    }
44  
45    @Override
46    protected void tearDown() throws java.lang.Exception {
47      System.setProperty("os.name", this.realOSName);
48    }
49  
50    public void testGetLinkerDarwinPlugin() {
51      System.setProperty("os.name", "Mac OS X");
52      final GccLinker linker = GccLinker.getInstance();
53      final OutputTypeEnum outputType = new OutputTypeEnum();
54      outputType.setValue("plugin");
55      final LinkType linkType = new LinkType();
56      linkType.setOutputType(outputType);
57      final Linker pluginLinker = linker.getLinker(linkType);
58      assertEquals("libfoo.bundle", pluginLinker.getOutputFileNames("foo", null)[0]);
59    }
60  
61    public void testGetLinkerDarwinShared() {
62      System.setProperty("os.name", "Mac OS X");
63      final GccLinker linker = GccLinker.getInstance();
64      final OutputTypeEnum outputType = new OutputTypeEnum();
65      outputType.setValue("shared");
66      final LinkType linkType = new LinkType();
67      linkType.setOutputType(outputType);
68      final Linker sharedLinker = linker.getLinker(linkType);
69      assertEquals("libfoo.dylib", sharedLinker.getOutputFileNames("foo", null)[0]);
70    }
71  
72    public void testGetLinkerNonDarwinPlugin() {
73      System.setProperty("os.name", "Microsoft Windows");
74      final GccLinker linker = GccLinker.getInstance();
75      final OutputTypeEnum outputType = new OutputTypeEnum();
76      outputType.setValue("plugin");
77      final LinkType linkType = new LinkType();
78      linkType.setOutputType(outputType);
79      final Linker pluginLinker = linker.getLinker(linkType);
80      assertEquals("libfoo.so", pluginLinker.getOutputFileNames("foo", null)[0]);
81    }
82  
83    public void testGetLinkerNonDarwinShared() {
84      System.setProperty("os.name", "Microsoft Windows");
85      final GccLinker linker = GccLinker.getInstance();
86      final OutputTypeEnum outputType = new OutputTypeEnum();
87      outputType.setValue("shared");
88      final LinkType linkType = new LinkType();
89      linkType.setOutputType(outputType);
90      final Linker sharedLinker = linker.getLinker(linkType);
91      assertEquals("libfoo.so", sharedLinker.getOutputFileNames("foo", null)[0]);
92    }
93  }