TDD用例

Signed-off-by: zhutianyi <zhutianyi2@huawei.com>
This commit is contained in:
zhutianyi
2022-06-27 15:41:47 +08:00
parent 3662dec7f5
commit 186f94ef6a
3 changed files with 90 additions and 10 deletions
@@ -447,11 +447,7 @@ bool TimeServiceClient::ProxyTimer(int32_t uid, bool isProxy)
TIME_HILOGE(TIME_MODULE_CLIENT, "ProxyTimer ConnectService failed.");
return false;
}
if (timeServiceProxy_->ProxyTimer(uid, isProxy) != ERR_OK) {
return false;
}
TIME_HILOGD(TIME_MODULE_CLIENT, "end");
return true;
return timeServiceProxy_->ProxyTimer(uid, isProxy);
}
bool TimeServiceClient::ResetAllProxy()
@@ -465,11 +461,7 @@ bool TimeServiceClient::ResetAllProxy()
TIME_HILOGE(TIME_MODULE_CLIENT, "ResetAllProxy ConnectService failed.");
return false;
}
if (timeServiceProxy_->ResetAllProxy() != ERR_OK) {
return false;
}
TIME_HILOGD(TIME_MODULE_CLIENT, "end");
return true;
return timeServiceProxy_->ResetAllProxy();
}
} // namespace MiscServices
} // namespace OHOS
@@ -15,6 +15,7 @@
#include <cstdlib>
#include <ctime>
#include <chrono>
#include "ipc_skeleton.h"
#include "timer_info_test.h"
#include "time_service_test.h"
@@ -306,3 +307,88 @@ HWTEST_F(TimeServiceTest, CreateTimer006, TestSize.Level0)
ret = TimeServiceClient::GetInstance()->StopTimer(timerId1);
EXPECT_FALSE(ret);
}
/**
* @tc.name: ProxyTimer001.
* @tc.desc: proxy timer.
* @tc.type: FUNC
*/
HWTEST_F(TimeServiceTest, ProxyTimer001, TestSize.Level0)
{
auto timerInfo = std::make_shared<TimerInfoTest>();
timerInfo->SetType(1);
timerInfo->SetRepeat(true);
timerInfo->SetInterval(5000);
timerInfo->SetWantAgent(nullptr);
timerInfo->SetCallbackInfo(TimeOutCallback1);
auto timerId1 = TimeServiceClient::GetInstance()->CreateTimer(timerInfo);
EXPECT_TRUE(timerId1 > 0);
auto ret = TimeServiceClient::GetInstance()->StartTimer(timerId1, 1000);
EXPECT_TRUE(ret);
int32_t uid = IPCSkeleton::GetCallingUid();
ret = TimeServiceClient::GetInstance()->ProxyTimer(uid, true);
EXPECT_TRUE(ret);
ret = TimeServiceClient::GetInstance()->ProxyTimer(uid, false);
EXPECT_TRUE(ret);
ret = TimeServiceClient::GetInstance()->StopTimer(timerId1);
EXPECT_TRUE(ret);
ret = TimeServiceClient::GetInstance()->DestroyTimer(timerId1);
EXPECT_TRUE(ret);
}
/**
* @tc.name: ProxyTimer002.
* @tc.desc: proxy timer.
* @tc.type: FUNC
*/
HWTEST_F(TimeServiceTest, ProxyTimer002, TestSize.Level0)
{
auto timerInfo = std::make_shared<TimerInfoTest>();
timerInfo->SetType(1);
timerInfo->SetRepeat(true);
timerInfo->SetInterval(5000);
timerInfo->SetWantAgent(nullptr);
timerInfo->SetCallbackInfo(TimeOutCallback1);
auto timerId1 = TimeServiceClient::GetInstance()->CreateTimer(timerInfo);
EXPECT_TRUE(timerId1 > 0);
auto ret = TimeServiceClient::GetInstance()->StartTimer(timerId1, 1000);
EXPECT_TRUE(ret);
int32_t uid = IPCSkeleton::GetCallingUid();
ret = TimeServiceClient::GetInstance()->ProxyTimer(uid, true);
EXPECT_TRUE(ret);
ret = TimeServiceClient::GetInstance()->ResetAllProxy();
EXPECT_TRUE(ret);
ret = TimeServiceClient::GetInstance()->StopTimer(timerId1);
EXPECT_TRUE(ret);
ret = TimeServiceClient::GetInstance()->DestroyTimer(timerId1);
EXPECT_TRUE(ret);
}
/**
* @tc.name: ProxyTimer003.
* @tc.desc: proxy timer.
* @tc.type: FUNC
*/
HWTEST_F(TimeServiceTest, ProxyTimer003, TestSize.Level0)
{
auto timerInfo = std::make_shared<TimerInfoTest>();
timerInfo->SetType(1);
timerInfo->SetRepeat(true);
timerInfo->SetInterval(5000);
timerInfo->SetWantAgent(nullptr);
timerInfo->SetCallbackInfo(TimeOutCallback1);
auto timerId1 = TimeServiceClient::GetInstance()->CreateTimer(timerInfo);
EXPECT_TRUE(timerId1 > 0);
auto ret = TimeServiceClient::GetInstance()->StartTimer(timerId1, 1000);
EXPECT_TRUE(ret);
int32_t uid = IPCSkeleton::GetCallingUid();
ret = TimeServiceClient::GetInstance()->ProxyTimer(uid, false);
EXPECT_FALSE(ret);
ret = TimeServiceClient::GetInstance()->StopTimer(timerId1);
EXPECT_TRUE(ret);
ret = TimeServiceClient::GetInstance()->DestroyTimer(timerId1);
EXPECT_TRUE(ret);
}
@@ -56,6 +56,8 @@ public:
virtual bool StopTimer(uint64_t timerNumber) = 0;
virtual bool DestroyTimer(uint64_t timerNumber) = 0;
virtual ~ITimerManager() = default;
virtual bool ProxyTimer(int32_t uid, bool isProxy) = 0;
virtual bool ResetAllProxy() = 0;
}; // ITimerManager
} // MiscService
} // OHOS