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 org.apache.tools.ant.BuildException;
25  
26  import com.github.maven_nar.cpptasks.CCTask;
27  import com.github.maven_nar.cpptasks.CompilerDef;
28  import com.github.maven_nar.cpptasks.ProcessorDef;
29  import com.github.maven_nar.cpptasks.VersionInfo;
30  import com.github.maven_nar.cpptasks.parser.CParser;
31  import com.github.maven_nar.cpptasks.parser.Parser;
32  
33  /**
34   * Test for abstract compiler class
35   *
36   * Override create to test concrete compiler implementions
37   */
38  public class TestAbstractCompiler extends TestAbstractProcessor {
39    private class DummyAbstractCompiler extends AbstractCompiler {
40      public DummyAbstractCompiler() {
41        super(new String[] {
42            ".cpp", ".c"
43        }, new String[] {
44            ".hpp", ".h", ".inl"
45        }, ".o");
46      }
47  
48      public void compile(final CCTask task, final File[] srcfile, final File[] outputfile,
49          final CompilerConfiguration config) throws BuildException {
50        throw new BuildException("Not implemented");
51      }
52  
53      @Override
54      public CompilerConfiguration createConfiguration(final CCTask task, final LinkType linkType,
55          final ProcessorDef[] def1, final CompilerDef def2,
56          final com.github.maven_nar.cpptasks.TargetDef targetPlatform, final VersionInfo versionInfo) {
57        return null;
58      }
59  
60      @Override
61      public Parser createParser(final File file) {
62        return new CParser();
63      }
64  
65      @Override
66      public String getIdentifier() {
67        return "dummy";
68      }
69  
70      @Override
71      public Linker getLinker(final LinkType type) {
72        return null;
73      }
74    }
75  
76    public TestAbstractCompiler(final String name) {
77      super(name);
78    }
79  
80    @Override
81    protected AbstractProcessor create() {
82      return new DummyAbstractCompiler();
83    }
84  
85    public void failingtestGetOutputFileName1() {
86      final AbstractProcessor compiler = create();
87      String[] output = compiler.getOutputFileNames("c:/foo\\bar\\hello.c", null);
88      assertEquals("hello" + getObjectExtension(), output[0]);
89      output = compiler.getOutputFileNames("c:/foo\\bar/hello.c", null);
90      assertEquals("hello" + getObjectExtension(), output[0]);
91      output = compiler.getOutputFileNames("hello.c", null);
92      assertEquals("hello" + getObjectExtension(), output[0]);
93      output = compiler.getOutputFileNames("c:/foo\\bar\\hello.h", null);
94      assertEquals(0, output.length);
95      output = compiler.getOutputFileNames("c:/foo\\bar/hello.h", null);
96      assertEquals(0, output.length);
97    }
98  
99    protected String getObjectExtension() {
100     return ".o";
101   }
102 
103   public void testCanParseTlb() {
104     final AbstractCompiler compiler = (AbstractCompiler) create();
105     assertEquals(false, compiler.canParse(new File("sample.tlb")));
106   }
107 }