1 /* 2 * Copyright (c) 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 <cstring> 17 #include <gmock/gmock.h> 18 #include <gtest/gtest.h> 19 20 #include "datashare_adapter_impl.h" 21 22 using namespace testing; 23 using namespace testing::ext; 24 25 namespace OHOS::NWeb { 26 class DatashareAdapterImplTest : public testing::Test { 27 public: 28 static void SetUpTestCase(void); 29 static void TearDownTestCase(void); 30 void SetUp(); 31 void TearDown(); 32 }; 33 SetUpTestCase(void)34void DatashareAdapterImplTest::SetUpTestCase(void) 35 {} 36 TearDownTestCase(void)37void DatashareAdapterImplTest::TearDownTestCase(void) 38 {} 39 SetUp(void)40void DatashareAdapterImplTest::SetUp(void) 41 {} 42 TearDown(void)43void DatashareAdapterImplTest::TearDown(void) 44 {} 45 46 /** 47 * @tc.name: DatashareAdapterImplTest_GetInstance_001 48 * @tc.desc: GetInstance. 49 * @tc.type: FUNC 50 * @tc.require: 51 */ 52 HWTEST_F(DatashareAdapterImplTest, DatashareAdapterImplTest_GetInstance_001, TestSize.Level1) 53 { 54 std::string uri = "file:///data/storage/el2/base/file/test.txt"; 55 int result = DatashareAdapterImpl::GetInstance().OpenDataShareUriForRead(uri); 56 EXPECT_EQ(result, -1); 57 std::string displayName = DatashareAdapterImpl::GetInstance().GetFileDisplayName(uri); 58 EXPECT_EQ(displayName, "test.txt"); 59 std::string real_path = DatashareAdapterImpl::GetInstance().GetRealPath(uri); 60 EXPECT_TRUE(real_path.find("test") != std::string::npos); 61 } 62 } // namespace OHOS