300 lines
7.0 KiB
YAML
300 lines
7.0 KiB
YAML
|
|
---
|
||
|
|
name: basic external non-encapsulated union
|
||
|
|
desc: Verify @external annotation usage on non-encapsulated unions.
|
||
|
|
idl: |
|
||
|
|
|
||
|
|
@include("../../../../../test_includes/test_includes_union.h")
|
||
|
|
program test
|
||
|
|
|
||
|
|
enum fruitType { apple, orange, banana, coconut, grape, papaya, kiwi }
|
||
|
|
|
||
|
|
@external
|
||
|
|
union unionType
|
||
|
|
{
|
||
|
|
case banana:
|
||
|
|
case papaya:
|
||
|
|
int32 x;
|
||
|
|
float y;
|
||
|
|
}
|
||
|
|
|
||
|
|
interface foo {
|
||
|
|
myUnion(fruitType discriminator, unionType unionVariable @discriminator(discriminator)) -> void
|
||
|
|
}
|
||
|
|
|
||
|
|
test_common.h:
|
||
|
|
- not: typedef union unionType unionType;
|
||
|
|
- not: union unionType
|
||
|
|
- not: int32 x;
|
||
|
|
- not: float y;
|
||
|
|
|
||
|
|
test_client.cpp:
|
||
|
|
- static void write_unionType_union(erpc::Codec * codec, int32_t discriminator, const unionType * data);
|
||
|
|
- static void write_unionType_union(erpc::Codec * codec, int32_t discriminator, const unionType * data)
|
||
|
|
|
||
|
|
test_server.cpp:
|
||
|
|
- static void read_unionType_union(erpc::Codec * codec, int32_t & discriminator, unionType * data);
|
||
|
|
- static void read_unionType_union(erpc::Codec * codec, int32_t & discriminator, unionType * data)
|
||
|
|
|
||
|
|
---
|
||
|
|
name: basic non-encapsulated union
|
||
|
|
desc: Verify "in" direction usage of non-encapsulated unions.
|
||
|
|
idl: |
|
||
|
|
|
||
|
|
enum fruitType { apple, orange, banana, coconut, grape, papaya, kiwi, returnVal }
|
||
|
|
|
||
|
|
struct foobar
|
||
|
|
{
|
||
|
|
float a
|
||
|
|
binary rawString
|
||
|
|
}
|
||
|
|
|
||
|
|
union unionType
|
||
|
|
{
|
||
|
|
case apple:
|
||
|
|
foobar myFoobar
|
||
|
|
case banana:
|
||
|
|
case papaya:
|
||
|
|
int32 x;
|
||
|
|
float y;
|
||
|
|
case orange:
|
||
|
|
list<int32> a
|
||
|
|
case coconut:
|
||
|
|
uint32 cx;
|
||
|
|
list<int32> cc @length(cx)
|
||
|
|
case returnVal:
|
||
|
|
int32 ret
|
||
|
|
default:
|
||
|
|
bool c
|
||
|
|
int32 blah
|
||
|
|
}
|
||
|
|
|
||
|
|
interface foo {
|
||
|
|
myUnion(fruitType discriminator, unionType unionVariable @discriminator(discriminator)) -> void
|
||
|
|
}
|
||
|
|
|
||
|
|
test_common.h:
|
||
|
|
- typedef union unionType unionType;
|
||
|
|
- union unionType
|
||
|
|
- "{"
|
||
|
|
- foobar myFoobar;
|
||
|
|
- struct
|
||
|
|
- "{"
|
||
|
|
- int32_t x;
|
||
|
|
- float y;
|
||
|
|
- "};"
|
||
|
|
- list_int32_1_t a;
|
||
|
|
- struct
|
||
|
|
- "{"
|
||
|
|
- int32_t cx;
|
||
|
|
- list_int32_1_t cc;
|
||
|
|
- "};"
|
||
|
|
- int32_t ret;
|
||
|
|
- struct
|
||
|
|
- "{"
|
||
|
|
- bool c;
|
||
|
|
- int32_t blah;
|
||
|
|
- "};"
|
||
|
|
- "};"
|
||
|
|
|
||
|
|
c_test_client.h:
|
||
|
|
- void myUnion(fruitType discriminator, const unionType * unionVariable);
|
||
|
|
|
||
|
|
test_client.cpp:
|
||
|
|
- static void write_unionType_union(erpc::Codec * codec, int32_t discriminator, const unionType * data);
|
||
|
|
- static void write_unionType_union(erpc::Codec * codec, int32_t discriminator, const unionType * data)
|
||
|
|
- "{"
|
||
|
|
- if(NULL == data)
|
||
|
|
- return;
|
||
|
|
- codec->startWriteUnion(discriminator);
|
||
|
|
- switch (discriminator)
|
||
|
|
- "{"
|
||
|
|
- "case apple:"
|
||
|
|
- "{"
|
||
|
|
- write_foobar_struct(codec, &(data->myFoobar));
|
||
|
|
- break;
|
||
|
|
- "}"
|
||
|
|
- "case banana:"
|
||
|
|
- "{"
|
||
|
|
- codec->write(data->x);
|
||
|
|
- codec->write(data->y);
|
||
|
|
- break;
|
||
|
|
- "}"
|
||
|
|
- "case papaya:"
|
||
|
|
- "{"
|
||
|
|
- codec->write(data->x);
|
||
|
|
- codec->write(data->y);
|
||
|
|
- break;
|
||
|
|
- "}"
|
||
|
|
- "case orange:"
|
||
|
|
- "{"
|
||
|
|
- write_list_int32_1_t_struct(codec, &(data->a));
|
||
|
|
- break;
|
||
|
|
- "}"
|
||
|
|
- "case coconut:"
|
||
|
|
- "{"
|
||
|
|
- codec->write(data->cx);
|
||
|
|
- write_list_int32_1_t_struct(codec, &(data->cc));
|
||
|
|
- break;
|
||
|
|
- "}"
|
||
|
|
- "case returnVal:"
|
||
|
|
- "{"
|
||
|
|
- codec->write(data->ret);
|
||
|
|
- break;
|
||
|
|
- "}"
|
||
|
|
- "default:"
|
||
|
|
- "{"
|
||
|
|
- codec->write(data->c);
|
||
|
|
- codec->write(data->blah);
|
||
|
|
- break;
|
||
|
|
- "}"
|
||
|
|
- "}"
|
||
|
|
- void foo_client::myUnion(fruitType discriminator, const unionType * unionVariable)
|
||
|
|
- not: codec->read(static_cast<int32_t>(discriminator));
|
||
|
|
- write_unionType_union(codec, static_cast<int32_t>(discriminator), unionVariable)
|
||
|
|
|
||
|
|
c_test_server.h:
|
||
|
|
- void myUnion(fruitType discriminator, const unionType * unionVariable);
|
||
|
|
|
||
|
|
test_server.cpp:
|
||
|
|
- static void read_unionType_union(erpc::Codec * codec, int32_t & discriminator, unionType * data);
|
||
|
|
- static void read_unionType_union(erpc::Codec * codec, int32_t & discriminator, unionType * data)
|
||
|
|
- "{"
|
||
|
|
- if(NULL == data)
|
||
|
|
- return;
|
||
|
|
- codec->startReadUnion(discriminator);
|
||
|
|
- switch (discriminator)
|
||
|
|
- "{"
|
||
|
|
- "case apple:"
|
||
|
|
- "{"
|
||
|
|
- read_foobar_struct(codec, &(data->myFoobar));
|
||
|
|
- break;
|
||
|
|
- "}"
|
||
|
|
- "case banana:"
|
||
|
|
- "{"
|
||
|
|
- codec->read(data->x);
|
||
|
|
- codec->read(data->y);
|
||
|
|
- break;
|
||
|
|
- "}"
|
||
|
|
- "case papaya:"
|
||
|
|
- "{"
|
||
|
|
- codec->read(data->x);
|
||
|
|
- codec->read(data->y);
|
||
|
|
- break;
|
||
|
|
- "}"
|
||
|
|
- "case orange:"
|
||
|
|
- "{"
|
||
|
|
- read_list_int32_1_t_struct(codec, &(data->a));
|
||
|
|
- break;
|
||
|
|
- "}"
|
||
|
|
- "case coconut:"
|
||
|
|
- "{"
|
||
|
|
- codec->read(data->cx);
|
||
|
|
- read_list_int32_1_t_struct(codec, &(data->cc));
|
||
|
|
- break;
|
||
|
|
- "}"
|
||
|
|
- "case returnVal:"
|
||
|
|
- "{"
|
||
|
|
- codec->read(data->ret);
|
||
|
|
- break;
|
||
|
|
- "}"
|
||
|
|
- "default:"
|
||
|
|
- "{"
|
||
|
|
- codec->read(data->c);
|
||
|
|
- codec->read(data->blah);
|
||
|
|
- break;
|
||
|
|
- "}"
|
||
|
|
- "}"
|
||
|
|
- static void free_unionType_union(int32_t discriminator, unionType * data);
|
||
|
|
- static void free_unionType_union(int32_t discriminator, unionType * data)
|
||
|
|
- "{"
|
||
|
|
- switch (discriminator)
|
||
|
|
- "{"
|
||
|
|
- "case banana:"
|
||
|
|
- not: "break;"
|
||
|
|
- "case papaya:"
|
||
|
|
- "case returnVal:"
|
||
|
|
- "default:"
|
||
|
|
- "{"
|
||
|
|
- "break;"
|
||
|
|
- "}"
|
||
|
|
- "case apple:"
|
||
|
|
- "{"
|
||
|
|
- free_foobar_struct(&data->myFoobar);
|
||
|
|
- break;
|
||
|
|
- "}"
|
||
|
|
- "case orange:"
|
||
|
|
- "{"
|
||
|
|
- free_list_int32_1_t_struct(&data->a);
|
||
|
|
- break;
|
||
|
|
- "}"
|
||
|
|
- "case coconut:"
|
||
|
|
- "{"
|
||
|
|
- free_list_int32_1_t_struct(&data->cc);
|
||
|
|
- break;
|
||
|
|
- "}"
|
||
|
|
- "}"
|
||
|
|
- fruitType discriminator;
|
||
|
|
- unionType *unionVariable = NULL;
|
||
|
|
- unionVariable = (unionType *) erpc_malloc(sizeof(unionType));
|
||
|
|
- if (unionVariable == NULL)
|
||
|
|
- "{"
|
||
|
|
- codec->updateStatus(kErpcStatus_MemoryError);
|
||
|
|
- "}"
|
||
|
|
- int32_t _tmp_local_i32;
|
||
|
|
- not: codec->read(_tmp_local_i32);
|
||
|
|
- not: discriminator = static_cast<fruitType>(_tmp_local_i32);
|
||
|
|
- read_unionType_union(codec, _tmp_local_i32, unionVariable);
|
||
|
|
- discriminator = static_cast<fruitType>(_tmp_local_i32);
|
||
|
|
- myUnion(discriminator, unionVariable);
|
||
|
|
|
||
|
|
---
|
||
|
|
name: basic non-encapsulated union inside struct
|
||
|
|
desc: Verify non-encapsulated unions usage in structures.
|
||
|
|
idl: |
|
||
|
|
|
||
|
|
enum fruitType { apple, orange, banana, coconut, grape, papaya, kiwi }
|
||
|
|
|
||
|
|
union unionType
|
||
|
|
{
|
||
|
|
case banana:
|
||
|
|
case papaya:
|
||
|
|
int32 x;
|
||
|
|
float y;
|
||
|
|
}
|
||
|
|
|
||
|
|
struct structType
|
||
|
|
{
|
||
|
|
fruitType discriminator
|
||
|
|
unionType unionVariable @discriminator(discriminator)
|
||
|
|
}
|
||
|
|
|
||
|
|
interface foo {
|
||
|
|
myUnion(structType structVariable) -> void
|
||
|
|
}
|
||
|
|
|
||
|
|
test_common.h:
|
||
|
|
- struct structType
|
||
|
|
- fruitType discriminator
|
||
|
|
- unionType unionVariable
|
||
|
|
|
||
|
|
c_test_client.h:
|
||
|
|
- void myUnion(const structType * structVariable);
|
||
|
|
|
||
|
|
test_client.cpp:
|
||
|
|
- write_unionType_union(codec, static_cast<int32_t>(data->discriminator), &data->unionVariable);
|
||
|
|
|
||
|
|
c_test_server.h:
|
||
|
|
- void myUnion(const structType * structVariable);
|
||
|
|
|
||
|
|
test_server.cpp:
|
||
|
|
- int32_t _tmp_local_i32;
|
||
|
|
- read_unionType_union(codec, _tmp_local_i32, &data->unionVariable);
|
||
|
|
|
||
|
|
#test_client.cpp:
|
||
|
|
# - static int32_t write_unionType_union(erpc::Codec * codec, int32_t discriminator, const unionType * data);
|
||
|
|
# - static int32_t write_unionType_union(erpc::Codec * codec, int32_t discriminator, const unionType * data)
|
||
|
|
|
||
|
|
#test_server.cpp:
|
||
|
|
# - static int32_t read_unionType_union(erpc::Codec * codec, int32_t discriminator, unionType * data);
|
||
|
|
# - static int32_t read_unionType_union(erpc::Codec * codec, int32_t discriminator, unionType * data)
|