From 63da7430c795c4bbc0aa989bfac5fbd37cc6337f Mon Sep 17 00:00:00 2001 From: chengjinsong2 Date: Tue, 18 Oct 2022 18:20:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=87=BD=E6=95=B0BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chengjinsong2 --- interfaces/innerkits/syspara/parameter.c | 12 ++++++++---- test/unittest/syspara/syspara_unittest.cpp | 2 ++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/interfaces/innerkits/syspara/parameter.c b/interfaces/innerkits/syspara/parameter.c index b7c914df..c8b0f6df 100644 --- a/interfaces/innerkits/syspara/parameter.c +++ b/interfaces/innerkits/syspara/parameter.c @@ -322,10 +322,12 @@ const char *GetBuildRootHash(void) 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) { + size_t size = sizeof(value); + int ret = SystemGetParameter(key, value, &size); + if (ret != 0) { return def; } + long long int result = 0; if (StringToLL(value, &result) != 0) { return def; @@ -339,10 +341,12 @@ int32_t GetIntParameter(const char *key, int32_t def) 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) { + size_t size = sizeof(value); + int ret = SystemGetParameter(key, value, &size); + if (ret != 0) { return def; } + unsigned long long int result = 0; if (StringToULL(value, &result) != 0) { return def; diff --git a/test/unittest/syspara/syspara_unittest.cpp b/test/unittest/syspara/syspara_unittest.cpp index c822bc03..f484c284 100644 --- a/test/unittest/syspara/syspara_unittest.cpp +++ b/test/unittest/syspara/syspara_unittest.cpp @@ -282,6 +282,8 @@ HWTEST_F(SysparaUnitTest, parameterTest0013, TestSize.Level0) EXPECT_EQ(GetUintParameter("test.int.get", 0), 0); EXPECT_EQ(GetIntParameter("test.uint.get", 0), TEST_VALUE); EXPECT_EQ(GetUintParameter("test.uint.get", 0), TEST_VALUE); + EXPECT_EQ(GetIntParameter("test.int.default", 10), 10); //key not find,value = default + EXPECT_EQ(GetUintParameter("test.uint.default", 10), 10); //key not find,value = default EXPECT_EQ(IsValidParamValue(nullptr, 0), 0); EXPECT_EQ(IsValidParamValue("testvalue", strlen("testvalue") + 1), 1); EXPECT_EQ(StringToLL("0x11", &out), 0); -- GitLab