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 junit.framework.TestCase;
23  
24  import com.github.maven_nar.cpptasks.CCTask;
25  import com.github.maven_nar.cpptasks.ProcessorDef;
26  import com.github.maven_nar.cpptasks.VersionInfo;
27  
28  /**
29   * Test for abstract compiler class
30   *
31   * Override create to test concrete compiler implementions
32   */
33  public class TestAbstractProcessor extends TestCase {
34    private class DummyAbstractProcessor extends AbstractProcessor {
35      public DummyAbstractProcessor() {
36        super(new String[] {
37            ".cpp", ".c"
38        }, new String[] {
39            ".hpp", ".h", ".inl"
40        });
41      }
42  
43      @Override
44      public ProcessorConfiguration createConfiguration(final CCTask task, final LinkType linkType,
45          final ProcessorDef[] defaultProvider, final ProcessorDef specificProvider,
46          final com.github.maven_nar.cpptasks.TargetDef targetPlatform, final VersionInfo versionInfo) {
47        return null;
48      }
49  
50      @Override
51      public String getIdentifier() {
52        return "dummy";
53      }
54  
55      @Override
56      public Linker getLinker(final LinkType type) {
57        return null;
58      }
59  
60      @Override
61      public String[] getOutputFileNames(final String sourceFile, final VersionInfo versionInfo) {
62        return new String[0];
63      }
64  
65      public String[][] getRuntimeLibraries(final boolean debug, final boolean multithreaded, final boolean staticLink) {
66        return new String[2][0];
67      }
68    }
69  
70    public TestAbstractProcessor(final String name) {
71      super(name);
72    }
73  
74    protected AbstractProcessor create() {
75      return new DummyAbstractProcessor();
76    }
77  
78    public void failingtestBid() {
79      final AbstractProcessor compiler = create();
80      int bid = compiler.bid("c:/foo\\bar\\hello.c");
81      assertEquals(100, bid);
82      bid = compiler.bid("c:/foo\\bar/hello.c");
83      assertEquals(100, bid);
84      bid = compiler.bid("c:/foo\\bar\\hello.h");
85      assertEquals(1, bid);
86      bid = compiler.bid("c:/foo\\bar/hello.h");
87      assertEquals(1, bid);
88      bid = compiler.bid("c:/foo\\bar/hello.pas");
89      assertEquals(0, bid);
90      bid = compiler.bid("c:/foo\\bar/hello.java");
91      assertEquals(0, bid);
92    }
93  
94    public void testGetIdentfier() {
95      final AbstractProcessor compiler = create();
96      final String id = compiler.getIdentifier();
97      assertEquals("dummy", id);
98    }
99  }