• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <gtest/gtest.h>
2 #include <locale.h>
3 using namespace testing::ext;
4 
5 class LocaleDuplocaleTest : public testing::Test {
SetUp()6     void SetUp() override {}
TearDown()7     void TearDown() override {}
8 };
9 
SameLocale(locale_t loc1,locale_t loc2)10 bool SameLocale(locale_t loc1, locale_t loc2)
11 {
12     wchar_t buf[] = { L'A', L'B', L'Z', L'Å', L'Ä', L'Ö', L'\0' };
13 
14     for (int i = 0; buf[i] != L'\0'; ++i) {
15         wchar_t c = buf[i];
16 
17         wchar_t lower1 = towlower_l(c, loc1);
18         wchar_t lower2 = towlower_l(c, loc2);
19         if (lower1 != lower2) {
20             return false;
21         }
22     }
23 
24     return true;
25 }
26 
27 extern "C" locale_t __duplocale(locale_t old);
28 /**
29  * @tc.name: __duplocale_001
30  * @tc.desc: Verify that the new object copied by __duplocale is the same as the original object
31  * @tc.type: FUNC
32  **/
33 HWTEST_F(LocaleDuplocaleTest, __duplocale_001, TestSize.Level1)
34 {
35     locale_t loc1 = newlocale(LC_ALL_MASK, "en_US.UTF-8", nullptr);
36     locale_t loc2 = __duplocale(loc1);
37     EXPECT_TRUE(SameLocale(loc1, loc2));
38 
39     freelocale(loc1);
40     freelocale(loc2);
41 }