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