Skip to content

Commit 23dd93e

Browse files
committed
Write a test for Basic Types.
Write a test for Basic Types such as boolean, short, double, and string. Not include long type testing in this patch because it has some problem. We should fix the issue in follow-up patch. ISSUE=#99,#100
1 parent 31e209a commit 23dd93e

File tree

4 files changed

+91
-0
lines changed

4 files changed

+91
-0
lines changed

test/interface_basic_types.test.ts

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
import * as bindings from 'bindings';
18+
19+
const bacardi = bindings('bacardi.node');
20+
21+
test('Test for IDL \'boolean\' type', async () => {
22+
let test_interface = new bacardi.TestInterface();
23+
24+
// The boolean type has two values: true and false.
25+
expect(test_interface.booleanMethod(true)).toBe(true);
26+
expect(test_interface.booleanMethod(false)).toBe(false);
27+
});
28+
29+
test('Test for IDL \'short\' type', async () => {
30+
let test_interface = new bacardi.TestInterface();
31+
32+
// The short type is a signed integer type that has values in the range
33+
// [−32768, 32767].
34+
expect(test_interface.shortMethod(32767)).toBe(32767);
35+
expect(test_interface.shortMethod(-32768)).toBe(-32768);
36+
expect(test_interface.shortMethod(32768) != 32768).toBe(true);
37+
expect(test_interface.shortMethod(-32769) != -32769).toBe(true);
38+
});
39+
40+
// FIXME(zino): We should write a test for long type.
41+
// Please see: https://github.com/lunchclass/bacardi/issues/120
42+
43+
test('Test for IDL \'double\' type', async () => {
44+
let test_interface = new bacardi.TestInterface();
45+
46+
// The double type is a floating point numeric type that corresponds to the
47+
// set of finite double-precision 64 bit IEEE 754 floating point numbers.
48+
expect(test_interface.doubleMethod(0.123456789012345))
49+
.toBe(0.123456789012345);
50+
51+
// FIXME(zino): We should test for comparing single-precision floating point.
52+
53+
// FIXME(zino): We should check whether the type is restricted or
54+
// unrestricted.
55+
});
56+
57+
test('Test for IDL \'string\' type', async () => {
58+
let test_interface = new bacardi.TestInterface();
59+
60+
// The string type is not exact matching WebIDL spec but it will convert
61+
// UTF8 string in platform side.
62+
expect(test_interface.stringMethod('Hello World!')).toBe('Hello World!');
63+
});

test/test_interface.cc

+16
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,19 @@ bool TestInterface::StaticMethod2(long number, const std::string& string) {
4848
last_call_info_ = "static boolean staticMethod2(long, string)";
4949
return 0;
5050
}
51+
52+
bool TestInterface::BooleanMethod(bool boolean) {
53+
return boolean;
54+
}
55+
56+
short TestInterface::ShortMethod(short number) {
57+
return number;
58+
}
59+
60+
double TestInterface::DoubleMethod(double number) {
61+
return number;
62+
}
63+
64+
const std::string TestInterface::StringMethod(const std::string& string) {
65+
return string;
66+
}

test/test_interface.h

+6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ class TestInterface {
3131
static void StaticMethod1();
3232
static bool StaticMethod2(long number, const std::string& string);
3333

34+
// Basic types
35+
bool BooleanMethod(bool boolean);
36+
short ShortMethod(short number);
37+
double DoubleMethod(double number);
38+
const std::string StringMethod(const std::string& string);
39+
3440
private:
3541
// FIXME(zino): Currently, we should set this variable in each methods. It's
3642
// not elegance way. We should find a way to get function name and signature

test/test_interface.idl

+6
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,10 @@ interface TestInterface {
2626

2727
static void staticMethod1();
2828
static boolean staticMethod2(long number, string string);
29+
30+
// Basic types
31+
boolean booleanMethod(boolean boolean);
32+
short shortMethod(short number);
33+
double doubleMethod(double number);
34+
string stringMethod(string string);
2935
};

0 commit comments

Comments
 (0)