Skip to content

Commit cdb4552

Browse files
committed
Add test/test_interface.* for testing.
This patch is adding a new test IDL interface to test/ directory. After this patch, we can build a multiple IDL files and use them. ISSUE=#99,#100 TBR=@hwanseung,@yjaeseok
1 parent de903fe commit cdb4552

10 files changed

+113
-19
lines changed

binding.gyp

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
'core/core.gypi',
1818
'examples/examples.gypi',
1919
'generator/generator.gypi',
20+
'test/test.gypi',
2021
],
2122

2223
'targets': [
@@ -53,6 +54,8 @@
5354
'<@(core_cpp_files)',
5455
'<@(examples_cpp_files)',
5556
'<@(examples_idl_output_files)',
57+
'<@(test_cpp_files)',
58+
'<@(test_idl_output_files)',
5659
'<(SHARED_INTERMEDIATE_DIR)/bacardi.cc',
5760
],
5861
'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ],
@@ -104,9 +107,11 @@
104107
'action_name': 'idl',
105108
'inputs': [
106109
'<@(examples_idl_files)',
110+
'<@(test_idl_files)',
107111
],
108112
'outputs': [
109113
'<@(examples_idl_output_files)',
114+
'<@(test_idl_output_files)',
110115
],
111116
'conditions': [
112117
['OS!="win"',

generator/main.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ async function generateBacardi(
3535
[file.read(path.resolve(TEMPLATE_DIR, 'bacardi_cpp.njk'))]);
3636
const cpp_file_path = path.resolve(output_path, 'bacardi.cc');
3737

38-
let idl_interface_names: string[] = [];
38+
let idl_interfaces: IDLDefinition[] = [];
3939
definitions.forEach(async (definition) => {
4040
if (definition.isIDLInterface()) {
41-
idl_interface_names.push(definition.name);
41+
idl_interfaces.push(definition);
4242
}
4343
});
4444

4545
return file.write(
46-
cpp_file_path, env.renderString(cpp_tmpl, {names: idl_interface_names}));
46+
cpp_file_path, env.renderString(cpp_tmpl, {interfaces: idl_interfaces}));
4747
}
4848

4949
async function generateInterface(
@@ -58,11 +58,11 @@ async function generateInterface(
5858
if (definition.isIDLInterface()) {
5959
const header_file_path = path.resolve(
6060
output_path,
61-
definition.idlDirName() + '/' + snakeCase(definition.name) +
61+
definition.idl_dir_name + '/' + snakeCase(definition.name) +
6262
'_bridge.h');
6363
const cpp_file_path = path.resolve(
6464
output_path,
65-
definition.idlDirName() + '/' + snakeCase(definition.name) +
65+
definition.idl_dir_name + '/' + snakeCase(definition.name) +
6666
'_bridge.cc');
6767

6868
await file.write(

generator/parser/idl_definition.ts

+4-8
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@
1616

1717
export default abstract class IDLDefinition {
1818
public readonly name: string;
19+
public readonly idl_base_name: string;
20+
public readonly idl_dir_name: string;
1921
protected readonly raw_idl_definition_info: {};
2022

2123
protected constructor(name: string, raw_idl_definition_info: {}) {
2224
this.name = name;
25+
this.idl_base_name = raw_idl_definition_info['idlBaseName'];
26+
this.idl_dir_name = raw_idl_definition_info['idlDirName'];
2327
this.raw_idl_definition_info = raw_idl_definition_info;
2428
}
2529

@@ -28,12 +32,4 @@ export default abstract class IDLDefinition {
2832
public isIDLInterface(): boolean {
2933
return this.raw_idl_definition_info['type'] == 'interface';
3034
}
31-
32-
public idlBaseName(): string {
33-
return this.raw_idl_definition_info['idlBaseName'];
34-
}
35-
36-
public idlDirName(): string {
37-
return this.raw_idl_definition_info['idlDirName'];
38-
}
3935
}

template/bacardi_cpp.njk

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919

2020
#include "core/bacardi.h"
2121

22-
{% for name in names %}
23-
#include "examples/{{name | snakecase}}_bridge.h"
22+
{% for interface in interfaces %}
23+
#include "{{interface.idl_dir_name}}/{{interface.name | snakecase}}_bridge.h"
2424
{% endfor %}
2525

2626
void Init(Napi::Env env, Napi::Object exports, Napi::Object module) {
27-
{% for name in names %}
28-
{{name}}Bridge::Init(env, exports);
27+
{% for interface in interfaces %}
28+
{{interface.name}}Bridge::Init(env, exports);
2929
{% endfor %}
3030
}
3131

template/interface_cpp.njk

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
#include "examples/{{name | snakecase}}_bridge.h"
17+
#include "{{idl_dir_name}}/{{name | snakecase}}_bridge.h"
1818

1919
#include "core/js_type_traits.h"
2020
#include "core/native_type_traits.h"

template/interface_header.njk

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include <memory>
2121
#include <napi.h>
2222

23-
#include "examples/{{name | snakecase}}.h"
23+
#include "{{idl_dir_name}}/{{name | snakecase}}.h"
2424

2525
class {{name}}Bridge : public Napi::ObjectWrap<{{name}}Bridge> {
2626
public:

test/test.gypi

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright (c) 2017 The Bacardi Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the 'License');
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an 'AS IS' BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
{
16+
'variables': {
17+
'test_cpp_files': [
18+
'test_interface.cc',
19+
'test_interface.h',
20+
],
21+
22+
'test_idl_files': [
23+
'<(module_root_dir)/test/test_interface.idl',
24+
],
25+
26+
'test_idl_output_files': [
27+
'<(SHARED_INTERMEDIATE_DIR)/test/test_interface_bridge.cc',
28+
'<(SHARED_INTERMEDIATE_DIR)/test/test_interface_bridge.h',
29+
],
30+
},
31+
}

test/test_interface.cc

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright (c) 2017 The Bacardi Authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "test/test_interface.h"
18+
19+
TestInterface::TestInterface() {}

test/test_interface.h

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Copyright (c) 2017 The Bacardi Authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef TEST_TEST_INTERFACE_H_
18+
#define TEST_TEST_INTERFACE_H_
19+
20+
class TestInterface {
21+
public:
22+
TestInterface();
23+
};
24+
25+
#endif // TEST_TEST_INTERFACE_H_

test/test_interface.idl

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Copyright (c) 2017 The Bacardi Authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
interface TestInterface {
18+
};

0 commit comments

Comments
 (0)