diff options
| author | Elliott Hughes <enh@google.com> | 2014-04-04 17:34:51 -0700 |
|---|---|---|
| committer | Elliott Hughes <enh@google.com> | 2014-04-07 14:29:28 -0700 |
| commit | 77e944fd46728075fe632bcb5211da9daf5b7e68 (patch) | |
| tree | 078c4ed4dcd4a8d857aa948de76dec223c588e0d /tests/wchar_test.cpp | |
| parent | dc5fcf3620bfc221954b3d42f459bfdcf8f48216 (diff) | |
| download | android_bionic-77e944fd46728075fe632bcb5211da9daf5b7e68.tar.gz android_bionic-77e944fd46728075fe632bcb5211da9daf5b7e68.tar.bz2 android_bionic-77e944fd46728075fe632bcb5211da9daf5b7e68.zip | |
Implement wctomb(3) for ltrace.
This is an implementation in the style of the rest: char == byte.
We might want to come back and implement UTF-8, but this is enough for ltrace.
Bug: 13747066
Change-Id: Ib2b63609c9014fdef9a8491e067467c4fc5ae3cc
Diffstat (limited to 'tests/wchar_test.cpp')
| -rw-r--r-- | tests/wchar_test.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/wchar_test.cpp b/tests/wchar_test.cpp new file mode 100644 index 000000000..20566f26a --- /dev/null +++ b/tests/wchar_test.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * 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 <gtest/gtest.h> + +#include <limits.h> +#include <wchar.h> + +TEST(wchar, sizeof_wchar_t) { + EXPECT_EQ(4U, sizeof(wchar_t)); + EXPECT_EQ(4U, sizeof(wint_t)); +} + +TEST(wchar, mbrlen) { + char bytes[] = { 'h', 'e', 'l', 'l', 'o', '\0' }; + EXPECT_EQ(0U, mbrlen(&bytes[0], 0, NULL)); + EXPECT_EQ(1U, mbrlen(&bytes[0], 1, NULL)); + + EXPECT_EQ(1U, mbrlen(&bytes[4], 1, NULL)); + EXPECT_EQ(0U, mbrlen(&bytes[5], 1, NULL)); +} + +TEST(wchar, wctomb_wcrtomb) { + // wctomb and wcrtomb behave differently when s == NULL. + EXPECT_EQ(0, wctomb(NULL, L'h')); + EXPECT_EQ(0, wctomb(NULL, L'\0')); + EXPECT_EQ(1U, wcrtomb(NULL, L'\0', NULL)); + EXPECT_EQ(1U, wcrtomb(NULL, L'h', NULL)); + + char bytes[MB_LEN_MAX]; + + // wctomb and wcrtomb behave similarly for the null wide character. + EXPECT_EQ(1, wctomb(bytes, L'\0')); + EXPECT_EQ(1U, wcrtomb(bytes, L'\0', NULL)); + + // ...and for regular characters. + bytes[0] = 'x'; + EXPECT_EQ(1, wctomb(bytes, L'h')); + EXPECT_EQ('h', bytes[0]); + + bytes[0] = 'x'; + EXPECT_EQ(1U, wcrtomb(bytes, L'h', NULL)); + EXPECT_EQ('h', bytes[0]); +} |
