Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
48a2d415
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
48a2d415
编写于
2月 21, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cfgtest
上级
863ad191
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
226 addition
and
3 deletion
+226
-3
include/libs/config/config.h
include/libs/config/config.h
+1
-1
source/libs/config/CMakeLists.txt
source/libs/config/CMakeLists.txt
+1
-1
source/libs/config/src/config.c
source/libs/config/src/config.c
+25
-0
source/libs/config/test/cfgTest.cpp
source/libs/config/test/cfgTest.cpp
+199
-1
未找到文件。
include/libs/config/config.h
浏览文件 @
48a2d415
...
...
@@ -66,7 +66,7 @@ typedef struct SConfigItem {
ECfgType
stype
;
ECfgUnitType
utype
;
ECfgDataType
dtype
;
c
onst
char
*
name
;
c
har
*
name
;
union
{
bool
boolVal
;
uint8_t
uint8Val
;
...
...
source/libs/config/CMakeLists.txt
浏览文件 @
48a2d415
aux_source_directory
(
src CONFIG_SRC
)
add_library
(
config
${
CONFIG_SRC
}
)
add_library
(
config
STATIC
${
CONFIG_SRC
}
)
target_include_directories
(
config
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/libs/config"
...
...
source/libs/config/src/config.c
浏览文件 @
48a2d415
...
...
@@ -18,6 +18,18 @@
SConfig
*
cfgInit
()
{
SConfig
*
pConfig
=
calloc
(
1
,
sizeof
(
SConfig
));
if
(
pConfig
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
}
pConfig
->
hash
=
taosHashInit
(
64
,
MurmurHash3_32
,
false
,
HASH_NO_LOCK
);
if
(
pConfig
->
hash
==
NULL
)
{
free
(
pConfig
);
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
NULL
;
}
return
pConfig
;
}
...
...
@@ -62,6 +74,19 @@ static int32_t cfgAddItem(SConfig *pConfig, SConfigItem *pItem, const char *name
}
if
(
taosHashPut
(
pConfig
->
hash
,
name
,
strlen
(
name
)
+
1
,
pItem
,
sizeof
(
SConfigItem
))
!=
0
)
{
if
(
pItem
->
dtype
==
CFG_DTYPE_STRING
)
{
free
(
pItem
->
strVal
);
}
else
if
(
pItem
->
dtype
==
CFG_DTYPE_FQDN
)
{
free
(
pItem
->
fqdnVal
);
}
else
if
(
pItem
->
dtype
==
CFG_DTYPE_IPSTR
)
{
free
(
pItem
->
ipstrVal
);
}
else
if
(
pItem
->
dtype
==
CFG_DTYPE_DIR
)
{
free
(
pItem
->
dirVal
);
}
else
if
(
pItem
->
dtype
==
CFG_DTYPE_FILE
)
{
free
(
pItem
->
fileVal
);
}
else
{
}
free
(
pItem
->
name
);
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
...
...
source/libs/config/test/cfgTest.cpp
浏览文件 @
48a2d415
...
...
@@ -21,9 +21,207 @@ class CfgTest : public ::testing::Test {
void
SetUp
()
override
{}
void
TearDown
()
override
{}
void
InitializeConfig
(
SConfig
*
pConfig
);
static
const
char
*
pConfig
;
};
const
char
*
CfgTest
::
pConfig
;
TEST_F
(
CfgTest
,
01
_Taos_File
)
{}
TEST_F
(
CfgTest
,
01
_Basic
)
{
SConfig
*
pConfig
=
cfgInit
();
cfgAddBool
(
pConfig
,
"test_bool"
,
0
,
CFG_UTYPE_NONE
);
cfgAddInt8
(
pConfig
,
"test_int8"
,
1
,
CFG_UTYPE_GB
);
cfgAddUInt8
(
pConfig
,
"test_uint8"
,
2
,
CFG_UTYPE_MB
);
cfgAddInt16
(
pConfig
,
"test_int16"
,
3
,
CFG_UTYPE_BYTE
);
cfgAddUInt16
(
pConfig
,
"test_uint16"
,
4
,
CFG_UTYPE_SECOND
);
cfgAddInt32
(
pConfig
,
"test_int32"
,
5
,
CFG_UTYPE_MS
);
cfgAddUInt32
(
pConfig
,
"test_uint32"
,
6
,
CFG_UTYPE_PERCENT
);
cfgAddInt64
(
pConfig
,
"test_int64"
,
7
,
CFG_UTYPE_NONE
);
cfgAddUInt64
(
pConfig
,
"test_uint64"
,
8
,
CFG_UTYPE_NONE
);
cfgAddFloat
(
pConfig
,
"test_float"
,
9
,
CFG_UTYPE_NONE
);
cfgAddDouble
(
pConfig
,
"test_double"
,
10
,
CFG_UTYPE_NONE
);
cfgAddString
(
pConfig
,
"test_string"
,
"11"
,
CFG_UTYPE_NONE
);
cfgAddFqdn
(
pConfig
,
"test_fqdn"
,
"localhost"
,
CFG_UTYPE_NONE
);
cfgAddIpStr
(
pConfig
,
"test_ipstr"
,
"192.168.0.1"
,
CFG_UTYPE_NONE
);
cfgAddDir
(
pConfig
,
"test_dir"
,
"/tmp"
,
CFG_UTYPE_NONE
);
cfgAddFile
(
pConfig
,
"test_file"
,
"/tmp/file1"
,
CFG_UTYPE_NONE
);
EXPECT_EQ
(
cfgGetSize
(
pConfig
),
16
);
int32_t
size
=
0
;
SConfigItem
*
pItem
=
cfgIterate
(
pConfig
,
NULL
);
while
(
pItem
!=
NULL
)
{
pItem
=
cfgIterate
(
pConfig
,
pItem
);
switch
(
pItem
->
dtype
)
{
case
CFG_DTYPE_BOOL
:
printf
(
"cfg:%s, value:%d
\n
"
,
pItem
->
name
,
pItem
->
boolVal
);
break
;
CFG_DTYPE_INT8:
printf
(
"cfg:%s, value:%d
\n
"
,
pItem
->
name
,
pItem
->
uint8Val
);
break
;
CFG_DTYPE_UINT8:
printf
(
"cfg:%s, value:%d
\n
"
,
pItem
->
name
,
pItem
->
int8Val
);
break
;
CFG_DTYPE_INT16:
printf
(
"cfg:%s, value:%d
\n
"
,
pItem
->
name
,
pItem
->
uint16Val
);
break
;
CFG_DTYPE_UINT16:
printf
(
"cfg:%s, value:%d
\n
"
,
pItem
->
name
,
pItem
->
int16Val
);
break
;
CFG_DTYPE_INT32:
printf
(
"cfg:%s, value:%d
\n
"
,
pItem
->
name
,
pItem
->
uint32Val
);
break
;
CFG_DTYPE_UINT32:
printf
(
"cfg:%s, value:%d
\n
"
,
pItem
->
name
,
pItem
->
int32Val
);
break
;
CFG_DTYPE_INT64:
printf
(
"cfg:%s, value:%"
PRIu64
,
pItem
->
name
,
pItem
->
uint64Val
);
break
;
CFG_DTYPE_UINT64:
printf
(
"cfg:%s, value:%"
PRId64
,
pItem
->
name
,
pItem
->
int64Val
);
break
;
CFG_DTYPE_FLOAT:
printf
(
"cfg:%s, value:%f
\n
"
,
pItem
->
name
,
pItem
->
floatVal
);
break
;
CFG_DTYPE_DOUBLE:
printf
(
"cfg:%s, value:%f
\n
"
,
pItem
->
name
,
pItem
->
doubleVal
);
break
;
CFG_DTYPE_STRING:
printf
(
"cfg:%s, value:%s
\n
"
,
pItem
->
name
,
pItem
->
strVal
);
break
;
CFG_DTYPE_FQDN:
printf
(
"cfg:%s, value:%s
\n
"
,
pItem
->
name
,
pItem
->
fqdnVal
);
break
;
CFG_DTYPE_IPSTR:
printf
(
"cfg:%s, value:%s
\n
"
,
pItem
->
name
,
pItem
->
ipstrVal
);
break
;
CFG_DTYPE_DIR:
printf
(
"cfg:%s, value:%s
\n
"
,
pItem
->
name
,
pItem
->
dirVal
);
break
;
CFG_DTYPE_FILE:
printf
(
"cfg:%s, value:%s
\n
"
,
pItem
->
name
,
pItem
->
fileVal
);
break
;
default:
break
;
}
size
++
;
}
cfgCancelIterate
(
pConfig
,
pItem
);
EXPECT_EQ
(
cfgGetSize
(
pConfig
),
16
);
pItem
=
cfgGetItem
(
pConfig
,
"test_bool"
);
EXPECT_EQ
(
pItem
->
stype
,
CFG_TYPE_DEFAULT
);
EXPECT_EQ
(
pItem
->
utype
,
CFG_UTYPE_NONE
);
EXPECT_EQ
(
pItem
->
dtype
,
CFG_DTYPE_BOOL
);
EXPECT_STREQ
(
pItem
->
name
,
"test_bool"
);
EXPECT_EQ
(
pItem
->
boolVal
,
0
);
pItem
=
cfgGetItem
(
pConfig
,
"test_int8"
);
EXPECT_EQ
(
pItem
->
stype
,
CFG_TYPE_DEFAULT
);
EXPECT_EQ
(
pItem
->
utype
,
CFG_UTYPE_GB
);
EXPECT_EQ
(
pItem
->
dtype
,
CFG_DTYPE_INT8
);
EXPECT_STREQ
(
pItem
->
name
,
"test_int8"
);
EXPECT_EQ
(
pItem
->
int8Val
,
1
);
pItem
=
cfgGetItem
(
pConfig
,
"test_uint8"
);
EXPECT_EQ
(
pItem
->
stype
,
CFG_TYPE_DEFAULT
);
EXPECT_EQ
(
pItem
->
utype
,
CFG_UTYPE_MB
);
EXPECT_EQ
(
pItem
->
dtype
,
CFG_DTYPE_UINT8
);
EXPECT_STREQ
(
pItem
->
name
,
"test_uint8"
);
EXPECT_EQ
(
pItem
->
uint8Val
,
2
);
pItem
=
cfgGetItem
(
pConfig
,
"test_int16"
);
EXPECT_EQ
(
pItem
->
stype
,
CFG_TYPE_DEFAULT
);
EXPECT_EQ
(
pItem
->
utype
,
CFG_UTYPE_BYTE
);
EXPECT_EQ
(
pItem
->
dtype
,
CFG_DTYPE_INT16
);
EXPECT_STREQ
(
pItem
->
name
,
"test_int16"
);
EXPECT_EQ
(
pItem
->
int16Val
,
3
);
pItem
=
cfgGetItem
(
pConfig
,
"test_uint16"
);
EXPECT_EQ
(
pItem
->
stype
,
CFG_TYPE_DEFAULT
);
EXPECT_EQ
(
pItem
->
utype
,
CFG_UTYPE_SECOND
);
EXPECT_EQ
(
pItem
->
dtype
,
CFG_DTYPE_UINT16
);
EXPECT_STREQ
(
pItem
->
name
,
"test_uint16"
);
EXPECT_EQ
(
pItem
->
uint16Val
,
4
);
pItem
=
cfgGetItem
(
pConfig
,
"test_int32"
);
EXPECT_EQ
(
pItem
->
stype
,
CFG_TYPE_DEFAULT
);
EXPECT_EQ
(
pItem
->
utype
,
CFG_UTYPE_MS
);
EXPECT_EQ
(
pItem
->
dtype
,
CFG_DTYPE_INT32
);
EXPECT_STREQ
(
pItem
->
name
,
"test_int32"
);
EXPECT_EQ
(
pItem
->
int32Val
,
5
);
pItem
=
cfgGetItem
(
pConfig
,
"test_uint32"
);
EXPECT_EQ
(
pItem
->
stype
,
CFG_TYPE_DEFAULT
);
EXPECT_EQ
(
pItem
->
utype
,
CFG_UTYPE_PERCENT
);
EXPECT_EQ
(
pItem
->
dtype
,
CFG_DTYPE_UINT32
);
EXPECT_STREQ
(
pItem
->
name
,
"test_uint32"
);
EXPECT_EQ
(
pItem
->
uint32Val
,
6
);
pItem
=
cfgGetItem
(
pConfig
,
"test_int64"
);
EXPECT_EQ
(
pItem
->
stype
,
CFG_TYPE_DEFAULT
);
EXPECT_EQ
(
pItem
->
utype
,
CFG_UTYPE_SECOND
);
EXPECT_EQ
(
pItem
->
dtype
,
CFG_UTYPE_NONE
);
EXPECT_STREQ
(
pItem
->
name
,
"test_int64"
);
EXPECT_EQ
(
pItem
->
int64Val
,
7
);
pItem
=
cfgGetItem
(
pConfig
,
"test_uint64"
);
EXPECT_EQ
(
pItem
->
stype
,
CFG_TYPE_DEFAULT
);
EXPECT_EQ
(
pItem
->
utype
,
CFG_UTYPE_NONE
);
EXPECT_EQ
(
pItem
->
dtype
,
CFG_DTYPE_UINT64
);
EXPECT_STREQ
(
pItem
->
name
,
"test_uint64"
);
EXPECT_EQ
(
pItem
->
uint64Val
,
8
);
pItem
=
cfgGetItem
(
pConfig
,
"test_float"
);
EXPECT_EQ
(
pItem
->
stype
,
CFG_TYPE_DEFAULT
);
EXPECT_EQ
(
pItem
->
utype
,
CFG_UTYPE_NONE
);
EXPECT_EQ
(
pItem
->
dtype
,
CFG_DTYPE_FLOAT
);
EXPECT_STREQ
(
pItem
->
name
,
"test_float"
);
EXPECT_EQ
(
pItem
->
floatVal
,
9
);
pItem
=
cfgGetItem
(
pConfig
,
"test_double"
);
EXPECT_EQ
(
pItem
->
stype
,
CFG_TYPE_DEFAULT
);
EXPECT_EQ
(
pItem
->
utype
,
CFG_UTYPE_NONE
);
EXPECT_EQ
(
pItem
->
dtype
,
CFG_DTYPE_DOUBLE
);
EXPECT_STREQ
(
pItem
->
name
,
"test_double"
);
EXPECT_EQ
(
pItem
->
doubleVal
,
10
);
pItem
=
cfgGetItem
(
pConfig
,
"test_string"
);
EXPECT_EQ
(
pItem
->
stype
,
CFG_TYPE_DEFAULT
);
EXPECT_EQ
(
pItem
->
utype
,
CFG_UTYPE_NONE
);
EXPECT_EQ
(
pItem
->
dtype
,
CFG_DTYPE_STRING
);
EXPECT_STREQ
(
pItem
->
name
,
"test_string"
);
EXPECT_STREQ
(
pItem
->
strVal
,
"11"
);
pItem
=
cfgGetItem
(
pConfig
,
"test_fqdn"
);
EXPECT_EQ
(
pItem
->
stype
,
CFG_TYPE_DEFAULT
);
EXPECT_EQ
(
pItem
->
utype
,
CFG_UTYPE_NONE
);
EXPECT_EQ
(
pItem
->
dtype
,
CFG_DTYPE_FQDN
);
EXPECT_STREQ
(
pItem
->
name
,
"test_fqdn"
);
EXPECT_STREQ
(
pItem
->
strVal
,
"localhost"
);
pItem
=
cfgGetItem
(
pConfig
,
"test_ipstr"
);
EXPECT_EQ
(
pItem
->
stype
,
CFG_TYPE_DEFAULT
);
EXPECT_EQ
(
pItem
->
utype
,
CFG_UTYPE_NONE
);
EXPECT_EQ
(
pItem
->
dtype
,
CFG_DTYPE_IPSTR
);
EXPECT_STREQ
(
pItem
->
name
,
"test_ipstr"
);
EXPECT_STREQ
(
pItem
->
ipstrVal
,
"192.168.0.1"
);
pItem
=
cfgGetItem
(
pConfig
,
"test_dir"
);
EXPECT_EQ
(
pItem
->
stype
,
CFG_TYPE_DEFAULT
);
EXPECT_EQ
(
pItem
->
utype
,
CFG_UTYPE_NONE
);
EXPECT_EQ
(
pItem
->
dtype
,
CFG_DTYPE_DIR
);
EXPECT_STREQ
(
pItem
->
name
,
"test_dir"
);
EXPECT_STREQ
(
pItem
->
dirVal
,
"/tmp"
);
pItem
=
cfgGetItem
(
pConfig
,
"test_file"
);
EXPECT_EQ
(
pItem
->
stype
,
CFG_TYPE_DEFAULT
);
EXPECT_EQ
(
pItem
->
utype
,
CFG_UTYPE_NONE
);
EXPECT_EQ
(
pItem
->
dtype
,
CFG_DTYPE_FILE
);
EXPECT_STREQ
(
pItem
->
name
,
"test_file"
);
EXPECT_STREQ
(
pItem
->
fileVal
,
"/tmp/file1"
);
cfgCleanup
(
pConfig
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录