1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.github.maven_nar.cpptasks;
21
22 import java.io.File;
23 import java.io.IOException;
24 import java.io.InputStream;
25 import java.util.HashMap;
26 import java.util.Map;
27 import java.util.Vector;
28
29 import junit.framework.TestCase;
30
31 import com.github.maven_nar.cpptasks.compiler.CommandLineCompilerConfiguration;
32 import com.github.maven_nar.cpptasks.compiler.CompilerConfiguration;
33 import com.github.maven_nar.cpptasks.gcc.GccCCompiler;
34
35
36
37
38
39 public final class TestCCTask extends TestCase {
40
41
42
43
44
45
46
47 public TestCCTask(final String name) {
48 super(name);
49 }
50
51
52
53
54
55
56
57
58 public void testAntlibXmlPresent() throws IOException {
59 final InputStream stream = TestCCTask.class.getClassLoader().getResourceAsStream(
60 "com/github/maven_nar/cpptasks/antlib.xml");
61 if (stream != null) {
62 stream.close();
63 }
64 assertNotNull("antlib.xml missing", stream);
65 }
66
67
68
69
70 public void testGetFailOnError() {
71 final CCTask task = new CCTask();
72 final boolean failOnError = task.getFailonerror();
73 assertEquals(true, failOnError);
74 }
75
76
77
78
79
80 public void testGetTargetsToBuildByConfiguration1() {
81 final CompilerConfiguration config1 = new CommandLineCompilerConfiguration(GccCCompiler.getInstance(), "dummy",
82 new File[0], new File[0], new File[0], "", new String[0], new ProcessorParam[0], true, new String[0]);
83 final TargetInfo target1 = new TargetInfo(config1, new File[] {
84 new File("src/foo.bar")
85 }, null, new File("foo.obj"), true);
86 final Map targets = new HashMap();
87 targets.put(target1.getOutput(), target1);
88 final Map targetsByConfig = CCTask.getTargetsToBuildByConfiguration(targets);
89 final Vector targetsForConfig1 = (Vector) targetsByConfig.get(config1);
90 assertNotNull(targetsForConfig1);
91 assertEquals(1, targetsForConfig1.size());
92 final TargetInfo targetx = (TargetInfo) targetsForConfig1.elementAt(0);
93 assertSame(target1, targetx);
94 }
95
96
97
98
99
100
101 public void testGetTargetsToBuildByConfiguration2() {
102 final CompilerConfiguration config1 = new CommandLineCompilerConfiguration(GccCCompiler.getInstance(), "dummy",
103 new File[0], new File[0], new File[0], "", new String[0], new ProcessorParam[0], false, new String[0]);
104
105
106
107 final TargetInfo target1 = new TargetInfo(config1, new File[] {
108 new File("src/foo.bar")
109 }, null, new File("foo.obj"), false);
110 final Map targets = new HashMap();
111 targets.put(target1.getOutput(), target1);
112
113
114
115 final Map targetsByConfig = CCTask.getTargetsToBuildByConfiguration(targets);
116 assertEquals(0, targetsByConfig.size());
117 }
118
119
120
121
122 public void testSetFailOnError() {
123 final CCTask task = new CCTask();
124 task.setFailonerror(false);
125 boolean failOnError = task.getFailonerror();
126 assertEquals(false, failOnError);
127 task.setFailonerror(true);
128 failOnError = task.getFailonerror();
129 assertEquals(true, failOnError);
130 }
131 }