mirror of
https://gitee.com/openharmony/base_location
synced 2025-02-12 22:29:56 +00:00
bugfix:passive test
Signed-off-by: 李文龙 <liwenlong22@huawei.com>
This commit is contained in:
parent
460ba68864
commit
08230384b5
@ -28,11 +28,12 @@ class PassiveAbilityTest : public testing::Test {
|
||||
public:
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void MockNativePermission();
|
||||
static void MockNativePermission();
|
||||
|
||||
sptr<PassiveAbilityProxy> proxy_;
|
||||
sptr<PassiveAbility> ability_;
|
||||
static sptr<PassiveAbility> ability_;
|
||||
static sptr<PassiveAbilityProxy> proxy_;
|
||||
};
|
||||
} // namespace Location
|
||||
} // namespace OHOS
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "constant_definition.h"
|
||||
#include "location_dumper.h"
|
||||
#include "permission_manager.h"
|
||||
#include "locationhub_ipc_interface_code.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
|
||||
@ -40,32 +41,32 @@ const int32_t LOCATION_PERM_NUM = 4;
|
||||
const std::string ARGS_HELP = "-h";
|
||||
const std::string UNLOAD_PASSIVE_TASK = "passive_sa_unload";
|
||||
const int32_t WAIT_EVENT_TIME = 1;
|
||||
|
||||
sptr<PassiveAbility> PassiveAbilityTest::ability_;
|
||||
sptr<PassiveAbilityProxy> PassiveAbilityTest::proxy_;
|
||||
|
||||
void PassiveAbilityTest::SetUp()
|
||||
{
|
||||
/*
|
||||
* @tc.setup: Get system ability's pointer and get sa proxy object.
|
||||
*/
|
||||
MockNativePermission();
|
||||
ability_ = new (std::nothrow) PassiveAbility();
|
||||
EXPECT_NE(nullptr, ability_);
|
||||
proxy_ = new (std::nothrow) PassiveAbilityProxy(ability_);
|
||||
EXPECT_NE(nullptr, proxy_);
|
||||
}
|
||||
|
||||
void PassiveAbilityTest::TearDown()
|
||||
{
|
||||
/*
|
||||
* @tc.teardown: release memory.
|
||||
*/
|
||||
ability_->passiveHandler_->RemoveTask(UNLOAD_PASSIVE_TASK);
|
||||
sleep(WAIT_EVENT_TIME);
|
||||
proxy_ = nullptr;
|
||||
ability_ = nullptr;
|
||||
}
|
||||
|
||||
void PassiveAbilityTest::SetUpTestCase()
|
||||
{
|
||||
MockNativePermission();
|
||||
ability_ = new (std::nothrow) PassiveAbility();
|
||||
proxy_ = new (std::nothrow) PassiveAbilityProxy(ability_);
|
||||
EXPECT_NE(nullptr, proxy_);
|
||||
}
|
||||
|
||||
void PassiveAbilityTest::TearDownTestCase()
|
||||
{
|
||||
ability_->passiveHandler_->RemoveAllEvents();
|
||||
sleep(WAIT_EVENT_TIME);
|
||||
proxy_ = nullptr;
|
||||
ability_ = nullptr;
|
||||
}
|
||||
|
||||
void PassiveAbilityTest::MockNativePermission()
|
||||
@ -155,10 +156,30 @@ HWTEST_F(PassiveAbilityTest, PassiveLocationMock001, TestSize.Level1)
|
||||
LBSLOGI(PASSIVE_TEST, "[PassiveAbilityStubTest] PassiveLocationMock001 begin");
|
||||
int timeInterval = 1;
|
||||
std::vector<std::shared_ptr<Location>> locations;
|
||||
Parcel parcel;
|
||||
for (int i = 0; i < 2; i++) {
|
||||
parcel.WriteDouble(10.6); // latitude
|
||||
parcel.WriteDouble(10.5); // longitude
|
||||
parcel.WriteDouble(10.4); // altitude
|
||||
parcel.WriteDouble(1.0); // accuracy
|
||||
parcel.WriteDouble(5.0); // speed
|
||||
parcel.WriteDouble(10); // direction
|
||||
parcel.WriteInt64(1611000000); // timestamp
|
||||
parcel.WriteInt64(1611000000); // time since boot
|
||||
parcel.WriteString16(u"additions"); // additions
|
||||
parcel.WriteInt64(1); // additionSize
|
||||
parcel.WriteInt32(1); // isFromMock
|
||||
locations.push_back(Location::UnmarshallingShared(parcel));
|
||||
}
|
||||
EXPECT_EQ(ERRCODE_SUCCESS, proxy_->EnableMock());
|
||||
EXPECT_EQ(ERRCODE_SUCCESS, proxy_->SetMocked(timeInterval, locations));
|
||||
ability_->passiveHandler_->RemoveEvent(static_cast<uint32_t>(PassiveInterfaceCode::SET_MOCKED_LOCATIONS));
|
||||
sleep(WAIT_EVENT_TIME);
|
||||
|
||||
EXPECT_EQ(ERRCODE_SUCCESS, proxy_->DisableMock());
|
||||
EXPECT_EQ(ERRCODE_NOT_SUPPORTED, proxy_->SetMocked(timeInterval, locations));
|
||||
ability_->passiveHandler_->RemoveEvent(static_cast<uint32_t>(PassiveInterfaceCode::SET_MOCKED_LOCATIONS));
|
||||
sleep(WAIT_EVENT_TIME);
|
||||
LBSLOGI(PASSIVE_TEST, "[PassiveAbilityStubTest] PassiveLocationMock001 end");
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user