diff --git a/aw/cxx/distributed/distributed.h b/aw/cxx/distributed/distributed.h index 857e2630bafd435cf776cfd48d1dbcc9218f00c1..44c712f8ea2848ead9b1ee2b9221fcf4ae082745 100644 --- a/aw/cxx/distributed/distributed.h +++ b/aw/cxx/distributed/distributed.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef _DISTRIBUTED_H_ -#define _DISTRIBUTED_H_ +#ifndef AW_CXX_DISTRIBUTED_DISTRIBUTED_H_ +#define AW_CXX_DISTRIBUTED_DISTRIBUTED_H_ #include #include "securec.h" @@ -50,4 +50,4 @@ using DistDeviceInfo = DistDevInfo; } // namespace DistributeSystemTest } // namespace OHOS -#endif // _DISTRIBUTED_H_ +#endif // AW_CXX_DISTRIBUTED_DISTRIBUTED_H_ diff --git a/aw/cxx/distributed/distributed_agent.cpp b/aw/cxx/distributed/distributed_agent.cpp index 3734a5ee7496016961693f2c3070ad36d9d20611..72a90a9a1bfcad6978248456977166fa684e4884 100644 --- a/aw/cxx/distributed/distributed_agent.cpp +++ b/aw/cxx/distributed/distributed_agent.cpp @@ -85,7 +85,11 @@ int DistributedAgent::InitAgentServer() } struct sockaddr_in addr; - memset_s(&addr, sizeof(addr), 0, sizeof(addr)); + errno_t ret = EOK; + ret = memset_s(&addr, sizeof(addr), 0, sizeof(addr)); + if (ret != EOK) { + return -1; + } addr.sin_family = AF_INET; if (agentIpAddr_ != "") { inet_pton(AF_INET, agentIpAddr_.c_str(), &addr.sin_addr); @@ -203,7 +207,8 @@ int DistributedAgent::DoCmdServer(int serverSockFd) auto pclinereturn = reinterpret_cast(returnValue); pclinereturn->no = pcline->no; pclinereturn->cmdTestType = htons(DST_COMMAND_CALL); - sprintf_s(pclinereturn->alignmentCmd, (MAX_BUFF_LEN - DST_COMMAND_HEAD_LEN), "%d", nresult); + (void)sprintf_s(pclinereturn->alignmentCmd, (MAX_BUFF_LEN - DST_COMMAND_HEAD_LEN), + "%d", nresult) < 0); rlen = strlen(pclinereturn->alignmentCmd) + 1; pclinereturn->len = htons(rlen); HiLog::Info(DistributedAgent::LABEL, "agent get message :%s .\n", @@ -413,4 +418,4 @@ int DistributedAgent::Stop() return 0; } } // namespace DistributeSystemTest -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/aw/cxx/distributed/distributed_agent.h b/aw/cxx/distributed/distributed_agent.h index 2a5aced4b5f6557238a372c1f848e387e34f1b19..cb5af1d383bd91a2c04c8cc7e73e39ed22feb4f6 100644 --- a/aw/cxx/distributed/distributed_agent.h +++ b/aw/cxx/distributed/distributed_agent.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef DISTRIBUTED_AGENT_H -#define DISTRIBUTED_AGENT_H +#ifndef AW_CXX_DISTRIBUTED_DISTRIBUTED_AGENT_H_ +#define AW_CXX_DISTRIBUTED_DISTRIBUTED_AGENT_H_ #include #include @@ -47,7 +47,7 @@ public: protected: virtual bool SetUp(); virtual bool TearDown(); - virtual void OnLocalInit() {}; + virtual void OnLocalInit() {} virtual int OnProcessCmd(const std::string &strCommand, int cmdLen, const std::string &strArgs, int argsLen, const std::string &strExpectValue, int expectValueLen); virtual int OnProcessMsg(const std::string &strMsg, int msgLen, std::string &strReturnValue, int returnBufLen); @@ -69,4 +69,5 @@ private: } // namespace DistributeSystemTest } // namespace OHOS -#endif // DISTRIBUTED_AGENT_H +#endif // AW_CXX_DISTRIBUTED_DISTRIBUTED_AGENT_H_ + diff --git a/aw/cxx/distributed/distributed_cfg.cpp b/aw/cxx/distributed/distributed_cfg.cpp index ad64fc60cd9dff2a19c7acdcdb5e5188a8932c1d..3addc39245cd5b272c34e881d52a71e97c7c2ac3 100644 --- a/aw/cxx/distributed/distributed_cfg.cpp +++ b/aw/cxx/distributed/distributed_cfg.cpp @@ -160,4 +160,4 @@ std::unique_ptr& DistributedCfg::GetInstance() std::unique_ptr DistributedCfg::getCfg_ = nullptr; } // namespace DistributeSystemTest -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/aw/cxx/distributed/distributed_cfg.h b/aw/cxx/distributed/distributed_cfg.h index e8fb0a1f6a3fe92d5dbbf46f369c25c630bddc3d..e9766e4881468fad763ee911216245b3e07aed65 100644 --- a/aw/cxx/distributed/distributed_cfg.h +++ b/aw/cxx/distributed/distributed_cfg.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef DISTRIBUTED_CFG_H -#define DISTRIBUTED_CFG_H +#ifndef AW_CXX_DISTRIBUTED_DISTRIBUTED_CFG_H_ +#define AW_CXX_DISTRIBUTED_DISTRIBUTED_CFG_H_ #include #include @@ -52,4 +52,5 @@ private: }; } // namespace DistributeSystemTest } // namespace OHOS -#endif \ No newline at end of file + +#endif // AW_CXX_DISTRIBUTED_DISTRIBUTED_CFG_H_ diff --git a/aw/cxx/distributed/distributed_major.cpp b/aw/cxx/distributed/distributed_major.cpp index 98d2d67901e4e3014c28d2e56577b933690aefd0..43c2f89a1dffe841939bedd4a4c1dc75a65949dc 100644 --- a/aw/cxx/distributed/distributed_major.cpp +++ b/aw/cxx/distributed/distributed_major.cpp @@ -504,4 +504,4 @@ bool DistributeTest::Notify(AGENT_NO devNo, const std::string ¬ifyType, const return false; } } // namespace DistributeSystemTest -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/aw/cxx/distributed/distributed_major.h b/aw/cxx/distributed/distributed_major.h index 1acb3dd587e62cf7466b0d52f6ec2d1b4d24c432..cb913a61344f74ce4f3bd70aa9f35d0e4c6961cb 100644 --- a/aw/cxx/distributed/distributed_major.h +++ b/aw/cxx/distributed/distributed_major.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef DISTRIBUTED_MAJOR_H -#define DISTRIBUTED_MAJOR_H +#ifndef AW_CXX_DISTRIBUTED_DISTRIBUTED_MAJOR_H_ +#define AW_CXX_DISTRIBUTED_DISTRIBUTED_MAJOR_H_ #include #include @@ -92,7 +92,7 @@ protected: int GetReturnVal(); private: - void OnProcessNotify() {}; + void OnProcessNotify() {} int returnVal_; static void SetUpTestCase(void); @@ -101,14 +101,14 @@ private: // init network environment, obtain all the address of agent and connect int InitEnv(std::vector clientList); - virtual void SetUp() {}; - virtual void TearDown() {}; + virtual void SetUp() {} + virtual void TearDown() {} - virtual void OnNotify() {}; + virtual void OnNotify() {} virtual bool OnProcessValue(const std::string &szbuf, int len); virtual bool OnMsgProc(const std::string &szbuf, int len); }; } // namespace DistributeSystemTest } // namespace OHOS -#endif // DISTRIBUTED_MAJOR_H \ No newline at end of file +#endif // AW_CXX_DISTRIBUTED_DISTRIBUTED_MAJOR_H_ diff --git a/aw/cxx/distributed/utils/csv_transform_xml.h b/aw/cxx/distributed/utils/csv_transform_xml.h index 89b20883b7ba7a3e400d79cb757ed91142eb1992..abb59a25e98b95844602b545436be47b2c60bc7e 100644 --- a/aw/cxx/distributed/utils/csv_transform_xml.h +++ b/aw/cxx/distributed/utils/csv_transform_xml.h @@ -13,8 +13,9 @@ * limitations under the License. */ -#ifndef UNTITLED_CSV_TO_XML_H -#define UNTITLED_CSV_TO_XML_H +#ifndef AW_CXX_DISTRIBUTED_UTILS_CSV_TRANSFORM_XML_H_ +#define AW_CXX_DISTRIBUTED_UTILS_CSV_TRANSFORM_XML_H_ + #include #include #include @@ -35,7 +36,7 @@ class CsvTransformXml { public: - CsvTransformXml(std::string targetFile) + explicit CsvTransformXml(std::string targetFile) { SetFileName(targetFile); SetCvsFileName(); @@ -137,4 +138,5 @@ public: } }; -#endif // UNTITLED_CVS_TO_XML_H +#endif // AW_CXX_DISTRIBUTED_UTILS_CSV_TRANSFORM_XML_H_ + diff --git a/aw/cxx/hwext/perf.cpp b/aw/cxx/hwext/perf.cpp index 5e59bf45102ca263919497cf15074b03887e8207..728e5224797ffa5abbb7faec4b8208f17c928599 100644 --- a/aw/cxx/hwext/perf.cpp +++ b/aw/cxx/hwext/perf.cpp @@ -32,8 +32,6 @@ namespace TestAW { #define ID_LARGER_IS_BETTER true #define ID_SMALLER_IS_BETTER false -#define _max(a,b) (((a)>=(b)) ? (a) : (b) ) -#define _min(a,b) (((a)<=(b)) ? (a) : (b)) namespace { const auto XML_TAG_ROOT = "configuration"; @@ -182,7 +180,7 @@ GtestPerfTestCase::GtestPerfTestCase(BaseLineManager* pManager, // get test case name from GTEST API. // should be use tester->XXX() instead of this. - if (tester != nullptr) { + if (tester != nullptr && ::testing::UnitTest::GetInstance() != nullptr) { m_strCaseName = string(::testing::UnitTest::GetInstance()->current_test_info()->name()); } @@ -284,11 +282,11 @@ bool GtestPerfTestCase::ExpectValue(double testValue, bool isLargerBetter) } else { double baseValue = -1; if (isLargerBetter) { - baseValue = _max(m_dbLastValue, m_dbBaseLine); + baseValue = (m_dbLastValue >= m_dbBaseLine) ? m_dbLastValue : m_dbBaseLine; EXPECT_GE(testValue, (baseValue * (1.0 - m_dbFloatRange))); m_bTestResult = (testValue >= (baseValue * (1.0 - m_dbFloatRange))) ? true : false; } else { - baseValue = _min(m_dbLastValue, m_dbBaseLine); + baseValue = (m_dbLastValue <= m_dbBaseLine) ? m_dbLastValue : m_dbBaseLine; EXPECT_LE(testValue, (baseValue * (1.0 + m_dbFloatRange))); m_bTestResult = (testValue <= (baseValue * (1.0 + m_dbFloatRange))) ? true : false; } @@ -311,22 +309,22 @@ bool GtestPerfTestCase::SaveResult(double testValue) INF_MSG("[ PERF ] %s: baseline:%f, test_result: %f\n", m_strCaseName.c_str(), m_dbBaseLine, testValue); - memset_s(buffer, sizeof(buffer), 0, sizeof(buffer)); + (void)memset_s(buffer, sizeof(buffer), 0, sizeof(buffer)); if (snprintf_s(buffer, sizeof(buffer), sizeof(buffer) - 1, "%g", m_dbBaseLine) > 0) { m_pTester->RecordProperty("baseline", buffer); } - memset_s(buffer, sizeof(buffer), 0, sizeof(buffer)); + (void)memset_s(buffer, sizeof(buffer), 0, sizeof(buffer)); if (snprintf_s(buffer, sizeof(buffer), sizeof(buffer) - 1, "%d", m_dCaseVersion) > 0) { m_pTester->RecordProperty("tc_version", buffer); } - memset_s(buffer, sizeof(buffer), 0, sizeof(buffer)); + (void)memset_s(buffer, sizeof(buffer), 0, sizeof(buffer)); if (snprintf_s(buffer, sizeof(buffer), sizeof(buffer) - 1, "%g", m_dbLastValue) > 0) { m_pTester->RecordProperty("lastvalue", m_bHasLastValue ? buffer : ""); } - memset_s(buffer, sizeof(buffer), 0, sizeof(buffer)); + (void)memset_s(buffer, sizeof(buffer), 0, sizeof(buffer)); if (snprintf_s(buffer, sizeof(buffer), sizeof(buffer) - 1, "%g", testValue) > 0) { m_pTester->RecordProperty("value", buffer); } @@ -337,5 +335,5 @@ bool GtestPerfTestCase::SaveResult(double testValue) return true; } -} // TestAW -} // OHOS \ No newline at end of file +} // namespace TestAW +} // namespace OHOS diff --git a/aw/cxx/hwext/perf.h b/aw/cxx/hwext/perf.h index 2ce761100996d0ad63f1cf8010af4bd40d3552b9..8dabe4f22a215d70c32c6a91ea4da4aa733c2a5f 100644 --- a/aw/cxx/hwext/perf.h +++ b/aw/cxx/hwext/perf.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef TEST_AW_CXX_HWEXT_PERF_H -#define TEST_AW_CXX_HWEXT_PERF_H +#ifndef AW_CXX_HWEXT_PERF_H_ +#define AW_CXX_HWEXT_PERF_H_ #include #include @@ -80,7 +80,7 @@ public: std::string testClassName = "", std::string testInterfaceName = ""); - ~GtestPerfTestCase() {}; + ~GtestPerfTestCase() {} // expect result is larger than or equal baseline*(1.0-float_range). bool ExpectLarger(double testValue); @@ -164,6 +164,7 @@ private: bool m_bTestResult; double m_dbTestResult; }; -} // TestAW -} // OHOS -#endif // TEST_AW_CXX_HWEXT_PERF_H \ No newline at end of file +} // namespace TestAW +} // namespace OHOS + +#endif // AW_CXX_HWEXT_PERF_H_ diff --git a/examples/calculator/test/fuzztest/common/parse_fuzzer/parse_fuzzer.cpp b/examples/calculator/test/fuzztest/common/parse_fuzzer/parse_fuzzer.cpp index e09b54ef388eb7c8b6dcac102ddeebb8103d2a67..beead983a4a1e81b5ad1837869849d7d71797503 100644 --- a/examples/calculator/test/fuzztest/common/parse_fuzzer/parse_fuzzer.cpp +++ b/examples/calculator/test/fuzztest/common/parse_fuzzer/parse_fuzzer.cpp @@ -25,6 +25,10 @@ const int FUZZ_FTH_DATA = 3; namespace OHOS { bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) { + if (data == nullptr) { + return false; + } + bool result = false; if (size >= FUZZ_DATA_LEN) { result = data[FUZZ_FST_DATA] == 'F' && @@ -34,7 +38,7 @@ namespace OHOS { } return result; } -} +} // namespace.OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) diff --git a/examples/detector/src/detector.cpp b/examples/detector/src/detector.cpp index 7392964c54ae83a1d0f98ef795266e3ed93b432f..9f84764ba2144982c3e0dfb3ce0d197a6905ece8 100644 --- a/examples/detector/src/detector.cpp +++ b/examples/detector/src/detector.cpp @@ -50,6 +50,9 @@ bool IsPrime(int n) bool FileExist(const char* fileName) { + if (fileName == nullptr) { + return false; + } struct stat myStat; return (!stat(fileName, &myStat)); } diff --git a/examples/distributedb/test/distributedtest/common/distribute_demo.cpp b/examples/distributedb/test/distributedtest/common/distribute_demo.cpp index eec2dff17fc0f82baab930c4c5b1aca8784fa43d..f485b7f58cfea055cf510285886d03f18d5406e6 100644 --- a/examples/distributedb/test/distributedtest/common/distribute_demo.cpp +++ b/examples/distributedb/test/distributedtest/common/distribute_demo.cpp @@ -45,11 +45,11 @@ public: DistributeDemo() = default; ~DistributeDemo() = default; - static void SetUpTestCase(void) {}; - static void TearDownTestCase(void) {}; + static void SetUpTestCase(void) {} + static void TearDownTestCase(void) {} - virtual void SetUp() {}; - virtual void TearDown() {}; + virtual void SetUp() {} + virtual void TearDown() {} }; /** @@ -252,4 +252,4 @@ int main(int argc, char *argv[]) testing::GTEST_FLAG(output) = "xml:./"; testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); -} \ No newline at end of file +} diff --git a/examples/lite/c_demo/include/calc_multi.h b/examples/lite/c_demo/include/calc_multi.h index 439809c5e35738c520f1b6c37f93c3571c307f3d..1bbda7f0405842b810ed0066ffc9c3e31a487360 100644 --- a/examples/lite/c_demo/include/calc_multi.h +++ b/examples/lite/c_demo/include/calc_multi.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef SERVICEDEMO_CALC_MULTI_H -#define SERVICEDEMO_CALC_MULTI_H +#ifndef EXAMPLE_LITE_C_DEMO_INCLUDE_CALC_MULTI_H_ +#define EXAMPLE_LITE_C_DEMO_INCLUDE_CALC_MULTI_H_ #ifdef __cplusplus #if __cplusplus @@ -30,4 +30,4 @@ int calc_multi(int a, int b); #endif #endif -#endif // SERVICEDEMO_CALC_MULTI_H +#endif // EXAMPLE_LITE_C_DEMO_INCLUDE_CALC_MULTI_H_ diff --git a/examples/sleep/test/performance/common/spent_time_test.cpp b/examples/sleep/test/performance/common/spent_time_test.cpp index b96b9475aa6b368a1d2df6f5672b03641e24c95b..421ffded7912dd3a614aa45b4685361f12e591ee 100644 --- a/examples/sleep/test/performance/common/spent_time_test.cpp +++ b/examples/sleep/test/performance/common/spent_time_test.cpp @@ -24,19 +24,19 @@ using namespace OHOS::TestAW; static BaseLineManager m_baseline(PERF_BASELINE_CONFIG_PATH); class SpentTimeTest : public testing::Test { public: - static void SetUpTestCase(void) {}; - static void TearDownTestCase(void) {}; - void SetUp() {}; - void TearDown() {}; + static void SetUpTestCase(void) {} + static void TearDownTestCase(void) {} + void SetUp() {} + void TearDown() {} }; static void LoopMsleep(void* pMsec) { - if (pMsec == NULL) { + if (pMsec == nullptr) { return; } - int msec = *(int*)pMsec; + int msec = *reinterpret_cast (pMsec); for (int index = 0; index < msec; index++) { Msleep(1); } diff --git a/libs/benchmark/README_zh.md b/libs/benchmark/README_zh.md index 8265e1c53f7dfd31c76a3a2b0890670d0b159d7e..ad5cb624f2432898428456ec1bb21501aa8f1cb8 100644 --- a/libs/benchmark/README_zh.md +++ b/libs/benchmark/README_zh.md @@ -263,20 +263,20 @@ import("//build/test.gni") module_output_path = "developertest/calculator" -ohos_unittest("BenchmarkDemoTest") { - module_out_path = module_output_path - sources = [ "benchmark_demo_test.cpp" ] +ohos_benchmarktest("BenchmarkDemoTest") { + module_out_path = module_output_path + sources = [ "benchmark_demo_test.cpp" ] } -group("unittest") { - testonly = true - deps = [] - - deps += [ - # deps file - ":BenchmarkDemoTest", - ] -} +group("benchmarktest") { + testonly = true + deps = [] + + deps += [ + # deps file + ":BenchmarkDemoTest", + ] +} ``` 详细内容如下: @@ -315,9 +315,9 @@ group("unittest") { 4. 指定测试套名称 ``` - ohos_unittest("BenchmarkDemoTest") { # benchmark测试编译模板 - module_out_path = module_output_path - sources = [ "benchmark_demo_test.cpp" ] # 指定测试用例文件 + ohos_benchmarktest("BenchmarkDemoTest") { + module_out_path = module_output_path + sources = [ "benchmark_demo_test.cpp" ] } ```