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  /**
25   */
26  public abstract class TestCompilerConfiguration extends TestCase {
27    public TestCompilerConfiguration(final String name) {
28      super(name);
29    }
30  
31    protected abstract CompilerConfiguration create();
32  
33    public String getObjectFileExtension() {
34      return ".o";
35    }
36  
37    public void testBid() {
38      final CompilerConfiguration compiler = create();
39      int bid = compiler.bid("c:/foo\\bar\\hello.c");
40      assertEquals(100, bid);
41      bid = compiler.bid("c:/foo\\bar/hello.c");
42      assertEquals(100, bid);
43      bid = compiler.bid("c:/foo\\bar\\hello.h");
44      assertEquals(1, bid);
45      bid = compiler.bid("c:/foo\\bar/hello.h");
46      assertEquals(1, bid);
47      bid = compiler.bid("c:/foo\\bar/hello.pas");
48      assertEquals(0, bid);
49      bid = compiler.bid("c:/foo\\bar/hello.java");
50      assertEquals(0, bid);
51    }
52  
53    public void testGetOutputFileName1() {
54      final CompilerConfiguration compiler = create();
55      final String input = "c:/foo\\bar\\hello.c";
56      //
57      // may cause IllegalStateException since
58      // setPlatformInfo has not been called
59      try {
60        final String[] output = compiler.getOutputFileNames(input, null);
61      } catch (final java.lang.IllegalStateException ex) {
62      }
63    }
64  
65    public void testGetOutputFileName2() {
66      final CompilerConfiguration compiler = create();
67  //    String[] output = compiler.getOutputFileNames("c:\\foo\\bar\\hello.c", null);  Windows only, on *nix gets treated as filename not pathed.
68      String[] output = compiler.getOutputFileNames("c:/foo/bar/hello.c", null);
69      String[] output2 = compiler.getOutputFileNames("c:/foo/bar/fake/../hello.c", null);
70      assertEquals(output[0], output2[0]); // files in same location get mangled same way - full path
71  
72      output = compiler.getOutputFileNames("hello.c", null);
73      assertNotSame(output[0], output2[0]); // files in different folders get mangled in different way
74      
75      output2 = compiler.getOutputFileNames("fake/../hello.c", null);
76      assertEquals(output[0], output2[0]); // files in same location get mangled same way - relative path
77      
78      output = compiler.getOutputFileNames("c:/foo/bar/hello.h", null);
79      assertEquals(0, output.length);
80      output = compiler.getOutputFileNames("c:/foo/bar/fake/../hello.h", null);
81      assertEquals(0, output.length);
82    }
83  }