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.compiler;
21  
22  import java.io.File;
23  
24  import com.github.maven_nar.cpptasks.CCTask;
25  import com.github.maven_nar.cpptasks.LinkerDef;
26  import com.github.maven_nar.cpptasks.ProcessorDef;
27  import com.github.maven_nar.cpptasks.TargetDef;
28  import com.github.maven_nar.cpptasks.VersionInfo;
29  import com.github.maven_nar.cpptasks.types.LibraryTypeEnum;
30  
31  /**
32   * Test for abstract compiler class
33   *
34   * Override create to test concrete compiler implementions
35   */
36  public class TestAbstractLinker extends TestAbstractProcessor {
37    private class DummyAbstractLinker extends AbstractLinker {
38      public DummyAbstractLinker() {
39        super(new String[] {
40            ".obj", ".lib"
41        }, new String[] {
42            ".map", ".exp"
43        });
44      }
45  
46      @Override
47      public LinkerConfiguration createConfiguration(final CCTask task, final LinkType linkType,
48          final ProcessorDef[] def1, final LinkerDef def2, final TargetDef targetPlatform, final VersionInfo versionInfo) {
49        return null;
50      }
51  
52      @Override
53      public String getIdentifier() {
54        return "dummy";
55      }
56  
57      @Override
58      public File[] getLibraryPath() {
59        return new File[0];
60      }
61  
62      @Override
63      public String[] getLibraryPatterns(final String[] libnames, final LibraryTypeEnum libType) {
64        return libnames;
65      }
66  
67      @Override
68      public Linker getLinker(final LinkType type) {
69        return null;
70      }
71  
72      @Override
73      public String[] getOutputFileNames(final String sourceFile, final VersionInfo versionInfo) {
74        return new String[0];
75      }
76  
77      public String[][] getRuntimeLibraries(final boolean debug, final boolean multithreaded, final boolean staticLink) {
78        return new String[2][0];
79      }
80  
81      @Override
82      public boolean isCaseSensitive() {
83        return true;
84      }
85    }
86  
87    public TestAbstractLinker(final String name) {
88      super(name);
89    }
90  
91    @Override
92    protected AbstractProcessor create() {
93      return new DummyAbstractLinker();
94    }
95  
96    public void testBid() {
97      final AbstractProcessor compiler = create();
98      int bid = compiler.bid("c:/foo\\bar\\hello.obj");
99      assertEquals(100, bid);
100     bid = compiler.bid("c:/foo\\bar/hello.lib");
101     assertEquals(100, bid);
102     bid = compiler.bid("c:/foo\\bar\\hello.map");
103     assertEquals(0, bid);
104     bid = compiler.bid("c:/foo\\bar/hello.map");
105     assertEquals(0, bid);
106     bid = compiler.bid("c:/foo\\bar/hello.c");
107     assertEquals(1, bid);
108     bid = compiler.bid("c:/foo\\bar/hello.cpp");
109     assertEquals(1, bid);
110   }
111 }