1e0857b17Sopenharmony_ci/* 2e0857b17Sopenharmony_ci * Copyright (c) 2021-2023 Huawei Device Co., Ltd. 3e0857b17Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4e0857b17Sopenharmony_ci * you may not use this file except in compliance with the License. 5e0857b17Sopenharmony_ci * You may obtain a copy of the License at 6e0857b17Sopenharmony_ci * 7e0857b17Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8e0857b17Sopenharmony_ci * 9e0857b17Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10e0857b17Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11e0857b17Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12e0857b17Sopenharmony_ci * See the License for the specific language governing permissions and 13e0857b17Sopenharmony_ci * limitations under the License. 14e0857b17Sopenharmony_ci */ 15e0857b17Sopenharmony_ci 16e0857b17Sopenharmony_ci#include <gtest/gtest.h> 17e0857b17Sopenharmony_ci#include "base_def.h" 18e0857b17Sopenharmony_ci#include "base_obj.h" 19e0857b17Sopenharmony_ci#include "bool_wrapper.h" 20e0857b17Sopenharmony_ci#include "zchar_wrapper.h" 21e0857b17Sopenharmony_ci#include "byte_wrapper.h" 22e0857b17Sopenharmony_ci#include "user_object_wrapper.h" 23e0857b17Sopenharmony_ci#include "short_wrapper.h" 24e0857b17Sopenharmony_ci#include "int_wrapper.h" 25e0857b17Sopenharmony_ci#include "long_wrapper.h" 26e0857b17Sopenharmony_ci#include "float_wrapper.h" 27e0857b17Sopenharmony_ci#include "double_wrapper.h" 28e0857b17Sopenharmony_ci#include "string_wrapper.h" 29e0857b17Sopenharmony_ci#include "refbase.h" 30e0857b17Sopenharmony_ci 31e0857b17Sopenharmony_ciusing namespace OHOS; 32e0857b17Sopenharmony_ciusing namespace OHOS::AAFwk; 33e0857b17Sopenharmony_ciusing testing::ext::TestSize; 34e0857b17Sopenharmony_ci 35e0857b17Sopenharmony_cinamespace OHOS { 36e0857b17Sopenharmony_cinamespace AAFwk { 37e0857b17Sopenharmony_ciclass AAFwkBaseObjectTest : public testing::Test { 38e0857b17Sopenharmony_cipublic: 39e0857b17Sopenharmony_ci static void SetUpTestCase(void); 40e0857b17Sopenharmony_ci static void TearDownTestCase(void); 41e0857b17Sopenharmony_ci void SetUp(); 42e0857b17Sopenharmony_ci void TearDown(); 43e0857b17Sopenharmony_ci}; 44e0857b17Sopenharmony_ci 45e0857b17Sopenharmony_civoid AAFwkBaseObjectTest::SetUpTestCase(void) 46e0857b17Sopenharmony_ci{} 47e0857b17Sopenharmony_ci 48e0857b17Sopenharmony_civoid AAFwkBaseObjectTest::TearDownTestCase(void) 49e0857b17Sopenharmony_ci{} 50e0857b17Sopenharmony_ci 51e0857b17Sopenharmony_civoid AAFwkBaseObjectTest::SetUp(void) 52e0857b17Sopenharmony_ci{} 53e0857b17Sopenharmony_ci 54e0857b17Sopenharmony_civoid AAFwkBaseObjectTest::TearDown(void) 55e0857b17Sopenharmony_ci{} 56e0857b17Sopenharmony_ci 57e0857b17Sopenharmony_ci/** 58e0857b17Sopenharmony_ci * @tc.number: BaseObject_test_001 59e0857b17Sopenharmony_ci * @tc.name: Query 60e0857b17Sopenharmony_ci * @tc.desc: test Query function and iid == g_IID_IWeakReferenceSource. 61e0857b17Sopenharmony_ci */ 62e0857b17Sopenharmony_ciHWTEST_F(AAFwkBaseObjectTest, BaseObject_test_001, TestSize.Level1) 63e0857b17Sopenharmony_ci{ 64e0857b17Sopenharmony_ci Object object; 65e0857b17Sopenharmony_ci InterfaceID iid = { 66e0857b17Sopenharmony_ci 0xbc3f5250, 0x34d7, 0x42d2, 0x9b40, {0xf, 0xf, 0xc, 0xe, 0x8, 0x3, 0xf, 0xd, 0x4, 0x0, 0x6, 0x1} 67e0857b17Sopenharmony_ci }; 68e0857b17Sopenharmony_ci EXPECT_TRUE(object.Query(iid)); 69e0857b17Sopenharmony_ci} 70e0857b17Sopenharmony_ci 71e0857b17Sopenharmony_ci/** 72e0857b17Sopenharmony_ci * @tc.number: BaseObject_test_002 73e0857b17Sopenharmony_ci * @tc.name: Query 74e0857b17Sopenharmony_ci * @tc.desc: test Query function and iid == g_IID_IInterface. 75e0857b17Sopenharmony_ci */ 76e0857b17Sopenharmony_ciHWTEST_F(AAFwkBaseObjectTest, BaseObject_test_002, TestSize.Level1) 77e0857b17Sopenharmony_ci{ 78e0857b17Sopenharmony_ci Object object; 79e0857b17Sopenharmony_ci InterfaceID iid = { 80e0857b17Sopenharmony_ci 0x00000000, 0x0000, 0x0000, 0x0000, {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1} 81e0857b17Sopenharmony_ci }; 82e0857b17Sopenharmony_ci EXPECT_TRUE(object.Query(iid)); 83e0857b17Sopenharmony_ci} 84e0857b17Sopenharmony_ci 85e0857b17Sopenharmony_ci/** 86e0857b17Sopenharmony_ci * @tc.number: BaseObject_test_003 87e0857b17Sopenharmony_ci * @tc.name: GetInterfaceID 88e0857b17Sopenharmony_ci * @tc.desc: test GetInterfaceID function and object == static_cast<IObject *>(this). 89e0857b17Sopenharmony_ci */ 90e0857b17Sopenharmony_ciHWTEST_F(AAFwkBaseObjectTest, BaseObject_test_003, TestSize.Level1) 91e0857b17Sopenharmony_ci{ 92e0857b17Sopenharmony_ci Object object; 93e0857b17Sopenharmony_ci InterfaceID iid = { 94e0857b17Sopenharmony_ci 0x8321f710, 0xa0c0, 0x4cbe, 0xbfbc, {0x5, 0xa, 0x7, 0x8, 0xf, 0x1, 0x3, 0x1, 0x2, 0xb, 0x1, 0xb} 95e0857b17Sopenharmony_ci }; 96e0857b17Sopenharmony_ci EXPECT_EQ(iid, object.GetInterfaceID(object.Query(iid))); 97e0857b17Sopenharmony_ci} 98e0857b17Sopenharmony_ci 99e0857b17Sopenharmony_ci/** 100e0857b17Sopenharmony_ci * @tc.number: BaseObject_test_004 101e0857b17Sopenharmony_ci * @tc.name: GetInterfaceID 102e0857b17Sopenharmony_ci * @tc.desc: test GetInterfaceID function and object == static_cast<IWeakReferenceSource *>(this). 103e0857b17Sopenharmony_ci */ 104e0857b17Sopenharmony_ciHWTEST_F(AAFwkBaseObjectTest, BaseObject_test_004, TestSize.Level1) 105e0857b17Sopenharmony_ci{ 106e0857b17Sopenharmony_ci Object object; 107e0857b17Sopenharmony_ci InterfaceID iid = { 108e0857b17Sopenharmony_ci 0xbc3f5250, 0x34d7, 0x42d2, 0x9b40, {0xf, 0xf, 0xc, 0xe, 0x8, 0x3, 0xf, 0xd, 0x4, 0x0, 0x6, 0x1} 109e0857b17Sopenharmony_ci }; 110e0857b17Sopenharmony_ci EXPECT_EQ(iid, object.GetInterfaceID(object.Query(iid))); 111e0857b17Sopenharmony_ci} 112e0857b17Sopenharmony_ci 113e0857b17Sopenharmony_ci/** 114e0857b17Sopenharmony_ci * @tc.number: BaseObject_test_005 115e0857b17Sopenharmony_ci * @tc.name: GetInterfaceID 116e0857b17Sopenharmony_ci * @tc.desc: test GetInterfaceID function and object is Any value. 117e0857b17Sopenharmony_ci */ 118e0857b17Sopenharmony_ciHWTEST_F(AAFwkBaseObjectTest, BaseObject_test_005, TestSize.Level1) 119e0857b17Sopenharmony_ci{ 120e0857b17Sopenharmony_ci Object object; 121e0857b17Sopenharmony_ci InterfaceID iid = { 122e0857b17Sopenharmony_ci 0x26ab1978, 0x1d11, 0x4a4f, 0x826d, {0x6, 0x1, 0x7, 0x8, 0x5, 0xc, 0x0, 0x4, 0x8, 0xc, 0xc, 0xa} 123e0857b17Sopenharmony_ci }; 124e0857b17Sopenharmony_ci EXPECT_EQ(InterfaceID::Empty, object.GetInterfaceID(object.Query(iid))); 125e0857b17Sopenharmony_ci} 126e0857b17Sopenharmony_ci 127e0857b17Sopenharmony_ci 128e0857b17Sopenharmony_ci/** 129e0857b17Sopenharmony_ci * @tc.number: BaseObject_test_006 130e0857b17Sopenharmony_ci * @tc.name: GetWeakReference 131e0857b17Sopenharmony_ci * @tc.desc: test GetWeakReference function and addr is not nullptr. 132e0857b17Sopenharmony_ci */ 133e0857b17Sopenharmony_ciHWTEST_F(AAFwkBaseObjectTest, BaseObject_test_006, TestSize.Level1) 134e0857b17Sopenharmony_ci{ 135e0857b17Sopenharmony_ci Object object; 136e0857b17Sopenharmony_ci sptr<IWeakReference> weakRef = nullptr; 137e0857b17Sopenharmony_ci EXPECT_EQ(ERR_OK, object.GetWeakReference(weakRef)); 138e0857b17Sopenharmony_ci} 139e0857b17Sopenharmony_ci 140e0857b17Sopenharmony_ci/** 141e0857b17Sopenharmony_ci * @tc.number: BaseObject_test_007 142e0857b17Sopenharmony_ci * @tc.name: ToString 143e0857b17Sopenharmony_ci * @tc.desc: test ToString function. 144e0857b17Sopenharmony_ci */ 145e0857b17Sopenharmony_ciHWTEST_F(AAFwkBaseObjectTest, BaseObject_test_007, TestSize.Level1) 146e0857b17Sopenharmony_ci{ 147e0857b17Sopenharmony_ci std::shared_ptr<Object> object = std::make_shared<Object>(); 148e0857b17Sopenharmony_ci ASSERT_NE(nullptr, object); 149e0857b17Sopenharmony_ci object->ToString(); 150e0857b17Sopenharmony_ci} 151e0857b17Sopenharmony_ci 152e0857b17Sopenharmony_ci/** 153e0857b17Sopenharmony_ci * @tc.number: BaseObject_test_008 154e0857b17Sopenharmony_ci * @tc.name: GetClassID 155e0857b17Sopenharmony_ci * @tc.desc: test GetInterfaceID function and object is Any value. 156e0857b17Sopenharmony_ci */ 157e0857b17Sopenharmony_ciHWTEST_F(AAFwkBaseObjectTest, BaseObject_test_008, TestSize.Level1) 158e0857b17Sopenharmony_ci{ 159e0857b17Sopenharmony_ci Object object; 160e0857b17Sopenharmony_ci EXPECT_EQ(ClassID::Empty, object.GetClassID()); 161e0857b17Sopenharmony_ci} 162e0857b17Sopenharmony_ci 163e0857b17Sopenharmony_ci/** 164e0857b17Sopenharmony_ci * @tc.number: BaseObject_test_009 165e0857b17Sopenharmony_ci * @tc.name: GetHashCode 166e0857b17Sopenharmony_ci * @tc.desc: test GetInterfaceID function and object is Any value. 167e0857b17Sopenharmony_ci */ 168e0857b17Sopenharmony_ciHWTEST_F(AAFwkBaseObjectTest, BaseObject_test_009, TestSize.Level1) 169e0857b17Sopenharmony_ci{ 170e0857b17Sopenharmony_ci std::shared_ptr<Object> object = std::make_shared<Object>(); 171e0857b17Sopenharmony_ci Object object1; 172e0857b17Sopenharmony_ci InterfaceID iid = { 173e0857b17Sopenharmony_ci 0x8321f710, 0xa0c0, 0x4cbe, 0xbfbc, {0x5, 0xa, 0x7, 0x8, 0xf, 0x1, 0x3, 0x1, 0x2, 0xb, 0x1, 0xb} 174e0857b17Sopenharmony_ci }; 175e0857b17Sopenharmony_ci Object object2; 176e0857b17Sopenharmony_ci EXPECT_EQ(false, object->Equals(*(object1.Query(iid)), *(object2.Query(iid)))); 177e0857b17Sopenharmony_ci} 178e0857b17Sopenharmony_ci 179e0857b17Sopenharmony_ci/** 180e0857b17Sopenharmony_ci * @tc.number: BaseObject_test_010 181e0857b17Sopenharmony_ci * @tc.name: GetHashCode 182e0857b17Sopenharmony_ci * @tc.desc: test GetInterfaceID function and object is Any value. 183e0857b17Sopenharmony_ci */ 184e0857b17Sopenharmony_ciHWTEST_F(AAFwkBaseObjectTest, BaseObject_test_010, TestSize.Level1) 185e0857b17Sopenharmony_ci{ 186e0857b17Sopenharmony_ci std::shared_ptr<Object> object = std::make_shared<Object>(); 187e0857b17Sopenharmony_ci Object object1; 188e0857b17Sopenharmony_ci InterfaceID iid = { 189e0857b17Sopenharmony_ci 0x8321f710, 0xa0c0, 0x4cbe, 0xbfbc, {0x5, 0xa, 0x7, 0x8, 0xf, 0x1, 0x3, 0x1, 0x2, 0xb, 0x1, 0xb} 190e0857b17Sopenharmony_ci }; 191e0857b17Sopenharmony_ci EXPECT_EQ(true, object->Equals(*(object1.Query(iid)), *(object1.Query(iid)))); 192e0857b17Sopenharmony_ci} 193e0857b17Sopenharmony_ci 194e0857b17Sopenharmony_ci/** 195e0857b17Sopenharmony_ci * @tc.number: UserObject_test_001 196e0857b17Sopenharmony_ci * @tc.name: ToString 197e0857b17Sopenharmony_ci * @tc.desc: test ToString function and value_ is nullptr. 198e0857b17Sopenharmony_ci */ 199e0857b17Sopenharmony_ciHWTEST_F(AAFwkBaseObjectTest, UserObject_test_001, TestSize.Level1) 200e0857b17Sopenharmony_ci{ 201e0857b17Sopenharmony_ci UserObject userObject(nullptr); 202e0857b17Sopenharmony_ci EXPECT_EQ("", userObject.ToString()); 203e0857b17Sopenharmony_ci} 204e0857b17Sopenharmony_ci 205e0857b17Sopenharmony_ci/** 206e0857b17Sopenharmony_ci * @tc.number: UserObject_test_002 207e0857b17Sopenharmony_ci * @tc.name: Box 208e0857b17Sopenharmony_ci * @tc.desc: test Box function and value is nullptr. 209e0857b17Sopenharmony_ci */ 210e0857b17Sopenharmony_ciHWTEST_F(AAFwkBaseObjectTest, UserObject_test_002, TestSize.Level1) 211e0857b17Sopenharmony_ci{ 212e0857b17Sopenharmony_ci UserObject userObject(nullptr); 213e0857b17Sopenharmony_ci EXPECT_EQ(nullptr, userObject.Box(nullptr)); 214e0857b17Sopenharmony_ci} 215e0857b17Sopenharmony_ci 216e0857b17Sopenharmony_ci/** 217e0857b17Sopenharmony_ci * @tc.number: UserObject_test_003 218e0857b17Sopenharmony_ci * @tc.name: Unbox 219e0857b17Sopenharmony_ci * @tc.desc: test Unbox function and object is nullptr. 220e0857b17Sopenharmony_ci */ 221e0857b17Sopenharmony_ciHWTEST_F(AAFwkBaseObjectTest, UserObject_test_003, TestSize.Level1) 222e0857b17Sopenharmony_ci{ 223e0857b17Sopenharmony_ci UserObject userObject(nullptr); 224e0857b17Sopenharmony_ci EXPECT_EQ(nullptr, userObject.Unbox(nullptr)); 225e0857b17Sopenharmony_ci} 226e0857b17Sopenharmony_ci 227e0857b17Sopenharmony_ci/** 228e0857b17Sopenharmony_ci * @tc.number: UserObject_test_004 229e0857b17Sopenharmony_ci * @tc.name: Parse 230e0857b17Sopenharmony_ci * @tc.desc: test Parse function and str is empty. 231e0857b17Sopenharmony_ci */ 232e0857b17Sopenharmony_ciHWTEST_F(AAFwkBaseObjectTest, UserObject_test_004, TestSize.Level1) 233e0857b17Sopenharmony_ci{ 234e0857b17Sopenharmony_ci UserObject userObject(nullptr); 235e0857b17Sopenharmony_ci std::string str = ""; 236e0857b17Sopenharmony_ci EXPECT_EQ(nullptr, userObject.Parse(str)); 237e0857b17Sopenharmony_ci} 238e0857b17Sopenharmony_ci 239e0857b17Sopenharmony_ci/** 240e0857b17Sopenharmony_ci * @tc.number: UserObject_test_005 241e0857b17Sopenharmony_ci * @tc.name: Parse 242e0857b17Sopenharmony_ci * @tc.desc: test Parse function and SPLIT is does not exist. 243e0857b17Sopenharmony_ci */ 244e0857b17Sopenharmony_ciHWTEST_F(AAFwkBaseObjectTest, UserObject_test_005, TestSize.Level1) 245e0857b17Sopenharmony_ci{ 246e0857b17Sopenharmony_ci UserObject userObject(nullptr); 247e0857b17Sopenharmony_ci std::string str = "acd"; 248e0857b17Sopenharmony_ci EXPECT_EQ(nullptr, userObject.Parse(str)); 249e0857b17Sopenharmony_ci} 250e0857b17Sopenharmony_ci 251e0857b17Sopenharmony_ci/** 252e0857b17Sopenharmony_ci * @tc.number: UserObject_test_006 253e0857b17Sopenharmony_ci * @tc.name: Parse 254e0857b17Sopenharmony_ci * @tc.desc: test Parse function and SPLIT is exist. 255e0857b17Sopenharmony_ci */ 256e0857b17Sopenharmony_ciHWTEST_F(AAFwkBaseObjectTest, UserObject_test_006, TestSize.Level1) 257e0857b17Sopenharmony_ci{ 258e0857b17Sopenharmony_ci UserObject userObject(nullptr); 259e0857b17Sopenharmony_ci std::string str = "a#cd"; 260e0857b17Sopenharmony_ci EXPECT_EQ(nullptr, userObject.Parse(str)); 261e0857b17Sopenharmony_ci} 262e0857b17Sopenharmony_ci 263e0857b17Sopenharmony_ci/** 264e0857b17Sopenharmony_ci * @tc.number: UserObject_test_007 265e0857b17Sopenharmony_ci * @tc.name: Parse 266e0857b17Sopenharmony_ci * @tc.desc: test Parse function and str == "true". 267e0857b17Sopenharmony_ci */ 268e0857b17Sopenharmony_ciHWTEST_F(AAFwkBaseObjectTest, UserObject_test_007, TestSize.Level1) 269e0857b17Sopenharmony_ci{ 270e0857b17Sopenharmony_ci Boolean boolean(true); 271e0857b17Sopenharmony_ci std::string str = "true"; 272e0857b17Sopenharmony_ci boolean.Parse(str); 273e0857b17Sopenharmony_ci EXPECT_EQ("true", boolean.ToString()); 274e0857b17Sopenharmony_ci} 275e0857b17Sopenharmony_ci} // namespace AAFwk 276e0857b17Sopenharmony_ci} // namespace OHOS 277