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