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 <gtest/gtest.h>
17 #include "ohos/aafwk/base/light_refbase.h"
18 #include "ohos/aafwk/base/array_wrapper.h"
19 #include "ohos/aafwk/base/base_object.h"
20 #include "ohos/aafwk/base/bool_wrapper.h"
21 #include "ohos/aafwk/base/zchar_wrapper.h"
22 #include "ohos/aafwk/base/byte_wrapper.h"
23 #include "ohos/aafwk/base/short_wrapper.h"
24 #include "ohos/aafwk/base/int_wrapper.h"
25 #include "ohos/aafwk/base/long_wrapper.h"
26 #include "ohos/aafwk/base/float_wrapper.h"
27 #include "ohos/aafwk/base/double_wrapper.h"
28 #include "ohos/aafwk/base/string_wrapper.h"
29 #include "refbase.h"
30
31 using namespace OHOS;
32 using namespace OHOS::AAFwk;
33 using testing::ext::TestSize;
34
35 namespace OHOS {
36 namespace AAFwk {
37 class AAFwkBaseTest : public testing::Test {
38 public:
39 static void SetUpTestCase(void);
40 static void TearDownTestCase(void);
41 void SetUp();
42 void TearDown();
43 };
44
SetUpTestCase(void)45 void AAFwkBaseTest::SetUpTestCase(void)
46 {}
47
TearDownTestCase(void)48 void AAFwkBaseTest::TearDownTestCase(void)
49 {}
50
SetUp(void)51 void AAFwkBaseTest::SetUp(void)
52 {}
53
TearDown(void)54 void AAFwkBaseTest::TearDown(void)
55 {}
56
57 class LightRefCountBaseTestClass : public LightRefCountBase {
58 public:
LightRefCountBaseTestClass()59 LightRefCountBaseTestClass()
60 {
61 gDestructorCalled_ = false;
62 }
63
~LightRefCountBaseTestClass()64 virtual ~LightRefCountBaseTestClass()
65 {
66 gDestructorCalled_ = true;
67 }
68
69 public:
70 static bool gDestructorCalled_;
71 };
72
73 bool LightRefCountBaseTestClass::gDestructorCalled_ = false;
74
75 class RefBaseTestClass : public RefBase {
76 public:
RefBaseTestClass()77 RefBaseTestClass()
78 {
79 gDestructorCalled_ = false;
80 }
81
~RefBaseTestClass()82 virtual ~RefBaseTestClass()
83 {
84 gDestructorCalled_ = true;
85 }
86
87 public:
88 static bool gDestructorCalled_;
89 };
90
91 bool RefBaseTestClass::gDestructorCalled_ = false;
92
93 CLASS(ObjectTestClass, 5afc4756 - 8f3c - 4d80 - a88b - 54521890beca)
94 {
95 public:
96 ObjectTestClass(
97 /* [in] */ int type)
98 : type_(type)
99 {
100 gDestructorCalled_ = false;
101 }
102
103 ~ObjectTestClass()
104 {
105 gDestructorCalled_ = true;
106 }
107
108 OBJECT_DECL();
109
110 int GetHashCode() override
111 {
112 return 19;
113 }
114
115 bool Equals(
116 /* [in] */
117 IObject * other) override
118 {
119 if (other == nullptr) {
120 return false;
121 }
122
123 if (other->GetClassID() == CID_ObjectTestClass) {
124 return type_ == static_cast<ObjectTestClass *>(other)->type_;
125 }
126
127 return false;
128 }
129
130 std::string ToString() override
131 {
132 return std::string("object[") + std::to_string(reinterpret_cast<uintptr_t>(this)) + std::string("]type_=") +
133 std::to_string(type_) + std::string(";");
134 }
135
136 public:
137 static bool gDestructorCalled_;
138
139 private:
140 int type_;
141 };
142
143 const ClassID CID_ObjectTestClass = {
144 0x5afc4756, 0x8f3c, 0x4d80, 0xa88b, {
145 0x5, 0x4, 0x5, 0x2, 0x1, 0x8, 0x9, 0x0, 0xb, 0xe, 0xc, 0xa
146 }
147 };
148
149 bool ObjectTestClass::gDestructorCalled_ = false;
150
151 OBJECT_IMPL(ObjectTestClass);
152
153 /*
154 * Feature: LightRefCountBase
155 * Function: IncStrongRef, DecStrongRef and GetRefCount
156 * SubFunction: NA
157 * FunctionPoints: IncStrongRef, DecStrongRef and GetRefCount
158 * EnvConditions: NA
159 * CaseDescription: Verify IncStrongRef, DecStrongRef and GetRefCount methods of RefBase.
160 */
161 HWTEST_F(AAFwkBaseTest, LightRefCountBase_test_001, TestSize.Level1)
162 {
163 sptr<LightRefCountBaseTestClass> testObject = new LightRefCountBaseTestClass();
164 EXPECT_FALSE(LightRefCountBaseTestClass::gDestructorCalled_);
165 EXPECT_EQ(testObject->GetRefCount(), 1);
166 testObject = nullptr;
167 EXPECT_TRUE(LightRefCountBaseTestClass::gDestructorCalled_);
168 }
169
170 /*
171 * Feature: RefBase
172 * Function: IncStrongRef and DecStrongRef
173 * SubFunction: NA
174 * FunctionPoints: IncStrongRef and DecStrongRef
175 * EnvConditions: NA
176 * CaseDescription: Verify IncStrongRef and DecStrongRef methods of RefBase.
177 */
178 HWTEST_F(AAFwkBaseTest, RefBase_test_001, TestSize.Level1)
179 {
180 sptr<RefBaseTestClass> testObject = new RefBaseTestClass();
181 EXPECT_FALSE(RefBaseTestClass::gDestructorCalled_);
182 testObject = nullptr;
183 EXPECT_TRUE(RefBaseTestClass::gDestructorCalled_);
184 }
185
186 /*
187 * Feature: Object
188 * Function: GetInterfaceID
189 * SubFunction: NA
190 * FunctionPoints: GetInterfaceID
191 * EnvConditions: NA
192 * CaseDescription: Verify the GetInterfaceID method of subclass.
193 */
194 HWTEST_F(AAFwkBaseTest, object_test_001, TestSize.Level1)
195 {
196 sptr<ObjectTestClass> testObject = new ObjectTestClass(999);
197 sptr<IObject> object = static_cast<IObject *>(testObject.GetRefPtr());
198 EXPECT_EQ(g_IID_IObject, object->GetInterfaceID(object));
199 }
200
201 /*
202 * Feature: Object
203 * Function: GetClassID
204 * SubFunction: NA
205 * FunctionPoints: GetClassID
206 * EnvConditions: NA
207 * CaseDescription: Verify the override GetClassID method of subclass.
208 */
209 HWTEST_F(AAFwkBaseTest, object_test_002, TestSize.Level1)
210 {
211 sptr<ObjectTestClass> testObject = new ObjectTestClass(999);
212 EXPECT_EQ(CID_ObjectTestClass, testObject->GetClassID());
213 testObject = nullptr;
214 EXPECT_TRUE(ObjectTestClass::gDestructorCalled_);
215 }
216
217 /*
218 * Feature: Object
219 * Function: GetHashCode
220 * SubFunction: NA
221 * FunctionPoints: GetHashCode
222 * EnvConditions: NA
223 * CaseDescription: Verify the override GetHashCode method of subclass.
224 */
225 HWTEST_F(AAFwkBaseTest, object_test_003, TestSize.Level1)
226 {
227 sptr<ObjectTestClass> testObject = new ObjectTestClass(999);
228 EXPECT_EQ(19, testObject->GetHashCode());
229 testObject = nullptr;
230 EXPECT_TRUE(ObjectTestClass::gDestructorCalled_);
231 }
232
233 /*
234 * Feature: Object
235 * Function: Equal
236 * SubFunction: NA
237 * FunctionPoints: Equal
238 * EnvConditions: NA
239 * CaseDescription: Verify the override Equal method of subclass.
240 */
241 HWTEST_F(AAFwkBaseTest, object_test_004, TestSize.Level1)
242 {
243 sptr<ObjectTestClass> testObject1 = new ObjectTestClass(999);
244 sptr<ObjectTestClass> testObject2 = new ObjectTestClass(9999);
245 sptr<ObjectTestClass> testObject3 = new ObjectTestClass(999);
246 EXPECT_FALSE(testObject1->Equals(testObject2));
247 EXPECT_TRUE(testObject1->Equals(testObject3));
248 }
249
250 /*
251 * Feature: Object
252 * Function: ToString
253 * SubFunction: NA
254 * FunctionPoints: ToString
255 * EnvConditions: NA
256 * CaseDescription: Verify the override ToString method of subclass.
257 */
258 HWTEST_F(AAFwkBaseTest, object_test_005, TestSize.Level1)
259 {
260 sptr<ObjectTestClass> testObject1 = new ObjectTestClass(999);
261 std::string objectStr = testObject1->ToString();
262 EXPECT_TRUE(objectStr.find("type_=999") != std::string::npos);
263 }
264
265 /*
266 * Feature: Object
267 * Function: GetWeakReference
268 * SubFunction: NA
269 * FunctionPoints: GetWeakReference
270 * EnvConditions: NA
271 * CaseDescription: Verify GetWeakReference method of subclass.
272 */
273 HWTEST_F(AAFwkBaseTest, object_test_006, TestSize.Level1)
274 {
275 sptr<ObjectTestClass> testObject1 = new ObjectTestClass(999);
276 EXPECT_FALSE(ObjectTestClass::gDestructorCalled_);
277 sptr<IWeakReference> weakRef;
278 testObject1->GetWeakReference(weakRef);
279 EXPECT_TRUE(weakRef != nullptr);
280 sptr<IObject> object;
281 weakRef->Resolve(g_IID_IObject, reinterpret_cast<IInterface **>(&object));
282 EXPECT_TRUE(object != nullptr);
283 EXPECT_EQ(static_cast<ObjectTestClass *>(object.GetRefPtr())->GetHashCode(), 19);
284 testObject1 = nullptr;
285 object = nullptr;
286 EXPECT_TRUE(ObjectTestClass::gDestructorCalled_);
287 weakRef->Resolve(g_IID_IObject, reinterpret_cast<IInterface **>(&object));
288 EXPECT_TRUE(object == nullptr);
289 }
290
291 /*
292 * Feature: wptr
293 * Function: wptr
294 * SubFunction: NA
295 * FunctionPoints: wptr
296 * EnvConditions: NA
297 * CaseDescription: Verify wptr.
298 */
299 HWTEST_F(AAFwkBaseTest, object_test_007, TestSize.Level1)
300 {
301 sptr<ObjectTestClass> testObject1 = new ObjectTestClass(999);
302 EXPECT_FALSE(ObjectTestClass::gDestructorCalled_);
303 wptr<ObjectTestClass> weakObject(testObject1);
304 testObject1 = nullptr;
305 EXPECT_TRUE(ObjectTestClass::gDestructorCalled_);
306 EXPECT_TRUE(weakObject.promote() == nullptr);
307 }
308
309 /*
310 * Feature: Boolean
311 * Function: GetValue
312 * SubFunction: NA
313 * FunctionPoints: GetValue
314 * EnvConditions: NA
315 * CaseDescription: Verify GetValue method of Boolean.
316 */
317 HWTEST_F(AAFwkBaseTest, boolean_test_001, TestSize.Level1)
318 {
319 sptr<Boolean> boolean = new Boolean(true);
320 bool value = false;
321 boolean->GetValue(&value);
322 EXPECT_TRUE(value);
323 boolean = new Boolean(false);
324 boolean->GetValue(&value);
325 EXPECT_FALSE(value);
326 }
327
328 /*
329 * Feature: Boolean
330 * Function: Box and Unbox
331 * SubFunction: NA
332 * FunctionPoints: Box and Unbox
333 * EnvConditions: NA
334 * CaseDescription: Verify Box and Unbox method of Boolean.
335 */
336 HWTEST_F(AAFwkBaseTest, boolean_test_002, TestSize.Level1)
337 {
338 sptr<IBoolean> boolean = Boolean::Box(true);
339 EXPECT_TRUE(Boolean::Unbox(boolean));
340 boolean = Boolean::Box(false);
341 EXPECT_FALSE(Boolean::Unbox(boolean));
342 }
343
344 /*
345 * Feature: Boolean
346 * Function: Parse
347 * SubFunction: NA
348 * FunctionPoints: Parse
349 * EnvConditions: NA
350 * CaseDescription: Verify Parse method of Boolean.
351 */
352 HWTEST_F(AAFwkBaseTest, boolean_test_003, TestSize.Level1)
353 {
354 sptr<IBoolean> boolean = Boolean::Parse("true");
355 EXPECT_TRUE(Boolean::Unbox(boolean));
356 boolean = Boolean::Parse("false");
357 EXPECT_FALSE(Boolean::Unbox(boolean));
358 }
359
360 /*
361 * Feature: Boolean
362 * Function: Equals
363 * SubFunction: NA
364 * FunctionPoints: Equals
365 * EnvConditions: NA
366 * CaseDescription: Verify Equals method of Boolean.
367 */
368 HWTEST_F(AAFwkBaseTest, boolean_test_004, TestSize.Level1)
369 {
370 sptr<Boolean> boolean1 = new Boolean(true);
371 sptr<Boolean> boolean2 = new Boolean(false);
372 sptr<Boolean> boolean3 = new Boolean(true);
373 EXPECT_FALSE(boolean1->Equals(boolean2));
374 EXPECT_TRUE(boolean1->Equals(boolean3));
375 }
376
377 /*
378 * Feature: Boolean
379 * Function: ToString
380 * SubFunction: NA
381 * FunctionPoints: ToString
382 * EnvConditions: NA
383 * CaseDescription: Verify ToString method of Boolean.
384 */
385 HWTEST_F(AAFwkBaseTest, boolean_test_005, TestSize.Level1)
386 {
387 EXPECT_EQ(Object::ToString(Boolean::Box(true)), "true");
388 EXPECT_EQ(Object::ToString(Boolean::Box(false)), "false");
389 }
390
391 /*
392 * Feature: Char
393 * Function: GetValue
394 * SubFunction: NA
395 * FunctionPoints: GetValue
396 * EnvConditions: NA
397 * CaseDescription: Verify GetValue method of Char.
398 */
399 HWTEST_F(AAFwkBaseTest, char_test_001, TestSize.Level1)
400 {
401 sptr<Char> charObj = new Char(U'中');
402 zchar value;
403 charObj->GetValue(&value);
404 EXPECT_EQ(value, U'中');
405 }
406
407 /*
408 * Feature: Char
409 * Function: Box and Unbox
410 * SubFunction: NA
411 * FunctionPoints: Box and Unbox
412 * EnvConditions: NA
413 * CaseDescription: Verify Box and Unbox method of Char.
414 */
415 HWTEST_F(AAFwkBaseTest, char_test_002, TestSize.Level1)
416 {
417 sptr<IChar> charObj = Char::Box(U'天');
418 EXPECT_EQ(Char::Unbox(charObj), U'天');
419 }
420
421 /*
422 * Feature: Char
423 * Function: Parse
424 * SubFunction: NA
425 * FunctionPoints: Parse
426 * EnvConditions: NA
427 * CaseDescription: Verify Parse method of Char.
428 */
429 HWTEST_F(AAFwkBaseTest, char_test_003, TestSize.Level1)
430 {
431 sptr<IChar> charObj = Char::Parse("气");
432 EXPECT_EQ(Char::Unbox(charObj), U'气');
433 }
434
435 /*
436 * Feature: Char
437 * Function: Equals
438 * SubFunction: NA
439 * FunctionPoints: Equals
440 * EnvConditions: NA
441 * CaseDescription: Verify Equals method of Char.
442 */
443 HWTEST_F(AAFwkBaseTest, char_test_004, TestSize.Level1)
444 {
445 sptr<Char> charObj1 = new Char(U'H');
446 sptr<Char> charObj2 = new Char('I');
447 sptr<Char> charObj3 = new Char(U'H');
448 EXPECT_FALSE(charObj1->Equals(charObj2));
449 EXPECT_TRUE(charObj1->Equals(charObj3));
450 }
451
452 /*
453 * Feature: Char
454 * Function: ToString
455 * SubFunction: NA
456 * FunctionPoints: ToString
457 * EnvConditions: NA
458 * CaseDescription: Verify ToString method of Char.
459 */
460 HWTEST_F(AAFwkBaseTest, char_test_005, TestSize.Level1)
461 {
462 EXPECT_EQ(Object::ToString(Char::Box(U'好')), "好");
463 }
464
465 /*
466 * Feature: Char
467 * Function: GetChar
468 * SubFunction: NA
469 * FunctionPoints: GetChar
470 * EnvConditions: NA
471 * CaseDescription: Verify GetChar method of Char.
472 */
473 HWTEST_F(AAFwkBaseTest, char_test_006, TestSize.Level1)
474 {
475 std::string str = "今天气温真不错有23摄氏度呢!";
476 EXPECT_EQ(Char::GetChar(str, 0), U'今');
477 EXPECT_EQ(Char::GetChar(str, 1), U'天');
478 EXPECT_EQ(Char::GetChar(str, 2), U'气');
479 EXPECT_EQ(Char::GetChar(str, 3), U'温');
480 EXPECT_EQ(Char::GetChar(str, 4), U'真');
481 EXPECT_EQ(Char::GetChar(str, 5), U'不');
482 EXPECT_EQ(Char::GetChar(str, 6), U'错');
483 EXPECT_EQ(Char::GetChar(str, 7), U'有');
484 EXPECT_EQ(Char::GetChar(str, 8), '2');
485 EXPECT_EQ(Char::GetChar(str, 9), '3');
486 EXPECT_EQ(Char::GetChar(str, 10), U'摄');
487 EXPECT_EQ(Char::GetChar(str, 11), U'氏');
488 EXPECT_EQ(Char::GetChar(str, 12), U'度');
489 EXPECT_EQ(Char::GetChar(str, 13), U'呢');
490 EXPECT_EQ(Char::GetChar(str, 14), U'!');
491 }
492
493 /*
494 * Feature: Byte
495 * Function: GetValue
496 * SubFunction: NA
497 * FunctionPoints: GetValue
498 * EnvConditions: NA
499 * CaseDescription: Verify GetValue method of Byte.
500 */
501 HWTEST_F(AAFwkBaseTest, byte_test_001, TestSize.Level1)
502 {
503 sptr<Byte> byteObj = new Byte(129);
504 byte value;
505 byteObj->GetValue(&value);
506 EXPECT_EQ(value, 129);
507 }
508
509 /*
510 * Feature: Byte
511 * Function: Box and Unbox
512 * SubFunction: NA
513 * FunctionPoints: Box and Unbox
514 * EnvConditions: NA
515 * CaseDescription: Verify Box and Unbox method of Byte.
516 */
517 HWTEST_F(AAFwkBaseTest, byte_test_002, TestSize.Level1)
518 {
519 sptr<IByte> byteObj = Byte::Box(129);
520 EXPECT_EQ(Byte::Unbox(byteObj), 129);
521 }
522
523 /*
524 * Feature: Byte
525 * Function: Parse
526 * SubFunction: NA
527 * FunctionPoints: Parse
528 * EnvConditions: NA
529 * CaseDescription: Verify Parse method of Byte.
530 */
531 HWTEST_F(AAFwkBaseTest, byte_test_003, TestSize.Level1)
532 {
533 sptr<IByte> byteObj = Byte::Parse("129");
534 EXPECT_EQ(Byte::Unbox(byteObj), 129);
535 }
536
537 /*
538 * Feature: Byte
539 * Function: Equals
540 * SubFunction: NA
541 * FunctionPoints: Equals
542 * EnvConditions: NA
543 * CaseDescription: Verify Equals method of Byte.
544 */
545 HWTEST_F(AAFwkBaseTest, byte_test_004, TestSize.Level1)
546 {
547 sptr<Byte> byteObj1 = new Byte(129);
548 sptr<Byte> byteObj2 = new Byte(130);
549 sptr<Byte> byteObj3 = new Byte(129);
550 EXPECT_FALSE(byteObj1->Equals(byteObj2));
551 EXPECT_TRUE(byteObj1->Equals(byteObj3));
552 }
553
554 /*
555 * Feature: Byte
556 * Function: ToString
557 * SubFunction: NA
558 * FunctionPoints: ToString
559 * EnvConditions: NA
560 * CaseDescription: Verify ToString method of Byte.
561 */
562 HWTEST_F(AAFwkBaseTest, byte_test_005, TestSize.Level1)
563 {
564 EXPECT_EQ(Object::ToString(Byte::Box(129)), "129");
565 }
566
567 /*
568 * Feature: Short
569 * Function: GetValue
570 * SubFunction: NA
571 * FunctionPoints: GetValue
572 * EnvConditions: NA
573 * CaseDescription: Verify GetValue method of Short.
574 */
575 HWTEST_F(AAFwkBaseTest, short_test_001, TestSize.Level1)
576 {
577 sptr<Short> shortObj = new Short(32767);
578 short value;
579 shortObj->GetValue(&value);
580 EXPECT_EQ(value, 32767);
581 }
582
583 /*
584 * Feature: Short
585 * Function: Box and Unbox
586 * SubFunction: NA
587 * FunctionPoints: Box and Unbox
588 * EnvConditions: NA
589 * CaseDescription: Verify Box and Unbox method of Short.
590 */
591 HWTEST_F(AAFwkBaseTest, short_test_002, TestSize.Level1)
592 {
593 sptr<IShort> shortObj = Short::Box(32767);
594 EXPECT_EQ(Short::Unbox(shortObj), 32767);
595 }
596
597 /*
598 * Feature: Short
599 * Function: Parse
600 * SubFunction: NA
601 * FunctionPoints: Parse
602 * EnvConditions: NA
603 * CaseDescription: Verify Parse method of Short.
604 */
605 HWTEST_F(AAFwkBaseTest, short_test_003, TestSize.Level1)
606 {
607 sptr<IShort> shortObj = Short::Parse("32767");
608 EXPECT_EQ(Short::Unbox(shortObj), 32767);
609 }
610
611 /*
612 * Feature: Short
613 * Function: Equals
614 * SubFunction: NA
615 * FunctionPoints: Equals
616 * EnvConditions: NA
617 * CaseDescription: Verify Equals method of Short.
618 */
619 HWTEST_F(AAFwkBaseTest, short_test_004, TestSize.Level1)
620 {
621 sptr<Short> shortObj1 = new Short(32767);
622 sptr<Short> shortObj2 = new Short(-32768);
623 sptr<Short> shortObj3 = new Short(32767);
624 EXPECT_FALSE(shortObj1->Equals(shortObj2));
625 EXPECT_TRUE(shortObj1->Equals(shortObj3));
626 }
627
628 /*
629 * Feature: Short
630 * Function: ToString
631 * SubFunction: NA
632 * FunctionPoints: ToString
633 * EnvConditions: NA
634 * CaseDescription: Verify ToString method of Short.
635 */
636 HWTEST_F(AAFwkBaseTest, short_test_005, TestSize.Level1)
637 {
638 EXPECT_EQ(Object::ToString(Short::Box(32767)), "32767");
639 }
640
641 /*
642 * Feature: Integer
643 * Function: GetValue
644 * SubFunction: NA
645 * FunctionPoints: GetValue
646 * EnvConditions: NA
647 * CaseDescription: Verify GetValue method of Integer.
648 */
649 HWTEST_F(AAFwkBaseTest, integer_test_001, TestSize.Level1)
650 {
651 sptr<Integer> intObj = new Integer(2147483647);
652 int value;
653 intObj->GetValue(&value);
654 EXPECT_EQ(value, 2147483647);
655 }
656
657 /*
658 * Feature: Integer
659 * Function: Box and Unbox
660 * SubFunction: NA
661 * FunctionPoints: Box and Unbox
662 * EnvConditions: NA
663 * CaseDescription: Verify Box and Unbox method of Integer.
664 */
665 HWTEST_F(AAFwkBaseTest, integer_test_002, TestSize.Level1)
666 {
667 sptr<IInteger> intObj = Integer::Box(2147483647);
668 EXPECT_EQ(Integer::Unbox(intObj), 2147483647);
669 }
670
671 /*
672 * Feature: Integer
673 * Function: Parse
674 * SubFunction: NA
675 * FunctionPoints: Parse
676 * EnvConditions: NA
677 * CaseDescription: Verify Parse method of Integer.
678 */
679 HWTEST_F(AAFwkBaseTest, integer_test_003, TestSize.Level1)
680 {
681 sptr<IInteger> intObj = Integer::Parse("-1");
682 EXPECT_EQ(Integer::Unbox(intObj), -1);
683 }
684
685 /*
686 * Feature: Integer
687 * Function: Equals
688 * SubFunction: NA
689 * FunctionPoints: Equals
690 * EnvConditions: NA
691 * CaseDescription: Verify Equals method of Integer.
692 */
693 HWTEST_F(AAFwkBaseTest, integer_test_004, TestSize.Level1)
694 {
695 sptr<Integer> intObj1 = new Integer(2147483647);
696 sptr<Integer> intObj2 = new Integer(-2147483648);
697 sptr<Integer> intObj3 = new Integer(2147483647);
698 EXPECT_FALSE(intObj1->Equals(intObj2));
699 EXPECT_TRUE(intObj1->Equals(intObj3));
700 }
701
702 /*
703 * Feature: Integer
704 * Function: ToString
705 * SubFunction: NA
706 * FunctionPoints: ToString
707 * EnvConditions: NA
708 * CaseDescription: Verify ToString method of Integer.
709 */
710 HWTEST_F(AAFwkBaseTest, integer_test_005, TestSize.Level1)
711 {
712 EXPECT_EQ(Object::ToString(Integer::Box(-2147483648)), "-2147483648");
713 }
714
715 /*
716 * Feature: Long
717 * Function: GetValue
718 * SubFunction: NA
719 * FunctionPoints: GetValue
720 * EnvConditions: NA
721 * CaseDescription: Verify GetValue method of Long.
722 */
723 HWTEST_F(AAFwkBaseTest, long_test_001, TestSize.Level1)
724 {
725 sptr<Long> longObj = new Long(2147483647L);
726 long value;
727 longObj->GetValue(&value);
728 EXPECT_EQ(value, 2147483647L);
729 }
730
731 /*
732 * Feature: Long
733 * Function: Box and Unbox
734 * SubFunction: NA
735 * FunctionPoints: Box and Unbox
736 * EnvConditions: NA
737 * CaseDescription: Verify Box and Unbox method of Long.
738 */
739 HWTEST_F(AAFwkBaseTest, long_test_002, TestSize.Level1)
740 {
741 sptr<ILong> longObj = Long::Box(2147483647L);
742 EXPECT_EQ(Long::Unbox(longObj), 2147483647L);
743 }
744
745 /*
746 * Feature: Long
747 * Function: Parse
748 * SubFunction: NA
749 * FunctionPoints: Parse
750 * EnvConditions: NA
751 * CaseDescription: Verify Parse method of Long.
752 */
753 HWTEST_F(AAFwkBaseTest, long_test_003, TestSize.Level1)
754 {
755 sptr<ILong> longObj = Long::Parse("-1");
756 EXPECT_EQ(Long::Unbox(longObj), -1);
757 }
758
759 /*
760 * Feature: Long
761 * Function: Equals
762 * SubFunction: NA
763 * FunctionPoints: Equals
764 * EnvConditions: NA
765 * CaseDescription: Verify Equals method of Long.
766 */
767 HWTEST_F(AAFwkBaseTest, long_test_004, TestSize.Level1)
768 {
769 sptr<Long> longObj1 = new Long(2147483647L);
770 sptr<Long> longObj2 = new Long(-2147483647L);
771 sptr<Long> longObj3 = new Long(2147483647L);
772 EXPECT_FALSE(longObj1->Equals(longObj2));
773 EXPECT_TRUE(longObj1->Equals(longObj3));
774 }
775
776 /*
777 * Feature: Long
778 * Function: ToString
779 * SubFunction: NA
780 * FunctionPoints: ToString
781 * EnvConditions: NA
782 * CaseDescription: Verify ToString method of Long.
783 */
784 HWTEST_F(AAFwkBaseTest, long_test_005, TestSize.Level1)
785 {
786 EXPECT_EQ(Object::ToString(Long::Box(-2147483647L)), "-9223372036854775807");
787 }
788
789 /*
790 * Feature: Float
791 * Function: GetValue
792 * SubFunction: NA
793 * FunctionPoints: GetValue
794 * EnvConditions: NA
795 * CaseDescription: Verify GetValue method of Float.
796 */
797 HWTEST_F(AAFwkBaseTest, float_test_001, TestSize.Level1)
798 {
799 sptr<Float> floatObj = new Float(-1.020);
800 float value;
801 floatObj->GetValue(&value);
802 EXPECT_FLOAT_EQ(value, -1.020);
803 }
804
805 /*
806 * Feature: Float
807 * Function: Box and Unbox
808 * SubFunction: NA
809 * FunctionPoints: Box and Unbox
810 * EnvConditions: NA
811 * CaseDescription: Verify Box and Unbox method of Float.
812 */
813 HWTEST_F(AAFwkBaseTest, float_test_002, TestSize.Level1)
814 {
815 sptr<IFloat> floatObj = Float::Box(-0.003);
816 EXPECT_FLOAT_EQ(Float::Unbox(floatObj), -0.003);
817 }
818
819 /*
820 * Feature: Float
821 * Function: Parse
822 * SubFunction: NA
823 * FunctionPoints: Parse
824 * EnvConditions: NA
825 * CaseDescription: Verify Parse method of Float.
826 */
827 HWTEST_F(AAFwkBaseTest, float_test_003, TestSize.Level1)
828 {
829 sptr<IFloat> floatObj = Float::Parse("-1.000400");
830 EXPECT_FLOAT_EQ(Float::Unbox(floatObj), -1.0004);
831 }
832
833 /*
834 * Feature: Float
835 * Function: Equals
836 * SubFunction: NA
837 * FunctionPoints: Equals
838 * EnvConditions: NA
839 * CaseDescription: Verify Equals method of Float.
840 */
841 HWTEST_F(AAFwkBaseTest, float_test_004, TestSize.Level1)
842 {
843 sptr<Float> floatObj1 = new Float(0.009);
844 sptr<Float> floatObj2 = new Float(-0.001);
845 sptr<Float> floatObj3 = new Float(0.009);
846 EXPECT_FALSE(floatObj1->Equals(floatObj2));
847 EXPECT_TRUE(floatObj1->Equals(floatObj3));
848 }
849
850 /*
851 * Feature: Float
852 * Function: ToString
853 * SubFunction: NA
854 * FunctionPoints: ToString
855 * EnvConditions: NA
856 * CaseDescription: Verify ToString method of Float.
857 */
858 HWTEST_F(AAFwkBaseTest, float_test_005, TestSize.Level1)
859 {
860 EXPECT_EQ(Object::ToString(Float::Box(-10.00006)), "-10.000060");
861 }
862
863 /*
864 * Feature: Double
865 * Function: GetValue
866 * SubFunction: NA
867 * FunctionPoints: GetValue
868 * EnvConditions: NA
869 * CaseDescription: Verify GetValue method of Double.
870 */
871 HWTEST_F(AAFwkBaseTest, double_test_001, TestSize.Level1)
872 {
873 sptr<Double> doubleObj = new Double(-1.00020);
874 double value;
875 doubleObj->GetValue(&value);
876 EXPECT_DOUBLE_EQ(value, -1.00020);
877 }
878
879 /*
880 * Feature: Double
881 * Function: Box and Unbox
882 * SubFunction: NA
883 * FunctionPoints: Box and Unbox
884 * EnvConditions: NA
885 * CaseDescription: Verify Box and Unbox method of Double.
886 */
887 HWTEST_F(AAFwkBaseTest, double_test_002, TestSize.Level1)
888 {
889 sptr<IDouble> doubleObj = Double::Box(-0.00003);
890 EXPECT_DOUBLE_EQ(Double::Unbox(doubleObj), -0.00003);
891 }
892
893 /*
894 * Feature: Double
895 * Function: Parse
896 * SubFunction: NA
897 * FunctionPoints: Parse
898 * EnvConditions: NA
899 * CaseDescription: Verify Parse method of Double.
900 */
901 HWTEST_F(AAFwkBaseTest, double_test_003, TestSize.Level1)
902 {
903 sptr<IDouble> doubleObj = Double::Parse("-1.0000000400");
904 EXPECT_DOUBLE_EQ(Double::Unbox(doubleObj), -1.00000004);
905 }
906
907 /*
908 * Feature: Double
909 * Function: Equals
910 * SubFunction: NA
911 * FunctionPoints: Equals
912 * EnvConditions: NA
913 * CaseDescription: Verify Equals method of Double.
914 */
915 HWTEST_F(AAFwkBaseTest, double_test_004, TestSize.Level1)
916 {
917 sptr<Double> doubleObj1 = new Double(0.000009);
918 sptr<Double> doubleObj2 = new Double(-0.000001);
919 sptr<Double> doubleObj3 = new Double(0.000009);
920 EXPECT_FALSE(doubleObj1->Equals(doubleObj2));
921 EXPECT_TRUE(doubleObj1->Equals(doubleObj3));
922 }
923
924 /*
925 * Feature: Double
926 * Function: ToString
927 * SubFunction: NA
928 * FunctionPoints: ToString
929 * EnvConditions: NA
930 * CaseDescription: Verify ToString method of Double.
931 */
932 HWTEST_F(AAFwkBaseTest, double_test_005, TestSize.Level1)
933 {
934 EXPECT_EQ(Object::ToString(Double::Box(-10.000006)), "-10.000006");
935 }
936
937 /*
938 * Feature: String
939 * Function: GetString
940 * SubFunction: NA
941 * FunctionPoints: GetString
942 * EnvConditions: NA
943 * CaseDescription: Verify GetString method of String.
944 */
945 HWTEST_F(AAFwkBaseTest, string_test_001, TestSize.Level1)
946 {
947 sptr<String> stringObj = new String("$hell0-w@rld#");
948 std::string string;
949 stringObj->GetString(&string);
950 EXPECT_EQ(string, std::string("$hell0-w@rld#"));
951 }
952
953 /*
954 * Feature: String
955 * Function: Box and Unbox
956 * SubFunction: NA
957 * FunctionPoints: Box and Unbox
958 * EnvConditions: NA
959 * CaseDescription: Verify Box and Unbox method of String.
960 */
961 HWTEST_F(AAFwkBaseTest, string_test_002, TestSize.Level1)
962 {
963 sptr<IString> stringObj = String::Box("1234567890");
964 EXPECT_EQ(String::Unbox(stringObj), std::string("1234567890"));
965 }
966
967 /*
968 * Feature: String
969 * Function: Parse
970 * SubFunction: NA
971 * FunctionPoints: Parse
972 * EnvConditions: NA
973 * CaseDescription: Verify Parse method of String.
974 */
975 HWTEST_F(AAFwkBaseTest, string_test_003, TestSize.Level1)
976 {
977 sptr<IString> stringObj = String::Parse("-1.0000000400");
978 EXPECT_EQ(String::Unbox(stringObj), std::string("-1.0000000400"));
979 }
980
981 /*
982 * Feature: String
983 * Function: Equals
984 * SubFunction: NA
985 * FunctionPoints: Equals
986 * EnvConditions: NA
987 * CaseDescription: Verify Equals method of String.
988 */
989 HWTEST_F(AAFwkBaseTest, string_test_004, TestSize.Level1)
990 {
991 sptr<String> stringObj1 = new String("$hell0-w@rld#");
992 sptr<String> stringObj2 = new String("-1.0000000400");
993 sptr<String> stringObj3 = new String("$hell0-w@rld#");
994 EXPECT_FALSE(stringObj1->Equals(stringObj2));
995 EXPECT_TRUE(stringObj1->Equals(stringObj3));
996 }
997
998 /*
999 * Feature: String
1000 * Function: ToString
1001 * SubFunction: NA
1002 * FunctionPoints: ToString
1003 * EnvConditions: NA
1004 * CaseDescription: Verify ToString method of String.
1005 */
1006 HWTEST_F(AAFwkBaseTest, string_test_005, TestSize.Level1)
1007 {
1008 EXPECT_EQ(Object::ToString(String::Box("-10.000006")), std::string("-10.000006"));
1009 }
1010
1011 /*
1012 * Feature: Array
1013 * Function: GetLength and GetType
1014 * SubFunction: NA
1015 * FunctionPoints: GetLength and GetType
1016 * EnvConditions: NA
1017 * CaseDescription: Verify GetLength and GetType method of Array.
1018 */
1019 HWTEST_F(AAFwkBaseTest, array_test_001, TestSize.Level1)
1020 {
1021 sptr<Array> arrayObj = new Array(9, g_IID_IInteger);
1022 long size;
1023 arrayObj->GetLength(&size);
1024 EXPECT_EQ(size, 9);
1025 InterfaceID type;
1026 arrayObj->GetType(&type);
1027 EXPECT_EQ(type, g_IID_IInteger);
1028 }
1029
1030 /*
1031 * Feature: Array
1032 * Function: Get and Set
1033 * SubFunction: NA
1034 * FunctionPoints: Get and Set
1035 * EnvConditions: NA
1036 * CaseDescription: Verify Get and Set method of Array.
1037 */
1038 HWTEST_F(AAFwkBaseTest, array_test_002, TestSize.Level1)
1039 {
1040 sptr<Array> arrayObj = new Array(19, g_IID_IInteger);
1041 arrayObj->Set(0, Integer::Box(23));
1042 sptr<IInterface> valueObj;
1043 arrayObj->Get(0, valueObj);
1044 EXPECT_TRUE(valueObj != nullptr);
1045 EXPECT_EQ(Integer::Unbox(IInteger::Query(valueObj)), 23);
1046 arrayObj->Get(1, valueObj);
1047 EXPECT_TRUE(valueObj == nullptr);
1048 }
1049
1050 /*
1051 * Feature: Array
1052 * Function: ToString
1053 * SubFunction: NA
1054 * FunctionPoints: ToString
1055 * EnvConditions: NA
1056 * CaseDescription: Verify ToString method of Array.
1057 */
1058 HWTEST_F(AAFwkBaseTest, array_test_003, TestSize.Level1)
1059 {
1060 sptr<Array> arrayObj = new Array(5, g_IID_IInteger);
1061 arrayObj->Set(0, Integer::Box(2));
1062 arrayObj->Set(1, Integer::Box(3));
1063 arrayObj->Set(2, Integer::Box(5));
1064 arrayObj->Set(3, Integer::Box(7));
1065 arrayObj->Set(4, Integer::Box(11));
1066 EXPECT_EQ(arrayObj->ToString(), std::string("I5{2,3,5,7,11}"));
1067 }
1068
1069 /*
1070 * Feature: Array
1071 * Function: Parse
1072 * SubFunction: NA
1073 * FunctionPoints: Parse
1074 * EnvConditions: NA
1075 * CaseDescription: Verify Parse method of Array.
1076 */
1077 HWTEST_F(AAFwkBaseTest, array_test_004, TestSize.Level1)
1078 {
1079 sptr<IArray> arrayObj = Array::Parse("I5{2,3,5,7,11}");
1080 sptr<IInterface> valueObj;
1081 arrayObj->Get(0, valueObj);
1082 EXPECT_EQ(Integer::Unbox(IInteger::Query(valueObj)), 2);
1083 arrayObj->Get(1, valueObj);
1084 EXPECT_EQ(Integer::Unbox(IInteger::Query(valueObj)), 3);
1085 arrayObj->Get(2, valueObj);
1086 EXPECT_EQ(Integer::Unbox(IInteger::Query(valueObj)), 5);
1087 arrayObj->Get(3, valueObj);
1088 EXPECT_EQ(Integer::Unbox(IInteger::Query(valueObj)), 7);
1089 arrayObj->Get(4, valueObj);
1090 EXPECT_EQ(Integer::Unbox(IInteger::Query(valueObj)), 11);
1091 }
1092
1093 /*
1094 * Feature: Array
1095 * Function: Equals
1096 * SubFunction: NA
1097 * FunctionPoints: Equals
1098 * EnvConditions: NA
1099 * CaseDescription: Verify Equals method of Array.
1100 */
1101 HWTEST_F(AAFwkBaseTest, array_test_005, TestSize.Level1)
1102 {
1103 sptr<IArray> arrayObj1 = Array::Parse("I5{2,3,5,7,11}");
1104 sptr<IArray> arrayObj2 = Array::Parse("I5{2,3,7,7,11}");
1105 sptr<IArray> arrayObj3 = Array::Parse("I5{2,3,5,7,11}");
1106 EXPECT_FALSE(Object::Equals(arrayObj1, arrayObj2));
1107 EXPECT_TRUE(Object::Equals(arrayObj1, arrayObj3));
1108 }
1109 } // namespace AAFwk
1110 } // namespace OHOS
1111