diff --git a/UNITTESTS/stubs/FileHandle_stub.h b/UNITTESTS/stubs/FileHandle_stub.h deleted file mode 100644 index 5dacb0b..0000000 --- a/UNITTESTS/stubs/FileHandle_stub.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) , Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * 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. - */ - -#ifndef __FILE_HANDLE_STUB_H__ -#define __FILE_HANDLE_STUB_H__ - -#include "FileHandle.h" - -namespace mbed { - -static uint8_t filehandle_stub_short_value_counter = 0; -static char *filehandle_stub_table = NULL; -static uint8_t filehandle_stub_table_pos = 0; - -class FileHandle_stub : public FileHandle { -public: - ssize_t size_value; - - FileHandle_stub() - { - size_value = 0; - } - - virtual ssize_t read(void *buffer, size_t size) - { - if (filehandle_stub_table) { - ssize_t ret = strlen(filehandle_stub_table) - filehandle_stub_table_pos; - if (size < ret) { - ret = size; - } - memcpy(buffer, filehandle_stub_table + filehandle_stub_table_pos, ret); - filehandle_stub_table_pos += ret; - return ret; - } - return 0; - } - - virtual ssize_t write(const void *buffer, size_t size) - { - if (size_value > 0) { - size_value--; - return size; - } else if (size_value < 0) { - return -1; - } - return 0; - } - - virtual off_t seek(off_t offset, int whence = SEEK_SET) - { - return 0; - } - - virtual int close() - { - return 0; - } - - virtual short poll(short events) const - { - if (filehandle_stub_short_value_counter) { - filehandle_stub_short_value_counter--; - return short_value; - } - return 0; - } - - virtual void sigio(Callback func) - { - if (func) { - func(); - } - } - - short short_value; -}; - -} // namespace mbed - -#endif diff --git a/UNITTESTS/stubs/connectivity/CMakeLists.txt b/UNITTESTS/stubs/connectivity/CMakeLists.txt index 5166442..e2056da 100644 --- a/UNITTESTS/stubs/connectivity/CMakeLists.txt +++ b/UNITTESTS/stubs/connectivity/CMakeLists.txt @@ -48,5 +48,6 @@ mbed-headers mbed-stubs-headers mbed-stubs-rtos + mbed-stubs-platform gtest ) diff --git a/UNITTESTS/stubs/mbed_poll_stub.h b/UNITTESTS/stubs/mbed_poll_stub.h deleted file mode 100644 index 930766e..0000000 --- a/UNITTESTS/stubs/mbed_poll_stub.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2017, Arm Limited and affiliates. - * SPDX-License-Identifier: Apache-2.0 - * - * 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. - */ - -#ifndef __MBED_POLL_STUB_H__ -#define __MBED_POLL_STUB_H__ - -#include - -namespace mbed_poll_stub { -extern int revents_value; -extern int int_value; -} - -#endif diff --git a/connectivity/cellular/tests/UNITTESTS/doubles/CMakeLists.txt b/connectivity/cellular/tests/UNITTESTS/doubles/CMakeLists.txt index adbed15..ffc3c64 100644 --- a/connectivity/cellular/tests/UNITTESTS/doubles/CMakeLists.txt +++ b/connectivity/cellular/tests/UNITTESTS/doubles/CMakeLists.txt @@ -46,7 +46,7 @@ PRIVATE mbed-headers-base mbed-headers-connectivity - mbed-headers-platform + mbed-stubs-platform mbed-headers-rtos mbed-headers-drivers mbed-headers-hal diff --git a/platform/tests/UNITTESTS/doubles/CMakeLists.txt b/platform/tests/UNITTESTS/doubles/CMakeLists.txt index f54e89e..81c34b1 100644 --- a/platform/tests/UNITTESTS/doubles/CMakeLists.txt +++ b/platform/tests/UNITTESTS/doubles/CMakeLists.txt @@ -26,6 +26,10 @@ randLIB_stub.c randLIB_stub.cpp ) +target_include_directories(mbed-stubs-platform + PUBLIC + . +) target_link_options(mbed-stubs-platform PRIVATE --coverage @@ -35,5 +39,4 @@ mbed-headers-base mbed-headers-hal mbed-headers-platform - mbed-stubs-headers ) diff --git a/platform/tests/UNITTESTS/doubles/FileHandle_stub.h b/platform/tests/UNITTESTS/doubles/FileHandle_stub.h new file mode 100644 index 0000000..5dacb0b --- /dev/null +++ b/platform/tests/UNITTESTS/doubles/FileHandle_stub.h @@ -0,0 +1,94 @@ +/* + * Copyright (c) , Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * 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. + */ + +#ifndef __FILE_HANDLE_STUB_H__ +#define __FILE_HANDLE_STUB_H__ + +#include "FileHandle.h" + +namespace mbed { + +static uint8_t filehandle_stub_short_value_counter = 0; +static char *filehandle_stub_table = NULL; +static uint8_t filehandle_stub_table_pos = 0; + +class FileHandle_stub : public FileHandle { +public: + ssize_t size_value; + + FileHandle_stub() + { + size_value = 0; + } + + virtual ssize_t read(void *buffer, size_t size) + { + if (filehandle_stub_table) { + ssize_t ret = strlen(filehandle_stub_table) - filehandle_stub_table_pos; + if (size < ret) { + ret = size; + } + memcpy(buffer, filehandle_stub_table + filehandle_stub_table_pos, ret); + filehandle_stub_table_pos += ret; + return ret; + } + return 0; + } + + virtual ssize_t write(const void *buffer, size_t size) + { + if (size_value > 0) { + size_value--; + return size; + } else if (size_value < 0) { + return -1; + } + return 0; + } + + virtual off_t seek(off_t offset, int whence = SEEK_SET) + { + return 0; + } + + virtual int close() + { + return 0; + } + + virtual short poll(short events) const + { + if (filehandle_stub_short_value_counter) { + filehandle_stub_short_value_counter--; + return short_value; + } + return 0; + } + + virtual void sigio(Callback func) + { + if (func) { + func(); + } + } + + short short_value; +}; + +} // namespace mbed + +#endif diff --git a/platform/tests/UNITTESTS/doubles/mbed_poll_stub.h b/platform/tests/UNITTESTS/doubles/mbed_poll_stub.h new file mode 100644 index 0000000..930766e --- /dev/null +++ b/platform/tests/UNITTESTS/doubles/mbed_poll_stub.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2017, Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * 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. + */ + +#ifndef __MBED_POLL_STUB_H__ +#define __MBED_POLL_STUB_H__ + +#include + +namespace mbed_poll_stub { +extern int revents_value; +extern int int_value; +} + +#endif