Skip to content

Commit

Permalink
Add test/test_interface.* for testing. (#113)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
romandev committed Oct 7, 2017
1 parent de903fe commit 347cec5
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 19 deletions.
5 changes: 5 additions & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
'core/core.gypi',
'examples/examples.gypi',
'generator/generator.gypi',
'test/test.gypi',
],

'targets': [
Expand Down Expand Up @@ -53,6 +54,8 @@
'<@(core_cpp_files)',
'<@(examples_cpp_files)',
'<@(examples_idl_output_files)',
'<@(test_cpp_files)',
'<@(test_idl_output_files)',
'<(SHARED_INTERMEDIATE_DIR)/bacardi.cc',
],
'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ],
Expand Down Expand Up @@ -104,9 +107,11 @@
'action_name': 'idl',
'inputs': [
'<@(examples_idl_files)',
'<@(test_idl_files)',
],
'outputs': [
'<@(examples_idl_output_files)',
'<@(test_idl_output_files)',
],
'conditions': [
['OS!="win"',
Expand Down
10 changes: 5 additions & 5 deletions generator/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ async function generateBacardi(
[file.read(path.resolve(TEMPLATE_DIR, 'bacardi_cpp.njk'))]);
const cpp_file_path = path.resolve(output_path, 'bacardi.cc');

let idl_interface_names: string[] = [];
let idl_interfaces: IDLDefinition[] = [];
definitions.forEach(async (definition) => {
if (definition.isIDLInterface()) {
idl_interface_names.push(definition.name);
idl_interfaces.push(definition);
}
});

return file.write(
cpp_file_path, env.renderString(cpp_tmpl, {names: idl_interface_names}));
cpp_file_path, env.renderString(cpp_tmpl, {interfaces: idl_interfaces}));
}

async function generateInterface(
Expand All @@ -58,11 +58,11 @@ async function generateInterface(
if (definition.isIDLInterface()) {
const header_file_path = path.resolve(
output_path,
definition.idlDirName() + '/' + snakeCase(definition.name) +
definition.idl_dir_name + '/' + snakeCase(definition.name) +
'_bridge.h');
const cpp_file_path = path.resolve(
output_path,
definition.idlDirName() + '/' + snakeCase(definition.name) +
definition.idl_dir_name + '/' + snakeCase(definition.name) +
'_bridge.cc');

await file.write(
Expand Down
12 changes: 4 additions & 8 deletions generator/parser/idl_definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@

export default abstract class IDLDefinition {
public readonly name: string;
public readonly idl_base_name: string;
public readonly idl_dir_name: string;
protected readonly raw_idl_definition_info: {};

protected constructor(name: string, raw_idl_definition_info: {}) {
this.name = name;
this.idl_base_name = raw_idl_definition_info['idlBaseName'];
this.idl_dir_name = raw_idl_definition_info['idlDirName'];
this.raw_idl_definition_info = raw_idl_definition_info;
}

Expand All @@ -28,12 +32,4 @@ export default abstract class IDLDefinition {
public isIDLInterface(): boolean {
return this.raw_idl_definition_info['type'] == 'interface';
}

public idlBaseName(): string {
return this.raw_idl_definition_info['idlBaseName'];
}

public idlDirName(): string {
return this.raw_idl_definition_info['idlDirName'];
}
}
8 changes: 4 additions & 4 deletions template/bacardi_cpp.njk
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@

#include "core/bacardi.h"

{% for name in names %}
#include "examples/{{name | snakecase}}_bridge.h"
{% for interface in interfaces %}
#include "{{interface.idl_dir_name}}/{{interface.name | snakecase}}_bridge.h"
{% endfor %}

void Init(Napi::Env env, Napi::Object exports, Napi::Object module) {
{% for name in names %}
{{name}}Bridge::Init(env, exports);
{% for interface in interfaces %}
{{interface.name}}Bridge::Init(env, exports);
{% endfor %}
}

Expand Down
2 changes: 1 addition & 1 deletion template/interface_cpp.njk
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

#include "examples/{{name | snakecase}}_bridge.h"
#include "{{idl_dir_name}}/{{name | snakecase}}_bridge.h"

#include "core/js_type_traits.h"
#include "core/native_type_traits.h"
Expand Down
2 changes: 1 addition & 1 deletion template/interface_header.njk
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <memory>
#include <napi.h>

#include "examples/{{name | snakecase}}.h"
#include "{{idl_dir_name}}/{{name | snakecase}}.h"

class {{name}}Bridge : public Napi::ObjectWrap<{{name}}Bridge> {
public:
Expand Down
31 changes: 31 additions & 0 deletions test/test.gypi
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright (c) 2017 The Bacardi Authors.
#
# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an 'AS IS' BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

{
'variables': {
'test_cpp_files': [
'test_interface.cc',
'test_interface.h',
],

'test_idl_files': [
'<(module_root_dir)/test/test_interface.idl',
],

'test_idl_output_files': [
'<(SHARED_INTERMEDIATE_DIR)/test/test_interface_bridge.cc',
'<(SHARED_INTERMEDIATE_DIR)/test/test_interface_bridge.h',
],
},
}
19 changes: 19 additions & 0 deletions test/test_interface.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright (c) 2017 The Bacardi Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "test/test_interface.h"

TestInterface::TestInterface() {}
25 changes: 25 additions & 0 deletions test/test_interface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright (c) 2017 The Bacardi Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef TEST_TEST_INTERFACE_H_
#define TEST_TEST_INTERFACE_H_

class TestInterface {
public:
TestInterface();
};

#endif // TEST_TEST_INTERFACE_H_
18 changes: 18 additions & 0 deletions test/test_interface.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Copyright (c) 2017 The Bacardi Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

interface TestInterface {
};

0 comments on commit 347cec5

Please sign in to comment.