29 lines · cpp
1//===-- Unittests for htons -----------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "src/__support/endian_internal.h"10#include "src/arpa/inet/htons.h"11#include "src/arpa/inet/ntohs.h"12#include "test/UnitTest/Test.h"13 14TEST(LlvmLibcHtons, SmokeTest) {15 uint16_t original = 0x2301;16 uint16_t swapped = 0x0123;17#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__18 EXPECT_EQ(LIBC_NAMESPACE::htons(original), swapped);19#endif20#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__21 EXPECT_EQ(LIBC_NAMESPACE::htons(original), original);22#endif23}24 25TEST(LlvmLibcHtons, CompleteTest) {26 uint16_t original = 0x0123;27 EXPECT_EQ(LIBC_NAMESPACE::htons(LIBC_NAMESPACE::ntohs(original)), original);28}29