Skip to content

Commit

Permalink
Write a test for Basic Types.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
romandev committed Oct 8, 2017
1 parent 31e209a commit 23dd93e
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 0 deletions.
63 changes: 63 additions & 0 deletions test/interface_basic_types.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* 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.
*/

import * as bindings from 'bindings';

const bacardi = bindings('bacardi.node');

test('Test for IDL \'boolean\' type', async () => {
let test_interface = new bacardi.TestInterface();

// The boolean type has two values: true and false.
expect(test_interface.booleanMethod(true)).toBe(true);
expect(test_interface.booleanMethod(false)).toBe(false);
});

test('Test for IDL \'short\' type', async () => {
let test_interface = new bacardi.TestInterface();

// The short type is a signed integer type that has values in the range
// [−32768, 32767].
expect(test_interface.shortMethod(32767)).toBe(32767);
expect(test_interface.shortMethod(-32768)).toBe(-32768);
expect(test_interface.shortMethod(32768) != 32768).toBe(true);
expect(test_interface.shortMethod(-32769) != -32769).toBe(true);
});

// FIXME(zino): We should write a test for long type.
// Please see: https://github.com/lunchclass/bacardi/issues/120

test('Test for IDL \'double\' type', async () => {
let test_interface = new bacardi.TestInterface();

// The double type is a floating point numeric type that corresponds to the
// set of finite double-precision 64 bit IEEE 754 floating point numbers.
expect(test_interface.doubleMethod(0.123456789012345))
.toBe(0.123456789012345);

// FIXME(zino): We should test for comparing single-precision floating point.

// FIXME(zino): We should check whether the type is restricted or
// unrestricted.
});

test('Test for IDL \'string\' type', async () => {
let test_interface = new bacardi.TestInterface();

// The string type is not exact matching WebIDL spec but it will convert
// UTF8 string in platform side.
expect(test_interface.stringMethod('Hello World!')).toBe('Hello World!');
});
16 changes: 16 additions & 0 deletions test/test_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,19 @@ bool TestInterface::StaticMethod2(long number, const std::string& string) {
last_call_info_ = "static boolean staticMethod2(long, string)";
return 0;
}

bool TestInterface::BooleanMethod(bool boolean) {
return boolean;
}

short TestInterface::ShortMethod(short number) {
return number;
}

double TestInterface::DoubleMethod(double number) {
return number;
}

const std::string TestInterface::StringMethod(const std::string& string) {
return string;
}
6 changes: 6 additions & 0 deletions test/test_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ class TestInterface {
static void StaticMethod1();
static bool StaticMethod2(long number, const std::string& string);

// Basic types
bool BooleanMethod(bool boolean);
short ShortMethod(short number);
double DoubleMethod(double number);
const std::string StringMethod(const std::string& string);

private:
// FIXME(zino): Currently, we should set this variable in each methods. It's
// not elegance way. We should find a way to get function name and signature
Expand Down
6 changes: 6 additions & 0 deletions test/test_interface.idl
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,10 @@ interface TestInterface {

static void staticMethod1();
static boolean staticMethod2(long number, string string);

// Basic types
boolean booleanMethod(boolean boolean);
short shortMethod(short number);
double doubleMethod(double number);
string stringMethod(string string);
};

0 comments on commit 23dd93e

Please sign in to comment.