mirror of
https://github.com/openharmony/miscservices_request.git
synced 2026-07-01 04:46:07 -04:00
@@ -36,8 +36,8 @@ public:
|
||||
|
||||
void TearDown();
|
||||
|
||||
MockFileAdapter adapter;
|
||||
ObtainFile obfile;
|
||||
std::shared_ptr<MockFileAdapter> adapter;
|
||||
std::shared_ptr<ObtainFile> obfile;
|
||||
};
|
||||
|
||||
void ObtainFileTest::SetUpTestCase(void)
|
||||
@@ -50,37 +50,17 @@ void ObtainFileTest::TearDownTestCase(void)
|
||||
|
||||
void ObtainFileTest::SetUp()
|
||||
{
|
||||
if (this->obfile.fileAdapter_.get() != &adapter) {
|
||||
this->obfile.fileAdapter_ = std::shared_ptr<IFileAdapter>(&adapter);
|
||||
}
|
||||
this->obfile = std::make_shared<ObtainFile>();
|
||||
this->obfile->fileAdapter_.reset();
|
||||
this->adapter = std::make_shared<MockFileAdapter>();
|
||||
this->obfile->fileAdapter_ = this->adapter;
|
||||
}
|
||||
|
||||
void ObtainFileTest::TearDown()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ObtainFileUtTest001
|
||||
* @tc.desc: GetFile with DataAbilityUri succsee
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ObtainFileTest, ObtainFileUtTest000, TestSize.Level0)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "ObtainFileUtTest000 start";
|
||||
FILE* file = nullptr;
|
||||
unsigned int fileSize = 0;
|
||||
unsigned int result = UPLOAD_ERRORCODE_NO_ERROR;
|
||||
std::string uri = "dataability:///com.domainname.dataability.persondata/person/10";
|
||||
std::shared_ptr<OHOS::AbilityRuntime::Context> context = nullptr;
|
||||
|
||||
EXPECT_CALL(this->adapter, DataAbilityOpenFile(testing::_, testing::_))
|
||||
.Times(1)
|
||||
.WillOnce(testing::Return(-1));
|
||||
result = this->obfile.GetFile(&file, uri, fileSize, context);
|
||||
EXPECT_EQ(result, UPLOAD_ERRORCODE_GET_FILE_ERROR);
|
||||
EXPECT_EQ(file, nullptr);
|
||||
EXPECT_EQ(fileSize, 0);
|
||||
GTEST_LOG_(INFO) << "ObtainFileUtTest000 end";
|
||||
this->obfile->fileAdapter_.reset();
|
||||
this->obfile.reset();
|
||||
this->adapter.reset();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,21 +70,21 @@ HWTEST_F(ObtainFileTest, ObtainFileUtTest000, TestSize.Level0)
|
||||
*/
|
||||
HWTEST_F(ObtainFileTest, ObtainFileUtTest001, TestSize.Level0)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "ObtainFileUtTest001 start";
|
||||
GTEST_LOG_(INFO) << "ObtainFileUtTest000 start";
|
||||
FILE* file = nullptr;
|
||||
unsigned int fileSize = 0;
|
||||
unsigned int result = UPLOAD_ERRORCODE_NO_ERROR;
|
||||
std::string uri = "dataability:///com.domainname.dataability.persondata/person/10";
|
||||
std::shared_ptr<OHOS::AbilityRuntime::Context> context = nullptr;
|
||||
|
||||
EXPECT_CALL(this->adapter, DataAbilityOpenFile(testing::_, testing::_))
|
||||
EXPECT_CALL(*(this->adapter.get()), DataAbilityOpenFile(testing::_, testing::_))
|
||||
.Times(1)
|
||||
.WillOnce(testing::Return(8888888));
|
||||
result = this->obfile.GetFile(&file, uri, fileSize, context);
|
||||
.WillOnce(testing::Return(-1));
|
||||
result = this->obfile->GetFile(&file, uri, fileSize, context);
|
||||
EXPECT_EQ(result, UPLOAD_ERRORCODE_GET_FILE_ERROR);
|
||||
EXPECT_NE(file, nullptr);
|
||||
EXPECT_EQ(fileSize, -1);
|
||||
GTEST_LOG_(INFO) << "ObtainFileUtTest001 end";
|
||||
EXPECT_EQ(file, nullptr);
|
||||
EXPECT_EQ(fileSize, 0);
|
||||
GTEST_LOG_(INFO) << "ObtainFileUtTest000 end";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,11 +111,11 @@ HWTEST_F(ObtainFileTest, ObtainFileUtTest002, TestSize.Level0)
|
||||
std::shared_ptr<OHOS::AbilityRuntime::Context> context = nullptr;
|
||||
uint32_t fd = fileno(fopen("/data/Dataability/file.txt", "r"));
|
||||
|
||||
EXPECT_CALL(this->adapter, DataAbilityOpenFile(testing::_, testing::_))
|
||||
EXPECT_CALL(*(this->adapter.get()), DataAbilityOpenFile(testing::_, testing::_))
|
||||
.Times(1)
|
||||
.WillOnce(testing::Return(fd));
|
||||
|
||||
result = this->obfile.GetFile(&file, uri, fileSize, context);
|
||||
result = this->obfile->GetFile(&file, uri, fileSize, context);
|
||||
|
||||
EXPECT_EQ(result, UPLOAD_ERRORCODE_NO_ERROR);
|
||||
EXPECT_NE(file, nullptr);
|
||||
@@ -160,7 +140,7 @@ HWTEST_F(ObtainFileTest, ObtainFileUtTest003, TestSize.Level0)
|
||||
std::string uri = "internal:--//cache/path/to/file.txt";
|
||||
std::shared_ptr<OHOS::AbilityRuntime::Context> context = nullptr;
|
||||
|
||||
result = this->obfile.GetFile(&file, uri, fileSize, context);
|
||||
result = this->obfile->GetFile(&file, uri, fileSize, context);
|
||||
|
||||
EXPECT_EQ(result, UPLOAD_ERRORCODE_UNSUPPORT_URI);
|
||||
EXPECT_EQ(file, nullptr);
|
||||
@@ -181,7 +161,7 @@ HWTEST_F(ObtainFileTest, ObtainFileUtTest004, TestSize.Level0)
|
||||
std::string uri = "internal:/ccc/cache/path/to/file.txt";
|
||||
std::shared_ptr<OHOS::AbilityRuntime::Context> context = nullptr;
|
||||
|
||||
result = this->obfile.GetFile(&file, uri, fileSize, context);
|
||||
result = this->obfile->GetFile(&file, uri, fileSize, context);
|
||||
|
||||
EXPECT_EQ(result, UPLOAD_ERRORCODE_UNSUPPORT_URI);
|
||||
EXPECT_EQ(file, nullptr);
|
||||
@@ -202,7 +182,7 @@ HWTEST_F(ObtainFileTest, ObtainFileUtTest005, TestSize.Level0)
|
||||
std::string uri = "internal://cache---/path/to/file.txt";
|
||||
std::shared_ptr<OHOS::AbilityRuntime::Context> context = nullptr;
|
||||
|
||||
result = this->obfile.GetFile(&file, uri, fileSize, context);
|
||||
result = this->obfile->GetFile(&file, uri, fileSize, context);
|
||||
|
||||
EXPECT_EQ(result, UPLOAD_ERRORCODE_UNSUPPORT_URI);
|
||||
EXPECT_EQ(file, nullptr);
|
||||
@@ -225,11 +205,11 @@ HWTEST_F(ObtainFileTest, ObtainFileUtTest006, TestSize.Level0)
|
||||
std::shared_ptr<OHOS::AbilityRuntime::Context> context = nullptr;
|
||||
std::string path = "";
|
||||
|
||||
EXPECT_CALL(this->adapter, InternalGetFilePath(testing::_))
|
||||
EXPECT_CALL(*(this->adapter.get()), InternalGetFilePath(testing::_))
|
||||
.Times(1)
|
||||
.WillOnce(testing::Return(path));
|
||||
|
||||
result = this->obfile.GetFile(&file, uri, fileSize, context);
|
||||
result = this->obfile->GetFile(&file, uri, fileSize, context);
|
||||
|
||||
EXPECT_EQ(result, UPLOAD_ERRORCODE_GET_FILE_ERROR);
|
||||
EXPECT_EQ(file, nullptr);
|
||||
@@ -251,11 +231,11 @@ HWTEST_F(ObtainFileTest, ObtainFileUtTest007, TestSize.Level0)
|
||||
std::shared_ptr<OHOS::AbilityRuntime::Context> context = nullptr;
|
||||
std::string path = "XXXXX";
|
||||
|
||||
EXPECT_CALL(this->adapter, InternalGetFilePath(testing::_))
|
||||
EXPECT_CALL(*(this->adapter.get()), InternalGetFilePath(testing::_))
|
||||
.Times(1)
|
||||
.WillOnce(testing::Return(path));
|
||||
|
||||
result = this->obfile.GetFile(&file, uri, fileSize, context);
|
||||
result = this->obfile->GetFile(&file, uri, fileSize, context);
|
||||
|
||||
EXPECT_EQ(result, UPLOAD_ERRORCODE_GET_FILE_ERROR);
|
||||
EXPECT_EQ(file, nullptr);
|
||||
@@ -286,11 +266,11 @@ HWTEST_F(ObtainFileTest, ObtainFileUtTest008, TestSize.Level0)
|
||||
std::shared_ptr<OHOS::AbilityRuntime::Context> context = nullptr;
|
||||
std::string path = "/data/testApp/CacheDir/";
|
||||
|
||||
EXPECT_CALL(this->adapter, InternalGetFilePath(testing::_))
|
||||
EXPECT_CALL(*(this->adapter.get()), InternalGetFilePath(testing::_))
|
||||
.Times(1)
|
||||
.WillOnce(testing::Return(path));
|
||||
|
||||
result = this->obfile.GetFile(&file, uri, fileSize, context);
|
||||
result = this->obfile->GetFile(&file, uri, fileSize, context);
|
||||
|
||||
EXPECT_EQ(result, UPLOAD_ERRORCODE_NO_ERROR);
|
||||
EXPECT_NE(file, nullptr);
|
||||
@@ -314,7 +294,7 @@ HWTEST_F(ObtainFileTest, ObtainFileUtTest009, TestSize.Level0)
|
||||
std::string uri = "XXXXXXXXXXXXXX://cache/path/to/file.txt";
|
||||
std::shared_ptr<OHOS::AbilityRuntime::Context> context = nullptr;
|
||||
|
||||
result = this->obfile.GetFile(&file, uri, fileSize, context);
|
||||
result = this->obfile->GetFile(&file, uri, fileSize, context);
|
||||
|
||||
EXPECT_EQ(result, UPLOAD_ERRORCODE_UNSUPPORT_URI);
|
||||
EXPECT_EQ(file, nullptr);
|
||||
|
||||
Reference in New Issue
Block a user