From 5e6b029169b6e5005d8aa6344a96af5343c046cc Mon Sep 17 00:00:00 2001 From: peilixia Date: Fri, 9 Sep 2022 09:28:49 +0800 Subject: [PATCH] modify code to clean warnings. Signed-off-by: peilixia Change-Id: Ieac5b67d0c069723ab7ebd3dcad40ab6eeb65721 --- base/src/ashmem.cpp | 4 +-- base/src/file_ex.cpp | 2 +- base/src/thread_ex.cpp | 10 +++--- base/src/unicode_ex.cpp | 18 +++++------ .../unittest/common/utils_datetime_test.cpp | 6 ++-- .../unittest/common/utils_directory_test.cpp | 6 ++-- base/test/unittest/common/utils_file_test.cpp | 31 ++++++++++--------- .../unittest/common/utils_observer_test.cpp | 8 ++--- .../unittest/common/utils_parcel_test.cpp | 6 ++-- .../unittest/common/utils_refbase_test.cpp | 6 ++-- .../common/utils_safe_block_queue_test.cpp | 12 +++---- .../utils_safe_block_queue_tracking.cpp | 14 +++------ .../unittest/common/utils_safe_map_test.cpp | 6 ++-- .../unittest/common/utils_safe_queue_test.cpp | 7 +++-- .../unittest/common/utils_singleton_test.cpp | 21 ++++++------- .../common/utils_sorted_vector_test.cpp | 6 ++-- .../unittest/common/utils_string_test.cpp | 5 ++- .../unittest/common/utils_thread_test.cpp | 28 +++-------------- .../test/unittest/common/utils_timer_test.cpp | 14 +++++---- .../unittest/common/utils_unique_fd_test.cpp | 6 ++-- 20 files changed, 105 insertions(+), 111 deletions(-) diff --git a/base/src/ashmem.cpp b/base/src/ashmem.cpp index 2e05397..059cf15 100644 --- a/base/src/ashmem.cpp +++ b/base/src/ashmem.cpp @@ -69,14 +69,14 @@ static void Trim(std::string &s) static int GetAshmemDeviceFd() { - static const std::string boot_id_path = "/proc/sys/kernel/random/boot_id"; + static const std::string bootIdPath = "/proc/sys/kernel/random/boot_id"; std::string boot_id; char buf[BUFSIZ]; ssize_t n; int fdBoot = -1; int fdAshmem = -1; - fdBoot = TEMP_FAILURE_RETRY(open(boot_id_path.c_str(), O_RDONLY | O_CLOEXEC)); + fdBoot = TEMP_FAILURE_RETRY(open(bootIdPath.c_str(), O_RDONLY | O_CLOEXEC)); if (fdBoot < 0) { return -1; } diff --git a/base/src/file_ex.cpp b/base/src/file_ex.cpp index 7ac2ba9..578b1be 100644 --- a/base/src/file_ex.cpp +++ b/base/src/file_ex.cpp @@ -172,7 +172,7 @@ bool SaveStringToFd(int fd, const std::string& content) return false; } - if ((unsigned long)len != content.length()) { + if (static_cast(len) != content.length()) { UTILS_LOGE("the length write to file is not equal to fileLength!len:%{public}ld, fileLen:%{public}zu", len, content.length()); return false; diff --git a/base/src/thread_ex.cpp b/base/src/thread_ex.cpp index 53e6461..3fb2982 100644 --- a/base/src/thread_ex.cpp +++ b/base/src/thread_ex.cpp @@ -30,7 +30,7 @@ struct ThreadParam { std::string name; // prctl only support set the name of the calling process. - static int proxy(const ThreadParam* t) + static int Proxy(const ThreadParam* t) { if (t == nullptr) { UTILS_LOGD("invalid param."); @@ -65,13 +65,13 @@ bool CreatePThread(ThreadParam& para, size_t stackSize, pthread_t *threadId) // create thread as "detached", so it cleans up after itself. pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - auto t = new ThreadParam; // t would be delete in ThreadParam::proxy + auto t = new ThreadParam; // t would be delete in ThreadParam::Proxy t->startRoutine = para.startRoutine; t->args = para.args; t->priority = para.priority; t->name = para.name; - para.startRoutine = (ThreadFunc)&ThreadParam::proxy; + para.startRoutine = reinterpret_cast(&ThreadParam::Proxy); para.args = t; if (stackSize) { @@ -80,14 +80,14 @@ bool CreatePThread(ThreadParam& para, size_t stackSize, pthread_t *threadId) errno = 0; pthread_t thread; - int result = pthread_create(&thread, &attr, (PThreadRoutine)para.startRoutine, para.args); + int result = pthread_create(&thread, &attr, reinterpret_cast(para.startRoutine), para.args); pthread_attr_destroy(&attr); if (result != 0) { return false; } - if (threadId != NULL) { + if (threadId != nullptr) { *threadId = thread; } diff --git a/base/src/unicode_ex.cpp b/base/src/unicode_ex.cpp index b5ee372..93d3553 100644 --- a/base/src/unicode_ex.cpp +++ b/base/src/unicode_ex.cpp @@ -59,22 +59,22 @@ void Utf32CodePointToUtf8(uint8_t* dstP, char32_t srcChar, size_t bytes) { dstP += bytes; if (bytes >= 4) { - *--dstP = (uint8_t)((srcChar | UTF8_BYTE_MARK) & UTF8_BYTE_MASK); + *--dstP = static_cast((srcChar | UTF8_BYTE_MARK) & UTF8_BYTE_MASK); srcChar >>= UTF8_OFFSET; } if (bytes >= 3) { - *--dstP = (uint8_t)((srcChar | UTF8_BYTE_MARK) & UTF8_BYTE_MASK); + *--dstP = static_cast((srcChar | UTF8_BYTE_MARK) & UTF8_BYTE_MASK); srcChar >>= UTF8_OFFSET; } if (bytes >= 2) { - *--dstP = (uint8_t)((srcChar | UTF8_BYTE_MARK) & UTF8_BYTE_MASK); + *--dstP = static_cast((srcChar | UTF8_BYTE_MARK) & UTF8_BYTE_MASK); srcChar >>= UTF8_OFFSET; } if (bytes >= 1) { - *--dstP = (uint8_t)(srcChar | UTF8_FIRST_BYTE_MARK[bytes]); + *--dstP = static_cast(srcChar | UTF8_FIRST_BYTE_MARK[bytes]); } } @@ -117,7 +117,7 @@ int Utf16ToUtf8Length(const char16_t* str16, size_t str16Len) charLen = 4; str16 += 2; } else { - charLen = Utf32CodePointUtf8Length((char32_t)* str16++); + charLen = Utf32CodePointUtf8Length(static_cast(*str16++)); } if (utf8Len > (INT_MAX - charLen)) { @@ -143,7 +143,7 @@ void StrncpyStr16ToStr8(const char16_t* utf16Str, size_t str16Len, char* utf8Str utf32 |= *curUtf16++ - 0xDC00; utf32 += 0x10000; } else { - utf32 = (char32_t)* curUtf16++; + utf32 = static_cast(*curUtf16++); } const size_t len = Utf32CodePointUtf8Length(utf32); if (str8Len < len) { @@ -282,16 +282,16 @@ char16_t* Utf8ToUtf16(const char* utf8Str, size_t u8len, char16_t* u16str, size_ // Convert the UTF32 codepoint to one or more UTF16 codepoints if (codepoint <= 0xFFFF) { // Single UTF16 character - *u16cur++ = (char16_t)codepoint; + *u16cur++ = static_cast(codepoint); } else { // Multiple UTF16 characters with surrogates codepoint = codepoint - 0x10000; - *u16cur++ = (char16_t)((codepoint >> 10) + 0xD800); + *u16cur++ = static_cast((codepoint >> 10) + 0xD800); if (u16cur >= u16end) { // Ooops... not enough room for this surrogate pair. return u16cur - 1; } - *u16cur++ = (char16_t)((codepoint & 0x3FF) + 0xDC00); + *u16cur++ = static_cast((codepoint & 0x3FF) + 0xDC00); } u8cur += len; diff --git a/base/test/unittest/common/utils_datetime_test.cpp b/base/test/unittest/common/utils_datetime_test.cpp index 9f6bd9a..8256d32 100644 --- a/base/test/unittest/common/utils_datetime_test.cpp +++ b/base/test/unittest/common/utils_datetime_test.cpp @@ -17,10 +17,11 @@ #include "datetime_ex.h" #include using namespace testing::ext; -using namespace OHOS; #include using namespace std; +namespace OHOS { +namespace { class UtilsDateTimeTest : public testing::Test { public : static void SetUpTestCase(void); @@ -149,4 +150,5 @@ HWTEST_F(UtilsDateTimeTest, testGetMicroTickCount001, TestSize.Level0) EXPECT_TRUE(end - begin >= 100000); EXPECT_TRUE(end - begin < 120000); } - +} // namespace +} // namespace OHOS \ No newline at end of file diff --git a/base/test/unittest/common/utils_directory_test.cpp b/base/test/unittest/common/utils_directory_test.cpp index 5a6bfce..06c5b72 100644 --- a/base/test/unittest/common/utils_directory_test.cpp +++ b/base/test/unittest/common/utils_directory_test.cpp @@ -18,9 +18,10 @@ #include #include using namespace testing::ext; -using namespace OHOS; using namespace std; +namespace OHOS { +namespace { class UtilsDirectoryTest : public testing::Test { public : static void SetUpTestCase(void); @@ -286,4 +287,5 @@ HWTEST_F(UtilsDirectoryTest, testPathToRealPath005, TestSize.Level0) bool ret = PathToRealPath(path, realpath); EXPECT_EQ(ret, false); } - +} // namespace +} // namespace OHOS \ No newline at end of file diff --git a/base/test/unittest/common/utils_file_test.cpp b/base/test/unittest/common/utils_file_test.cpp index e897cfd..b8bd84a 100644 --- a/base/test/unittest/common/utils_file_test.cpp +++ b/base/test/unittest/common/utils_file_test.cpp @@ -21,12 +21,11 @@ #include #include #include - using namespace testing::ext; -using namespace OHOS; using namespace std; - +namespace OHOS { +namespace { class UtilsFileTest : public testing::Test { public : static void SetUpTestCase(void); @@ -140,7 +139,7 @@ HWTEST_F(UtilsFileTest, testLoadStringFromFile005, TestSize.Level0) { string str; string filename = "./tmp.txt"; - string content(32*1024*1024, 't'); + string content(32 * 1024 * 1024, 't'); CreateTestFile(filename, content); EXPECT_TRUE(LoadStringFromFile(filename, str)); RemoveTestFile(filename); @@ -155,7 +154,7 @@ HWTEST_F(UtilsFileTest, testLoadStringFromFile006, TestSize.Level0) { string str; string filename = "./tmp.txt"; - string content(32*1024*1024 + 1, 't'); + string content(32 * 1024 * 1024 + 1, 't'); CreateTestFile(filename, content); EXPECT_FALSE(LoadStringFromFile(filename, str)); RemoveTestFile(filename); @@ -216,7 +215,7 @@ HWTEST_F(UtilsFileTest, testLoadStringFromFd004, TestSize.Level0) { string result; string filename = "./tmp.txt"; - string content(32*1024*1024, 't'); + string content(32 * 1024 * 1024, 't'); CreateTestFile(filename, content); int fd = open(filename.c_str(), O_RDONLY); EXPECT_TRUE(LoadStringFromFd(fd, result)); @@ -419,7 +418,7 @@ HWTEST_F(UtilsFileTest, testSaveStringToFd005, TestSize.Level0) { string content; string filename = "./tmp3.txt"; - int fd = open(filename.c_str(), O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); + int fd = open(filename.c_str(), O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); bool ret = SaveStringToFd(fd, content); close(fd); EXPECT_EQ(ret, true); @@ -441,7 +440,7 @@ HWTEST_F(UtilsFileTest, testSaveStringToFd006, TestSize.Level0) { string content = "TTTTTTTT"; string filename = "./tmp3.txt"; - int fd = open(filename.c_str(), O_RDWR|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); + int fd = open(filename.c_str(), O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); bool ret = SaveStringToFd(fd, content); close(fd); EXPECT_EQ(ret, true); @@ -495,7 +494,7 @@ HWTEST_F(UtilsFileTest, testLoadBufferFromFile003, TestSize.Level0) { vector buff; string filename = "./tmp1.txt"; - string content(32*1024*1024 + 1, 't'); + string content(32 * 1024 * 1024 + 1, 't'); CreateTestFile(filename, content); bool ret = LoadBufferFromFile(filename, buff); RemoveTestFile(filename); @@ -631,10 +630,10 @@ HWTEST_F(UtilsFileTest, testStringExistsInFile003, TestSize.Level0) */ HWTEST_F(UtilsFileTest, testStringExistsInFile004, TestSize.Level0) { - string str1(32*1024*1024+1, 't'); - string str2(32*1024*1024, 't'); + string str1(32 * 1024 * 1024 + 1, 't'); + string str2(32 * 1024 * 1024, 't'); string filename = "./tmp.txt"; - string content(32*1024*1024, 't'); + string content(32 * 1024 * 1024, 't'); CreateTestFile(filename, content); EXPECT_FALSE(StringExistsInFile(filename, str1, true)); EXPECT_TRUE(StringExistsInFile(filename, str2, true)); @@ -751,10 +750,10 @@ HWTEST_F(UtilsFileTest, testCountStrInFile002, TestSize.Level0) */ HWTEST_F(UtilsFileTest, testCountStrInFile003, TestSize.Level0) { - string str1(32*1024*1024+1, 't'); - string str2(32*1024*1024, 't'); + string str1(32 * 1024 * 1024 + 1, 't'); + string str2(32 * 1024 * 1024, 't'); string filename = "./tmp.txt"; - string content(32*1024*1024, 't'); + string content(32 * 1024 * 1024, 't'); CreateTestFile(filename, content); EXPECT_EQ(CountStrInFile(filename, str1, true), 0); EXPECT_EQ(CountStrInFile(filename, str2, true), 1); @@ -797,3 +796,5 @@ HWTEST_F(UtilsFileTest, testCountStrInFile005, TestSize.Level0) EXPECT_EQ(CountStrInFile(filename, str1, false), 3); RemoveTestFile(filename); } +} // namespace +} // namespace OHOS \ No newline at end of file diff --git a/base/test/unittest/common/utils_observer_test.cpp b/base/test/unittest/common/utils_observer_test.cpp index b446b73..208f4f1 100644 --- a/base/test/unittest/common/utils_observer_test.cpp +++ b/base/test/unittest/common/utils_observer_test.cpp @@ -18,10 +18,10 @@ #include #include using namespace testing::ext; -using namespace OHOS; using namespace std; - +namespace OHOS { +namespace { class BookList: public Observable { public: BookList() { books_.clear(); } @@ -84,7 +84,6 @@ void UtilsObserverTest::TearDown(void) { } - HWTEST_F(UtilsObserverTest, test_ObserverNotify, TestSize.Level0) { BookList bookList; @@ -140,4 +139,5 @@ HWTEST_F(UtilsObserverTest, test_RemoveAllObserver, TestSize.Level0) EXPECT_EQ(bookObserver3->GetBooksCount(), 1); EXPECT_EQ(bookList.GetObserversCount(), 0); } - +} // namespace +} // namespace OHOS \ No newline at end of file diff --git a/base/test/unittest/common/utils_parcel_test.cpp b/base/test/unittest/common/utils_parcel_test.cpp index 63fe2ee..81b5d4f 100644 --- a/base/test/unittest/common/utils_parcel_test.cpp +++ b/base/test/unittest/common/utils_parcel_test.cpp @@ -21,11 +21,11 @@ #include "parcel.h" #include "refbase.h" #include "securec.h" - using namespace testing::ext; -using namespace OHOS; using namespace std; +namespace OHOS { +namespace { const int MAX_PARCEL_SIZE = 1000; char g_data[MAX_PARCEL_SIZE]; class UtilsParcelTest : public testing::Test { @@ -967,3 +967,5 @@ HWTEST_F(UtilsParcelTest, test_SetMaxCapacity_002, TestSize.Level0) ret = parcel.ReadString16Vector(&val); EXPECT_EQ(false, ret); } +} // namespace +} // namespace OHOS \ No newline at end of file diff --git a/base/test/unittest/common/utils_refbase_test.cpp b/base/test/unittest/common/utils_refbase_test.cpp index 6919203..51103b2 100644 --- a/base/test/unittest/common/utils_refbase_test.cpp +++ b/base/test/unittest/common/utils_refbase_test.cpp @@ -24,11 +24,11 @@ #include "singleton.h" #include - using namespace testing::ext; -using namespace OHOS; using namespace std; +namespace OHOS { +namespace { static constexpr int FLAG_OF_CONS = 1; static constexpr int FLAG_OF_DEST = 2; static int g_sptrCount = 0; @@ -866,3 +866,5 @@ HWTEST_F(UtilsRefbaseTest, testWptrefbase008, TestSize.Level0) testObject2 = testObject1.GetRefPtr(); EXPECT_EQ(testObject1->GetWptrRefCount(), 2); } +} // namespace +} // namespace OHOS \ No newline at end of file diff --git a/base/test/unittest/common/utils_safe_block_queue_test.cpp b/base/test/unittest/common/utils_safe_block_queue_test.cpp index fc6e272..01c2d08 100644 --- a/base/test/unittest/common/utils_safe_block_queue_test.cpp +++ b/base/test/unittest/common/utils_safe_block_queue_test.cpp @@ -26,19 +26,14 @@ #include // std::chrono::seconds #include // std::cout #include // std::thread, std::this_thread::sleep_for - using namespace testing::ext; -using namespace OHOS; using namespace std; +namespace OHOS { +namespace { class UtilsSafeBlockQueue : public testing::Test { }; -void task_put(SafeBlockQueue& q, int i) -{ - q.Push(i); -} - const unsigned int QUEUE_SLOTS = 10; const unsigned int THREAD_NUM = QUEUE_SLOTS + 1; @@ -65,6 +60,7 @@ public: getStatus = true; } }; + SafeBlockQueue DemoThreadData::shareQueue(QUEUE_SLOTS); void PutHandleThreadData(DemoThreadData& q, int i) @@ -666,3 +662,5 @@ HWTEST_F(UtilsSafeBlockQueue, testMutilthreadConcurrentGetAndPopInfullqueue001, demoDatas[0].Get(); } } +} // namespace +} // namespace OHOS \ No newline at end of file diff --git a/base/test/unittest/common/utils_safe_block_queue_tracking.cpp b/base/test/unittest/common/utils_safe_block_queue_tracking.cpp index d4422d6..e5ed313 100644 --- a/base/test/unittest/common/utils_safe_block_queue_tracking.cpp +++ b/base/test/unittest/common/utils_safe_block_queue_tracking.cpp @@ -18,24 +18,16 @@ #include #include #include - #include - #include // std::chrono::seconds - - using namespace testing::ext; -using namespace OHOS; using namespace std; +namespace OHOS { +namespace { class UtilsSafeBlockQueueTracking : public testing::Test { }; -void taskPut(SafeBlockQueueTracking& q, int i) -{ - q.Push(i); -} - const unsigned int QUEUE_SLOTS = 10; const unsigned int THREAD_NUM = QUEUE_SLOTS + 1; @@ -690,3 +682,5 @@ HWTEST_F(UtilsSafeBlockQueueTracking, testMutilthreadConcurrentGetAndPopInfullqu ASSERT_TRUE(demoDatas[0].joinStatus); demoDatas[0].joinStatus = false; } +} // namespace +} // namespace OHOS \ No newline at end of file diff --git a/base/test/unittest/common/utils_safe_map_test.cpp b/base/test/unittest/common/utils_safe_map_test.cpp index 345a140..a06b2ba 100644 --- a/base/test/unittest/common/utils_safe_map_test.cpp +++ b/base/test/unittest/common/utils_safe_map_test.cpp @@ -20,11 +20,11 @@ #include #include #include // std::chrono::seconds - using namespace testing::ext; -using namespace OHOS; using namespace std; +namespace OHOS { +namespace { class UtilsSafeMap : public testing::Test { }; @@ -443,3 +443,5 @@ HWTEST_F(UtilsSafeMap, testUtilsConcurrentWriteAndFindAndSet001, TestSize.Level0 } }); } +} // namespace +} // namespace OHOS \ No newline at end of file diff --git a/base/test/unittest/common/utils_safe_queue_test.cpp b/base/test/unittest/common/utils_safe_queue_test.cpp index 5fcbd31..b198982 100644 --- a/base/test/unittest/common/utils_safe_queue_test.cpp +++ b/base/test/unittest/common/utils_safe_queue_test.cpp @@ -20,11 +20,11 @@ #include #include #include // std::chrono::seconds - using namespace testing::ext; -using namespace OHOS; using namespace std; +namespace OHOS { +namespace { class UtilsSafeQueue : public testing::Test { }; @@ -56,6 +56,7 @@ public: getStatus = true; } }; + SafeQueue DemoThreadData::shareQueue; void PutHandleThreadDataTime(DemoThreadData &q, int i, std::chrono::system_clock::time_point absTime) @@ -285,3 +286,5 @@ HWTEST_F(UtilsSafeQueue, testMutilthreadConcurrentGetAndPopInNotEmptyQueue, Test putInTestThread.ResetStatus(); getOutTestThread.ResetStatus(); } +} // namespace +} // namespace OHOS \ No newline at end of file diff --git a/base/test/unittest/common/utils_singleton_test.cpp b/base/test/unittest/common/utils_singleton_test.cpp index 0a0e22b..37c28ff 100644 --- a/base/test/unittest/common/utils_singleton_test.cpp +++ b/base/test/unittest/common/utils_singleton_test.cpp @@ -18,14 +18,14 @@ #include #include using namespace testing::ext; -using namespace OHOS; using namespace std; - +namespace OHOS { +namespace { class DelayedSingletonDeclearTest { DECLARE_DELAYED_SINGLETON(DelayedSingletonDeclearTest); public: - void* GetObjAddr() { return (void*)this; } + void* GetObjAddr() { return static_cast(this); } }; DelayedSingletonDeclearTest::~DelayedSingletonDeclearTest() {}; @@ -34,7 +34,7 @@ DelayedSingletonDeclearTest::DelayedSingletonDeclearTest() {}; class SingletonDeclearTest { DECLARE_SINGLETON(SingletonDeclearTest); public: - void* GetObjAddr() { return (void*)this; } + void* GetObjAddr() { return static_cast(this); } }; SingletonDeclearTest::~SingletonDeclearTest() {}; @@ -42,19 +42,19 @@ SingletonDeclearTest::SingletonDeclearTest() {}; class SingletonTest: public Singleton { public: - void* GetObjAddr() { return (void*)this; } + void* GetObjAddr() { return static_cast(this); } }; class DelayedSingletonTest: public DelayedSingleton { public: - void* GetObjAddr() { return (void*)this; } + void* GetObjAddr() { return static_cast(this); } }; class DelayedRefSingletonDeclearTest { DECLARE_DELAYED_REF_SINGLETON(DelayedRefSingletonDeclearTest); public: - void* GetObjAddr() { return (void*)this; } + void* GetObjAddr() { return static_cast(this); } }; DelayedRefSingletonDeclearTest::DelayedRefSingletonDeclearTest() {}; @@ -62,7 +62,7 @@ DelayedRefSingletonDeclearTest::~DelayedRefSingletonDeclearTest() {}; class DelayedRefSingletonTest: public DelayedRefSingleton { public: - void* GetObjAddr() { return (void*)this; } + void* GetObjAddr() { return static_cast(this); } }; @@ -95,7 +95,6 @@ void UtilsSingletonTest::TearDown(void) // step 3: input testcase teardown step } - HWTEST_F(UtilsSingletonTest, test_DelayedSingletonDeclearTest, TestSize.Level0) { shared_ptr sp1 = DelayedSingleton::GetInstance(); @@ -146,5 +145,5 @@ HWTEST_F(UtilsSingletonTest, test_DelayedRefSingletonDeclearTest, TestSize.Level DelayedRefSingletonDeclearTest& p2 = DelayedRefSingleton::GetInstance(); EXPECT_EQ(p1.GetObjAddr(), p2.GetObjAddr()); } - - +} // namespace +} // namespace OHOS \ No newline at end of file diff --git a/base/test/unittest/common/utils_sorted_vector_test.cpp b/base/test/unittest/common/utils_sorted_vector_test.cpp index 56e6938..8316b54 100644 --- a/base/test/unittest/common/utils_sorted_vector_test.cpp +++ b/base/test/unittest/common/utils_sorted_vector_test.cpp @@ -16,11 +16,11 @@ #include #include - using namespace testing::ext; -using namespace OHOS; using namespace std; +namespace OHOS { +namespace { class UtilsSortedVector : public testing::Test { }; @@ -595,3 +595,5 @@ HWTEST_F(UtilsSortedVector, testAddNotAllowDuplicate, TestSize.Level0) ASSERT_EQ(i, svec[i]); } } +} // namespace +} // namespace OHOS \ No newline at end of file diff --git a/base/test/unittest/common/utils_string_test.cpp b/base/test/unittest/common/utils_string_test.cpp index 5ce9e8a..1cce9d7 100644 --- a/base/test/unittest/common/utils_string_test.cpp +++ b/base/test/unittest/common/utils_string_test.cpp @@ -17,9 +17,10 @@ #include "string_ex.h" #include using namespace testing::ext; -using namespace OHOS; using namespace std; +namespace OHOS { +namespace { class UtilsStringTest : public testing::Test { public : @@ -583,3 +584,5 @@ HWTEST_F(UtilsStringTest, DexToHexString_01, TestSize.Level0) result = DexToHexString(11259375, false); EXPECT_EQ(result, "abcdef"); } +} // namespace +} // namespace OHOS \ No newline at end of file diff --git a/base/test/unittest/common/utils_thread_test.cpp b/base/test/unittest/common/utils_thread_test.cpp index 8163ca6..bc8e81b 100644 --- a/base/test/unittest/common/utils_thread_test.cpp +++ b/base/test/unittest/common/utils_thread_test.cpp @@ -17,11 +17,11 @@ #include #include #include - using namespace testing::ext; -using namespace OHOS; using namespace std; +namespace OHOS { +namespace { static int times = 0; using ThreadRunFunc = bool (*)(int& data); @@ -55,27 +55,6 @@ void UtilsThreadTest::TearDown(void) times = 0; } -// get priority of thread -int GetThreadPriority(const pthread_t& thread) -{ - sched_param param; - int priority; - int policy; - int ret; - - // scheduling parameters of target thread - ret = pthread_getschedparam(thread, &policy, ¶m); - if (ret != 0) { - printf("pthread_getschedparam failed! thread:%lu, ret:%d\n", thread, ret); - return -1; - } - - // sched_priority contains the priority of the thread - priority = param.sched_priority; - return priority; -} - - bool TestRun01(int& data) { ++data; @@ -313,4 +292,5 @@ HWTEST_F(UtilsThreadTest, testThread006, TestSize.Level0) // times > 10, TestRun03 return false, thread exit EXPECT_EQ(pthread_equal(test->GetThread(), -1) != 0, (test->IsRunning() ? false : true)); } - +} // namespace +} // namespace OHOS \ No newline at end of file diff --git a/base/test/unittest/common/utils_timer_test.cpp b/base/test/unittest/common/utils_timer_test.cpp index 392cc74..acaed1b 100644 --- a/base/test/unittest/common/utils_timer_test.cpp +++ b/base/test/unittest/common/utils_timer_test.cpp @@ -21,11 +21,10 @@ #include #include #include - using namespace testing::ext; -using namespace OHOS; using namespace std; +namespace OHOS { namespace { int64_t CurMs() { @@ -33,7 +32,7 @@ int64_t CurMs() gettimeofday(&tpend, nullptr); return (tpend.tv_sec * 1000000 + tpend.tv_usec) / 1000; } -} + class UtilsTimerTest : public testing::Test { public : static void SetUpTestCase(void); @@ -88,7 +87,6 @@ HWTEST_F(UtilsTimerTest, testTimer001, TestSize.Level0) timer.Shutdown(); EXPECT_GE(g_data1, 2); EXPECT_GE(10, g_data1); -} */ /* @@ -152,7 +150,10 @@ public: void StopTimer(); int GetData() const {return data_;} private: - void TimeOutProc() {data_ -= 1;}; + void TimeOutProc() + { + data_ -= 1; + }; int data_; Utils::Timer timer_; }; @@ -336,4 +337,5 @@ HWTEST_F(UtilsTimerTest, testTimer011, TestSize.Level0) timer.Shutdown(); EXPECT_GE(g_data1, 8); /* 12 for max */ } - +} // namespace +} // namespace OHOS \ No newline at end of file diff --git a/base/test/unittest/common/utils_unique_fd_test.cpp b/base/test/unittest/common/utils_unique_fd_test.cpp index 1286d53..4734acc 100644 --- a/base/test/unittest/common/utils_unique_fd_test.cpp +++ b/base/test/unittest/common/utils_unique_fd_test.cpp @@ -20,11 +20,11 @@ #include #include #include - using namespace testing::ext; -using namespace OHOS; using namespace std; +namespace OHOS { +namespace { class UtilsUniqueFd : public testing::Test { public: static void SetUpTestCase(void); @@ -166,3 +166,5 @@ HWTEST_F(UtilsUniqueFd, testUtilsUniqueFdDefineDeletorCloseStatus, TestSize.Leve int ret = write(fd, buf, sizeof(buf)); ASSERT_EQ(ret, -1); }; +} // namespace +} // namespace OHOS \ No newline at end of file -- Gitee