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 java.util.Vector;
23  
24  import junit.framework.TestCase;
25  
26  /**
27   * Tests for gcc compatible compilers
28   *
29   * @author CurtA
30   */
31  public abstract class TestGccCompatibleCCompiler extends TestCase {
32    /**
33     * Constructor
34     * 
35     * @param name
36     *          test case name
37     */
38    public TestGccCompatibleCCompiler(final String name) {
39      super(name);
40    }
41  
42    /**
43     * Compiler creation method
44     * 
45     * Must be overriden by extending classes
46     * 
47     * @return GccCompatibleCCompiler
48     */
49    protected abstract GccCompatibleCCompiler create();
50  
51    /**
52     * Tests command lines switches for warning = 0
53     */
54    public void testWarningLevel0() {
55      final GccCompatibleCCompiler compiler = create();
56      final Vector args = new Vector();
57      compiler.addWarningSwitch(args, 0);
58      assertEquals(1, args.size());
59      assertEquals("-w", args.elementAt(0));
60    }
61  
62    /**
63     * Tests command lines switches for warning = 1
64     */
65    public void testWarningLevel1() {
66      final GccCompatibleCCompiler compiler = create();
67      final Vector args = new Vector();
68      compiler.addWarningSwitch(args, 1);
69      assertEquals(0, args.size());
70    }
71  
72    /**
73     * Tests command lines switches for warning = 2
74     */
75    public void testWarningLevel2() {
76      final GccCompatibleCCompiler compiler = create();
77      final Vector args = new Vector();
78      compiler.addWarningSwitch(args, 2);
79      assertEquals(0, args.size());
80    }
81  
82    /**
83     * Tests command lines switches for warning = 3
84     */
85    public void testWarningLevel3() {
86      final GccCompatibleCCompiler compiler = create();
87      final Vector args = new Vector();
88      compiler.addWarningSwitch(args, 3);
89      assertEquals(1, args.size());
90      assertEquals("-Wall", args.elementAt(0));
91    }
92  
93    /**
94     * Tests command lines switches for warning = 4
95     */
96    public void testWarningLevel4() {
97      final GccCompatibleCCompiler compiler = create();
98      final Vector args = new Vector();
99      compiler.addWarningSwitch(args, 4);
100     assertEquals(2, args.size());
101     assertEquals("-W", args.elementAt(0));
102     assertEquals("-Wall", args.elementAt(1));
103   }
104 
105   /**
106    * Tests command lines switches for warning = 5
107    */
108   public void testWarningLevel5() {
109     final GccCompatibleCCompiler compiler = create();
110     final Vector args = new Vector();
111     compiler.addWarningSwitch(args, 5);
112     assertEquals(3, args.size());
113     assertEquals("-Werror", args.elementAt(0));
114     assertEquals("-W", args.elementAt(1));
115     assertEquals("-Wall", args.elementAt(2));
116   }
117 }