• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "ecmascript/ecma_string-inl.h"
17 #include "ecmascript/object_factory.h"
18 #include "ecmascript/tests/test_helper.h"
19 
20 using namespace panda::ecmascript;
21 
22 namespace panda::test {
23 class EcmaStringTest : public testing::Test {
24 public:
SetUpTestCase()25     static void SetUpTestCase()
26     {
27         GTEST_LOG_(INFO) << "SetUpTestCase";
28         uint8_t arrayU8[] = {12, 34, 77, 127, 99, 1};
29         uint16_t arrayU16Comp[] = {1, 4, 37, 91, 127, 1};
30         uint16_t arrayU16NotComp[] = {72, 43, 337, 961, 1317, 65535};
31         EXPECT_TRUE(EcmaString::CanBeCompressed(arrayU8, sizeof(arrayU8) / sizeof(arrayU8[0])));
32         EXPECT_TRUE(EcmaString::CanBeCompressed(arrayU16Comp, sizeof(arrayU16Comp) / sizeof(arrayU16Comp[0])));
33         EXPECT_FALSE(EcmaString::CanBeCompressed(arrayU16NotComp, sizeof(arrayU16Comp) / sizeof(arrayU16Comp[0])));
34     }
35 
TearDownTestCase()36     static void TearDownTestCase()
37     {
38         GTEST_LOG_(INFO) << "TearDownCase";
39     }
40 
SetUp()41     void SetUp() override
42     {
43         TestHelper::CreateEcmaVMWithScope(ecmaVMPtr, thread, scope);
44     }
45 
TearDown()46     void TearDown() override
47     {
48         TestHelper::DestroyEcmaVMWithScope(ecmaVMPtr, scope);
49     }
50 
51     EcmaVM *ecmaVMPtr {nullptr};
52     ecmascript::EcmaHandleScope *scope {nullptr};
53     JSThread *thread {nullptr};
54 };
55 
56 /*
57  * @tc.name: CanBeCompressed
58  * @tc.desc: Check whether the bool returned through calling CanBeCompressed function is within expectations.
59  * @tc.type: FUNC
60  * @tc.require:
61  */
HWTEST_F_L0(EcmaStringTest,CanBeCompressed)62 HWTEST_F_L0(EcmaStringTest, CanBeCompressed)
63 {
64     uint8_t arrayU8[] = {12, 34, 77, 127, 99, 1};
65     uint16_t arrayU16Comp[] = {1, 4, 37, 91, 127, 1};
66     uint16_t arrayU16NotComp[] = {72, 43, 337, 961, 1317, 65535};
67     EXPECT_TRUE(EcmaString::CanBeCompressed(arrayU8, sizeof(arrayU8) / sizeof(arrayU8[0])));
68     EXPECT_TRUE(EcmaString::CanBeCompressed(arrayU16Comp, sizeof(arrayU16Comp) / sizeof(arrayU16Comp[0])));
69     EXPECT_FALSE(EcmaString::CanBeCompressed(arrayU16NotComp, sizeof(arrayU16Comp) / sizeof(arrayU16Comp[0])));
70 }
71 
72 /*
73  * @tc.name: CreateEmptyString
74  * @tc.desc: Check whether the EcmaString created through calling CreateEmptyString function is within expectations.
75  * @tc.type: FUNC
76  * @tc.require:
77  */
HWTEST_F_L0(EcmaStringTest,CreateEmptyString)78 HWTEST_F_L0(EcmaStringTest, CreateEmptyString)
79 {
80     JSHandle<EcmaString> handleEcmaStrEmpty(thread, EcmaString::CreateEmptyString(ecmaVMPtr));
81     EXPECT_EQ(handleEcmaStrEmpty->GetLength(), 0U);
82     EXPECT_TRUE(handleEcmaStrEmpty->IsUtf8());
83     EXPECT_FALSE(handleEcmaStrEmpty->IsUtf16());
84 }
85 
86 /*
87  * @tc.name: CreateLineString
88  * @tc.desc: Check whether the EcmaString created through calling CreateLineString function is within expectations.
89  * @tc.type: FUNC
90  * @tc.require:
91  */
HWTEST_F_L0(EcmaStringTest,CreateLineString)92 HWTEST_F_L0(EcmaStringTest, CreateLineString)
93 {
94     // CreateLineString( , true, ).
95     size_t sizeAllocComp = 5;
96     JSHandle<EcmaString> handleEcmaStrAllocComp(thread, EcmaString::CreateLineString(ecmaVMPtr, sizeAllocComp, true));
97     for (uint32_t i = 0; i < sizeAllocComp; i++) {
98         EXPECT_EQ(handleEcmaStrAllocComp->At(i), 0U);
99     }
100     EXPECT_EQ(handleEcmaStrAllocComp->GetLength(), sizeAllocComp);
101     EXPECT_TRUE(handleEcmaStrAllocComp->IsUtf8());
102     EXPECT_FALSE(handleEcmaStrAllocComp->IsUtf16());
103 
104     // CreateLineString( , false, ).
105     size_t sizeAllocNotComp = 5;
106     JSHandle<EcmaString> handleEcmaStrAllocNotComp(thread,
107         EcmaString::CreateLineString(ecmaVMPtr, sizeAllocNotComp, false));
108     for (uint32_t i = 0; i < sizeAllocNotComp; i++) {
109         EXPECT_EQ(handleEcmaStrAllocNotComp->At(i), 0U);
110     }
111     EXPECT_EQ(handleEcmaStrAllocNotComp->GetLength(), sizeAllocNotComp);
112     EXPECT_FALSE(handleEcmaStrAllocNotComp->IsUtf8());
113     EXPECT_TRUE(handleEcmaStrAllocNotComp->IsUtf16());
114 }
115 
116 /*
117  * @tc.name: CreateFromUtf8
118  * @tc.desc: Check whether the EcmaString created through calling CreateFromUtf8 function is within expectations.
119  * @tc.type: FUNC
120  * @tc.require:
121  */
HWTEST_F_L0(EcmaStringTest,CreateFromUtf8)122 HWTEST_F_L0(EcmaStringTest, CreateFromUtf8)
123 {
124     uint8_t arrayU8[] = {"xyz123!@#"};
125     size_t lengthEcmaStrU8 = sizeof(arrayU8) - 1;
126     JSHandle<EcmaString> handleEcmaStrU8(thread,
127         EcmaString::CreateFromUtf8(ecmaVMPtr, &arrayU8[0], lengthEcmaStrU8, true));
128     for (uint32_t i = 0; i < lengthEcmaStrU8; i++) {
129         EXPECT_EQ(arrayU8[i], handleEcmaStrU8->At(i));
130     }
131     EXPECT_EQ(handleEcmaStrU8->GetLength(), lengthEcmaStrU8);
132     EXPECT_TRUE(handleEcmaStrU8->IsUtf8());
133     EXPECT_FALSE(handleEcmaStrU8->IsUtf16());
134 }
135 
136 /*
137  * @tc.name: CreateFromUtf16
138  * @tc.desc: Check whether the EcmaString created through calling CreateFromUtf16 function is within expectations.
139  * @tc.type: FUNC
140  * @tc.require:
141  */
HWTEST_F_L0(EcmaStringTest,CreateFromUtf16)142 HWTEST_F_L0(EcmaStringTest, CreateFromUtf16)
143 {
144     // CreateFromUtf16( , , , true).
145     uint16_t arrayU16Comp[] = {1, 23, 45, 67, 127};
146     size_t lengthEcmaStrU16Comp = sizeof(arrayU16Comp) / sizeof(arrayU16Comp[0]);
147     JSHandle<EcmaString> handleEcmaStrU16Comp(thread,
148         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16Comp[0], lengthEcmaStrU16Comp, true));
149     EXPECT_EQ(handleEcmaStrU16Comp->GetLength(), lengthEcmaStrU16Comp);
150     EXPECT_TRUE(handleEcmaStrU16Comp->IsUtf8());
151     EXPECT_FALSE(handleEcmaStrU16Comp->IsUtf16());
152 
153     // CreateFromUtf16( , , , false).
154     uint16_t arrayU16NotComp[] = {127, 33, 128, 12, 256, 11100, 65535};
155     size_t lengthEcmaStrU16NotComp = sizeof(arrayU16NotComp) / sizeof(arrayU16NotComp[0]);
156     JSHandle<EcmaString> handleEcmaStrU16NotComp(thread,
157         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16NotComp[0], lengthEcmaStrU16NotComp, false));
158     EXPECT_EQ(handleEcmaStrU16NotComp->GetLength(), lengthEcmaStrU16NotComp);
159     EXPECT_FALSE(handleEcmaStrU16NotComp->IsUtf8());
160     EXPECT_TRUE(handleEcmaStrU16NotComp->IsUtf16());
161 }
162 
163 /*
164  * @tc.name: ObjectSize
165  * @tc.desc: Check whether the value returned through calling ObjectSize function is within expectations.
166  * @tc.type: FUNC
167  * @tc.require:
168  */
HWTEST_F_L0(EcmaStringTest,ObjectSize)169 HWTEST_F_L0(EcmaStringTest, ObjectSize)
170 {
171     JSHandle<EcmaString> handleEcmaStrEmpty(thread, EcmaString::CreateEmptyString(ecmaVMPtr));
172     EXPECT_EQ(handleEcmaStrEmpty->ObjectSize(), EcmaString::SIZE + 0);
173 
174     size_t lengthEcmaStrAllocComp = 5;
175     JSHandle<EcmaString> handleEcmaStrAllocComp(thread,
176         EcmaString::CreateLineString(ecmaVMPtr, lengthEcmaStrAllocComp, true));
177     EXPECT_EQ(handleEcmaStrAllocComp->ObjectSize(), EcmaString::SIZE + sizeof(uint8_t) * lengthEcmaStrAllocComp);
178 
179     size_t lengthEcmaStrAllocNotComp = 5;
180     JSHandle<EcmaString> handleEcmaStrAllocNotComp(thread,
181         EcmaString::CreateLineString(ecmaVMPtr, lengthEcmaStrAllocNotComp, false));
182     EXPECT_EQ(handleEcmaStrAllocNotComp->ObjectSize(),
183         EcmaString::SIZE + sizeof(uint16_t) * lengthEcmaStrAllocNotComp);
184 
185     uint8_t arrayU8[] = {"abcde"};
186     size_t lengthEcmaStrU8 = sizeof(arrayU8) - 1;
187     JSHandle<EcmaString> handleEcmaStrU8(thread,
188         EcmaString::CreateFromUtf8(ecmaVMPtr, &arrayU8[0], lengthEcmaStrU8, true));
189     EXPECT_EQ(handleEcmaStrU8->ObjectSize(), EcmaString::SIZE + sizeof(uint8_t) * lengthEcmaStrU8);
190 
191     // ObjectSize(). EcmaString made by CreateFromUtf16( , , , true).
192     uint16_t arrayU16Comp[] = {1, 23, 45, 67, 127};
193     size_t lengthEcmaStrU16Comp = sizeof(arrayU16Comp) / sizeof(arrayU16Comp[0]);
194     JSHandle<EcmaString> handleEcmaStrU16Comp(thread,
195         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16Comp[0], lengthEcmaStrU16Comp, true));
196     EXPECT_EQ(handleEcmaStrU16Comp->ObjectSize(), EcmaString::SIZE + sizeof(uint8_t) * lengthEcmaStrU16Comp);
197 
198     // ObjectSize(). EcmaString made by CreateFromUtf16( , , , false).
199     uint16_t arrayU16NotComp[] = {127, 128, 256, 11100, 65535};
200     size_t lengthEcmaStrU16NotComp = sizeof(arrayU16NotComp) / sizeof(arrayU16NotComp[0]);
201     JSHandle<EcmaString> handleEcmaStrU16NotComp(thread,
202         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16NotComp[0], lengthEcmaStrU16NotComp, false));
203     EXPECT_EQ(handleEcmaStrU16NotComp->ObjectSize(), EcmaString::SIZE + sizeof(uint16_t) * lengthEcmaStrU16NotComp);
204 }
205 
206 /*
207  * @tc.name: Compare_001
208  * @tc.desc: Check whether the value returned through calling Compare function between EcmaStrings made by
209  * CreateFromUtf8() is within expectations.
210  * @tc.type: FUNC
211  * @tc.require:
212  */
HWTEST_F_L0(EcmaStringTest,Compare_001)213 HWTEST_F_L0(EcmaStringTest, Compare_001)
214 {
215     // Compare(). Between EcmaStrings made by CreateFromUtf8().
216     uint8_t arrayU8No1[3] = {1, 23};
217     uint8_t arrayU8No2[4] = {1, 23, 49};
218     uint8_t arrayU8No3[6] = {1, 23, 45, 97, 127};
219     uint32_t lengthEcmaStrU8No1 = sizeof(arrayU8No1) - 1;
220     uint32_t lengthEcmaStrU8No2 = sizeof(arrayU8No2) - 1;
221     uint32_t lengthEcmaStrU8No3 = sizeof(arrayU8No3) - 1;
222     JSHandle<EcmaString> handleEcmaStrU8No1(thread,
223         EcmaString::CreateFromUtf8(ecmaVMPtr, &arrayU8No1[0], lengthEcmaStrU8No1, true));
224     JSHandle<EcmaString> handleEcmaStrU8No2(thread,
225         EcmaString::CreateFromUtf8(ecmaVMPtr, &arrayU8No2[0], lengthEcmaStrU8No2, true));
226     JSHandle<EcmaString> handleEcmaStrU8No3(thread,
227         EcmaString::CreateFromUtf8(ecmaVMPtr, &arrayU8No3[0], lengthEcmaStrU8No3, true));
228     EXPECT_EQ(EcmaString::Compare(*handleEcmaStrU8No1, *handleEcmaStrU8No2), -1);
229     EXPECT_EQ(EcmaString::Compare(*handleEcmaStrU8No2, *handleEcmaStrU8No1), 1);
230     EXPECT_EQ(EcmaString::Compare(*handleEcmaStrU8No2, *handleEcmaStrU8No3), 49 - 45);
231     EXPECT_EQ(EcmaString::Compare(*handleEcmaStrU8No3, *handleEcmaStrU8No2), 45 - 49);
232 }
233 
234 /*
235  * @tc.name: Compare_002
236  * @tc.desc: Check whether the value returned through calling Compare function between EcmaStrings made by
237  * CreateFromUtf16( , , , true) is within expectations.
238  * @tc.type: FUNC
239  * @tc.require:
240  */
HWTEST_F_L0(EcmaStringTest,Compare_002)241 HWTEST_F_L0(EcmaStringTest, Compare_002)
242 {
243     // Compare(). Between EcmaStrings made by CreateFromUtf16( , , , true).
244     uint16_t arrayU16CompNo1[] = {1, 23};
245     uint16_t arrayU16CompNo2[] = {1, 23, 49};
246     uint16_t arrayU16CompNo3[] = {1, 23, 45, 97, 127};
247     uint32_t lengthEcmaStrU16CompNo1 = sizeof(arrayU16CompNo1) / sizeof(arrayU16CompNo1[0]);
248     uint32_t lengthEcmaStrU16CompNo2 = sizeof(arrayU16CompNo2) / sizeof(arrayU16CompNo2[0]);
249     uint32_t lengthEcmaStrU16CompNo3 = sizeof(arrayU16CompNo3) / sizeof(arrayU16CompNo3[0]);
250     JSHandle<EcmaString> handleEcmaStrU16CompNo1(thread,
251         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16CompNo1[0], lengthEcmaStrU16CompNo1, true));
252     JSHandle<EcmaString> handleEcmaStrU16CompNo2(thread,
253         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16CompNo2[0], lengthEcmaStrU16CompNo2, true));
254     JSHandle<EcmaString> handleEcmaStrU16CompNo3(thread,
255         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16CompNo3[0], lengthEcmaStrU16CompNo3, true));
256     EXPECT_EQ(EcmaString::Compare(*handleEcmaStrU16CompNo1, *handleEcmaStrU16CompNo2), -1);
257     EXPECT_EQ(EcmaString::Compare(*handleEcmaStrU16CompNo2, *handleEcmaStrU16CompNo1), 1);
258     EXPECT_EQ(EcmaString::Compare(*handleEcmaStrU16CompNo2, *handleEcmaStrU16CompNo3), 49 - 45);
259     EXPECT_EQ(EcmaString::Compare(*handleEcmaStrU16CompNo3, *handleEcmaStrU16CompNo2), 45 - 49);
260 }
261 
262 /*
263  * @tc.name: Compare_003
264  * @tc.desc: Check whether the value returned through calling Compare function between EcmaString made by
265  * CreateFromUtf8() and EcmaString made by CreateFromUtf16( , , , true) made by CreateFromUtf16( , , , true) is within
266  * expectations.
267  * @tc.type: FUNC
268  * @tc.require:
269  */
HWTEST_F_L0(EcmaStringTest,Compare_003)270 HWTEST_F_L0(EcmaStringTest, Compare_003)
271 {
272     // Compare(). EcmaString made by CreateFromUtf8() and EcmaString made by CreateFromUtf16( , , , true).
273     uint8_t arrayU8No1[3] = {1, 23};
274     uint8_t arrayU8No2[4] = {1, 23, 49};
275     uint16_t arrayU16CompNo1[] = {1, 23};
276     uint16_t arrayU16CompNo2[] = {1, 23, 49};
277     uint16_t arrayU16CompNo3[] = {1, 23, 45, 97, 127};
278     uint32_t lengthEcmaStrU8No1 = sizeof(arrayU8No1) - 1;
279     uint32_t lengthEcmaStrU8No2 = sizeof(arrayU8No2) - 1;
280     uint32_t lengthEcmaStrU16CompNo1 = sizeof(arrayU16CompNo1) / sizeof(arrayU16CompNo1[0]);
281     uint32_t lengthEcmaStrU16CompNo2 = sizeof(arrayU16CompNo2) / sizeof(arrayU16CompNo2[0]);
282     uint32_t lengthEcmaStrU16CompNo3 = sizeof(arrayU16CompNo3) / sizeof(arrayU16CompNo3[0]);
283     JSHandle<EcmaString> handleEcmaStrU8No1(thread,
284         EcmaString::CreateFromUtf8(ecmaVMPtr, &arrayU8No1[0], lengthEcmaStrU8No1, true));
285     JSHandle<EcmaString> handleEcmaStrU8No2(thread,
286         EcmaString::CreateFromUtf8(ecmaVMPtr, &arrayU8No2[0], lengthEcmaStrU8No2, true));
287     JSHandle<EcmaString> handleEcmaStrU16CompNo1(thread,
288         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16CompNo1[0], lengthEcmaStrU16CompNo1, true));
289     JSHandle<EcmaString> handleEcmaStrU16CompNo2(thread,
290         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16CompNo2[0], lengthEcmaStrU16CompNo2, true));
291     JSHandle<EcmaString> handleEcmaStrU16CompNo3(thread,
292         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16CompNo3[0], lengthEcmaStrU16CompNo3, true));
293     EXPECT_EQ(EcmaString::Compare(*handleEcmaStrU8No1, *handleEcmaStrU16CompNo1), 0);
294     EXPECT_EQ(EcmaString::Compare(*handleEcmaStrU16CompNo1, *handleEcmaStrU8No1), 0);
295     EXPECT_EQ(EcmaString::Compare(*handleEcmaStrU8No1, *handleEcmaStrU16CompNo2), -1);
296     EXPECT_EQ(EcmaString::Compare(*handleEcmaStrU16CompNo2, *handleEcmaStrU8No1), 1);
297     EXPECT_EQ(EcmaString::Compare(*handleEcmaStrU8No2, *handleEcmaStrU16CompNo3), 49 - 45);
298     EXPECT_EQ(EcmaString::Compare(*handleEcmaStrU16CompNo3, *handleEcmaStrU8No2), 45 - 49);
299 }
300 
301 /*
302  * @tc.name: Compare_004
303  * @tc.desc: Check whether the value returned through calling Compare function between EcmaStrings made by
304  * CreateFromUtf16( , , , false) is within expectations.
305  * @tc.type: FUNC
306  * @tc.require:
307  */
HWTEST_F_L0(EcmaStringTest,Compare_004)308 HWTEST_F_L0(EcmaStringTest, Compare_004)
309 {
310     // Compare(). Between EcmaStrings made by CreateFromUtf16( , , , false).
311     uint16_t arrayU16NotCompNo1[] = {1, 23};
312     uint16_t arrayU16NotCompNo2[] = {1, 23, 49};
313     uint16_t arrayU16NotCompNo3[] = {1, 23, 456, 6789, 65535, 127};
314     uint32_t lengthEcmaStrU16NotCompNo1 = sizeof(arrayU16NotCompNo1) / sizeof(arrayU16NotCompNo1[0]);
315     uint32_t lengthEcmaStrU16NotCompNo2 = sizeof(arrayU16NotCompNo2) / sizeof(arrayU16NotCompNo2[0]);
316     uint32_t lengthEcmaStrU16NotCompNo3 = sizeof(arrayU16NotCompNo3) / sizeof(arrayU16NotCompNo3[0]);
317     JSHandle<EcmaString> handleEcmaStrU16NotCompNo1(thread,
318         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16NotCompNo1[0], lengthEcmaStrU16NotCompNo1, true));
319     JSHandle<EcmaString> handleEcmaStrU16NotCompNo2(thread,
320         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16NotCompNo2[0], lengthEcmaStrU16NotCompNo2, true));
321     JSHandle<EcmaString> handleEcmaStrU16NotCompNo3(thread,
322         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16NotCompNo3[0], lengthEcmaStrU16NotCompNo3, false));
323     EXPECT_EQ(EcmaString::Compare(*handleEcmaStrU16NotCompNo1, *handleEcmaStrU16NotCompNo2), -1);
324     EXPECT_EQ(EcmaString::Compare(*handleEcmaStrU16NotCompNo2, *handleEcmaStrU16NotCompNo1), 1);
325     EXPECT_EQ(EcmaString::Compare(*handleEcmaStrU16NotCompNo2, *handleEcmaStrU16NotCompNo3), 49 - 456);
326     EXPECT_EQ(EcmaString::Compare(*handleEcmaStrU16NotCompNo3, *handleEcmaStrU16NotCompNo2), 456 - 49);
327 }
328 
329 /*
330  * @tc.name: Compare_005
331  * @tc.desc: Check whether the value returned through calling Compare function between EcmaString made by
332  * CreateFromUtf8() and EcmaString made by CreateFromUtf16( , , , false) is within expectations.
333  * @tc.type: FUNC
334  * @tc.require:
335  */
HWTEST_F_L0(EcmaStringTest,Compare_005)336 HWTEST_F_L0(EcmaStringTest, Compare_005)
337 {
338     // Compare(). EcmaString made by CreateFromUtf8() and EcmaString made by CreateFromUtf16( , , , false).
339     uint8_t arrayU8No1[3] = {1, 23};
340     uint8_t arrayU8No2[4] = {1, 23, 49};
341     uint16_t arrayU16NotCompNo1[] = {1, 23};
342     uint16_t arrayU16NotCompNo2[] = {1, 23, 49};
343     uint16_t arrayU16NotCompNo3[] = {1, 23, 456, 6789, 65535, 127};
344     uint32_t lengthEcmaStrU8No1 = sizeof(arrayU8No1) - 1;
345     uint32_t lengthEcmaStrU8No2 = sizeof(arrayU8No2) - 1;
346     uint32_t lengthEcmaStrU16NotCompNo1 = sizeof(arrayU16NotCompNo1) / sizeof(arrayU16NotCompNo1[0]);
347     uint32_t lengthEcmaStrU16NotCompNo2 = sizeof(arrayU16NotCompNo2) / sizeof(arrayU16NotCompNo2[0]);
348     uint32_t lengthEcmaStrU16NotCompNo3 = sizeof(arrayU16NotCompNo3) / sizeof(arrayU16NotCompNo3[0]);
349     JSHandle<EcmaString> handleEcmaStrU8No1(thread,
350         EcmaString::CreateFromUtf8(ecmaVMPtr, &arrayU8No1[0], lengthEcmaStrU8No1, true));
351     JSHandle<EcmaString> handleEcmaStrU8No2(thread,
352         EcmaString::CreateFromUtf8(ecmaVMPtr, &arrayU8No2[0], lengthEcmaStrU8No2, true));
353     JSHandle<EcmaString> handleEcmaStrU16NotCompNo1(thread,
354         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16NotCompNo1[0], lengthEcmaStrU16NotCompNo1, true));
355     JSHandle<EcmaString> handleEcmaStrU16NotCompNo2(thread,
356         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16NotCompNo2[0], lengthEcmaStrU16NotCompNo2, true));
357     JSHandle<EcmaString> handleEcmaStrU16NotCompNo3(thread,
358         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16NotCompNo3[0], lengthEcmaStrU16NotCompNo3, false));
359     EXPECT_EQ(EcmaString::Compare(*handleEcmaStrU8No1, *handleEcmaStrU16NotCompNo1), 0);
360     EXPECT_EQ(EcmaString::Compare(*handleEcmaStrU16NotCompNo1, *handleEcmaStrU8No1), 0);
361     EXPECT_EQ(EcmaString::Compare(*handleEcmaStrU8No1, *handleEcmaStrU16NotCompNo2), -1);
362     EXPECT_EQ(EcmaString::Compare(*handleEcmaStrU16NotCompNo2, *handleEcmaStrU8No1), 1);
363     EXPECT_EQ(EcmaString::Compare(*handleEcmaStrU8No2, *handleEcmaStrU16NotCompNo3), 49 - 456);
364     EXPECT_EQ(EcmaString::Compare(*handleEcmaStrU16NotCompNo3, *handleEcmaStrU8No2), 456 - 49);
365 }
366 
367 /*
368  * @tc.name: Compare_006
369  * @tc.desc: Check whether the value returned through calling Compare function between EcmaString made by
370  * CreateFromUtf16( , , , true) and EcmaString made by CreateFromUtf16( , , , false) is within expectations.
371  * @tc.type: FUNC
372  * @tc.require:
373  */
HWTEST_F_L0(EcmaStringTest,Compare_006)374 HWTEST_F_L0(EcmaStringTest, Compare_006)
375 {
376     // Compare(). EcmaString made by CreateFromUtf16( , , , true) and EcmaString made by CreateFromUtf16( , , , false).
377     uint16_t arrayU16CompNo1[] = {1, 23};
378     uint16_t arrayU16CompNo2[] = {1, 23, 49};
379     uint16_t arrayU16NotCompNo1[] = {1, 23};
380     uint16_t arrayU16NotCompNo2[] = {1, 23, 49};
381     uint16_t arrayU16NotCompNo3[] = {1, 23, 456, 6789, 65535, 127};
382     uint32_t lengthEcmaStrU16CompNo1 = sizeof(arrayU16CompNo1) / sizeof(arrayU16CompNo1[0]);
383     uint32_t lengthEcmaStrU16CompNo2 = sizeof(arrayU16CompNo2) / sizeof(arrayU16CompNo2[0]);
384     uint32_t lengthEcmaStrU16NotCompNo1 = sizeof(arrayU16NotCompNo1) / sizeof(arrayU16NotCompNo1[0]);
385     uint32_t lengthEcmaStrU16NotCompNo2 = sizeof(arrayU16NotCompNo2) / sizeof(arrayU16NotCompNo2[0]);
386     uint32_t lengthEcmaStrU16NotCompNo3 = sizeof(arrayU16NotCompNo3) / sizeof(arrayU16NotCompNo3[0]);
387     JSHandle<EcmaString> handleEcmaStrU16CompNo1(thread,
388         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16CompNo1[0], lengthEcmaStrU16CompNo1, true));
389     JSHandle<EcmaString> handleEcmaStrU16CompNo2(thread,
390         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16CompNo2[0], lengthEcmaStrU16CompNo2, true));
391     JSHandle<EcmaString> handleEcmaStrU16NotCompNo1(thread,
392         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16NotCompNo1[0], lengthEcmaStrU16NotCompNo1, true));
393     JSHandle<EcmaString> handleEcmaStrU16NotCompNo2(thread,
394         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16NotCompNo2[0], lengthEcmaStrU16NotCompNo2, true));
395     JSHandle<EcmaString> handleEcmaStrU16NotCompNo3(thread,
396         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16NotCompNo3[0], lengthEcmaStrU16NotCompNo3, false));
397     EXPECT_EQ(EcmaString::Compare(*handleEcmaStrU16CompNo1, *handleEcmaStrU16NotCompNo1), 0);
398     EXPECT_EQ(EcmaString::Compare(*handleEcmaStrU16NotCompNo1, *handleEcmaStrU16CompNo1), 0);
399     EXPECT_EQ(EcmaString::Compare(*handleEcmaStrU16CompNo1, *handleEcmaStrU16NotCompNo2), -1);
400     EXPECT_EQ(EcmaString::Compare(*handleEcmaStrU16NotCompNo2, *handleEcmaStrU16CompNo1), 1);
401     EXPECT_EQ(EcmaString::Compare(*handleEcmaStrU16CompNo2, *handleEcmaStrU16NotCompNo3), 49 - 456);
402     EXPECT_EQ(EcmaString::Compare(*handleEcmaStrU16NotCompNo3, *handleEcmaStrU16CompNo2), 456 - 49);
403 }
404 
405 /*
406  * @tc.name: Concat_001
407  * @tc.desc: Check whether the EcmaString returned through calling Concat function between EcmaString made by
408  * CreateFromUtf8() and EcmaString made by CreateFromUtf8() is within expectations.
409  * @tc.type: FUNC
410  * @tc.require:
411  */
HWTEST_F_L0(EcmaStringTest,Concat_001)412 HWTEST_F_L0(EcmaStringTest, Concat_001)
413 {
414     // Concat(). EcmaString made by CreateFromUtf8() and EcmaString made by CreateFromUtf8().
415     uint8_t arrayFrontU8[] = {"abcdef"};
416     uint8_t arrayBackU8[] = {"ABCDEF"};
417     uint32_t lengthEcmaStrFrontU8 = sizeof(arrayFrontU8) - 1;
418     uint32_t lengthEcmaStrBackU8 = sizeof(arrayBackU8) - 1;
419     JSHandle<EcmaString> handleEcmaStrFrontU8(thread,
420         EcmaString::CreateFromUtf8(ecmaVMPtr, &arrayFrontU8[0], lengthEcmaStrFrontU8, true));
421     JSHandle<EcmaString> handleEcmaStrBackU8(thread,
422         EcmaString::CreateFromUtf8(ecmaVMPtr, &arrayBackU8[0], lengthEcmaStrBackU8, true));
423     JSHandle<EcmaString> handleEcmaStrConcatU8(thread,
424         EcmaString::Concat(ecmaVMPtr, handleEcmaStrFrontU8, handleEcmaStrBackU8));
425     EXPECT_TRUE(handleEcmaStrConcatU8->IsUtf8());
426     for (uint32_t i = 0; i < lengthEcmaStrFrontU8; i++) {
427         EXPECT_EQ(handleEcmaStrConcatU8->At(i), arrayFrontU8[i]);
428     }
429     for (uint32_t i = 0; i < lengthEcmaStrBackU8; i++) {
430         EXPECT_EQ(handleEcmaStrConcatU8->At(i + lengthEcmaStrFrontU8), arrayBackU8[i]);
431     }
432     EXPECT_EQ(handleEcmaStrConcatU8->GetLength(), lengthEcmaStrFrontU8 + lengthEcmaStrBackU8);
433 }
434 
435 /*
436  * @tc.name: Concat_002
437  * @tc.desc: Check whether the EcmaString returned through calling Concat function between EcmaString made by
438  * CreateFromUtf16( , , , false) and EcmaString made by CreateFromUtf16( , , , false) is within expectations.
439  * @tc.type: FUNC
440  * @tc.require:
441  */
HWTEST_F_L0(EcmaStringTest,Concat_002)442 HWTEST_F_L0(EcmaStringTest, Concat_002)
443 {
444     // Concat(). EcmaString made by CreateFromUtf16( , , , false) and EcmaString made by CreateFromUtf16( , , , false).
445     uint16_t arrayFrontU16NotComp[] = {128, 129, 256, 11100, 65535, 100};
446     uint16_t arrayBackU16NotComp[] = {88, 768, 1, 270, 345, 333};
447     uint32_t lengthEcmaStrFrontU16NotComp = sizeof(arrayFrontU16NotComp) / sizeof(arrayFrontU16NotComp[0]);
448     uint32_t lengthEcmaStrBackU16NotComp = sizeof(arrayBackU16NotComp) / sizeof(arrayBackU16NotComp[0]);
449     JSHandle<EcmaString> handleEcmaStrFrontU16NotComp(thread,
450         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayFrontU16NotComp[0], lengthEcmaStrFrontU16NotComp, false));
451     JSHandle<EcmaString> handleEcmaStrBackU16NotComp(thread,
452         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayBackU16NotComp[0], lengthEcmaStrBackU16NotComp, false));
453     JSHandle<EcmaString> handleEcmaStrConcatU16NotComp(thread,
454         EcmaString::Concat(ecmaVMPtr, handleEcmaStrFrontU16NotComp, handleEcmaStrBackU16NotComp));
455     EXPECT_TRUE(handleEcmaStrConcatU16NotComp->IsUtf16());
456     for (uint32_t i = 0; i < lengthEcmaStrFrontU16NotComp; i++) {
457         EXPECT_EQ(handleEcmaStrConcatU16NotComp->At(i), arrayFrontU16NotComp[i]);
458     }
459     for (uint32_t i = 0; i < lengthEcmaStrBackU16NotComp; i++) {
460         EXPECT_EQ(handleEcmaStrConcatU16NotComp->At(i + lengthEcmaStrFrontU16NotComp), arrayBackU16NotComp[i]);
461     }
462     EXPECT_EQ(handleEcmaStrConcatU16NotComp->GetLength(), lengthEcmaStrFrontU16NotComp + lengthEcmaStrBackU16NotComp);
463 }
464 
465 /*
466  * @tc.name: Concat_003
467  * @tc.desc: Check whether the EcmaString returned through calling Concat function between EcmaString made by
468  * CreateFromUtf8() and EcmaString made by CreateFromUtf16( , , , false) is within expectations.
469  * @tc.type: FUNC
470  * @tc.require:
471  */
HWTEST_F_L0(EcmaStringTest,Concat_003)472 HWTEST_F_L0(EcmaStringTest, Concat_003)
473 {
474     // Concat(). EcmaString made by CreateFromUtf8() and EcmaString made by CreateFromUtf16( , , , false).
475     uint8_t arrayFrontU8[] = {"abcdef"};
476     uint16_t arrayBackU16NotComp[] = {88, 768, 1, 270, 345, 333};
477     uint32_t lengthEcmaStrFrontU8 = sizeof(arrayFrontU8) - 1;
478     uint32_t lengthEcmaStrBackU16NotComp = sizeof(arrayBackU16NotComp) / sizeof(arrayBackU16NotComp[0]);
479     JSHandle<EcmaString> handleEcmaStrFrontU8(thread,
480         EcmaString::CreateFromUtf8(ecmaVMPtr, &arrayFrontU8[0], lengthEcmaStrFrontU8, true));
481     JSHandle<EcmaString> handleEcmaStrBackU16NotComp(thread,
482         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayBackU16NotComp[0], lengthEcmaStrBackU16NotComp, false));
483     JSHandle<EcmaString> handleEcmaStrConcatU8U16NotComp(thread,
484         EcmaString::Concat(ecmaVMPtr, handleEcmaStrFrontU8, handleEcmaStrBackU16NotComp));
485     EXPECT_TRUE(handleEcmaStrConcatU8U16NotComp->IsUtf16());
486     for (uint32_t i = 0; i < lengthEcmaStrFrontU8; i++) {
487         EXPECT_EQ(handleEcmaStrConcatU8U16NotComp->At(i), arrayFrontU8[i]);
488     }
489     for (uint32_t i = 0; i < lengthEcmaStrBackU16NotComp; i++) {
490         EXPECT_EQ(handleEcmaStrConcatU8U16NotComp->At(i + lengthEcmaStrFrontU8), arrayBackU16NotComp[i]);
491     }
492     EXPECT_EQ(handleEcmaStrConcatU8U16NotComp->GetLength(), lengthEcmaStrFrontU8 + lengthEcmaStrBackU16NotComp);
493 }
494 
495 /*
496  * @tc.name: FastSubString_001
497  * @tc.desc: Check whether the EcmaString returned through calling FastSubString function from EcmaString made by
498  * CreateFromUtf8() is within expectations.
499  * @tc.type: FUNC
500  * @tc.require:
501  */
HWTEST_F_L0(EcmaStringTest,FastSubString_001)502 HWTEST_F_L0(EcmaStringTest, FastSubString_001)
503 {
504     // FastSubString(). From EcmaString made by CreateFromUtf8().
505     uint8_t arrayU8[6] = {3, 7, 19, 54, 99};
506     uint32_t lengthEcmaStrU8 = sizeof(arrayU8) - 1;
507     JSHandle<EcmaString> handleEcmaStrU8(thread,
508         EcmaString::CreateFromUtf8(ecmaVMPtr, &arrayU8[0], lengthEcmaStrU8, true));
509     uint32_t indexStartSubU8 = 2;
510     uint32_t lengthSubU8 = 2;
511     JSHandle<EcmaString> handleEcmaStrSubU8(thread,
512         EcmaString::FastSubString(ecmaVMPtr, handleEcmaStrU8, indexStartSubU8, lengthSubU8));
513     for (uint32_t i = 0; i < lengthSubU8; i++) {
514         EXPECT_EQ(handleEcmaStrSubU8->At(i), handleEcmaStrU8->At(i + indexStartSubU8));
515     }
516     EXPECT_EQ(handleEcmaStrSubU8->GetLength(), lengthSubU8);
517 }
518 
519 /*
520  * @tc.name: FastSubString_002
521  * @tc.desc: Check whether the EcmaString returned through calling FastSubString function from EcmaString made by
522  * CreateFromUtf16( , , , true) is within expectations.
523  * @tc.type: FUNC
524  * @tc.require:
525  */
HWTEST_F_L0(EcmaStringTest,FastSubString_002)526 HWTEST_F_L0(EcmaStringTest, FastSubString_002)
527 {
528     // FastSubString(). From EcmaString made by CreateFromUtf16( , , , true).
529     uint16_t arrayU16Comp[] = {1, 12, 34, 56, 127};
530     uint32_t lengthEcmaStrU16Comp = sizeof(arrayU16Comp) / sizeof(arrayU16Comp[0]);
531     JSHandle<EcmaString> handleEcmaStrU16Comp(thread,
532         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16Comp[0], lengthEcmaStrU16Comp, true));
533     uint32_t indexStartSubU16Comp = 0;
534     uint32_t lengthSubU16Comp = 2;
535     JSHandle<EcmaString> handleEcmaStrSubU16Comp(thread,
536         EcmaString::FastSubString(ecmaVMPtr, handleEcmaStrU16Comp, indexStartSubU16Comp, lengthSubU16Comp));
537     for (uint32_t i = 0; i < lengthSubU16Comp; i++) {
538         EXPECT_EQ(handleEcmaStrSubU16Comp->At(i), handleEcmaStrU16Comp->At(i + indexStartSubU16Comp));
539     }
540     EXPECT_EQ(handleEcmaStrSubU16Comp->GetLength(), lengthSubU16Comp);
541 }
542 
543 /*
544  * @tc.name: FastSubString_003
545  * @tc.desc: Check whether the EcmaString returned through calling FastSubString function from EcmaString made by
546  * CreateFromUtf16( , , , false) is within expectations.
547  * @tc.type: FUNC
548  * @tc.require:
549  */
HWTEST_F_L0(EcmaStringTest,FastSubString_003)550 HWTEST_F_L0(EcmaStringTest, FastSubString_003)
551 {
552     // FastSubString(). From EcmaString made by CreateFromUtf16( , , , false).
553     uint16_t arrayU16NotComp[] = {19, 54, 256, 11100, 65535};
554     uint32_t lengthEcmaStrU16NotComp = sizeof(arrayU16NotComp) / sizeof(arrayU16NotComp[0]);
555     JSHandle<EcmaString> handleEcmaStrU16NotComp(thread,
556         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16NotComp[0], lengthEcmaStrU16NotComp, false));
557     uint32_t indexStartSubU16NotComp = 0;
558     uint32_t lengthSubU16NotComp = 2;
559     JSHandle<EcmaString> handleEcmaStrSubU16NotComp(thread,
560         EcmaString::FastSubString(ecmaVMPtr, handleEcmaStrU16NotComp, indexStartSubU16NotComp, lengthSubU16NotComp));
561     for (uint32_t i = 0; i < lengthSubU16NotComp; i++) {
562         EXPECT_EQ(handleEcmaStrSubU16NotComp->At(i), handleEcmaStrU16NotComp->At(i + indexStartSubU16NotComp));
563     }
564     EXPECT_EQ(handleEcmaStrSubU16NotComp->GetLength(), lengthSubU16NotComp);
565 }
566 
567 /*
568  * @tc.name: FastSubString_004
569  * @tc.desc: Check whether the EcmaString returned through calling FastSubString function from EcmaString
570  * @tc.type: FUNC
571  * @tc.require:
572  */
HWTEST_F_L0(EcmaStringTest,FastSubString_004)573 HWTEST_F_L0(EcmaStringTest, FastSubString_004)
574 {
575     ObjectFactory* factory = ecmaVMPtr->GetFactory();
576     {
577         JSHandle<EcmaString> sourceString = factory->NewFromUtf8("æ•´æ•°integer");
578         JSHandle<EcmaString> tmpString = factory->NewFromASCII("integer");
579         EXPECT_TRUE(sourceString->IsUtf16());
580         EcmaString *res = EcmaString::FastSubString(ecmaVMPtr, sourceString, 2, 7);
581         EXPECT_TRUE(res->IsUtf8());
582         EXPECT_TRUE(EcmaString::StringsAreEqual(res, *tmpString));
583     }
584     {
585         JSHandle<EcmaString> sourceString = factory->NewFromUtf8("æ•´æ•°integer");
586         JSHandle<EcmaString> tmpString = factory->NewFromUtf8("æ•´æ•°");
587         EXPECT_TRUE(sourceString->IsUtf16());
588         EcmaString *res = EcmaString::FastSubString(ecmaVMPtr, sourceString, 0, 2);
589         EXPECT_TRUE(res->IsUtf16());
590         EXPECT_TRUE(EcmaString::StringsAreEqual(res, *tmpString));
591     }
592     {
593         JSHandle<EcmaString> sourceString = factory->NewFromUtf8("æ•´æ•°integer");
594         JSHandle<EcmaString> tmpString = factory->NewFromUtf8("æ•°intege");
595         EXPECT_TRUE(sourceString->IsUtf16());
596         EcmaString *res = EcmaString::FastSubString(ecmaVMPtr, sourceString, 1, 7);
597         EXPECT_TRUE(res->IsUtf16());
598         EXPECT_TRUE(EcmaString::StringsAreEqual(res, *tmpString));
599     }
600     {
601         JSHandle<EcmaString> sourceString = factory->NewFromASCII("integer123");
602         JSHandle<EcmaString> tmpString = factory->NewFromASCII("integer");
603         EXPECT_TRUE(sourceString->IsUtf8());
604         EcmaString *res = EcmaString::FastSubString(ecmaVMPtr, sourceString, 0, 7);
605         EXPECT_TRUE(res->IsUtf8());
606         EXPECT_TRUE(EcmaString::StringsAreEqual(res, *tmpString));
607     }
608 }
609 
610 /*
611  * @tc.name: WriteData_001
612  * @tc.desc: Check whether the target EcmaString made by CreateLineString( , true, ) changed through calling WriteData
613  * function with a source EcmaString made by CreateFromUtf8() is within expectations.
614  * @tc.type: FUNC
615  * @tc.require:
616  */
HWTEST_F_L0(EcmaStringTest,WriteData_001)617 HWTEST_F_L0(EcmaStringTest, WriteData_001)
618 {
619     // WriteData(). From EcmaString made by CreateFromUtf8() to EcmaString made by CreateLineString( , true, ).
620     uint8_t arrayU8WriteFrom[6] = {1, 12, 34, 56, 127};
621     uint32_t lengthEcmaStrU8WriteFrom = sizeof(arrayU8WriteFrom) - 1;
622     JSHandle<EcmaString> handleEcmaStrU8WriteFrom(thread,
623         EcmaString::CreateFromUtf8(ecmaVMPtr, &arrayU8WriteFrom[0], lengthEcmaStrU8WriteFrom, true));
624     size_t sizeEcmaStrU8WriteTo = 5;
625     JSHandle<EcmaString> handleEcmaStrAllocTrueWriteTo(thread,
626         EcmaString::CreateLineString(ecmaVMPtr, sizeEcmaStrU8WriteTo, true));
627     uint32_t indexStartWriteFromArrayU8 = 2;
628     uint32_t lengthWriteFromArrayU8 = 2;
629     handleEcmaStrAllocTrueWriteTo->WriteData(*handleEcmaStrU8WriteFrom, indexStartWriteFromArrayU8,
630         sizeEcmaStrU8WriteTo, lengthWriteFromArrayU8);
631     for (uint32_t i = 0; i < lengthWriteFromArrayU8; i++) {
632         EXPECT_EQ(handleEcmaStrAllocTrueWriteTo->At(i + indexStartWriteFromArrayU8), handleEcmaStrU8WriteFrom->At(i));
633     }
634 }
635 
636 /*
637  * @tc.name: WriteData_002
638  * @tc.desc: Check whether the target EcmaString made by CreateLineString( , true, ) changed through calling WriteData
639  * function from a source char is within expectations.
640  * @tc.type: FUNC
641  * @tc.require:
642  */
HWTEST_F_L0(EcmaStringTest,WriteData_002)643 HWTEST_F_L0(EcmaStringTest, WriteData_002)
644 {
645     // WriteData(). From char to EcmaString made by CreateLineString( , true, ).
646     char u8Write = 'a';
647     size_t sizeEcmaStrU8WriteTo = 5;
648     JSHandle<EcmaString> handleEcmaStrAllocTrueWriteTo(thread,
649         EcmaString::CreateLineString(ecmaVMPtr, sizeEcmaStrU8WriteTo, true));
650     uint32_t indexAtWriteFromU8 = 4;
651     handleEcmaStrAllocTrueWriteTo->WriteData(u8Write, indexAtWriteFromU8);
652     EXPECT_EQ(handleEcmaStrAllocTrueWriteTo->At(indexAtWriteFromU8), u8Write);
653 }
654 
655 /*
656  * @tc.name: WriteData_003
657  * @tc.desc: Check whether the target EcmaString made by CreateLineString( , false, ) changed through calling
658  * WriteData function with a source EcmaString made by CreateFromUtf16( , , , false) is within expectations.
659  * @tc.type: FUNC
660  * @tc.require:
661  */
HWTEST_F_L0(EcmaStringTest,WriteData_003)662 HWTEST_F_L0(EcmaStringTest, WriteData_003)
663 {
664     /* WriteData(). From EcmaString made by CreateFromUtf16( , , , false) to EcmaStringU16 made by
665      * CreateLineString( , false, ).
666      */
667     uint16_t arrayU16WriteFrom[10] = {67, 777, 1999, 1, 45, 66, 23456, 65535, 127, 333};
668     uint32_t lengthEcmaStrU16WriteFrom = sizeof(arrayU16WriteFrom) / sizeof(arrayU16WriteFrom[0]);
669     JSHandle<EcmaString> handleEcmaStrU16WriteFrom(thread,
670         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16WriteFrom[0], lengthEcmaStrU16WriteFrom, false));
671     size_t sizeEcmaStrU16WriteTo = 10;
672     JSHandle<EcmaString> handleEcmaStrU16WriteTo(thread,
673         EcmaString::CreateLineString(ecmaVMPtr, sizeEcmaStrU16WriteTo, false));
674     uint32_t indexStartWriteFromArrayU16 = 3;
675     uint32_t numBytesWriteFromArrayU16 = 2 * 3;
676     handleEcmaStrU16WriteTo->WriteData(*handleEcmaStrU16WriteFrom, indexStartWriteFromArrayU16, sizeEcmaStrU16WriteTo,
677         numBytesWriteFromArrayU16);
678     for (uint32_t i = 0; i < (numBytesWriteFromArrayU16 / 2); i++) {
679         EXPECT_EQ(handleEcmaStrU16WriteTo->At(i + indexStartWriteFromArrayU16), handleEcmaStrU16WriteFrom->At(i));
680     }
681 }
682 
683 /*
684  * @tc.name: WriteData_004
685  * @tc.desc: Check whether the target EcmaString made by CreateLineString( , false, ) changed through calling
686  * WriteData function with a source EcmaString made by CreateFromUtf8() is within expectations.
687  * @tc.type: FUNC
688  * @tc.require:
689  */
HWTEST_F_L0(EcmaStringTest,WriteData_004)690 HWTEST_F_L0(EcmaStringTest, WriteData_004)
691 {
692     // WriteData(). From EcmaString made by CreateFromUtf8() to EcmaString made by CreateLineString( , false, ).
693     uint8_t arrayU8WriteFrom[6] = {1, 12, 34, 56, 127};
694     uint32_t lengthEcmaStrU8WriteFrom = sizeof(arrayU8WriteFrom) - 1;
695     JSHandle<EcmaString> handleEcmaStrU8WriteFrom(thread,
696         EcmaString::CreateFromUtf8(ecmaVMPtr, &arrayU8WriteFrom[0], lengthEcmaStrU8WriteFrom, true));
697     size_t sizeEcmaStrU16WriteTo = 10;
698     JSHandle<EcmaString> handleEcmaStrU16WriteTo(thread,
699         EcmaString::CreateLineString(ecmaVMPtr, sizeEcmaStrU16WriteTo, false));
700     uint32_t indexStartWriteFromU8ToU16 = 1;
701     uint32_t numBytesWriteFromU8ToU16 = 4;
702     handleEcmaStrU16WriteTo->WriteData(*handleEcmaStrU8WriteFrom, indexStartWriteFromU8ToU16, sizeEcmaStrU16WriteTo,
703         numBytesWriteFromU8ToU16);
704     for (uint32_t i = 0; i < numBytesWriteFromU8ToU16; i++) {
705         EXPECT_EQ(handleEcmaStrU16WriteTo->At(i + indexStartWriteFromU8ToU16), handleEcmaStrU8WriteFrom->At(i));
706     }
707 }
708 
709 /*
710  * @tc.name: WriteData_005
711  * @tc.desc: Check whether the target EcmaString made by CreateLineString( , false, ) changed through calling
712  * WriteData function with a source char is within expectations.
713  * @tc.type: FUNC
714  * @tc.require:
715  */
HWTEST_F_L0(EcmaStringTest,WriteData_005)716 HWTEST_F_L0(EcmaStringTest, WriteData_005)
717 {
718     // WriteData(). From char to EcmaString made by CreateLineString( , false, ).
719     size_t sizeEcmaStrU16WriteTo = 10;
720     JSHandle<EcmaString> handleEcmaStrU16WriteTo(thread,
721         EcmaString::CreateLineString(ecmaVMPtr, sizeEcmaStrU16WriteTo, false));
722     char u8Write = 'a';
723     uint32_t indexAt = 4;
724     handleEcmaStrU16WriteTo->WriteData(u8Write, indexAt);
725     EXPECT_EQ(handleEcmaStrU16WriteTo->At(indexAt), u8Write);
726 }
727 
728 /*
729  * @tc.name: GetUtf8Length
730  * @tc.desc: Check whether the value returned through calling GetUtf8Length function is within expectations.
731  * @tc.type: FUNC
732  * @tc.require:
733  */
HWTEST_F_L0(EcmaStringTest,GetUtf8Length)734 HWTEST_F_L0(EcmaStringTest, GetUtf8Length)
735 {
736     uint8_t arrayU8[6] = {3, 7, 19, 54, 99};
737     uint16_t arrayU16Comp[] = {1, 12, 34, 56, 127};
738     uint16_t arrayU16NotComp[] = {19, 54, 256, 11100, 65535};
739     uint32_t lengthEcmaStrU8 = sizeof(arrayU8) - 1;
740     uint32_t lengthEcmaStrU16Comp = sizeof(arrayU16Comp) / sizeof(arrayU16Comp[0]);
741     uint32_t lengthEcmaStrU16NotComp = sizeof(arrayU16NotComp) / sizeof(arrayU16NotComp[0]);
742     JSHandle<EcmaString> handleEcmaStrU8(thread,
743         EcmaString::CreateFromUtf8(ecmaVMPtr, &arrayU8[0], lengthEcmaStrU8, true));
744     JSHandle<EcmaString> handleEcmaStrU16Comp(thread,
745         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16Comp[0], lengthEcmaStrU16Comp, true));
746     JSHandle<EcmaString> handleEcmaStrU16NotComp(thread,
747         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16NotComp[0], lengthEcmaStrU16NotComp, false));
748     EXPECT_EQ(handleEcmaStrU8->GetUtf8Length(), lengthEcmaStrU8 + 1);
749     EXPECT_EQ(handleEcmaStrU16Comp->GetUtf8Length(), lengthEcmaStrU16Comp + 1);
750     EXPECT_EQ(handleEcmaStrU16NotComp->GetUtf8Length(), 2 * lengthEcmaStrU16NotComp + 1);
751 }
752 
753 /*
754  * @tc.name: GetDataUtf8
755  * @tc.desc: Check whether the pointer returned through calling GetDataUtf8 function is within expectations.
756  * @tc.type: FUNC
757  * @tc.require:
758  */
HWTEST_F_L0(EcmaStringTest,GetDataUtf8)759 HWTEST_F_L0(EcmaStringTest, GetDataUtf8)
760 {
761     // From EcmaString made by CreateFromUtf8().
762     uint8_t arrayU8[] = {"abcde"};
763     uint32_t lengthEcmaStrU8 = sizeof(arrayU8) - 1;
764     JSHandle<EcmaString> handleEcmaStrU8(thread,
765         EcmaString::CreateFromUtf8(ecmaVMPtr, &arrayU8[0], lengthEcmaStrU8, true));
766     for (uint32_t i = 0; i < lengthEcmaStrU8; i++) {
767         EXPECT_EQ(*(handleEcmaStrU8->GetDataUtf8() + i), arrayU8[i]);
768     }
769 
770     // From EcmaString made by CreateFromUtf16( , , , true).
771     uint16_t arrayU16Comp[] = {3, 1, 34, 123, 127, 111, 42, 3, 20, 10};
772     uint32_t lengthEcmaStrU16Comp = sizeof(arrayU16Comp) / sizeof(arrayU16Comp[0]);
773     JSHandle<EcmaString> handleEcmaStrU16Comp(thread,
774         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16Comp[0], lengthEcmaStrU16Comp, true));
775     for (uint32_t i = 0; i < sizeof(arrayU16Comp) / arrayU16Comp[0]; i++) {
776         EXPECT_EQ(*(handleEcmaStrU16Comp->GetDataUtf8() + i), arrayU16Comp[i]);
777     }
778 }
779 
780 /*
781  * @tc.name: GetDataUtf16
782  * @tc.desc: Check whether the pointer returned through calling GetDataUtf16 function is within expectations.
783  * @tc.type: FUNC
784  * @tc.require:
785  */
HWTEST_F_L0(EcmaStringTest,GetDataUtf16)786 HWTEST_F_L0(EcmaStringTest, GetDataUtf16)
787 {
788     // From EcmaString made by CreateFromUtf16( , , , false).
789     uint16_t arrayU16NotComp[] = {67, 777, 1999, 1, 45, 66, 23456, 65535, 127, 333};
790     uint32_t lengthEcmaStrU16NotComp = sizeof(arrayU16NotComp) / sizeof(arrayU16NotComp[0]);
791     JSHandle<EcmaString> handleEcmaStrU16NotComp(thread,
792         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16NotComp[0], lengthEcmaStrU16NotComp, false));
793     for (uint32_t i = 0; i < lengthEcmaStrU16NotComp; i++) {
794         EXPECT_EQ(*(handleEcmaStrU16NotComp->GetDataUtf16() + i), arrayU16NotComp[i]);
795     }
796 }
797 
798 /*
799  * @tc.name: CopyDataRegionUtf8
800  * @tc.desc: Check whether the returned value and the changed array through a source EcmaString's calling
801  * CopyDataRegionUtf8 function are within expectations.
802  * @tc.type: FUNC
803  * @tc.require:
804  */
HWTEST_F_L0(EcmaStringTest,CopyDataRegionUtf8)805 HWTEST_F_L0(EcmaStringTest, CopyDataRegionUtf8)
806 {
807     // CopyDataRegionUtf8(). From EcmaString made by CreateFromUtf8().
808     uint8_t arrayU8CopyFrom[6] = {1, 12, 34, 56, 127};
809     uint32_t lengthEcmaStrU8CopyFrom = sizeof(arrayU8CopyFrom) - 1;
810     JSHandle<EcmaString> handleEcmaStrU8CopyFrom(thread,
811         EcmaString::CreateFromUtf8(ecmaVMPtr, &arrayU8CopyFrom[0], lengthEcmaStrU8CopyFrom, true));
812     const size_t lengthArrayU8Target = 7;
813     uint8_t defaultByteForU8CopyTo = 1;
814     uint8_t arrayU8CopyTo[lengthArrayU8Target];
815     int checkResUtf8 = memset_s(&arrayU8CopyTo[0], lengthArrayU8Target, defaultByteForU8CopyTo, lengthArrayU8Target);
816     EXPECT_TRUE(checkResUtf8 == 0);
817 
818     size_t indexStartFromArrayU8 = 2;
819     size_t lengthCopyToEcmaStrU8 = 3;
820     size_t lengthReturnU8 = handleEcmaStrU8CopyFrom->CopyDataRegionUtf8(arrayU8CopyTo, indexStartFromArrayU8,
821         lengthCopyToEcmaStrU8, lengthArrayU8Target);
822 
823     EXPECT_EQ(lengthReturnU8, lengthCopyToEcmaStrU8);
824     for (uint32_t i = 0; i < lengthCopyToEcmaStrU8; i++) {
825         EXPECT_EQ(arrayU8CopyTo[i], handleEcmaStrU8CopyFrom->At(i + indexStartFromArrayU8));
826     }
827     for (uint32_t i = lengthCopyToEcmaStrU8; i < lengthArrayU8Target; i++) {
828         EXPECT_EQ(arrayU8CopyTo[i], defaultByteForU8CopyTo);
829     }
830 
831     // CopyDataRegionUtf8(). From EcmaString made by CreateFromUtf16( , , , true).
832     uint16_t arrayU16CompCopyFrom[] = {1, 12, 34, 56, 127};
833     uint32_t lengthEcmaStrU16CompCopyFrom = sizeof(arrayU16CompCopyFrom) / sizeof(arrayU16CompCopyFrom[0]);
834     JSHandle<EcmaString> handleEcmaStrU16CompCopyFrom(thread,
835         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16CompCopyFrom[0], lengthEcmaStrU16CompCopyFrom, true));
836     const size_t lengthArrayU16Target = 8;
837     uint8_t defaultByteForU16CompCopyTo = 1;
838     uint8_t arrayU16CompCopyTo[lengthArrayU16Target];
839     int checkResUtf16 = memset_s(&arrayU16CompCopyTo[0], lengthArrayU16Target, defaultByteForU16CompCopyTo,
840                                  lengthArrayU16Target);
841     EXPECT_TRUE(checkResUtf16 == 0);
842 
843     size_t indexStartFromArrayU16Comp = 2;
844     size_t lengthCopyToEcmaStrU16Comp = 3;
845     size_t lengthReturnU16Comp = handleEcmaStrU16CompCopyFrom->CopyDataRegionUtf8(&arrayU16CompCopyTo[0],
846         indexStartFromArrayU16Comp, lengthCopyToEcmaStrU16Comp, lengthArrayU16Target);
847 
848     EXPECT_EQ(lengthReturnU16Comp, lengthCopyToEcmaStrU16Comp);
849     for (uint32_t i = 0; i < lengthReturnU16Comp; i++) {
850         EXPECT_EQ(arrayU16CompCopyTo[i], handleEcmaStrU16CompCopyFrom->At(i + indexStartFromArrayU16Comp));
851     }
852     for (uint32_t i = lengthReturnU16Comp; i < lengthArrayU16Target; i++) {
853         EXPECT_EQ(arrayU16CompCopyTo[i], defaultByteForU16CompCopyTo);
854     }
855 }
856 
857 /*
858  * @tc.name: CopyDataUtf8
859  * @tc.desc: Check whether the returned value and the changed array through a source EcmaString's calling
860  * CopyDataUtf8 function are within expectations.
861  * @tc.type: FUNC
862  * @tc.require:
863  */
HWTEST_F_L0(EcmaStringTest,CopyDataUtf8)864 HWTEST_F_L0(EcmaStringTest, CopyDataUtf8)
865 {
866     // CopyDataUtf8(). From EcmaString made by CreateFromUtf8().
867     uint8_t arrayU8CopyFrom[6] = {1, 12, 34, 56, 127};
868     uint32_t lengthEcmaStrU8CopyFrom = sizeof(arrayU8CopyFrom) - 1;
869     JSHandle<EcmaString> handleEcmaStrU8CopyFrom(thread,
870         EcmaString::CreateFromUtf8(ecmaVMPtr, &arrayU8CopyFrom[0], lengthEcmaStrU8CopyFrom, true));
871     const size_t lengthArrayU8Target = 6;
872     uint8_t arrayU8CopyTo[lengthArrayU8Target];
873 
874     size_t lengthReturnU8 = handleEcmaStrU8CopyFrom->CopyDataUtf8(&arrayU8CopyTo[0], lengthArrayU8Target);
875 
876     EXPECT_EQ(lengthReturnU8, lengthArrayU8Target);
877     for (uint32_t i = 0; i < lengthReturnU8 - 1; i++) {
878         EXPECT_EQ(arrayU8CopyTo[i], arrayU8CopyFrom[i]);
879     }
880     EXPECT_EQ(arrayU8CopyTo[lengthReturnU8 - 1], 0);
881 
882     // CopyDataUtf8(). From EcmaString made by CreateFromUtf16( , , , true).
883     uint16_t arrayU16CompCopyFrom[] = {1, 12, 34, 56, 127};
884     uint32_t lengthEcmaStrU16CompCopyFrom = sizeof(arrayU16CompCopyFrom) / sizeof(arrayU16CompCopyFrom[0]);
885     JSHandle<EcmaString> handleEcmaStrU16CompCopyFrom(thread,
886         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16CompCopyFrom[0], lengthEcmaStrU16CompCopyFrom, true));
887     const size_t lengthArrayU16Target = 6;
888     uint8_t arrayU8CompCopyTo[lengthArrayU16Target];
889 
890     size_t lengthReturnU16Comp = handleEcmaStrU16CompCopyFrom->CopyDataUtf8(&arrayU8CompCopyTo[0],
891         lengthArrayU16Target);
892 
893     EXPECT_EQ(lengthReturnU16Comp, lengthArrayU16Target);
894     for (uint32_t i = 0; i < lengthReturnU16Comp - 1; i++) {
895         EXPECT_EQ(arrayU8CompCopyTo[i], arrayU16CompCopyFrom[i]);
896     }
897     EXPECT_EQ(arrayU8CompCopyTo[lengthReturnU16Comp - 1], 0U);
898 }
899 
900 /*
901  * @tc.name: CopyDataRegionUtf16
902  * @tc.desc: Check whether the returned value and the changed array through a source EcmaString's calling
903  * CopyDataRegionUtf16 function are within expectations.
904  * @tc.type: FUNC
905  * @tc.require:
906  */
HWTEST_F_L0(EcmaStringTest,CopyDataRegionUtf16)907 HWTEST_F_L0(EcmaStringTest, CopyDataRegionUtf16)
908 {
909     // CopyDataRegionUtf16(). From EcmaString made by CreateFromUtf16( , , , false).
910     uint16_t arrayU16NotCompCopyFrom[10] = {67, 777, 1999, 1, 45, 66, 23456, 65535, 127, 333};
911     uint32_t lengthEcmaStrU16NotCompCopyFrom = sizeof(arrayU16NotCompCopyFrom) / sizeof(arrayU16NotCompCopyFrom[0]);
912     JSHandle<EcmaString> handleEcmaStrU16NotCompCopyFrom(thread,
913         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16NotCompCopyFrom[0], lengthEcmaStrU16NotCompCopyFrom, false));
914     const size_t lengthArrayU16Target = 13;
915     uint16_t arrayU16NotCompCopyTo[lengthArrayU16Target];
916     uint8_t defaultOneByteValueOfArrayU16NotCompCopyTo = 244;
917     int checkResUtf16 = memset_s(&arrayU16NotCompCopyTo[0], sizeof(uint16_t) * lengthArrayU16Target,
918         defaultOneByteValueOfArrayU16NotCompCopyTo, sizeof(uint16_t) * lengthArrayU16Target);
919     EXPECT_TRUE(checkResUtf16 == 0);
920 
921     size_t startIndexFromArrayU16NotComp = 2;
922     size_t lengthCopyFromArrayU16NotComp = 3;
923     size_t lengthReturnU16NotComp = handleEcmaStrU16NotCompCopyFrom->CopyDataRegionUtf16(&arrayU16NotCompCopyTo[0],
924         startIndexFromArrayU16NotComp, lengthCopyFromArrayU16NotComp, lengthArrayU16Target);
925 
926     EXPECT_EQ(lengthReturnU16NotComp, lengthCopyFromArrayU16NotComp);
927     for (uint32_t i = 0; i < lengthReturnU16NotComp; i++) {
928         EXPECT_EQ(arrayU16NotCompCopyTo[i], handleEcmaStrU16NotCompCopyFrom->At(i + startIndexFromArrayU16NotComp));
929     }
930     for (uint32_t i = lengthReturnU16NotComp; i < lengthArrayU16Target; i++) {
931         EXPECT_EQ(arrayU16NotCompCopyTo[i], ((uint16_t)defaultOneByteValueOfArrayU16NotCompCopyTo) * (1 + (1 << 8)));
932     }
933 }
934 
935 /*
936  * @tc.name: CopyDataUtf16
937  * @tc.desc: Check whether the returned value and the changed array through a source EcmaString's calling
938  * CopyDataUtf16 function are within expectations.
939  * @tc.type: FUNC
940  * @tc.require:
941  */
HWTEST_F_L0(EcmaStringTest,CopyDataUtf16)942 HWTEST_F_L0(EcmaStringTest, CopyDataUtf16)
943 {
944     // CopyDataUtf16(). From EcmaString made by CreateFromUtf16( , , , false).
945     uint16_t arrayU16NotCompCopyFrom[10] = {67, 777, 1999, 1, 45, 66, 23456, 65535, 127, 333};
946     uint32_t lengthEcmaStrU16NotCompCopyFrom = sizeof(arrayU16NotCompCopyFrom) / sizeof(arrayU16NotCompCopyFrom[0]);
947     JSHandle<EcmaString> handleEcmaStrU16NotCompCopyFrom(thread,
948         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16NotCompCopyFrom[0], lengthEcmaStrU16NotCompCopyFrom, false));
949     const size_t lengthArrayU16Target = 13;
950     uint16_t arrayU16NotCompCopyTo[lengthArrayU16Target];
951     uint8_t defaultOneByteValueOfArrayU16NotCompCopyTo = 244;
952     int checkResUtf16 = memset_s(&arrayU16NotCompCopyTo[0], sizeof(uint16_t) * lengthArrayU16Target,
953         defaultOneByteValueOfArrayU16NotCompCopyTo, sizeof(uint16_t) * lengthArrayU16Target);
954     EXPECT_TRUE(checkResUtf16 == 0);
955 
956     size_t lengthReturnU16NotComp = handleEcmaStrU16NotCompCopyFrom->CopyDataUtf16(&arrayU16NotCompCopyTo[0],
957         lengthArrayU16Target);
958 
959     EXPECT_EQ(lengthReturnU16NotComp, lengthEcmaStrU16NotCompCopyFrom);
960     for (uint32_t i = 0; i < lengthReturnU16NotComp; i++) {
961         EXPECT_EQ(arrayU16NotCompCopyTo[i], handleEcmaStrU16NotCompCopyFrom->At(i));
962     }
963     for (uint32_t i = lengthReturnU16NotComp; i < lengthArrayU16Target; i++) {
964         EXPECT_EQ(arrayU16NotCompCopyTo[i], ((uint16_t)defaultOneByteValueOfArrayU16NotCompCopyTo) * (1 + (1 << 8)));
965     }
966 }
967 
968 /*
969  * @tc.name: IndexOf_001
970  * @tc.desc: Check whether the value returned through a source EcmaString made by CreateFromUtf8() calling IndexOf
971  * function with a target EcmaString made by CreateFromUtf8() is within expectations.
972  * @tc.type: FUNC
973  * @tc.require:
974  */
HWTEST_F_L0(EcmaStringTest,IndexOf_001)975 HWTEST_F_L0(EcmaStringTest, IndexOf_001)
976 {
977     // IndexOf(). Find EcmaString made by CreateFromUtf8() From EcmaString made by CreateFromUtf8().
978     uint8_t arrayU8From[7] = {23, 25, 1, 3, 39, 80};
979     uint8_t arrayU8Target[4] = {1, 3, 39};
980     uint32_t lengthEcmaStrU8From = sizeof(arrayU8From) - 1;
981     uint32_t lengthEcmaStrU8Target = sizeof(arrayU8Target) - 1;
982     JSHandle<EcmaString> handleEcmaStr(thread,
983         EcmaString::CreateFromUtf8(ecmaVMPtr, &arrayU8From[0], lengthEcmaStrU8From, true));
984     JSHandle<EcmaString> handleEcmaStr1(thread,
985         EcmaString::CreateFromUtf8(ecmaVMPtr, &arrayU8Target[0], lengthEcmaStrU8Target, true));
986     int32_t posStart = 0;
987     EXPECT_EQ(handleEcmaStr->IndexOf(*handleEcmaStr1, posStart), 2);
988     EXPECT_EQ(handleEcmaStr1->IndexOf(*handleEcmaStr, posStart), -1);
989     posStart = -1;
990     EXPECT_EQ(handleEcmaStr->IndexOf(*handleEcmaStr1, posStart), 2);
991     posStart = 1;
992     EXPECT_EQ(handleEcmaStr->IndexOf(*handleEcmaStr1, posStart), 2);
993     posStart = 2;
994     EXPECT_EQ(handleEcmaStr->IndexOf(*handleEcmaStr1, posStart), 2);
995     posStart = 3;
996     EXPECT_EQ(handleEcmaStr->IndexOf(*handleEcmaStr1, posStart), -1);
997 }
998 
999 /*
1000  * @tc.name: IndexOf_002
1001  * @tc.desc: Check whether the value returned through a source EcmaString made by CreateFromUtf16( , , , false) calling
1002  * IndexOf function with a target EcmaString made by CreateFromUtf8() is within expectations.
1003  * @tc.type: FUNC
1004  * @tc.require:
1005  */
HWTEST_F_L0(EcmaStringTest,IndexOf_002)1006 HWTEST_F_L0(EcmaStringTest, IndexOf_002)
1007 {
1008     // IndexOf(). Find EcmaString made by CreateFromUtf8() From EcmaString made by CreateFromUtf16( , , , false).
1009     uint8_t arrayU8Target[4] = {1, 3, 39};
1010     uint16_t arrayU16NotCompFromNo1[] = {67, 65535, 127, 777, 1453, 44, 1, 3, 39, 80, 333};
1011     uint32_t lengthEcmaStrU8Target = sizeof(arrayU8Target) - 1;
1012     uint32_t lengthEcmaStrU16NotCompFromNo1 = sizeof(arrayU16NotCompFromNo1) / sizeof(arrayU16NotCompFromNo1[0]);
1013     JSHandle<EcmaString> handleEcmaStr(thread,
1014         EcmaString::CreateFromUtf8(ecmaVMPtr, &arrayU8Target[0], lengthEcmaStrU8Target, true));
1015     JSHandle<EcmaString> handleEcmaStr1(thread,
1016         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16NotCompFromNo1[0], lengthEcmaStrU16NotCompFromNo1, false));
1017     int32_t posStart = 0;
1018     EXPECT_EQ(handleEcmaStr1->IndexOf(*handleEcmaStr, posStart), 6);
1019     EXPECT_EQ(handleEcmaStr->IndexOf(*handleEcmaStr1, posStart), -1);
1020     posStart = -1;
1021     EXPECT_EQ(handleEcmaStr1->IndexOf(*handleEcmaStr, posStart), 6);
1022     posStart = 1;
1023     EXPECT_EQ(handleEcmaStr1->IndexOf(*handleEcmaStr, posStart), 6);
1024     posStart = 6;
1025     EXPECT_EQ(handleEcmaStr1->IndexOf(*handleEcmaStr, posStart), 6);
1026     posStart = 7;
1027     EXPECT_EQ(handleEcmaStr1->IndexOf(*handleEcmaStr, posStart), -1);
1028 }
1029 
1030 /*
1031  * @tc.name: IndexOf_003
1032  * @tc.desc: Check whether the value returned through a source EcmaString made by CreateFromUtf16( , , , false) calling
1033  * IndexOf function with a target EcmaString made by CreateFromUtf16( , , , false) is within expectations.
1034  * @tc.type: FUNC
1035  * @tc.require:
1036  */
HWTEST_F_L0(EcmaStringTest,IndexOf_003)1037 HWTEST_F_L0(EcmaStringTest, IndexOf_003)
1038 {
1039     /* IndexOf(). Find EcmaString made by CreateFromUtf16( , , , false) From EcmaString made by
1040      * CreateFromUtf16( , , , false).
1041      */
1042     uint16_t arrayU16NotCompTarget[] = {1453, 44};
1043     uint16_t arrayU16NotCompFrom[] = {67, 65535, 127, 777, 1453, 44, 1, 3, 39, 80, 333};
1044     uint32_t lengthEcmaStrU16NotCompTarget = sizeof(arrayU16NotCompTarget) / sizeof(arrayU16NotCompTarget[0]);
1045     uint32_t lengthEcmaStrU16NotCompFrom = sizeof(arrayU16NotCompFrom) / sizeof(arrayU16NotCompFrom[0]);
1046     JSHandle<EcmaString> handleEcmaStrU16NotCompTarget(thread,
1047         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16NotCompTarget[0], lengthEcmaStrU16NotCompTarget, false));
1048     JSHandle<EcmaString> handleEcmaStrU16NotCompFrom(thread,
1049         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16NotCompFrom[0], lengthEcmaStrU16NotCompFrom, false));
1050     int32_t posStart = 0;
1051     EXPECT_EQ(handleEcmaStrU16NotCompFrom->IndexOf(*handleEcmaStrU16NotCompTarget, posStart), 4);
1052     EXPECT_EQ(handleEcmaStrU16NotCompTarget->IndexOf(*handleEcmaStrU16NotCompFrom, posStart), -1);
1053     posStart = -1;
1054     EXPECT_EQ(handleEcmaStrU16NotCompFrom->IndexOf(*handleEcmaStrU16NotCompTarget, posStart), 4);
1055     posStart = 1;
1056     EXPECT_EQ(handleEcmaStrU16NotCompFrom->IndexOf(*handleEcmaStrU16NotCompTarget, posStart), 4);
1057     posStart = 4;
1058     EXPECT_EQ(handleEcmaStrU16NotCompFrom->IndexOf(*handleEcmaStrU16NotCompTarget, posStart), 4);
1059     posStart = 5;
1060     EXPECT_EQ(handleEcmaStrU16NotCompFrom->IndexOf(*handleEcmaStrU16NotCompTarget, posStart), -1);
1061 }
1062 
1063 /*
1064  * @tc.name: IndexOf_004
1065  * @tc.desc: Check whether the value returned through a source EcmaString made by CreateFromUtf8() calling IndexOf
1066  * function with a target EcmaString made by CreateFromUtf16() is within expectations.
1067  * @tc.type: FUNC
1068  * @tc.require:
1069  */
HWTEST_F_L0(EcmaStringTest,IndexOf_004)1070 HWTEST_F_L0(EcmaStringTest, IndexOf_004)
1071 {
1072     // IndexOf(). Find EcmaString made by CreateFromUtf16() From EcmaString made by CreateFromUtf8().
1073     uint16_t ecmaStrU16NotCompTarget[] = {3, 39, 80};
1074     uint8_t arrayU8From[7] = {23, 25, 1, 3, 39, 80};
1075     uint32_t lengthEcmaStrU16NotCompTarget = sizeof(ecmaStrU16NotCompTarget) / sizeof(ecmaStrU16NotCompTarget[0]);
1076     uint32_t lengthEcmaStrU8From = sizeof(arrayU8From) - 1;
1077     JSHandle<EcmaString> handleEcmaStrU16NotCompTarget(thread,
1078         EcmaString::CreateFromUtf16(ecmaVMPtr, &ecmaStrU16NotCompTarget[0], lengthEcmaStrU16NotCompTarget, true));
1079     JSHandle<EcmaString> handleEcmaStrU8From(thread,
1080         EcmaString::CreateFromUtf8(ecmaVMPtr, &arrayU8From[0], lengthEcmaStrU8From, true));
1081     int32_t posStart = 0;
1082     EXPECT_EQ(handleEcmaStrU8From->IndexOf(*handleEcmaStrU16NotCompTarget, posStart), 3);
1083     EXPECT_EQ(handleEcmaStrU16NotCompTarget->IndexOf(*handleEcmaStrU8From, posStart), -1);
1084     posStart = -1;
1085     EXPECT_EQ(handleEcmaStrU8From->IndexOf(*handleEcmaStrU16NotCompTarget, posStart), 3);
1086     posStart = 1;
1087     EXPECT_EQ(handleEcmaStrU8From->IndexOf(*handleEcmaStrU16NotCompTarget, posStart), 3);
1088     posStart = 3;
1089     EXPECT_EQ(handleEcmaStrU8From->IndexOf(*handleEcmaStrU16NotCompTarget, posStart), 3);
1090     posStart = 4;
1091     EXPECT_EQ(handleEcmaStrU8From->IndexOf(*handleEcmaStrU16NotCompTarget, posStart), -1);
1092 }
1093 
1094 /*
1095  * @tc.name: StringsAreEqual_001
1096  * @tc.desc: Check whether the bool returned through calling StringsAreEqual function with two EcmaStrings made by
1097  * CreateFromUtf8() is within expectations.
1098  * @tc.type: FUNC
1099  * @tc.require:
1100  */
HWTEST_F_L0(EcmaStringTest,StringsAreEqual_001)1101 HWTEST_F_L0(EcmaStringTest, StringsAreEqual_001)
1102 {
1103     // StringsAreEqual().
1104     uint8_t arrayU8No1[4] = {45, 92, 78};
1105     uint8_t arrayU8No2[4] = {45, 92, 78};
1106     uint8_t arrayU8No3[5] = {45, 92, 78, 1};
1107     uint32_t lengthEcmaStrU8No1 = sizeof(arrayU8No1) - 1;
1108     uint32_t lengthEcmaStrU8No2 = sizeof(arrayU8No2) - 1;
1109     uint32_t lengthEcmaStrU8No3 = sizeof(arrayU8No3) - 1;
1110     JSHandle<EcmaString> handleEcmaStrU8No1(thread,
1111         EcmaString::CreateFromUtf8(ecmaVMPtr, &arrayU8No1[0], lengthEcmaStrU8No1, true));
1112     JSHandle<EcmaString> handleEcmaStrU8No2(thread,
1113         EcmaString::CreateFromUtf8(ecmaVMPtr, &arrayU8No2[0], lengthEcmaStrU8No2, true));
1114     JSHandle<EcmaString> handleEcmaStrU8No3(thread,
1115         EcmaString::CreateFromUtf8(ecmaVMPtr, &arrayU8No3[0], lengthEcmaStrU8No3, true));
1116     EXPECT_TRUE(EcmaString::StringsAreEqual(*handleEcmaStrU8No1, *handleEcmaStrU8No2));
1117     EXPECT_FALSE(EcmaString::StringsAreEqual(*handleEcmaStrU8No1, *handleEcmaStrU8No3));
1118     EXPECT_FALSE(EcmaString::StringsAreEqual(*handleEcmaStrU8No3, *handleEcmaStrU8No1));
1119 }
1120 
1121 /*
1122  * @tc.name: StringsAreEqual_002
1123  * @tc.desc: Check whether the bool returned through calling StringsAreEqual function with a EcmaString made by
1124  * CreateFromUtf8() and a EcmaString made by CreateFromUtf16(, , , true) is within expectations.
1125  * @tc.type: FUNC
1126  * @tc.require:
1127  */
HWTEST_F_L0(EcmaStringTest,StringsAreEqual_002)1128 HWTEST_F_L0(EcmaStringTest, StringsAreEqual_002)
1129 {
1130     // StringsAreEqual().
1131     uint8_t arrayU8No1[4] = {45, 92, 78};
1132     uint16_t arrayU16CompNo2[] = {45, 92, 78};
1133     uint16_t arrayU16CompNo3[] = {45, 92, 78, 1};
1134     uint32_t lengthEcmaStrU8No1 = sizeof(arrayU8No1) - 1;
1135     uint32_t lengthEcmaStrU16CompNo2 = sizeof(arrayU16CompNo2) / sizeof(arrayU16CompNo2[0]);
1136     uint32_t lengthEcmaStrU16CompNo3 = sizeof(arrayU16CompNo3) / sizeof(arrayU16CompNo3[0]);
1137     JSHandle<EcmaString> handleEcmaStrU8No1(thread,
1138         EcmaString::CreateFromUtf8(ecmaVMPtr, &arrayU8No1[0], lengthEcmaStrU8No1, true));
1139     JSHandle<EcmaString> handleEcmaStrU16CompNo2(thread,
1140         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16CompNo2[0], lengthEcmaStrU16CompNo2, true));
1141     JSHandle<EcmaString> handleEcmaStrU16CompNo3(thread,
1142         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16CompNo3[0], lengthEcmaStrU16CompNo3, true));
1143     EXPECT_TRUE(EcmaString::StringsAreEqual(*handleEcmaStrU8No1, *handleEcmaStrU16CompNo2));
1144     EXPECT_FALSE(EcmaString::StringsAreEqual(*handleEcmaStrU8No1, *handleEcmaStrU16CompNo3));
1145 }
1146 
1147 /*
1148  * @tc.name: StringsAreEqual_003
1149  * @tc.desc: Check whether the bool returned through calling StringsAreEqual function with two EcmaStrings made by
1150  * CreateFromUtf16(, , , true) is within expectations.
1151  * @tc.type: FUNC
1152  * @tc.require:
1153  */
HWTEST_F_L0(EcmaStringTest,StringsAreEqual_003)1154 HWTEST_F_L0(EcmaStringTest, StringsAreEqual_003)
1155 {
1156     // StringsAreEqual().
1157     uint16_t arrayU16CompNo1[] = {45, 92, 78};
1158     uint16_t arrayU16CompNo2[] = {45, 92, 78};
1159     uint16_t arrayU16CompNo3[] = {45, 92, 78, 1};
1160     uint32_t lengthEcmaStrU16CompNo1 = sizeof(arrayU16CompNo1) / sizeof(arrayU16CompNo1[0]);
1161     uint32_t lengthEcmaStrU16CompNo2 = sizeof(arrayU16CompNo2) / sizeof(arrayU16CompNo2[0]);
1162     uint32_t lengthEcmaStrU16CompNo3 = sizeof(arrayU16CompNo3) / sizeof(arrayU16CompNo3[0]);
1163     JSHandle<EcmaString> handleEcmaStrU16CompNo1(thread,
1164         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16CompNo1[0], lengthEcmaStrU16CompNo1, true));
1165     JSHandle<EcmaString> handleEcmaStrU16CompNo2(thread,
1166         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16CompNo2[0], lengthEcmaStrU16CompNo2, true));
1167     JSHandle<EcmaString> handleEcmaStrU16CompNo3(thread,
1168         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16CompNo3[0], lengthEcmaStrU16CompNo3, true));
1169     EXPECT_TRUE(EcmaString::StringsAreEqual(*handleEcmaStrU16CompNo1, *handleEcmaStrU16CompNo2));
1170     EXPECT_FALSE(EcmaString::StringsAreEqual(*handleEcmaStrU16CompNo1, *handleEcmaStrU16CompNo3));
1171     EXPECT_FALSE(EcmaString::StringsAreEqual(*handleEcmaStrU16CompNo3, *handleEcmaStrU16CompNo1));
1172 }
1173 
1174 /*
1175  * @tc.name: StringsAreEqual_004
1176  * @tc.desc: Check whether the bool returned through calling StringsAreEqual function with a EcmaString made by
1177  * CreateFromUtf8() and a EcmaString made by CreateFromUtf16(, , , false) is within expectations.
1178  * @tc.type: FUNC
1179  * @tc.require:
1180  */
HWTEST_F_L0(EcmaStringTest,StringsAreEqual_004)1181 HWTEST_F_L0(EcmaStringTest, StringsAreEqual_004)
1182 {
1183     // StringsAreEqual().
1184     uint8_t arrayU8No1[4] = {45, 92, 78};
1185     uint16_t arrayU16NotCompNo1[] = {45, 92, 78};
1186     uint32_t lengthEcmaStrU8No1 = sizeof(arrayU8No1) - 1;
1187     uint32_t lengthEcmaStrU16NotCompNo1 = sizeof(arrayU16NotCompNo1) / sizeof(arrayU16NotCompNo1[0]);
1188     JSHandle<EcmaString> handleEcmaStrU8No1(thread,
1189         EcmaString::CreateFromUtf8(ecmaVMPtr, &arrayU8No1[0], lengthEcmaStrU8No1, true));
1190     JSHandle<EcmaString> handleEcmaStrU16NotCompNo1(thread,
1191         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16NotCompNo1[0], lengthEcmaStrU16NotCompNo1, true));
1192     EXPECT_TRUE(EcmaString::StringsAreEqual(*handleEcmaStrU8No1, *handleEcmaStrU16NotCompNo1));
1193     EXPECT_TRUE(EcmaString::StringsAreEqual(*handleEcmaStrU16NotCompNo1, *handleEcmaStrU8No1));
1194 }
1195 
1196 /*
1197  * @tc.name: StringsAreEqual_005
1198  * @tc.desc: Check whether the bool returned through calling StringsAreEqual function with a EcmaString made by
1199  * CreateFromUtf16(, , , true) and a EcmaString made by CreateFromUtf16(, , , false) is within expectations.
1200  * @tc.type: FUNC
1201  * @tc.require:
1202  */
HWTEST_F_L0(EcmaStringTest,StringsAreEqual_005)1203 HWTEST_F_L0(EcmaStringTest, StringsAreEqual_005)
1204 {
1205     // StringsAreEqual().
1206     uint16_t arrayU16CompNo1[] = {45, 92, 78};
1207     uint16_t arrayU16NotCompNo1[] = {45, 92, 78};
1208     uint32_t lengthEcmaStrU16CompNo1 = sizeof(arrayU16CompNo1) / sizeof(arrayU16CompNo1[0]);
1209     uint32_t lengthEcmaStrU16NotCompNo1 = sizeof(arrayU16NotCompNo1) / sizeof(arrayU16NotCompNo1[0]);
1210     JSHandle<EcmaString> handleEcmaStrU16CompNo1(thread,
1211         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16CompNo1[0], lengthEcmaStrU16CompNo1, true));
1212     JSHandle<EcmaString> handleEcmaStrU16NotCompNo1(thread,
1213         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16NotCompNo1[0], lengthEcmaStrU16NotCompNo1, true));
1214     EXPECT_TRUE(EcmaString::StringsAreEqual(*handleEcmaStrU16CompNo1, *handleEcmaStrU16NotCompNo1));
1215     EXPECT_TRUE(EcmaString::StringsAreEqual(*handleEcmaStrU16NotCompNo1, *handleEcmaStrU16CompNo1));
1216 }
1217 
1218 /*
1219  * @tc.name: StringsAreEqual_006
1220  * @tc.desc: Check whether the bool returned through calling StringsAreEqual function with two EcmaStrings made by
1221  * CreateFromUtf16(, , , false) is within expectations.
1222  * @tc.type: FUNC
1223  * @tc.require:
1224  */
HWTEST_F_L0(EcmaStringTest,StringsAreEqual_006)1225 HWTEST_F_L0(EcmaStringTest, StringsAreEqual_006)
1226 {
1227     // StringsAreEqual().
1228     uint16_t arrayU16NotCompNo1[] = {234, 345, 127, 2345, 65535, 5};
1229     uint16_t arrayU16NotCompNo2[] = {234, 345, 127, 2345, 65535, 5};
1230     uint16_t arrayU16NotCompNo3[] = {1, 234, 345, 127, 2345, 65535, 5};
1231     uint32_t lengthEcmaStrU16NotCompNo1 = sizeof(arrayU16NotCompNo1) / sizeof(arrayU16NotCompNo1[0]);
1232     uint32_t lengthEcmaStrU16NotCompNo2 = sizeof(arrayU16NotCompNo2) / sizeof(arrayU16NotCompNo2[0]);
1233     uint32_t lengthEcmaStrU16NotCompNo3 = sizeof(arrayU16NotCompNo3) / sizeof(arrayU16NotCompNo3[0]);
1234     JSHandle<EcmaString> handleEcmaStrU16NotCompNo1(thread,
1235         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16NotCompNo1[0], lengthEcmaStrU16NotCompNo1, false));
1236     JSHandle<EcmaString> handleEcmaStrU16NotCompNo2(thread,
1237         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16NotCompNo2[0], lengthEcmaStrU16NotCompNo2, false));
1238     JSHandle<EcmaString> handleEcmaStrU16NotCompNo3(thread,
1239         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16NotCompNo3[0], lengthEcmaStrU16NotCompNo3, false));
1240     EXPECT_TRUE(EcmaString::StringsAreEqual(*handleEcmaStrU16NotCompNo1, *handleEcmaStrU16NotCompNo2));
1241     EXPECT_FALSE(EcmaString::StringsAreEqual(*handleEcmaStrU16NotCompNo1, *handleEcmaStrU16NotCompNo3));
1242     EXPECT_FALSE(EcmaString::StringsAreEqual(*handleEcmaStrU16NotCompNo3, *handleEcmaStrU16NotCompNo1));
1243 }
1244 
1245 /*
1246  * @tc.name: StringsAreEqualUtf8_001
1247  * @tc.desc: Check whether the bool returned through calling StringIsEqualUint8Data function with an EcmaString made by
1248  * CreateFromUtf8() and an Array(uint8_t) is within expectations.
1249  * @tc.type: FUNC
1250  * @tc.require:
1251  */
HWTEST_F_L0(EcmaStringTest,StringsAreEqualUtf8_001)1252 HWTEST_F_L0(EcmaStringTest, StringsAreEqualUtf8_001)
1253 {
1254     // StringIsEqualUint8Data(). EcmaString made by CreateFromUtf8(), Array:U8.
1255     uint8_t arrayU8No1[4] = {45, 92, 78};
1256     uint8_t arrayU8No2[5] = {45, 92, 78, 24};
1257     uint8_t arrayU8No3[3] = {45, 92};
1258     uint32_t lengthEcmaStrU8No1 = sizeof(arrayU8No1) - 1;
1259     uint32_t lengthEcmaStrU8No2 = sizeof(arrayU8No2) - 1;
1260     uint32_t lengthEcmaStrU8No3 = sizeof(arrayU8No3) - 1;
1261     JSHandle<EcmaString> handleEcmaStrU8No1(thread,
1262         EcmaString::CreateFromUtf8(ecmaVMPtr, &arrayU8No1[0], lengthEcmaStrU8No1, true));
1263     JSHandle<EcmaString> handleEcmaStrU8No2(thread,
1264         EcmaString::CreateFromUtf8(ecmaVMPtr, &arrayU8No2[0], lengthEcmaStrU8No2, true));
1265     JSHandle<EcmaString> handleEcmaStrU8No3(thread,
1266         EcmaString::CreateFromUtf8(ecmaVMPtr, &arrayU8No3[0], lengthEcmaStrU8No3, true));
1267     EXPECT_TRUE(EcmaString::StringIsEqualUint8Data(*handleEcmaStrU8No1, &arrayU8No1[0], lengthEcmaStrU8No1, true));
1268     EXPECT_FALSE(EcmaString::StringIsEqualUint8Data(*handleEcmaStrU8No1, &arrayU8No1[0], lengthEcmaStrU8No1, false));
1269     EXPECT_FALSE(EcmaString::StringIsEqualUint8Data(*handleEcmaStrU8No2, &arrayU8No1[0], lengthEcmaStrU8No1, true));
1270     EXPECT_FALSE(EcmaString::StringIsEqualUint8Data(*handleEcmaStrU8No3, &arrayU8No1[0], lengthEcmaStrU8No1, true));
1271 }
1272 
1273 /*
1274  * @tc.name: StringsAreEqualUtf8_002
1275  * @tc.desc: Check whether the bool returned through calling StringIsEqualUint8Data function with an EcmaString made by
1276  * CreateFromUtf16( , , , true) and an Array(uint8_t) is within expectations.
1277  * @tc.type: FUNC
1278  * @tc.require:
1279  */
HWTEST_F_L0(EcmaStringTest,StringsAreEqualUtf8_002)1280 HWTEST_F_L0(EcmaStringTest, StringsAreEqualUtf8_002)
1281 {
1282     // StringIsEqualUint8Data(). EcmaString made by CreateFromUtf16( , , , true), Array:U8.
1283     uint8_t arrayU8No1[4] = {45, 92, 78};
1284     uint16_t arrayU16CompNo1[] = {45, 92, 78};
1285     uint16_t arrayU16CompNo2[] = {45, 92, 78, 24};
1286     uint16_t arrayU16CompNo3[] = {45, 92};
1287     uint32_t lengthEcmaStrU8No1 = sizeof(arrayU8No1) - 1;
1288     uint32_t lengthEcmaStrU16CompNo1 = sizeof(arrayU16CompNo1) / sizeof(arrayU16CompNo1[0]);
1289     uint32_t lengthEcmaStrU16CompNo2 = sizeof(arrayU16CompNo2) / sizeof(arrayU16CompNo2[0]);
1290     uint32_t lengthEcmaStrU16CompNo3 = sizeof(arrayU16CompNo3) / sizeof(arrayU16CompNo3[0]);
1291     JSHandle<EcmaString> handleEcmaStrU16CompNo1(thread,
1292         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16CompNo1[0], lengthEcmaStrU16CompNo1, true));
1293     JSHandle<EcmaString> handleEcmaStrU16CompNo2(thread,
1294         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16CompNo2[0], lengthEcmaStrU16CompNo2, true));
1295     JSHandle<EcmaString> handleEcmaStrU16CompNo3(thread,
1296         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16CompNo3[0], lengthEcmaStrU16CompNo3, true));
1297     EXPECT_TRUE(EcmaString::StringIsEqualUint8Data(*handleEcmaStrU16CompNo1,
1298                                                    &arrayU8No1[0], lengthEcmaStrU8No1, true));
1299     EXPECT_FALSE(EcmaString::StringIsEqualUint8Data(*handleEcmaStrU16CompNo1,
1300                                                     &arrayU8No1[0], lengthEcmaStrU8No1, false));
1301     EXPECT_FALSE(EcmaString::StringIsEqualUint8Data(*handleEcmaStrU16CompNo2,
1302                                                     &arrayU8No1[0], lengthEcmaStrU8No1, true));
1303     EXPECT_FALSE(EcmaString::StringIsEqualUint8Data(*handleEcmaStrU16CompNo3,
1304                                                     &arrayU8No1[0], lengthEcmaStrU8No1, true));
1305 }
1306 
1307 /*
1308  * @tc.name: StringsAreEqualUtf8_003
1309  * @tc.desc: Check whether the bool returned through calling StringIsEqualUint8Data function with an EcmaString made by
1310  * CreateFromUtf16( , , , false) and an Array(uint8_t) is within expectations.
1311  * @tc.type: FUNC
1312  * @tc.require:
1313  */
HWTEST_F_L0(EcmaStringTest,StringsAreEqualUtf8_003)1314 HWTEST_F_L0(EcmaStringTest, StringsAreEqualUtf8_003)
1315 {
1316     // StringIsEqualUint8Data(). EcmaString made by CreateFromUtf16( , , , false), Array:U8.
1317     uint8_t arrayU8No1[4] = {45, 92, 78};
1318     uint16_t arrayU16NotCompNo1[] = {45, 92, 78};
1319     uint16_t arrayU16NotCompNo2[] = {45, 92, 78, 24};
1320     uint16_t arrayU16NotCompNo3[] = {45, 92};
1321     uint16_t arrayU16NotCompNo4[] = {25645, 25692, 25678};
1322     uint32_t lengthEcmaStrU8No1 = sizeof(arrayU8No1) - 1;
1323     uint32_t lengthEcmaStrU16NotCompNo1 = sizeof(arrayU16NotCompNo1) / sizeof(arrayU16NotCompNo1[0]);
1324     uint32_t lengthEcmaStrU16NotCompNo2 = sizeof(arrayU16NotCompNo2) / sizeof(arrayU16NotCompNo2[0]);
1325     uint32_t lengthEcmaStrU16NotCompNo3 = sizeof(arrayU16NotCompNo3) / sizeof(arrayU16NotCompNo3[0]);
1326     uint32_t lengthEcmaStrU16NotCompNo4 = sizeof(arrayU16NotCompNo4) / sizeof(arrayU16NotCompNo4[0]);
1327     JSHandle<EcmaString> handleEcmaStrU16NotCompNo1(thread,
1328         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16NotCompNo1[0], lengthEcmaStrU16NotCompNo1, true));
1329     JSHandle<EcmaString> handleEcmaStrU16NotCompNo2(thread,
1330         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16NotCompNo2[0], lengthEcmaStrU16NotCompNo2, true));
1331     JSHandle<EcmaString> handleEcmaStrU16NotCompNo3(thread,
1332         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16NotCompNo3[0], lengthEcmaStrU16NotCompNo3, true));
1333     JSHandle<EcmaString> handleEcmaStrU16NotCompNo4(thread,
1334         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16NotCompNo4[0], lengthEcmaStrU16NotCompNo4, false));
1335     EXPECT_FALSE(
1336         EcmaString::StringIsEqualUint8Data(*handleEcmaStrU16NotCompNo1, &arrayU8No1[0], lengthEcmaStrU8No1, false));
1337     EXPECT_TRUE(
1338         EcmaString::StringIsEqualUint8Data(*handleEcmaStrU16NotCompNo1, &arrayU8No1[0], lengthEcmaStrU8No1, true));
1339     EXPECT_FALSE(
1340         EcmaString::StringIsEqualUint8Data(*handleEcmaStrU16NotCompNo2, &arrayU8No1[0], lengthEcmaStrU8No1, false));
1341     EXPECT_FALSE(
1342         EcmaString::StringIsEqualUint8Data(*handleEcmaStrU16NotCompNo3, &arrayU8No1[0], lengthEcmaStrU8No1, false));
1343     EXPECT_FALSE(
1344         EcmaString::StringIsEqualUint8Data(*handleEcmaStrU16NotCompNo4, &arrayU8No1[0], lengthEcmaStrU8No1, false));
1345 }
1346 
1347 /*
1348  * @tc.name: StringsAreEqualUtf16_001
1349  * @tc.desc: Check whether the bool returned through calling StringsAreEqualUtf16 function with an EcmaString made by
1350  * CreateFromUtf8() and an Array(uint16_t) is within expectations.
1351  * @tc.type: FUNC
1352  * @tc.require:
1353  */
HWTEST_F_L0(EcmaStringTest,StringsAreEqualUtf16_001)1354 HWTEST_F_L0(EcmaStringTest, StringsAreEqualUtf16_001)
1355 {
1356     // StringsAreEqualUtf16(). EcmaString made by CreateFromUtf8, Array:U16(1-127).
1357     uint8_t arrayU8No1[4] = {45, 92, 78};
1358     uint8_t arrayU8No2[5] = {45, 92, 78, 24};
1359     uint8_t arrayU8No3[3] = {45, 92};
1360     uint16_t arrayU16NotCompNo1[] = {45, 92, 78};
1361     uint32_t lengthEcmaStrU8No1 = sizeof(arrayU8No1) - 1;
1362     uint32_t lengthEcmaStrU8No2 = sizeof(arrayU8No2) - 1;
1363     uint32_t lengthEcmaStrU8No3 = sizeof(arrayU8No3) - 1;
1364     uint32_t lengthEcmaStrU16NotCompNo1 = sizeof(arrayU16NotCompNo1) / sizeof(arrayU16NotCompNo1[0]);
1365     JSHandle<EcmaString> handleEcmaStrU8No1(thread,
1366         EcmaString::CreateFromUtf8(ecmaVMPtr, &arrayU8No1[0], lengthEcmaStrU8No1, true));
1367     JSHandle<EcmaString> handleEcmaStrU8No2(thread,
1368         EcmaString::CreateFromUtf8(ecmaVMPtr, &arrayU8No2[0], lengthEcmaStrU8No2, true));
1369     JSHandle<EcmaString> handleEcmaStrU8No3(thread,
1370         EcmaString::CreateFromUtf8(ecmaVMPtr, &arrayU8No3[0], lengthEcmaStrU8No3, true));
1371     EXPECT_TRUE(
1372         EcmaString::StringsAreEqualUtf16(*handleEcmaStrU8No1, &arrayU16NotCompNo1[0], lengthEcmaStrU16NotCompNo1));
1373     EXPECT_FALSE(
1374         EcmaString::StringsAreEqualUtf16(*handleEcmaStrU8No2, &arrayU16NotCompNo1[0], lengthEcmaStrU16NotCompNo1));
1375     EXPECT_FALSE(
1376         EcmaString::StringsAreEqualUtf16(*handleEcmaStrU8No3, &arrayU16NotCompNo1[0], lengthEcmaStrU16NotCompNo1));
1377 }
1378 
1379 /*
1380  * @tc.name: StringsAreEqualUtf16_002
1381  * @tc.desc: Check whether the bool returned through calling StringsAreEqualUtf16 function with an EcmaString made by
1382  * CreateFromUtf16( , , , true) and an Array(uint16_t) is within expectations.
1383  * @tc.type: FUNC
1384  * @tc.require:
1385  */
HWTEST_F_L0(EcmaStringTest,StringsAreEqualUtf16_002)1386 HWTEST_F_L0(EcmaStringTest, StringsAreEqualUtf16_002)
1387 {
1388     // StringsAreEqualUtf16(). EcmaString made by CreateFromUtf16( , , , true), Array:U16(1-127).
1389     uint16_t arrayU16CompNo1[] = {45, 92, 78};
1390     uint16_t arrayU16CompNo2[] = {45, 92, 78, 24};
1391     uint16_t arrayU16CompNo3[] = {45, 92};
1392     uint16_t arrayU16CompNo4[] = {25645, 25692, 25678}; // 25645 % 256 == 45...
1393     uint32_t lengthEcmaStrU16CompNo1 = sizeof(arrayU16CompNo1) / sizeof(arrayU16CompNo1[0]);
1394     uint32_t lengthEcmaStrU16CompNo2 = sizeof(arrayU16CompNo2) / sizeof(arrayU16CompNo2[0]);
1395     uint32_t lengthEcmaStrU16CompNo3 = sizeof(arrayU16CompNo3) / sizeof(arrayU16CompNo3[0]);
1396     uint32_t lengthEcmaStrU16CompNo4 = sizeof(arrayU16CompNo4) / sizeof(arrayU16CompNo4[0]);
1397     JSHandle<EcmaString> handleEcmaStrU16CompNo1(thread,
1398         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16CompNo1[0], lengthEcmaStrU16CompNo1, true));
1399     JSHandle<EcmaString> handleEcmaStrU16CompNo2(thread,
1400         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16CompNo2[0], lengthEcmaStrU16CompNo2, true));
1401     JSHandle<EcmaString> handleEcmaStrU16CompNo3(thread,
1402         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16CompNo3[0], lengthEcmaStrU16CompNo3, true));
1403     JSHandle<EcmaString> handleEcmaStrU16CompNo4(thread,
1404         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16CompNo4[0], lengthEcmaStrU16CompNo4, true));
1405     EXPECT_TRUE(
1406         EcmaString::StringsAreEqualUtf16(*handleEcmaStrU16CompNo1, &arrayU16CompNo1[0], lengthEcmaStrU16CompNo1));
1407     EXPECT_FALSE(
1408         EcmaString::StringsAreEqualUtf16(*handleEcmaStrU16CompNo2, &arrayU16CompNo1[0], lengthEcmaStrU16CompNo1));
1409     EXPECT_FALSE(
1410         EcmaString::StringsAreEqualUtf16(*handleEcmaStrU16CompNo3, &arrayU16CompNo1[0], lengthEcmaStrU16CompNo1));
1411     EXPECT_TRUE(
1412         EcmaString::StringsAreEqualUtf16(*handleEcmaStrU16CompNo4, &arrayU16CompNo1[0], lengthEcmaStrU16CompNo1));
1413 }
1414 
1415 /*
1416  * @tc.name: StringsAreEqualUtf16_003
1417  * @tc.desc: Check whether the bool returned through calling StringsAreEqualUtf16 function with an EcmaString made by
1418  * CreateFromUtf16( , , , false) and an Array(uint16_t) is within expectations.
1419  * @tc.type: FUNC
1420  * @tc.require:
1421  */
HWTEST_F_L0(EcmaStringTest,StringsAreEqualUtf16_003)1422 HWTEST_F_L0(EcmaStringTest, StringsAreEqualUtf16_003)
1423 {
1424     // StringsAreEqualUtf16(). EcmaString made by CreateFromUtf16( , , , false), Array:U16(0-65535).
1425     uint16_t arrayU16NotCompNo1[] = {25645, 25692, 25678};
1426     uint16_t arrayU16NotCompNo2[] = {25645, 25692, 78}; // 25645 % 256 == 45...
1427     uint16_t arrayU16NotCompNo3[] = {25645, 25692, 25678, 65535};
1428     uint16_t arrayU16NotCompNo4[] = {25645, 25692};
1429     uint32_t lengthEcmaStrU16NotCompNo1 = sizeof(arrayU16NotCompNo1) / sizeof(arrayU16NotCompNo1[0]);
1430     uint32_t lengthEcmaStrU16NotCompNo2 = sizeof(arrayU16NotCompNo2) / sizeof(arrayU16NotCompNo2[0]);
1431     uint32_t lengthEcmaStrU16NotCompNo3 = sizeof(arrayU16NotCompNo3) / sizeof(arrayU16NotCompNo3[0]);
1432     uint32_t lengthEcmaStrU16NotCompNo4 = sizeof(arrayU16NotCompNo4) / sizeof(arrayU16NotCompNo4[0]);
1433     JSHandle<EcmaString> handleEcmaStrU16NotCompNo1(thread,
1434         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16NotCompNo1[0], lengthEcmaStrU16NotCompNo1, false));
1435     JSHandle<EcmaString> handleEcmaStrU16NotCompNo2(thread,
1436         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16NotCompNo2[0], lengthEcmaStrU16NotCompNo2, false));
1437     JSHandle<EcmaString> handleEcmaStrU16NotCompNo3(thread,
1438         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16NotCompNo3[0], lengthEcmaStrU16NotCompNo3, false));
1439     JSHandle<EcmaString> handleEcmaStrU16NotCompNo4(thread,
1440         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16NotCompNo4[0], lengthEcmaStrU16NotCompNo4, false));
1441     EXPECT_TRUE(EcmaString::StringsAreEqualUtf16(*handleEcmaStrU16NotCompNo1, &arrayU16NotCompNo1[0],
1442         lengthEcmaStrU16NotCompNo1));
1443     EXPECT_FALSE(EcmaString::StringsAreEqualUtf16(*handleEcmaStrU16NotCompNo1, &arrayU16NotCompNo2[0],
1444         lengthEcmaStrU16NotCompNo2));
1445     EXPECT_FALSE(EcmaString::StringsAreEqualUtf16(*handleEcmaStrU16NotCompNo2, &arrayU16NotCompNo1[0],
1446         lengthEcmaStrU16NotCompNo1));
1447     EXPECT_FALSE(EcmaString::StringsAreEqualUtf16(*handleEcmaStrU16NotCompNo3, &arrayU16NotCompNo1[0],
1448         lengthEcmaStrU16NotCompNo1));
1449     EXPECT_FALSE(EcmaString::StringsAreEqualUtf16(*handleEcmaStrU16NotCompNo4, &arrayU16NotCompNo1[0],
1450         lengthEcmaStrU16NotCompNo1));
1451 }
1452 
1453 /*
1454  * @tc.name: ComputeHashcodeUtf8
1455  * @tc.desc: Check whether the value returned through calling ComputeHashcodeUtf8 function with an Array(uint8_t) is
1456  * within expectations.
1457  * @tc.type: FUNC
1458  * @tc.require:
1459  */
HWTEST_F_L0(EcmaStringTest,ComputeHashcodeUtf8)1460 HWTEST_F_L0(EcmaStringTest, ComputeHashcodeUtf8)
1461 {
1462     uint8_t arrayU8[] = {"abc"};
1463     uint32_t lengthEcmaStrU8 = sizeof(arrayU8) - 1;
1464     uint32_t hashExpect = 0;
1465     for (uint32_t i = 0; i < lengthEcmaStrU8; i++) {
1466         hashExpect = hashExpect * 31 + arrayU8[i];
1467     }
1468     EXPECT_EQ(EcmaString::ComputeHashcodeUtf8(&arrayU8[0], lengthEcmaStrU8, true), hashExpect);
1469 }
1470 
1471 /*
1472  * @tc.name: ComputeHashcodeUtf16
1473  * @tc.desc: Check whether the value returned through calling ComputeHashcodeUtf16 function with an Array(uint16_t) is
1474  * within expectations.
1475  * @tc.type: FUNC
1476  * @tc.require:
1477  */
HWTEST_F_L0(EcmaStringTest,ComputeHashcodeUtf16)1478 HWTEST_F_L0(EcmaStringTest, ComputeHashcodeUtf16)
1479 {
1480     uint16_t arrayU16[] = {199, 1, 256, 65535, 777};
1481     uint32_t lengthEcmaStrU16 = sizeof(arrayU16) / sizeof(arrayU16[0]);
1482     uint32_t hashExpect = 0;
1483     for (uint32_t i = 0; i < lengthEcmaStrU16; i++) {
1484         hashExpect = hashExpect * 31 + arrayU16[i];
1485     }
1486     EXPECT_EQ(EcmaString::ComputeHashcodeUtf16(&arrayU16[0], lengthEcmaStrU16), hashExpect);
1487 }
1488 
1489 /*
1490  * @tc.name: GetHashcode_001
1491  * @tc.desc: Check whether the value returned through an EcmaString made by CreateFromUtf8() calling GetHashcode
1492  * function is within expectations.
1493  * @tc.type: FUNC
1494  * @tc.require:
1495  */
HWTEST_F_L0(EcmaStringTest,GetHashcode_001)1496 HWTEST_F_L0(EcmaStringTest, GetHashcode_001)
1497 {
1498     // GetHashcode(). EcmaString made by CreateFromUtf8().
1499     uint8_t arrayU8[] = {"abc"};
1500     uint32_t lengthEcmaStrU8 = sizeof(arrayU8) - 1;
1501     JSHandle<EcmaString> handleEcmaStrU8(thread,
1502         EcmaString::CreateFromUtf8(ecmaVMPtr, &arrayU8[0], lengthEcmaStrU8, true));
1503     uint32_t hashExpect = 0;
1504     for (uint32_t i = 0; i < lengthEcmaStrU8; i++) {
1505         hashExpect = hashExpect * 31 + arrayU8[i];
1506     }
1507     EXPECT_EQ(handleEcmaStrU8->GetHashcode(), hashExpect);
1508 }
1509 
1510 /*
1511  * @tc.name: GetHashcode_002
1512  * @tc.desc: Check whether the value returned through an EcmaString made by CreateFromUtf16( , , , true) calling
1513  * GetHashcode function is within expectations.
1514  * @tc.type: FUNC
1515  * @tc.require:
1516  */
HWTEST_F_L0(EcmaStringTest,GetHashcode_002)1517 HWTEST_F_L0(EcmaStringTest, GetHashcode_002)
1518 {
1519     // GetHashcode(). EcmaString made by CreateFromUtf16( , , , true).
1520     uint16_t arrayU16Comp[] = {45, 92, 78, 24};
1521     uint32_t lengthEcmaStrU16Comp = sizeof(arrayU16Comp) / sizeof(arrayU16Comp[0]);
1522     JSHandle<EcmaString> handleEcmaStrU16Comp(thread,
1523         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16Comp[0], lengthEcmaStrU16Comp, true));
1524     uint32_t hashExpect = 0;
1525     for (uint32_t i = 0; i < lengthEcmaStrU16Comp; i++) {
1526         hashExpect = hashExpect * 31 + arrayU16Comp[i];
1527     }
1528     EXPECT_EQ(handleEcmaStrU16Comp->GetHashcode(), hashExpect);
1529 }
1530 
1531 /*
1532  * @tc.name: GetHashcode_003
1533  * @tc.desc: Check whether the value returned through an EcmaString made by CreateFromUtf16( , , , false) calling
1534  * GetHashcode function is within expectations.
1535  * @tc.type: FUNC
1536  * @tc.require:
1537  */
HWTEST_F_L0(EcmaStringTest,GetHashcode_003)1538 HWTEST_F_L0(EcmaStringTest, GetHashcode_003)
1539 {
1540     // GetHashcode(). EcmaString made by CreateFromUtf16( , , , false).
1541     uint16_t arrayU16NotComp[] = {199, 1, 256, 65535, 777};
1542     uint32_t lengthEcmaStrU16NotComp = sizeof(arrayU16NotComp) / sizeof(arrayU16NotComp[0]);
1543     JSHandle<EcmaString> handleEcmaStrU16NotComp(thread,
1544         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16NotComp[0], lengthEcmaStrU16NotComp, false));
1545     uint32_t hashExpect = 0;
1546     for (uint32_t i = 0; i < lengthEcmaStrU16NotComp; i++) {
1547         hashExpect = hashExpect * 31 + arrayU16NotComp[i];
1548     }
1549     EXPECT_EQ(handleEcmaStrU16NotComp->GetHashcode(), hashExpect);
1550 }
1551 
1552 /*
1553  * @tc.name: GetHashcode_004
1554  * @tc.desc: Check whether the value returned through an EcmaString made by CreateEmptyString() calling GetHashcode
1555  * function is within expectations.
1556  * @tc.type: FUNC
1557  * @tc.require:
1558  */
HWTEST_F_L0(EcmaStringTest,GetHashcode_004)1559 HWTEST_F_L0(EcmaStringTest, GetHashcode_004)
1560 {
1561     // GetHashcode(). EcmaString made by CreateEmptyString().
1562     JSHandle<EcmaString> handleEcmaStrEmpty(thread, EcmaString::CreateEmptyString(ecmaVMPtr));
1563     EXPECT_EQ(handleEcmaStrEmpty->GetHashcode(), 0U);
1564 }
1565 
1566 /*
1567  * @tc.name: GetHashcode_005
1568  * @tc.desc: Check whether the value returned through an EcmaString made by CreateLineString(, true/false, ) calling
1569  * GetHashcode function is within expectations.
1570  * @tc.type: FUNC
1571  * @tc.require:
1572  */
HWTEST_F_L0(EcmaStringTest,GetHashcode_005)1573 HWTEST_F_L0(EcmaStringTest, GetHashcode_005)
1574 {
1575     // GetHashcode(). EcmaString made by CreateLineString().
1576     size_t sizeAlloc = 5;
1577     JSHandle<EcmaString> handleEcmaStrAllocComp(thread, EcmaString::CreateLineString(ecmaVMPtr, sizeAlloc, true));
1578     JSHandle<EcmaString> handleEcmaStrAllocNotComp(thread, EcmaString::CreateLineString(ecmaVMPtr, sizeAlloc, false));
1579     EXPECT_EQ(handleEcmaStrAllocComp->GetHashcode(), 0U);
1580     EXPECT_EQ(handleEcmaStrAllocNotComp->GetHashcode(), 0U);
1581 }
1582 
1583 /*
1584  * @tc.name: SetIsInternString
1585  * @tc.desc: Call SetIsInternString function, check whether the bool returned through calling IsInternString function
1586  * is within expectations.
1587  * @tc.type: FUNC
1588  * @tc.require:
1589  */
HWTEST_F_L0(EcmaStringTest,SetIsInternString)1590 HWTEST_F_L0(EcmaStringTest, SetIsInternString)
1591 {
1592     uint8_t arrayU8[] = {"abc"};
1593     uint32_t lengthEcmaStrU8 = sizeof(arrayU8) - 1;
1594     JSHandle<EcmaString> handleEcmaStrU8(thread,
1595         EcmaString::CreateFromUtf8(ecmaVMPtr, &arrayU8[0], lengthEcmaStrU8, true));
1596     EXPECT_FALSE(handleEcmaStrU8->IsInternString());
1597     handleEcmaStrU8->SetIsInternString();
1598     EXPECT_TRUE(handleEcmaStrU8->IsInternString());
1599 
1600     uint16_t arrayU16Comp[] = {97, 98, 99};
1601     uint32_t lengthEcmaStrU16Comp = sizeof(arrayU16Comp) / sizeof(arrayU16Comp[0]);
1602     JSHandle<EcmaString> handleEcmaStrU16Comp(thread,
1603         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16Comp[0], lengthEcmaStrU16Comp, true));
1604     EXPECT_FALSE(handleEcmaStrU16Comp->IsInternString());
1605     handleEcmaStrU16Comp->SetIsInternString();
1606     EXPECT_TRUE(handleEcmaStrU16Comp->IsInternString());
1607 
1608     uint16_t arrayU16NotComp[] = {97, 98, 99};
1609     uint32_t lengthEcmaStrU16NotComp = sizeof(arrayU16NotComp) / sizeof(arrayU16NotComp[0]);
1610     JSHandle<EcmaString> handleEcmaStrU16NotComp(thread,
1611         EcmaString::CreateFromUtf16(ecmaVMPtr, &arrayU16NotComp[0], lengthEcmaStrU16NotComp, true));
1612     EXPECT_FALSE(handleEcmaStrU16NotComp->IsInternString());
1613     handleEcmaStrU16NotComp->SetIsInternString();
1614     EXPECT_TRUE(handleEcmaStrU16NotComp->IsInternString());
1615 }
1616 
1617 /*
1618  * @tc.name: EqualToSplicedString
1619  * @tc.desc: Tests whether the source string is equal to the concatenated string.
1620  * is within expectations.
1621  * @tc.type: FUNC
1622  * @tc.require:
1623  */
HWTEST_F_L0(EcmaStringTest,EqualToSplicedString)1624 HWTEST_F_L0(EcmaStringTest, EqualToSplicedString)
1625 {
1626     ObjectFactory* factory = ecmaVMPtr->GetFactory();
1627     {
1628         JSHandle<EcmaString> sourceString = factory->NewFromUtf8("Start开始");
1629         JSHandle<EcmaString> firstString = factory->NewFromASCII("Start");
1630         JSHandle<EcmaString> secondString = factory->NewFromUtf8("开始");
1631         EXPECT_TRUE(sourceString->IsUtf16());
1632         EXPECT_TRUE(firstString->IsUtf8());
1633         EXPECT_TRUE(secondString->IsUtf16());
1634         bool result = sourceString->EqualToSplicedString(*firstString, *secondString);
1635         EXPECT_TRUE(result);
1636     }
1637 
1638     {
1639         JSHandle<EcmaString> sourceString = factory->NewFromUtf8("Start开始");
1640         JSHandle<EcmaString> firstString = factory->NewFromASCII("Start");
1641         JSHandle<EcmaString> secondString = factory->NewFromASCII("start");
1642         EXPECT_TRUE(sourceString->IsUtf16());
1643         EXPECT_TRUE(firstString->IsUtf8());
1644         EXPECT_TRUE(secondString->IsUtf8());
1645         bool result = sourceString->EqualToSplicedString(*firstString, *secondString);
1646         EXPECT_TRUE(!result);
1647     }
1648 
1649     {
1650         JSHandle<EcmaString> sourceString = factory->NewFromUtf8("Start开始");
1651         JSHandle<EcmaString> firstString = factory->NewFromUtf8("Startå¼€");
1652         JSHandle<EcmaString> secondString = factory->NewFromUtf8("始");
1653         EXPECT_TRUE(sourceString->IsUtf16());
1654         EXPECT_TRUE(firstString->IsUtf16());
1655         EXPECT_TRUE(secondString->IsUtf16());
1656         bool result = sourceString->EqualToSplicedString(*firstString, *secondString);
1657         EXPECT_TRUE(result);
1658     }
1659 
1660     {
1661         JSHandle<EcmaString> sourceString = factory->NewFromUtf8("Startstart");
1662         JSHandle<EcmaString> firstString = factory->NewFromASCII("Start");
1663         JSHandle<EcmaString> secondString = factory->NewFromASCII("start");
1664         EXPECT_TRUE(sourceString->IsUtf8());
1665         EXPECT_TRUE(firstString->IsUtf8());
1666         EXPECT_TRUE(secondString->IsUtf8());
1667         bool result = sourceString->EqualToSplicedString(*firstString, *secondString);
1668         EXPECT_TRUE(result);
1669     }
1670 
1671     {
1672         JSHandle<EcmaString> sourceString = factory->NewFromUtf8("Startstart");
1673         JSHandle<EcmaString> firstString = factory->NewFromASCII("Start");
1674         JSHandle<EcmaString> secondString = factory->NewFromUtf8("开始");
1675         EXPECT_TRUE(sourceString->IsUtf8());
1676         EXPECT_TRUE(firstString->IsUtf8());
1677         EXPECT_TRUE(secondString->IsUtf16());
1678         bool result = sourceString->EqualToSplicedString(*firstString, *secondString);
1679         EXPECT_TRUE(!result);
1680     }
1681 
1682     {
1683         JSHandle<EcmaString> sourceString = factory->NewFromUtf8("Startstat");
1684         JSHandle<EcmaString> firstString = factory->NewFromASCII("Start");
1685         JSHandle<EcmaString> secondString = factory->NewFromASCII("start");
1686         EXPECT_TRUE(sourceString->IsUtf8());
1687         EXPECT_TRUE(firstString->IsUtf8());
1688         EXPECT_TRUE(secondString->IsUtf8());
1689         bool result = sourceString->EqualToSplicedString(*firstString, *secondString);
1690         EXPECT_TRUE(!result);
1691     }
1692 
1693     {
1694         JSHandle<EcmaString> sourceString = factory->NewFromUtf8("Start开始");
1695         JSHandle<EcmaString> firstString = factory->NewFromUtf8("Statå¼€");
1696         JSHandle<EcmaString> secondString = factory->NewFromUtf8("始");
1697         EXPECT_TRUE(sourceString->IsUtf16());
1698         EXPECT_TRUE(firstString->IsUtf16());
1699         EXPECT_TRUE(secondString->IsUtf16());
1700         bool result = sourceString->EqualToSplicedString(*firstString, *secondString);
1701         EXPECT_TRUE(!result);
1702     }
1703 
1704     {
1705         JSHandle<EcmaString> sourceString = factory->NewFromUtf8("Start开始");
1706         JSHandle<EcmaString> firstString = factory->NewFromASCII("Stat");
1707         JSHandle<EcmaString> secondString = factory->NewFromUtf8("开始");
1708         EXPECT_TRUE(sourceString->IsUtf16());
1709         EXPECT_TRUE(firstString->IsUtf8());
1710         EXPECT_TRUE(secondString->IsUtf16());
1711         bool result = sourceString->EqualToSplicedString(*firstString, *secondString);
1712         EXPECT_TRUE(!result);
1713     }
1714 }
1715 
1716 /*
1717  * @tc.name: ConvertUtf8ToLowerOrUpper
1718  * @tc.desc: Check whether the EcmaString created through calling ConvertUtf8ToLowerOrUpper is within expectations.
1719  * is within expectations.
1720  * @tc.type: FUNC
1721  * @tc.require:
1722  */
HWTEST_F_L0(EcmaStringTest,ConvertUtf8ToLowerOrUpper)1723 HWTEST_F_L0(EcmaStringTest, ConvertUtf8ToLowerOrUpper)
1724 {
1725     ObjectFactory* factory = ecmaVMPtr->GetFactory();
1726     JSHandle<EcmaString> lowerStr = factory->NewFromASCII("aaabbbcccddd");
1727     JSHandle<EcmaString> upperStr = factory->NewFromASCII("AAABBBCCCDDD");
1728     JSHandle<EcmaString> testStr1 = factory->NewFromASCII("aaaBBBcccDDD");
1729     JSHandle<EcmaString> testStr2 = factory->NewFromASCII("AAAbbbcccDDD");
1730     {
1731         auto testStrFlat = JSHandle<EcmaString>(ecmaVMPtr->GetJSThread(), Flatten(ecmaVMPtr, testStr1));
1732         JSHandle<EcmaString> testEcmaString(thread, ConvertUtf8ToLowerOrUpper(ecmaVMPtr, testStrFlat, true));
1733         EXPECT_TRUE(JSTaggedValue::SameValue(lowerStr.GetTaggedValue(), testEcmaString.GetTaggedValue()));
1734         EXPECT_EQ(lowerStr->GetLength(), testEcmaString->GetLength());
1735         EXPECT_TRUE(testEcmaString->IsUtf8());
1736         EXPECT_FALSE(testEcmaString->IsUtf16());
1737     }
1738 
1739     {
1740         auto testStrFlat = JSHandle<EcmaString>(ecmaVMPtr->GetJSThread(), Flatten(ecmaVMPtr, testStr1));
1741         JSHandle<EcmaString> testEcmaString(thread, ConvertUtf8ToLowerOrUpper(ecmaVMPtr, testStrFlat, false));
1742         EXPECT_TRUE(JSTaggedValue::SameValue(upperStr.GetTaggedValue(), testEcmaString.GetTaggedValue()));
1743         EXPECT_EQ(upperStr->GetLength(), testEcmaString->GetLength());
1744         EXPECT_TRUE(testEcmaString->IsUtf8());
1745         EXPECT_FALSE(testEcmaString->IsUtf16());
1746     }
1747 
1748     {
1749         auto testStrFlat = JSHandle<EcmaString>(ecmaVMPtr->GetJSThread(), Flatten(ecmaVMPtr, testStr2));
1750         JSHandle<EcmaString> testEcmaString(thread, ConvertUtf8ToLowerOrUpper(ecmaVMPtr, testStrFlat, true));
1751         EXPECT_TRUE(JSTaggedValue::SameValue(lowerStr.GetTaggedValue(), testEcmaString.GetTaggedValue()));
1752         EXPECT_EQ(lowerStr->GetLength(), testEcmaString->GetLength());
1753         EXPECT_TRUE(testEcmaString->IsUtf8());
1754         EXPECT_FALSE(testEcmaString->IsUtf16());
1755     }
1756 
1757     {
1758         auto testStrFlat = JSHandle<EcmaString>(ecmaVMPtr->GetJSThread(), Flatten(ecmaVMPtr, testStr2));
1759         JSHandle<EcmaString> testEcmaString(thread, ConvertUtf8ToLowerOrUpper(ecmaVMPtr, testStrFlat, false));
1760         EXPECT_TRUE(JSTaggedValue::SameValue(upperStr.GetTaggedValue(), testEcmaString.GetTaggedValue()));
1761         EXPECT_EQ(upperStr->GetLength(), testEcmaString->GetLength());
1762         EXPECT_TRUE(testEcmaString->IsUtf8());
1763         EXPECT_FALSE(testEcmaString->IsUtf16());
1764     }
1765 }
1766 
1767 /*
1768  * @tc.name: TryToLower
1769  * @tc.desc: Check whether the EcmaString created through calling TryToLower function is within expectations.
1770  * is within expectations.
1771  * @tc.type: FUNC
1772  * @tc.require:upperStr
1773  */
HWTEST_F_L0(EcmaStringTest,TryToLower)1774 HWTEST_F_L0(EcmaStringTest, TryToLower)
1775 {
1776     ObjectFactory* factory = ecmaVMPtr->GetFactory();
1777     JSHandle<EcmaString> lowerStr = factory->NewFromASCII("aaabbbcccddd");
1778     JSHandle<EcmaString> upperStr = factory->NewFromASCII("AAABBBCCCDDD");
1779     JSHandle<EcmaString> testStr1 = factory->NewFromASCII("aaaBBBcccDDD");
1780     JSHandle<EcmaString> testStr2 = factory->NewFromASCII("AAAbbbcccDDD");
1781     {
1782         JSHandle<EcmaString> lowerEcmaString(thread, TryToLower(ecmaVMPtr, lowerStr));
1783         EXPECT_TRUE(JSTaggedValue::SameValue(lowerStr.GetTaggedValue(), lowerEcmaString.GetTaggedValue()));
1784         EXPECT_EQ(lowerStr->GetLength(), lowerEcmaString->GetLength());
1785         EXPECT_TRUE(lowerEcmaString->IsUtf8());
1786         EXPECT_FALSE(lowerEcmaString->IsUtf16());
1787     }
1788 
1789     {
1790         JSHandle<EcmaString> lowerEcmaString(thread, TryToLower(ecmaVMPtr, upperStr));
1791         EXPECT_TRUE(JSTaggedValue::SameValue(lowerStr.GetTaggedValue(), lowerEcmaString.GetTaggedValue()));
1792         EXPECT_EQ(lowerStr->GetLength(), lowerEcmaString->GetLength());
1793         EXPECT_TRUE(lowerEcmaString->IsUtf8());
1794         EXPECT_FALSE(lowerEcmaString->IsUtf16());
1795     }
1796 
1797     {
1798         JSHandle<EcmaString> testEcmaString(thread, TryToLower(ecmaVMPtr, testStr1));
1799         EXPECT_TRUE(JSTaggedValue::SameValue(lowerStr.GetTaggedValue(), testEcmaString.GetTaggedValue()));
1800         EXPECT_EQ(lowerStr->GetLength(), testEcmaString->GetLength());
1801         EXPECT_TRUE(testEcmaString->IsUtf8());
1802         EXPECT_FALSE(testEcmaString->IsUtf16());
1803     }
1804 
1805     {
1806         JSHandle<EcmaString> testEcmaString(thread, TryToLower(ecmaVMPtr, testStr2));
1807         EXPECT_TRUE(JSTaggedValue::SameValue(lowerStr.GetTaggedValue(), testEcmaString.GetTaggedValue()));
1808         EXPECT_EQ(lowerStr->GetLength(), testEcmaString->GetLength());
1809         EXPECT_TRUE(testEcmaString->IsUtf8());
1810         EXPECT_FALSE(testEcmaString->IsUtf16());
1811     }
1812 }
1813 }  // namespace panda::test