|
| 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 | +}); |
0 commit comments