Skip to content

Commit

Permalink
Add tests for enum features
Browse files Browse the repository at this point in the history
 - add test for function which return enum values.
 - add test passing unexpected value instead of enum.

ISSUE=lunchclass#80
  • Loading branch information
hwanseung committed Nov 18, 2017
1 parent f031760 commit c4682b0
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
38 changes: 38 additions & 0 deletions test/enum.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
// });
6 changes: 6 additions & 0 deletions test/test_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
}
Expand Down
1 change: 1 addition & 0 deletions test/test_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class TestInterface {

// Enum
void VoidMethodTestEnumArg(const std::string& string);
const std::string EnumReturnMethod(long index);

// Attributes
void ReadonlyAssignTest(double number);
Expand Down
1 change: 1 addition & 0 deletions test/test_interface.idl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ interface TestInterface {

// enum
void voidMethodTestEnumArg(TestEnum enumValue);
TestEnum enumReturnMethod(long index);

// Attributes
attribute double doubleNumber;
Expand Down

0 comments on commit c4682b0

Please sign in to comment.