From 604b910e533af03419f96e773d0976b51c08e3eb Mon Sep 17 00:00:00 2001 From: Madhura Jayaraman Date: Mon, 8 Jan 2024 10:36:26 -0800 Subject: [PATCH 1/4] Add POSIX tests b/316954263 Change-Id: I3e0452f0bb623042a905c8a65841fac1282d0820 --- starboard/nplb/BUILD.gn | 2 + .../posix_string_compare_no_case_n_test.cc | 61 +++++++++++++++++++ .../posix_string_compare_no_case_test.cc | 43 +++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 starboard/nplb/posix_compliance/posix_string_compare_no_case_n_test.cc create mode 100644 starboard/nplb/posix_compliance/posix_string_compare_no_case_test.cc diff --git a/starboard/nplb/BUILD.gn b/starboard/nplb/BUILD.gn index 6f8577fe4af8..0fc5c6ab3081 100644 --- a/starboard/nplb/BUILD.gn +++ b/starboard/nplb/BUILD.gn @@ -135,6 +135,8 @@ target(gtest_target_type, "nplb") { "player_test_util.cc", "player_test_util.h", "player_write_sample_test.cc", + "posix_compliance/posix_string_compare_no_case_n_test.cc", + "posix_compliance/posix_string_compare_no_case_test.cc", "random_helpers.cc", "recursive_mutex_test.cc", "rwlock_test.cc", diff --git a/starboard/nplb/posix_compliance/posix_string_compare_no_case_n_test.cc b/starboard/nplb/posix_compliance/posix_string_compare_no_case_n_test.cc new file mode 100644 index 000000000000..a93eefd904ff --- /dev/null +++ b/starboard/nplb/posix_compliance/posix_string_compare_no_case_n_test.cc @@ -0,0 +1,61 @@ +// Copyright 2015 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. + +#include "starboard/common/string.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace starboard { +namespace nplb { +namespace { + +#if SB_API_VERSION >= 16 +TEST(SbStringCompareNoCaseNTest, SunnyDaySelf) { + const char kString[] = "0123456789"; + EXPECT_EQ(0, strncasecmp(kString, kString, strlen(kString))); + EXPECT_EQ(0, strncasecmp("", "", 0)); +} + +TEST(SbStringCompareNoCaseNTest, SunnyDayEmptyLessThanNotEmpty) { + const char kString[] = "0123456789"; + EXPECT_GT(0, strncasecmp("", kString, strlen(kString))); +} + +TEST(SbStringCompareNoCaseNTest, SunnyDayEmptyZeroNEqual) { + const char kString[] = "0123456789"; + EXPECT_EQ(0, strncasecmp("", kString, 0)); +} + +TEST(SbStringCompareNoCaseNTest, SunnyDayBigN) { + const char kString[] = "0123456789"; + EXPECT_EQ(0, strncasecmp(kString, kString, strlen(kString) * 2)); +} + +TEST(SbStringCompareNoCaseNTest, SunnyDayCase) { + const char kString1[] = "aBcDeFgHiJkLmNoPqRsTuVwXyZ"; + const char kString2[] = "AbCdEfGhIjKlMnOpQrStUvWxYz"; + EXPECT_EQ(0, strncasecmp(kString1, kString2, strlen(kString1))); + EXPECT_EQ(0, strncasecmp(kString2, kString1, strlen(kString2))); + + const char kString3[] = "aBcDeFgHiJkLmaBcDeFgHiJkLm"; + const char kString4[] = "AbCdEfGhIjKlMnOpQrStUvWxYz"; + EXPECT_GT(0, strncasecmp(kString3, kString4, strlen(kString3))); + EXPECT_LT(0, strncasecmp(kString4, kString3, strlen(kString4))); + EXPECT_EQ(0, strncasecmp(kString3, kString4, strlen(kString3) / 2)); + EXPECT_EQ(0, strncasecmp(kString4, kString3, strlen(kString4) / 2)); +} +#endif // SB_API_VERSION >= 16 + +} // namespace +} // namespace nplb +} // namespace starboard diff --git a/starboard/nplb/posix_compliance/posix_string_compare_no_case_test.cc b/starboard/nplb/posix_compliance/posix_string_compare_no_case_test.cc new file mode 100644 index 000000000000..e97572a018ae --- /dev/null +++ b/starboard/nplb/posix_compliance/posix_string_compare_no_case_test.cc @@ -0,0 +1,43 @@ +// Copyright 2015 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. + +#include "starboard/common/string.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace starboard { +namespace nplb { +namespace { + +#if SB_API_VERSION >= 16 +TEST(SbStringCompareNoCaseTest, SunnyDaySelf) { + const char kString[] = "0123456789"; + EXPECT_EQ(0, strcasecmp(kString, kString)); + EXPECT_EQ(0, strcasecmp("", "")); +} + +TEST(SbStringCompareNoCaseTest, SunnyDayEmptyLessThanNotEmpty) { + const char kString[] = "0123456789"; + EXPECT_GT(0, strcasecmp("", kString)); +} + +TEST(SbStringCompareNoCaseTest, SunnyDayCase) { + const char kString1[] = "aBcDeFgHiJkLmNoPqRsTuVwXyZ"; + const char kString2[] = "AbCdEfGhIjKlMnOpQrStUvWxYz"; + EXPECT_EQ(0, strcasecmp(kString1, kString2)); + EXPECT_EQ(0, strcasecmp(kString2, kString1)); +} +#endif // SB_API_VERSION >= 16 +} // namespace +} // namespace nplb +} // namespace starboard From 39a4ee54fe66719007a79f9619c0ab14262a4f0f Mon Sep 17 00:00:00 2001 From: Madhura Jayaraman Date: Mon, 8 Jan 2024 13:47:29 -0800 Subject: [PATCH 2/4] Add POSIX tests b/316954263 Change-Id: I757da3e74823c3886a82597b5af2a6c6a2a1a87a --- .../posix_string_compare_no_case_n_test.cc | 10 +++++----- .../posix_string_compare_no_case_test.cc | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/starboard/nplb/posix_compliance/posix_string_compare_no_case_n_test.cc b/starboard/nplb/posix_compliance/posix_string_compare_no_case_n_test.cc index a93eefd904ff..40adce568943 100644 --- a/starboard/nplb/posix_compliance/posix_string_compare_no_case_n_test.cc +++ b/starboard/nplb/posix_compliance/posix_string_compare_no_case_n_test.cc @@ -20,28 +20,28 @@ namespace nplb { namespace { #if SB_API_VERSION >= 16 -TEST(SbStringCompareNoCaseNTest, SunnyDaySelf) { +TEST(SbStringCompareNoCaseNPosixTest, SunnyDaySelf) { const char kString[] = "0123456789"; EXPECT_EQ(0, strncasecmp(kString, kString, strlen(kString))); EXPECT_EQ(0, strncasecmp("", "", 0)); } -TEST(SbStringCompareNoCaseNTest, SunnyDayEmptyLessThanNotEmpty) { +TEST(SbStringCompareNoCaseNPosixTest, SunnyDayEmptyLessThanNotEmpty) { const char kString[] = "0123456789"; EXPECT_GT(0, strncasecmp("", kString, strlen(kString))); } -TEST(SbStringCompareNoCaseNTest, SunnyDayEmptyZeroNEqual) { +TEST(SbStringCompareNoCaseNPosixTest, SunnyDayEmptyZeroNEqual) { const char kString[] = "0123456789"; EXPECT_EQ(0, strncasecmp("", kString, 0)); } -TEST(SbStringCompareNoCaseNTest, SunnyDayBigN) { +TEST(SbStringCompareNoCaseNPosixTest, SunnyDayBigN) { const char kString[] = "0123456789"; EXPECT_EQ(0, strncasecmp(kString, kString, strlen(kString) * 2)); } -TEST(SbStringCompareNoCaseNTest, SunnyDayCase) { +TEST(SbStringCompareNoCaseNPosixTest, SunnyDayCase) { const char kString1[] = "aBcDeFgHiJkLmNoPqRsTuVwXyZ"; const char kString2[] = "AbCdEfGhIjKlMnOpQrStUvWxYz"; EXPECT_EQ(0, strncasecmp(kString1, kString2, strlen(kString1))); diff --git a/starboard/nplb/posix_compliance/posix_string_compare_no_case_test.cc b/starboard/nplb/posix_compliance/posix_string_compare_no_case_test.cc index e97572a018ae..e18d73c1fdb1 100644 --- a/starboard/nplb/posix_compliance/posix_string_compare_no_case_test.cc +++ b/starboard/nplb/posix_compliance/posix_string_compare_no_case_test.cc @@ -20,18 +20,18 @@ namespace nplb { namespace { #if SB_API_VERSION >= 16 -TEST(SbStringCompareNoCaseTest, SunnyDaySelf) { +TEST(SbStringCompareNoCasePosixTest, SunnyDaySelf) { const char kString[] = "0123456789"; EXPECT_EQ(0, strcasecmp(kString, kString)); EXPECT_EQ(0, strcasecmp("", "")); } -TEST(SbStringCompareNoCaseTest, SunnyDayEmptyLessThanNotEmpty) { +TEST(SbStringCompareNoCasePosixTest, SunnyDayEmptyLessThanNotEmpty) { const char kString[] = "0123456789"; EXPECT_GT(0, strcasecmp("", kString)); } -TEST(SbStringCompareNoCaseTest, SunnyDayCase) { +TEST(SbStringCompareNoCasePosixTest, SunnyDayCase) { const char kString1[] = "aBcDeFgHiJkLmNoPqRsTuVwXyZ"; const char kString2[] = "AbCdEfGhIjKlMnOpQrStUvWxYz"; EXPECT_EQ(0, strcasecmp(kString1, kString2)); From 0f8e19c85ffa087d3b0483b4df413895cafa413a Mon Sep 17 00:00:00 2001 From: Madhura Jayaraman Date: Mon, 8 Jan 2024 14:27:20 -0800 Subject: [PATCH 3/4] Add POSIX tests b/316954263 Change-Id: Ib248c50b9fc3b1c1f80955ffde8e86e6b1413af9 --- .../posix_string_compare_no_case_n_test.cc | 12 +++++++----- .../posix_string_compare_no_case_test.cc | 8 +++++--- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/starboard/nplb/posix_compliance/posix_string_compare_no_case_n_test.cc b/starboard/nplb/posix_compliance/posix_string_compare_no_case_n_test.cc index 40adce568943..843b5800f45e 100644 --- a/starboard/nplb/posix_compliance/posix_string_compare_no_case_n_test.cc +++ b/starboard/nplb/posix_compliance/posix_string_compare_no_case_n_test.cc @@ -17,31 +17,32 @@ namespace starboard { namespace nplb { +namespace posix_compliance { namespace { #if SB_API_VERSION >= 16 -TEST(SbStringCompareNoCaseNPosixTest, SunnyDaySelf) { +TEST(PosixCompareNoCaseNTest, SunnyDaySelf) { const char kString[] = "0123456789"; EXPECT_EQ(0, strncasecmp(kString, kString, strlen(kString))); EXPECT_EQ(0, strncasecmp("", "", 0)); } -TEST(SbStringCompareNoCaseNPosixTest, SunnyDayEmptyLessThanNotEmpty) { +TEST(PosixCompareNoCaseNTest, SunnyDayEmptyLessThanNotEmpty) { const char kString[] = "0123456789"; EXPECT_GT(0, strncasecmp("", kString, strlen(kString))); } -TEST(SbStringCompareNoCaseNPosixTest, SunnyDayEmptyZeroNEqual) { +TEST(PosixCompareNoCaseNTest, SunnyDayEmptyZeroNEqual) { const char kString[] = "0123456789"; EXPECT_EQ(0, strncasecmp("", kString, 0)); } -TEST(SbStringCompareNoCaseNPosixTest, SunnyDayBigN) { +TEST(PosixCompareNoCaseNTest, SunnyDayBigN) { const char kString[] = "0123456789"; EXPECT_EQ(0, strncasecmp(kString, kString, strlen(kString) * 2)); } -TEST(SbStringCompareNoCaseNPosixTest, SunnyDayCase) { +TEST(PosixCompareNoCaseNTest, SunnyDayCase) { const char kString1[] = "aBcDeFgHiJkLmNoPqRsTuVwXyZ"; const char kString2[] = "AbCdEfGhIjKlMnOpQrStUvWxYz"; EXPECT_EQ(0, strncasecmp(kString1, kString2, strlen(kString1))); @@ -57,5 +58,6 @@ TEST(SbStringCompareNoCaseNPosixTest, SunnyDayCase) { #endif // SB_API_VERSION >= 16 } // namespace +} // namespace posix_compliance } // namespace nplb } // namespace starboard diff --git a/starboard/nplb/posix_compliance/posix_string_compare_no_case_test.cc b/starboard/nplb/posix_compliance/posix_string_compare_no_case_test.cc index e18d73c1fdb1..8de3563b7548 100644 --- a/starboard/nplb/posix_compliance/posix_string_compare_no_case_test.cc +++ b/starboard/nplb/posix_compliance/posix_string_compare_no_case_test.cc @@ -17,21 +17,22 @@ namespace starboard { namespace nplb { +namespace posix_compliance { namespace { #if SB_API_VERSION >= 16 -TEST(SbStringCompareNoCasePosixTest, SunnyDaySelf) { +TEST(PosixCompareNoCaseTest, SunnyDaySelf) { const char kString[] = "0123456789"; EXPECT_EQ(0, strcasecmp(kString, kString)); EXPECT_EQ(0, strcasecmp("", "")); } -TEST(SbStringCompareNoCasePosixTest, SunnyDayEmptyLessThanNotEmpty) { +TEST(PosixCompareNoCaseTest, SunnyDayEmptyLessThanNotEmpty) { const char kString[] = "0123456789"; EXPECT_GT(0, strcasecmp("", kString)); } -TEST(SbStringCompareNoCasePosixTest, SunnyDayCase) { +TEST(PosixCompareNoCaseTest, SunnyDayCase) { const char kString1[] = "aBcDeFgHiJkLmNoPqRsTuVwXyZ"; const char kString2[] = "AbCdEfGhIjKlMnOpQrStUvWxYz"; EXPECT_EQ(0, strcasecmp(kString1, kString2)); @@ -39,5 +40,6 @@ TEST(SbStringCompareNoCasePosixTest, SunnyDayCase) { } #endif // SB_API_VERSION >= 16 } // namespace +} // namespace posix_compliance } // namespace nplb } // namespace starboard From a970b173a895ff18688cabad298edb00d1f7e846 Mon Sep 17 00:00:00 2001 From: Madhura Jayaraman Date: Mon, 8 Jan 2024 15:23:04 -0800 Subject: [PATCH 4/4] Add POSIX tests b/316954263 Change-Id: I913c2f13a4c9748ae88f47ca79ffe4500fca3a63 --- starboard/nplb/BUILD.gn | 2 + .../posix_string_compare_no_case_n_test.cc | 2 - .../posix_string_compare_no_case_test.cc | 2 - .../posix_string_format_test.cc | 50 +++++++++++++++++ .../posix_string_format_wide_test.cc | 53 +++++++++++++++++++ 5 files changed, 105 insertions(+), 4 deletions(-) create mode 100644 starboard/nplb/posix_compliance/posix_string_format_test.cc create mode 100644 starboard/nplb/posix_compliance/posix_string_format_wide_test.cc diff --git a/starboard/nplb/BUILD.gn b/starboard/nplb/BUILD.gn index 0fc5c6ab3081..9e42544a8a68 100644 --- a/starboard/nplb/BUILD.gn +++ b/starboard/nplb/BUILD.gn @@ -137,6 +137,8 @@ target(gtest_target_type, "nplb") { "player_write_sample_test.cc", "posix_compliance/posix_string_compare_no_case_n_test.cc", "posix_compliance/posix_string_compare_no_case_test.cc", + "posix_compliance/posix_string_format_test.cc", + "posix_compliance/posix_string_format_wide_test.cc", "random_helpers.cc", "recursive_mutex_test.cc", "rwlock_test.cc", diff --git a/starboard/nplb/posix_compliance/posix_string_compare_no_case_n_test.cc b/starboard/nplb/posix_compliance/posix_string_compare_no_case_n_test.cc index 843b5800f45e..6b98cb4c6c40 100644 --- a/starboard/nplb/posix_compliance/posix_string_compare_no_case_n_test.cc +++ b/starboard/nplb/posix_compliance/posix_string_compare_no_case_n_test.cc @@ -17,7 +17,6 @@ namespace starboard { namespace nplb { -namespace posix_compliance { namespace { #if SB_API_VERSION >= 16 @@ -58,6 +57,5 @@ TEST(PosixCompareNoCaseNTest, SunnyDayCase) { #endif // SB_API_VERSION >= 16 } // namespace -} // namespace posix_compliance } // namespace nplb } // namespace starboard diff --git a/starboard/nplb/posix_compliance/posix_string_compare_no_case_test.cc b/starboard/nplb/posix_compliance/posix_string_compare_no_case_test.cc index 8de3563b7548..1417a10bf693 100644 --- a/starboard/nplb/posix_compliance/posix_string_compare_no_case_test.cc +++ b/starboard/nplb/posix_compliance/posix_string_compare_no_case_test.cc @@ -17,7 +17,6 @@ namespace starboard { namespace nplb { -namespace posix_compliance { namespace { #if SB_API_VERSION >= 16 @@ -40,6 +39,5 @@ TEST(PosixCompareNoCaseTest, SunnyDayCase) { } #endif // SB_API_VERSION >= 16 } // namespace -} // namespace posix_compliance } // namespace nplb } // namespace starboard diff --git a/starboard/nplb/posix_compliance/posix_string_format_test.cc b/starboard/nplb/posix_compliance/posix_string_format_test.cc new file mode 100644 index 000000000000..e1a793dc15c9 --- /dev/null +++ b/starboard/nplb/posix_compliance/posix_string_format_test.cc @@ -0,0 +1,50 @@ +// Copyright 2015 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. + +// Here we are not trying to do anything fancy, just to really sanity check that +// this is hooked up to something. +#if SB_API_VERSION >= 16 + +#include "starboard/common/string.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace starboard { +namespace nplb { +namespace { + +int Format(char* out_buffer, size_t buffer_size, const char* format, ...) { + va_list arguments; + va_start(arguments, format); + int result = vsnprintf(out_buffer, buffer_size, format, arguments); + va_end(arguments); + return result; +} + +TEST(PosixFormatTest, SunnyDay) { + const char kExpected[] = "a1b2c3test"; + char destination[1024] = {0}; + int result = Format(destination, SB_ARRAY_SIZE(destination), "a%db%dc%d%s", 1, + 2, 3, "test"); + size_t expected_length = strlen(kExpected); + EXPECT_EQ(expected_length, result); + for (size_t i = 0; i <= expected_length; ++i) { + EXPECT_EQ(kExpected[i], destination[i]); + } +} + +} // namespace +} // namespace nplb +} // namespace starboard + // +#endif // SB_API_VERSION >= 16 diff --git a/starboard/nplb/posix_compliance/posix_string_format_wide_test.cc b/starboard/nplb/posix_compliance/posix_string_format_wide_test.cc new file mode 100644 index 000000000000..1a6e39defc38 --- /dev/null +++ b/starboard/nplb/posix_compliance/posix_string_format_wide_test.cc @@ -0,0 +1,53 @@ +// Copyright 2015 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. + +// Here we are not trying to do anything fancy, just to really sanity check that +// this is hooked up to something. +#if SB_API_VERSION >= 16 + +#include "starboard/common/string.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace starboard { +namespace nplb { +namespace { + +int Format(wchar_t* out_buffer, + size_t buffer_size, + const wchar_t* format, + ...) { + va_list arguments; + va_start(arguments, format); + int result = vswprintf(out_buffer, buffer_size, format, arguments); + va_end(arguments); + return result; +} + +TEST(PosixFormatWideTest, SunnyDay) { + const wchar_t kExpected[] = L"a1b2c3test"; + wchar_t destination[1024] = {0}; + int result = Format(destination, SB_ARRAY_SIZE(destination), L"a%db%dc%d%s", + 1, 2, 3, "test"); + size_t expected_length = wcslen(kExpected); + EXPECT_EQ(expected_length, result); + for (size_t i = 0; i <= expected_length; ++i) { + EXPECT_EQ(kExpected[i], destination[i]); + } +} + +} // namespace +} // namespace nplb +} // namespace starboard + +#endif // SB_API_VERSION >= 16