Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
bf901d20
S
Startup Init Lite
项目概览
OpenHarmony
/
Startup Init Lite
接近 2 年 前同步成功
通知
3
Star
37
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Startup Init Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
bf901d20
编写于
9月 23, 2022
作者:
C
chengjinsong2
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
添加service_watcher moduletest
Signed-off-by:
N
chengjinsong2
<
chengjinsong2@huawei.com
>
上级
dada4574
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
79 addition
and
4 deletion
+79
-4
interfaces/innerkits/syspara/parameter.c
interfaces/innerkits/syspara/parameter.c
+3
-3
test/moduletest/BUILD.gn
test/moduletest/BUILD.gn
+8
-1
test/moduletest/service_watcher_moduleTest.cpp
test/moduletest/service_watcher_moduleTest.cpp
+68
-0
未找到文件。
interfaces/innerkits/syspara/parameter.c
浏览文件 @
bf901d20
...
...
@@ -320,14 +320,14 @@ int32_t GetIntParameter(const char *key, int32_t def)
{
char
value
[
MAX_INT_LEN
]
=
{
0
};
int
ret
=
GetParameter
(
key
,
"0"
,
value
,
sizeof
(
value
));
if
(
ret
!=
0
)
{
if
(
ret
<
0
)
{
return
def
;
}
long
long
int
result
=
0
;
if
(
StringToLL
(
value
,
&
result
)
!=
0
)
{
return
def
;
}
if
(
result
<=
INT32_MIN
&&
result
>=
INT32_MAX
)
{
if
(
result
<=
INT32_MIN
||
result
>=
INT32_MAX
)
{
return
def
;
}
return
(
int32_t
)
result
;
...
...
@@ -337,7 +337,7 @@ uint32_t GetUintParameter(const char *key, uint32_t def)
{
char
value
[
MAX_INT_LEN
]
=
{
0
};
int
ret
=
GetParameter
(
key
,
"0"
,
value
,
sizeof
(
value
));
if
(
ret
!=
0
)
{
if
(
ret
<
0
)
{
return
def
;
}
unsigned
long
long
int
result
=
0
;
...
...
test/moduletest/BUILD.gn
浏览文件 @
bf901d20
...
...
@@ -49,11 +49,18 @@ ohos_moduletest("InitModuleTest") {
sources = [
"hookmgr_moduletest.cpp",
"modulemgr_moduletest.cpp",
"service_watcher_moduleTest.cpp",
]
include_dirs = [ "//base/startup/init/interfaces/innerkits/include" ]
include_dirs = [
"//base/startup/init/interfaces/innerkits/include",
"//base/startup/init/interfaces/innerkits/include/syspara",
"//base/startup/init/interfaces/innerkits/syspara",
"//base/startup/init/services/include/param",
]
deps = [
"//base/startup/init/interfaces/innerkits:libbeget_proxy",
"//base/startup/init/interfaces/innerkits:libbegetutil",
"//third_party/googletest:gtest_main",
]
...
...
test/moduletest/service_watcher_moduleTest.cpp
0 → 100644
浏览文件 @
bf901d20
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <thread>
#include <string>
#include <gtest/gtest.h>
#include "service_control.h"
#include "service_watcher.h"
#include "test_utils.h"
using
namespace
testing
::
ext
;
namespace
initModuleTest
{
class
serviceWatcherModuleTest
:
public
testing
::
Test
{
public:
static
void
SetUpTestCase
(
void
)
{};
static
void
TearDownTestCase
(
void
)
{};
void
SetUp
(
void
)
{};
void
TearDown
(
void
)
{};
};
static
void
ServiceStatusChange
(
const
char
*
key
,
ServiceStatus
status
)
{
std
::
cout
<<
"service Name is: "
<<
key
<<
", ServiceStatus is: "
<<
status
<<
std
::
endl
;
}
HWTEST_F
(
serviceWatcherModuleTest
,
serviceWatcher_test_001
,
TestSize
.
Level0
)
{
GTEST_LOG_
(
INFO
)
<<
"serviceWatcher_test_001 start"
;
string
serviceName
=
"test.Service"
;
int
ret
=
ServiceWatchForStatus
(
serviceName
.
c_str
(),
ServiceStatusChange
);
EXPECT_EQ
(
ret
,
0
);
// No matter if service exist or not, ServiceWatchForStatus always success.
auto
status
=
GetServiceStatus
(
serviceName
);
EXPECT_TRUE
(
status
.
empty
());
GTEST_LOG_
(
INFO
)
<<
"serviceWatcher_test_001 end"
;
}
HWTEST_F
(
serviceWatcherModuleTest
,
serviceWatcher_test_002
,
TestSize
.
Level0
)
{
GTEST_LOG_
(
INFO
)
<<
"serviceWatcher_test_002 start"
;
string
serviceName
=
"media_service"
;
auto
status
=
GetServiceStatus
(
serviceName
);
if
(
status
==
"running"
)
{
int
ret
=
ServiceControl
(
serviceName
.
c_str
(),
STOP
);
ASSERT_EQ
(
ret
,
0
);
}
else
if
(
status
!=
"created"
&&
status
!=
"stopped"
)
{
std
::
cout
<<
serviceName
<<
" in invalid status "
<<
status
<<
std
::
endl
;
ASSERT_TRUE
(
0
);
}
int
ret
=
ServiceWatchForStatus
(
serviceName
.
c_str
(),
ServiceStatusChange
);
EXPECT_EQ
(
ret
,
0
);
status
=
GetServiceStatus
(
serviceName
);
EXPECT_TRUE
(
status
==
"stopped"
);
GTEST_LOG_
(
INFO
)
<<
"serviceWatcher_test_002 end"
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录