1 /* 2 * Copyright (c) 2023 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 <random> 18 #include "calendar_log.h" 19 #include "data_share_helper_manager.h" 20 21 namespace OHOS::CalendarApi::Native { 22 class DataShareHelperManagerTest : public testing::Test { 23 public: 24 /* SetUpTestCase:The preset action of the test suite is executed before the first TestCase */ SetUpTestSuite(void)25 static void SetUpTestSuite(void) 26 { 27 // save helper 28 helper = DataShareHelperManager::GetInstance().GetDataShareHelper(); 29 } 30 31 /* TearDownTestCase:The test suite cleanup action is executed after the last TestCase */ TearDownTestSuite(void)32 static void TearDownTestSuite(void) 33 { 34 DataShareHelperManager::GetInstance().SetDataShareHelper(helper); 35 } 36 /* SetUp:Execute before each test case */ SetUp()37 void SetUp() 38 { 39 } 40 41 /* TearDown:Execute after each test case */ TearDown()42 void TearDown() 43 { 44 } 45 46 static std::shared_ptr<DataShare::DataShareHelper> helper; 47 }; 48 49 std::shared_ptr<DataShare::DataShareHelper> DataShareHelperManagerTest::helper = nullptr; 50 51 HWTEST_F(DataShareHelperManagerTest, Insert_test_001, testing::ext::TestSize.Level1) 52 { 53 OHOS::Uri testUrl(""); 54 DataShare::DataShareValuesBucket value; 55 DataShareHelperManager::GetInstance().SetDataShareHelper(nullptr); 56 auto ret = DataShareHelperManager::GetInstance().Insert(testUrl, value); 57 ASSERT_TRUE(ret == -1); 58 } 59 60 HWTEST_F(DataShareHelperManagerTest, Update_test_001, testing::ext::TestSize.Level1) 61 { 62 OHOS::Uri testUrl(""); 63 DataShare::DataSharePredicates predicates; 64 DataShare::DataShareValuesBucket value; 65 DataShareHelperManager::GetInstance().SetDataShareHelper(nullptr); 66 auto ret = DataShareHelperManager::GetInstance().Update(testUrl, predicates, value); 67 ASSERT_TRUE(ret == -1); 68 } 69 70 HWTEST_F(DataShareHelperManagerTest, Delete_test_001, testing::ext::TestSize.Level1) 71 { 72 OHOS::Uri testUrl(""); 73 DataShare::DataSharePredicates predicates; 74 DataShareHelperManager::GetInstance().SetDataShareHelper(nullptr); 75 auto ret = DataShareHelperManager::GetInstance().Delete(testUrl, predicates); 76 ASSERT_TRUE(ret == -1); 77 } 78 79 HWTEST_F(DataShareHelperManagerTest, Query_test_001, testing::ext::TestSize.Level1) 80 { 81 OHOS::Uri testUrl(""); 82 DataShare::DataSharePredicates predicates; 83 std::vector<std::string> columns; 84 DataShare::DatashareBusinessError error; 85 DataShareHelperManager::GetInstance().SetDataShareHelper(nullptr); 86 auto ret = DataShareHelperManager::GetInstance().Query(testUrl, predicates, columns, &error); 87 ASSERT_TRUE(ret == nullptr); 88 } 89 }