diff --git a/starboard/client_porting/poem/inet_poem.h b/starboard/client_porting/poem/inet_poem.h deleted file mode 100644 index 26d86c433b00..000000000000 --- a/starboard/client_porting/poem/inet_poem.h +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2016 The Cobalt Authors. All Rights Reserved. -// -// 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. - -// A poem (POsix EMulation) for functions usually declared in - -#ifndef STARBOARD_CLIENT_PORTING_POEM_INET_POEM_H_ -#define STARBOARD_CLIENT_PORTING_POEM_INET_POEM_H_ - -#if defined(STARBOARD) - -#if SB_API_VERSION < 16 - -#include "starboard/common/byte_swap.h" - -#undef htonl -#define htonl(x) SB_HOST_TO_NET_U32(x) - -#undef htons -#define htons(x) SB_HOST_TO_NET_U16(x) - -#undef ntohl -#define ntohl(x) SB_NET_TO_HOST_U32(x) - -#undef ntohs -#define ntohs(x) SB_NET_TO_HOST_U16(x) - -#else // SB_API_VERSION < 16 - -#include - -#endif // SB_API_VERSION < 16 - -#endif // defined(STARBOARD) - -#endif // STARBOARD_CLIENT_PORTING_POEM_INET_POEM_H_ diff --git a/starboard/common/BUILD.gn b/starboard/common/BUILD.gn index 71e6d5a5acfa..b46e127e8ea7 100644 --- a/starboard/common/BUILD.gn +++ b/starboard/common/BUILD.gn @@ -36,7 +36,6 @@ static_library("common") { "//starboard/shared/media_session/playback_state.h", "allocator.cc", "allocator.h", - "byte_swap.h", "common.cc", "condition_variable.cc", "condition_variable.h", diff --git a/starboard/common/byte_swap.h b/starboard/common/byte_swap.h deleted file mode 100644 index 96142be40b92..000000000000 --- a/starboard/common/byte_swap.h +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2016 The Cobalt Authors. All Rights Reserved. -// -// 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. - -// Module Overview: Starboard Byte Swap macros -// -// Specifies macros for swapping byte order. These functions are used to -// deal with endianness when performing I/O. - -#ifndef STARBOARD_COMMON_BYTE_SWAP_H_ -#define STARBOARD_COMMON_BYTE_SWAP_H_ - -#if SB_API_VERSION < 16 - -#include "starboard/byte_swap.h" - -#else // SB_API_VERSION < 16 - -#ifdef _WIN32 -#include -#endif - -#include "starboard/configuration.h" - -#if SB_IS(BIG_ENDIAN) -#define SB_HOST_TO_NET_S16(x) (x) -#define SB_HOST_TO_NET_U16(x) (x) -#define SB_HOST_TO_NET_S32(x) (x) -#define SB_HOST_TO_NET_U32(x) (x) -#define SB_HOST_TO_NET_S64(x) (x) -#define SB_HOST_TO_NET_U64(x) (x) -#elif defined(_WIN32) -#define SB_HOST_TO_NET_S16(x) _byteswap_ushort(x) -#define SB_HOST_TO_NET_U16(x) _byteswap_ushort(x) -#define SB_HOST_TO_NET_S32(x) _byteswap_ulong(x) -#define SB_HOST_TO_NET_U32(x) _byteswap_ulong(x) -#define SB_HOST_TO_NET_S64(x) _byteswap_uint64(x) -#define SB_HOST_TO_NET_U64(x) _byteswap_uint64(x) -#else -#define SB_HOST_TO_NET_S16(x) __builtin_bswap16(x) -#define SB_HOST_TO_NET_U16(x) __builtin_bswap16(x) -#define SB_HOST_TO_NET_S32(x) __builtin_bswap32(x) -#define SB_HOST_TO_NET_U32(x) __builtin_bswap32(x) -#define SB_HOST_TO_NET_S64(x) __builtin_bswap64(x) -#define SB_HOST_TO_NET_U64(x) __builtin_bswap64(x) -#endif - -#define SB_NET_TO_HOST_S16(x) SB_HOST_TO_NET_S16(x) -#define SB_NET_TO_HOST_U16(x) SB_HOST_TO_NET_U16(x) -#define SB_NET_TO_HOST_S32(x) SB_HOST_TO_NET_S32(x) -#define SB_NET_TO_HOST_U32(x) SB_HOST_TO_NET_U32(x) -#define SB_NET_TO_HOST_S64(x) SB_HOST_TO_NET_S64(x) -#define SB_NET_TO_HOST_U64(x) SB_HOST_TO_NET_U64(x) - -#endif // SB_API_VERSION < 16 - -#endif // STARBOARD_COMMON_BYTE_SWAP_H_ diff --git a/starboard/nplb/BUILD.gn b/starboard/nplb/BUILD.gn index 866a9275ad22..6f8577fe4af8 100644 --- a/starboard/nplb/BUILD.gn +++ b/starboard/nplb/BUILD.gn @@ -31,6 +31,7 @@ target(gtest_target_type, "nplb") { "//starboard/testing/fake_graphics_context_provider.h", "accessibility_test.cc", "align_test.cc", + "arpa_inet_test.cc", "atomic_base_test.cc", "atomic_test.cc", "audio_sink_create_test.cc", diff --git a/starboard/nplb/arpa_inet_test.cc b/starboard/nplb/arpa_inet_test.cc new file mode 100644 index 000000000000..9597c9f32ea1 --- /dev/null +++ b/starboard/nplb/arpa_inet_test.cc @@ -0,0 +1,54 @@ +// Copyright 2024 The Cobalt Authors. All Rights Reserved. +// +// 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. + +#if SB_API_VERSION >= 16 + +#include +#include + +#include "starboard/configuration.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace starboard { +namespace nplb { +namespace { + +const uint16_t kTestU16 = 0xABCD; +const uint16_t kExpectedU16 = 0xCDAB; +const uint32_t kTestU32 = 0xFEDCBA98; +const uint32_t kExpectedU32 = 0x98BADCFE; + +#if SB_IS(BIG_ENDIAN) +TEST(ArpaInet, BigEndian) { + EXPECT_EQ(kTestU16, htons(kTestU16)); + EXPECT_EQ(kTestU16, ntohs(kTestU16)); + + EXPECT_EQ(kTestU32, htonl(kTestU32)); + EXPECT_EQ(kTestU32, ntohl(kTestU32)); +} +#else +TEST(SbByteSwapTest, LittleEndian) { + EXPECT_EQ(kExpectedU16, htons(kTestU16)); + EXPECT_EQ(kExpectedU16, ntohs(kTestU16)); + + EXPECT_EQ(kExpectedU32, htonl(kTestU32)); + EXPECT_EQ(kExpectedU32, ntohl(kTestU32)); +} +#endif + +} // namespace +} // namespace nplb +} // namespace starboard + +#endif // SB_API_VERSION >= 16 diff --git a/starboard/nplb/byte_swap_test.cc b/starboard/nplb/byte_swap_test.cc index 91ff92e347d7..83fe64d68ee0 100644 --- a/starboard/nplb/byte_swap_test.cc +++ b/starboard/nplb/byte_swap_test.cc @@ -12,7 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "starboard/common/byte_swap.h" +#if SB_API_VERSION < 16 + +#include "starboard/byte_swap.h" #include @@ -36,7 +38,6 @@ const int64_t kTestS64 = static_cast(SB_INT64_C(0xFEDCBA9876543210)); const int64_t kExpectedS64 = static_cast(SB_INT64_C(0x1032547698BADCFE)); -#if SB_API_VERSION < 16 TEST(SbByteSwapTest, SunnyDay) { EXPECT_EQ(kExpectedU16, SbByteSwapU16(kTestU16)); EXPECT_EQ(kExpectedS16, SbByteSwapS16(kTestS16)); @@ -47,7 +48,6 @@ TEST(SbByteSwapTest, SunnyDay) { EXPECT_EQ(kExpectedU64, SbByteSwapU64(kTestU64)); EXPECT_EQ(kExpectedS64, SbByteSwapS64(kTestS64)); } -#endif #if SB_IS(BIG_ENDIAN) TEST(SbByteSwapTest, BigEndian) { @@ -76,3 +76,5 @@ TEST(SbByteSwapTest, LittleEndian) { } // namespace } // namespace nplb } // namespace starboard + +#endif // SB_API_VERSION < 16