Skip to content

Commit dac4c7f

Browse files
authored
Merge pull request #158 from btc-ag/add-basic-good-tests
Add basic good tests
2 parents faf8d7c + d342f12 commit dac4c7f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+442
-159
lines changed

com.btc.serviceidl.tests/src/com/btc/serviceidl/tests/cmdline/CommandLineRunnerTest.xtend

+4-4
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,13 @@ class CommandLineRunnerTest
226226
"cpp/modules/BTC/Commons/Core/Proxy/include/btc_commons_core_proxy_export.h",
227227
"cpp/modules/BTC/Commons/Core/Proxy/source/CFooProxy.cpp",
228228
"cpp/modules/BTC/Commons/Core/Proxy/source/Dependencies.cpp",
229-
"cpp/modules/BTC/Commons/Core/ServerRunner/BTC.Commons.Core.ServerRunner.Foo.vcxproj",
230-
"cpp/modules/BTC/Commons/Core/ServerRunner/BTC.Commons.Core.ServerRunner.Foo.vcxproj.filters",
231-
"cpp/modules/BTC/Commons/Core/ServerRunner/BTC.Commons.Core.ServerRunner.Foo.vcxproj.user",
229+
"cpp/modules/BTC/Commons/Core/ServerRunner/BTC.Commons.Core.ServerRunner.vcxproj",
230+
"cpp/modules/BTC/Commons/Core/ServerRunner/BTC.Commons.Core.ServerRunner.vcxproj.filters",
231+
"cpp/modules/BTC/Commons/Core/ServerRunner/BTC.Commons.Core.ServerRunner.vcxproj.user",
232232
"cpp/modules/BTC/Commons/Core/ServerRunner/etc/ServerFactory.xml",
233233
"cpp/modules/BTC/Commons/Core/ServerRunner/include/btc_commons_core_serverrunner_export.h",
234234
"cpp/modules/BTC/Commons/Core/ServerRunner/source/Dependencies.cpp",
235-
"cpp/modules/BTC/Commons/Core/ServerRunner/source/FooServerRunner.cpp",
235+
"cpp/modules/BTC/Commons/Core/ServerRunner/source/ServerRunner.cpp",
236236
"cpp/modules/BTC/Commons/Core/ServiceAPI/BTC.Commons.Core.ServiceAPI.vcxproj",
237237
"cpp/modules/BTC/Commons/Core/ServiceAPI/BTC.Commons.Core.ServiceAPI.vcxproj.filters",
238238
"cpp/modules/BTC/Commons/Core/ServiceAPI/include/IFoo.h",

com.btc.serviceidl.tests/src/com/btc/serviceidl/tests/generator/IdlGeneratorTest.xtend

+5-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
**********************************************************************/
1111
package com.btc.serviceidl.tests.generator
1212

13+
import com.btc.serviceidl.FileSystemAccessWrapper
1314
import com.btc.serviceidl.generator.DefaultGenerationSettingsProvider
1415
import com.btc.serviceidl.generator.IGenerationSettingsProvider
1516
import com.btc.serviceidl.idl.IDLSpecification
@@ -41,11 +42,12 @@ class IdlGeneratorTest
4142
val defaultGenerationSettingsProvider = generationSettingsProvider as DefaultGenerationSettingsProvider
4243
defaultGenerationSettingsProvider.reset() // TODO remove this, it is necessary because the dependencies are reused across test cases
4344
val spec = input.parse
44-
val fsa = new InMemoryFileSystemAccess()
45+
val baseFsa = new InMemoryFileSystemAccess()
46+
val fsa = new FileSystemAccessWrapper[baseFsa]
4547
val generatorContext = new GeneratorContext()
4648
underTest.doGenerate(spec.eResource, fsa, generatorContext)
47-
println(fsa.textFiles.keySet.join("\n"))
48-
fsa
49+
println(baseFsa.textFiles.keySet.join("\n"))
50+
baseFsa
4951
}
5052

5153
@Test

com.btc.serviceidl.tests/src/com/btc/serviceidl/tests/testdata/TestData.xtend

+47-33
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,18 @@
1010
**********************************************************************/
1111
package com.btc.serviceidl.tests.testdata
1212

13-
import java.util.Map
14-
import java.util.HashMap
15-
import java.util.Collections
16-
import java.nio.file.Paths
1713
import com.google.common.io.Resources
18-
import java.nio.charset.Charset
19-
import java.util.jar.JarFile
14+
import java.io.IOException
15+
import java.net.URL
2016
import java.net.URLDecoder
17+
import java.nio.charset.Charset
2118
import java.nio.charset.StandardCharsets
19+
import java.nio.file.Paths
2220
import java.util.ArrayList
23-
import java.net.URL
21+
import java.util.HashMap
22+
import java.util.Map
23+
import java.util.jar.JarFile
24+
import org.eclipse.core.runtime.FileLocator
2425

2526
class TestData
2627
{
@@ -102,44 +103,54 @@ class TestData
102103
{
103104
val filenames = new ArrayList<URL>();
104105

105-
val url = Thread.currentThread().getContextClassLoader().getResource(directoryName);
106-
if (url !== null)
106+
var url = Thread.currentThread().getContextClassLoader().getResource(directoryName);
107+
if (url === null)
108+
throw new IOException(
109+
"Thread.currentThread().getContextClassLoader().getResource(directoryName) returned null for directoryName == " +
110+
directoryName)
111+
112+
if (url.getProtocol().equals("bundleresource"))
113+
{
114+
url = FileLocator.toFileURL(url)
115+
}
116+
117+
if (url.getProtocol().equals("file"))
107118
{
108-
if (url.getProtocol().equals("file"))
119+
val file = Paths.get(url.toURI()).toFile();
120+
if (file !== null)
109121
{
110-
val file = Paths.get(url.toURI()).toFile();
111-
if (file !== null)
122+
val files = file.listFiles();
123+
if (files !== null)
112124
{
113-
val files = file.listFiles();
114-
if (files !== null)
125+
for (filename : files)
115126
{
116-
for (filename : files)
117-
{
118-
filenames.add(filename.toURI.toURL);
119-
}
127+
filenames.add(filename.toURI.toURL);
120128
}
121129
}
122130
}
123-
else if (url.getProtocol().equals("jar"))
131+
}
132+
else if (url.getProtocol().equals("jar"))
133+
{
134+
val dirname = directoryName + "/";
135+
val path = url.getPath();
136+
val jarPath = path.substring(5, path.indexOf("!"));
137+
// TODO this should use try-with-resources
138+
val jar = new JarFile(URLDecoder.decode(jarPath, StandardCharsets.UTF_8.name()))
139+
val entries = jar.entries();
140+
while (entries.hasMoreElements())
124141
{
125-
val dirname = directoryName + "/";
126-
val path = url.getPath();
127-
val jarPath = path.substring(5, path.indexOf("!"));
128-
// TODO this should use try-with-resources
129-
val jar = new JarFile(URLDecoder.decode(jarPath, StandardCharsets.UTF_8.name()))
130-
val entries = jar.entries();
131-
while (entries.hasMoreElements())
142+
val entry = entries.nextElement();
143+
val name = entry.getName();
144+
if (name.startsWith(dirname) && !dirname.equals(name))
132145
{
133-
val entry = entries.nextElement();
134-
val name = entry.getName();
135-
if (name.startsWith(dirname) && !dirname.equals(name))
136-
{
137-
val resource = Thread.currentThread().getContextClassLoader().getResource(name);
138-
filenames.add(resource);
139-
}
146+
val resource = Thread.currentThread().getContextClassLoader().getResource(name);
147+
filenames.add(resource);
140148
}
141149
}
142150
}
151+
else
152+
throw new IOException("Unknown protocol in URL: " + url)
153+
143154
return filenames;
144155
}
145156

@@ -153,6 +164,9 @@ class TestData
153164
getFilenamesForDirnameFromClassPath("com/btc/serviceidl/tests/testdata/good_ext/")
154165
].flatten
155166

167+
if (testCaseFiles.empty)
168+
throw new Exception("No good test cases found, something is wrong!")
169+
156170
val resultMap = new HashMap<String, CharSequence>
157171
for (testCaseFile : testCaseFiles)
158172
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module Test {
2+
3+
struct A {
4+
string key;
5+
};
6+
7+
struct B : A {
8+
string value;
9+
};
10+
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module Test {
2+
3+
struct A {
4+
optional int64 aValue;
5+
};
6+
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module Test {
2+
3+
struct A {
4+
sequence<int64> aValue;
5+
};
6+
7+
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
module Test {
22

3-
struct ModificationEvent {
4-
string key;
5-
optional string value;
6-
};
3+
struct A {
4+
int64 aValue;
5+
};
76

87
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
11
module Test {
2-
typedef string KeyType;
3-
typedef string ValueType;
2+
typedef string TypeA;
3+
typedef int64 TypeB;
4+
// typedef sequence<string> TypeC;
5+
struct Bar
6+
{
7+
string A;
8+
};
9+
typedef Bar TypeD;
10+
// typedef sequence<failable string> TypeE;
11+
12+
struct Foo
13+
{
14+
TypeA a;
15+
TypeB b;
16+
// TypeC c;
17+
TypeD d;
18+
// TypeE e;
19+
};
20+
21+
422
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Test {
2+
exception FooException {};
3+
exception BarException : FooException {};
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module Test {
2+
exception FooException {};
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module foo {
2+
3+
<# This is a documentation comment #>
4+
interface IntfA[guid=384E277A-C343-4F37-B910-C2CE6B37FC8E] {
5+
};
6+
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module foo {
2+
3+
abstract interface IntfA[guid=384E277A-C343-4F37-B910-C2CE6B37FC8E] {
4+
DoSomethingA() returns void;
5+
};
6+
7+
interface IntfB[guid=f1721f8c-9201-4ad4-84a2-9b3696f60954] : IntfA {
8+
DoSomethingB() returns void;
9+
};
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module foo {
2+
3+
interface IntfA[guid=384E277A-C343-4F37-B910-C2CE6B37FC8E] {
4+
DoSomethingA() returns void;
5+
};
6+
7+
interface IntfB[guid=f1721f8c-9201-4ad4-84a2-9b3696f60954] : IntfA {
8+
DoSomethingB() returns void;
9+
};
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module foo {
2+
3+
interface Test[guid=384E277A-C343-4F37-B910-C2CE6B37FC8E] {
4+
<# This is a documentation comment for a query #>
5+
query DoSomething() returns sequence<failable uuid>;
6+
};
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module foo {
2+
exception FooException {};
3+
4+
interface Test[guid=384E277A-C343-4F37-B910-C2CE6B37FC8E] {
5+
query DoSomething() returns sequence<failable uuid> raises FooException;
6+
};
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module foo {
2+
3+
interface Test[guid=384E277A-C343-4F37-B910-C2CE6B37FC8E] {
4+
query DoSomething() returns sequence<failable uuid>;
5+
};
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module foo {
2+
3+
exception FooException {};
4+
5+
interface Test[guid=384E277A-C343-4F37-B910-C2CE6B37FC8E] {
6+
DoSomething() returns sequence<failable uuid> raises FooException;
7+
};
8+
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module foo {
2+
3+
interface Test[guid=384E277A-C343-4F37-B910-C2CE6B37FC8E] {
4+
enum ModificationKind {
5+
ModificationKind_Added,
6+
ModificationKind_Modified,
7+
ModificationKind_Removed
8+
};
9+
10+
DoSomething(in ModificationKind modificationKind) returns void;
11+
};
12+
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module foo {
2+
3+
interface Test[guid=384E277A-C343-4F37-B910-C2CE6B37FC8E] {
4+
DoSomething(in float inputFloat) returns void;
5+
};
6+
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module foo {
2+
3+
interface Test[guid=384E277A-C343-4F37-B910-C2CE6B37FC8E] {
4+
DoSomething(in int64 inputInt) returns void;
5+
};
6+
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module foo {
2+
3+
interface Test[guid=384E277A-C343-4F37-B910-C2CE6B37FC8E] {
4+
DoSomething(in sequence<string> inputSequence) returns void;
5+
};
6+
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module foo {
2+
3+
interface Test[guid=384E277A-C343-4F37-B910-C2CE6B37FC8E] {
4+
DoSomething(in string inputString) returns void;
5+
};
6+
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module foo {
2+
3+
interface Test[guid=384E277A-C343-4F37-B910-C2CE6B37FC8E] {
4+
struct ModificationEvent {
5+
string key;
6+
optional string value;
7+
};
8+
9+
DoSomething(in ModificationEvent modificationEvent) returns void;
10+
};
11+
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module foo {
2+
3+
interface Test[guid=384E277A-C343-4F37-B910-C2CE6B37FC8E] {
4+
enum ModificationKind {
5+
ModificationKind_Added,
6+
ModificationKind_Modified,
7+
ModificationKind_Removed
8+
};
9+
10+
struct Wrapper {
11+
ModificationKind modificationKind;
12+
};
13+
14+
DoSomething(out Wrapper modificationKind) returns void;
15+
};
16+
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module foo {
2+
3+
interface Test[guid=384E277A-C343-4F37-B910-C2CE6B37FC8E] {
4+
struct Wrapper
5+
{
6+
float outputFloat;
7+
};
8+
9+
DoSomething(out Wrapper inputString) returns void;
10+
};
11+
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module foo {
2+
3+
interface Test[guid=384E277A-C343-4F37-B910-C2CE6B37FC8E] {
4+
struct Wrapper
5+
{
6+
int64 outputInt;
7+
};
8+
DoSomething(out Wrapper outputInt) returns void;
9+
};
10+
11+
}

0 commit comments

Comments
 (0)