From c4682b0366ffe16bea4e9881d26c0914f85b7853 Mon Sep 17 00:00:00 2001 From: Hwanseung Lee Date: Sat, 18 Nov 2017 12:18:26 +0900 Subject: [PATCH] Add tests for enum features - add test for function which return enum values. - add test passing unexpected value instead of enum. ISSUE=#80 --- test/enum.test.ts | 38 ++++++++++++++++++++++++++++++++++++++ test/test_interface.cc | 6 ++++++ test/test_interface.h | 1 + test/test_interface.idl | 1 + 4 files changed, 46 insertions(+) diff --git a/test/enum.test.ts b/test/enum.test.ts index ae7772f..0d05d5a 100644 --- a/test/enum.test.ts +++ b/test/enum.test.ts @@ -37,6 +37,10 @@ test('Test for enum', async () => { test('Passing unexpected enum value should throw error', async () => { let test_interface = new bacardi.TestInterface(); + expect(() => { + test_interface.voidMethodTestEnumArg(); + }).toThrowError(); + expect(() => { test_interface.voidMethodTestEnumArg(1); }).toThrowError(); @@ -49,4 +53,38 @@ test('Passing unexpected enum value should throw error', async () => { test_interface.voidMethodTestEnumArg('value'); }).toThrowError(); + expect(() => { + test_interface.voidMethodTestEnumArg(undefined); + }).toThrowError(); + + expect(() => { + test_interface.voidMethodTestEnumArg({a: 1}); + }).toThrowError(); + + expect(() => { + test_interface.voidMethodTestEnumArg('value1', 1); + }).toThrowError(); +}); + +test('Test for returning enum value', async () => { + let test_interface = new bacardi.TestInterface(); + + // enumReturnMethod function will be return a string which is combined prefix + // "value" and passed parameter value. + // eg. enumReturnMethod(1) will be return "value1" + + expect(test_interface.enumReturnMethod(1)).toBe('value1'); + + expect(test_interface.enumReturnMethod(2)).toBe('value2'); + + expect(test_interface.enumReturnMethod(3)).toBe('value3'); }); + +// FIXME(hwanseung): when return values which is not included in enum, +// should be thrown error. +// test('Returning unexpected enum value should throw error', +// async () => { +// let test_interface = new bacardi.TestInterface(); + +// expect(() => {test_interface.enumReturnMethod(4)}).toThrowError(); +// }); diff --git a/test/test_interface.cc b/test/test_interface.cc index 0e88be2..0431896 100644 --- a/test/test_interface.cc +++ b/test/test_interface.cc @@ -98,6 +98,12 @@ void TestInterface::VoidMethodTestEnumArg(const std::string& string) { last_call_info_ = "VoidMethodTestEnumArg(" + string + ")"; } +const std::string TestInterface::EnumReturnMethod(long index) { + std::string ret = "value"; + ret.append(std::to_string(index)); + return ret; +} + double TestInterface::StaticTest(double number) { return TestInterface::static_double_number_; } diff --git a/test/test_interface.h b/test/test_interface.h index 0f93abd..5e6f4fe 100644 --- a/test/test_interface.h +++ b/test/test_interface.h @@ -46,6 +46,7 @@ class TestInterface { // Enum void VoidMethodTestEnumArg(const std::string& string); + const std::string EnumReturnMethod(long index); // Attributes void ReadonlyAssignTest(double number); diff --git a/test/test_interface.idl b/test/test_interface.idl index 3becfc8..9424809 100644 --- a/test/test_interface.idl +++ b/test/test_interface.idl @@ -42,6 +42,7 @@ interface TestInterface { // enum void voidMethodTestEnumArg(TestEnum enumValue); + TestEnum enumReturnMethod(long index); // Attributes attribute double doubleNumber;