mirror of
https://github.com/espressif/openthread.git
synced 2026-08-06 02:37:47 +00:00
Fix otNetifAddress declaration to work between C & C++ (#1037)
* Fix otNetifAddress declaration to work between C & C++
This commit is contained in:
@@ -72,6 +72,7 @@
|
||||
<ClCompile Include="..\..\tests\unit\test_ncp_buffer.cpp" />
|
||||
<ClCompile Include="..\..\tests\unit\test_platform.cpp" />
|
||||
<ClCompile Include="..\..\tests\unit\test_timer.cpp" />
|
||||
<ClCompile Include="..\..\tests\unit\test_toolchain_c.c" />
|
||||
<ClCompile Include="..\..\tests\unit\test_toolchain.cpp" />
|
||||
<ClCompile Include="..\..\tests\unit\test_util.cpp" />
|
||||
<ClCompile Include="..\..\tests\unit\test_windows.cpp" />
|
||||
|
||||
@@ -245,7 +245,7 @@ void otPlatRadioSetShortAddress(_In_ otInstance *otCtx, uint16_t address)
|
||||
}
|
||||
}
|
||||
|
||||
void otPlatRadioSetPromiscuous(_In_ otInstance *otCtx, int aEnable)
|
||||
void otPlatRadioSetPromiscuous(_In_ otInstance *otCtx, bool aEnable)
|
||||
{
|
||||
NT_ASSERT(otCtx);
|
||||
PMS_FILTER pFilter = otCtxToFilter(otCtx);
|
||||
@@ -444,7 +444,7 @@ otRadioCaps otPlatRadioGetCaps(_In_ otInstance *otCtx)
|
||||
return otCtxToFilter(otCtx)->otRadioCapabilities;
|
||||
}
|
||||
|
||||
int otPlatRadioGetPromiscuous(_In_ otInstance *otCtx)
|
||||
bool otPlatRadioGetPromiscuous(_In_ otInstance *otCtx)
|
||||
{
|
||||
NT_ASSERT(otCtx);
|
||||
PMS_FILTER pFilter = otCtxToFilter(otCtx);
|
||||
|
||||
@@ -48,6 +48,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma warning(disable:4214) // nonstandard extension used: bit field types other than int
|
||||
#ifdef _KERNEL_MODE
|
||||
#include <ntdef.h>
|
||||
#else
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
|
||||
#ifndef __cplusplus
|
||||
|
||||
typedef int bool;
|
||||
typedef _Bool bool;
|
||||
#define false 0
|
||||
#define true 1
|
||||
|
||||
|
||||
@@ -145,7 +145,7 @@ test_timer_LDADD = $(COMMON_LDADD)
|
||||
test_timer_SOURCES = test_platform.cpp test_timer.cpp
|
||||
|
||||
test_toolchain_LDADD = $(COMMON_LDADD)
|
||||
test_toolchain_SOURCES = test_platform.cpp test_toolchain.cpp
|
||||
test_toolchain_SOURCES = test_platform.cpp test_toolchain.cpp test_toolchain_c.c
|
||||
|
||||
if OPENTHREAD_ENABLE_DIAG
|
||||
test_diag_LDADD = $(top_builddir)/src/diag/libopenthread-diag.a \
|
||||
|
||||
@@ -32,6 +32,12 @@
|
||||
#include <thread/topology.hpp>
|
||||
#include "test_util.h"
|
||||
|
||||
extern "C" {
|
||||
uint32_t otNetifAddress_Size_c();
|
||||
uint32_t otNetifAddress_offset_mNext_c();
|
||||
otNetifAddress CreateNetif_c();
|
||||
}
|
||||
|
||||
void test_packed1()
|
||||
{
|
||||
OT_TOOL_PACKED_BEGIN
|
||||
@@ -93,12 +99,26 @@ void test_packed_enum()
|
||||
VerifyOrQuit(neighbor.mState == Thread::Neighbor::kStateValid, "Toolchain::OT_TOOL_PACKED failed 4\n");
|
||||
}
|
||||
|
||||
void test_addr_sizes()
|
||||
{
|
||||
VerifyOrQuit(offsetof(otNetifAddress, mNext) == otNetifAddress_offset_mNext_c(),
|
||||
"mNext should offset the same in C & C++");
|
||||
VerifyOrQuit(sizeof(otNetifAddress) == otNetifAddress_Size_c(), "otNetifAddress should the same in C & C++");
|
||||
}
|
||||
|
||||
void test_addr_bitfield()
|
||||
{
|
||||
VerifyOrQuit(CreateNetif_c().mScopeOverrideValid == true, "Toolchain::test_addr_size_cpp\n");
|
||||
}
|
||||
|
||||
void TestToolchain(void)
|
||||
{
|
||||
test_packed1();
|
||||
test_packed2();
|
||||
test_packed_union();
|
||||
test_packed_enum();
|
||||
test_addr_sizes();
|
||||
test_addr_bitfield();
|
||||
}
|
||||
|
||||
#ifdef ENABLE_TEST_MAIN
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2016, The OpenThread Authors.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <platform/toolchain.h>
|
||||
#include "test_util.h"
|
||||
|
||||
uint32_t otNetifAddress_Size_c()
|
||||
{
|
||||
return sizeof(otNetifAddress);
|
||||
}
|
||||
|
||||
uint32_t otNetifAddress_offset_mNext_c()
|
||||
{
|
||||
return offsetof(otNetifAddress, mNext);
|
||||
}
|
||||
|
||||
otNetifAddress CreateNetif_c()
|
||||
{
|
||||
otNetifAddress addr;
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.mScopeOverrideValid = true;
|
||||
return addr;
|
||||
}
|
||||
@@ -80,6 +80,8 @@ void test_packed1();
|
||||
void test_packed2();
|
||||
void test_packed_union();
|
||||
void test_packed_enum();
|
||||
void test_addr_sizes();
|
||||
void test_addr_bitfield();
|
||||
|
||||
// test_fuzz.cpp
|
||||
void TestFuzz(uint32_t aSeconds);
|
||||
@@ -155,6 +157,8 @@ namespace Thread
|
||||
TEST_METHOD(test_packed2) { ::test_packed2(); }
|
||||
TEST_METHOD(test_packed_union) { ::test_packed_union(); }
|
||||
TEST_METHOD(test_packed_enum) { ::test_packed_enum(); }
|
||||
TEST_METHOD(test_addr_sizes) { ::test_addr_sizes(); }
|
||||
TEST_METHOD(test_addr_bitfield) { ::test_addr_bitfield(); }
|
||||
|
||||
// test_settings.cpp
|
||||
TEST_METHOD(RunTestFuzz) { ::TestFuzz(30); }
|
||||
|
||||
Reference in New Issue
Block a user