mirror of
https://github.com/openharmony/utils_native.git
synced 2026-07-21 01:25:42 -04:00
modify the code according to CodeCheck
Signed-off-by: liujialiang <liujialiang10@huawei.com>
This commit is contained in:
@@ -292,7 +292,6 @@ public:
|
||||
bool WriteUint8Unaligned(uint8_t value);
|
||||
bool WriteUint16Unaligned(uint16_t value);
|
||||
|
||||
|
||||
bool ReadBoolUnaligned();
|
||||
bool ReadInt8Unaligned(int8_t &value);
|
||||
bool ReadInt16Unaligned(int16_t &value);
|
||||
|
||||
@@ -121,7 +121,7 @@ public:
|
||||
unfinishedTaskCount_ = 0;
|
||||
}
|
||||
|
||||
virtual ~SafeBlockQueueTracking(){};
|
||||
virtual ~SafeBlockQueueTracking() {};
|
||||
|
||||
virtual void Push(T const& elem)
|
||||
{
|
||||
|
||||
@@ -43,7 +43,7 @@ public:
|
||||
|
||||
SortedVector(const std::vector<TYPE>& orivect);
|
||||
|
||||
virtual ~SortedVector(){};
|
||||
virtual ~SortedVector() {};
|
||||
// copy operator
|
||||
SortedVector<TYPE, AllowDuplicate>& operator=(const SortedVector<TYPE, false>& rhs);
|
||||
SortedVector<TYPE, AllowDuplicate>& operator=(const SortedVector<TYPE, true>& rhs);
|
||||
|
||||
@@ -46,7 +46,7 @@ public:
|
||||
* others: wait(until event-trigger)
|
||||
*/
|
||||
explicit Timer(const std::string& name, int timeoutMs = 1000);
|
||||
virtual ~Timer(){}
|
||||
virtual ~Timer() {}
|
||||
|
||||
virtual uint32_t Setup();
|
||||
|
||||
|
||||
@@ -14,10 +14,10 @@
|
||||
*/
|
||||
|
||||
#include "directory_ex.h"
|
||||
#include "securec.h"
|
||||
#include "unistd.h"
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include "securec.h"
|
||||
#include "unistd.h"
|
||||
#include "utils_log.h"
|
||||
using namespace std;
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ public:
|
||||
EventHandler(const EventHandler&) = delete;
|
||||
EventHandler& operator=(const EventHandler&&) = delete;
|
||||
EventHandler(const EventHandler&&) = delete;
|
||||
~EventHandler(){};
|
||||
~EventHandler() {};
|
||||
|
||||
int GetHandle() const { return (fd_); }
|
||||
uint32_t Events() const { return (events_); }
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
*/
|
||||
|
||||
#include "file_ex.h"
|
||||
#include "directory_ex.h"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
@@ -25,6 +24,7 @@
|
||||
#include <cstdio>
|
||||
#include <securec.h>
|
||||
#include <cstring>
|
||||
#include "directory_ex.h"
|
||||
#include "utils_log.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
+1
-1
@@ -696,7 +696,7 @@ bool Parcel::Read(T &value)
|
||||
template <typename T>
|
||||
T Parcel::Read()
|
||||
{
|
||||
T lvalue{};
|
||||
T lvalue {};
|
||||
return Read<T>(lvalue) ? lvalue : 0;
|
||||
}
|
||||
|
||||
|
||||
+11
-11
@@ -34,7 +34,7 @@ WeakRefCounter::~WeakRefCounter()
|
||||
|
||||
void* WeakRefCounter::GetRefPtr()
|
||||
{
|
||||
if ((cookie_ != nullptr) && (!refCounter_->IsRefPtrValid())){
|
||||
if ((cookie_ != nullptr) && (!refCounter_->IsRefPtrValid())) {
|
||||
cookie_ = nullptr;
|
||||
}
|
||||
return cookie_;
|
||||
@@ -103,7 +103,7 @@ RefCounter::~RefCounter()
|
||||
{
|
||||
}
|
||||
|
||||
int RefCounter::IncStrongRefCount(const void* /*objectId*/)
|
||||
int RefCounter::IncStrongRefCount(const void* /* objectId */)
|
||||
{
|
||||
int curCount = atomicStrong_.load(std::memory_order_relaxed);
|
||||
|
||||
@@ -117,7 +117,7 @@ int RefCounter::IncStrongRefCount(const void* /*objectId*/)
|
||||
return curCount;
|
||||
}
|
||||
|
||||
int RefCounter::DecStrongRefCount(const void* /*objectId*/)
|
||||
int RefCounter::DecStrongRefCount(const void* /* objectId */)
|
||||
{
|
||||
int curCount = GetStrongRefCount();
|
||||
if (curCount == INITIAL_PRIMARY_VALUE) {
|
||||
@@ -136,12 +136,12 @@ int RefCounter::GetStrongRefCount()
|
||||
return atomicStrong_.load(std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
int RefCounter::IncWeakRefCount(const void* /*objectId*/)
|
||||
int RefCounter::IncWeakRefCount(const void* /* objectId */)
|
||||
{
|
||||
return atomicWeak_.fetch_add(1, std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
int RefCounter::DecWeakRefCount(const void* /*objectId*/)
|
||||
int RefCounter::DecWeakRefCount(const void* /* objectId */)
|
||||
{
|
||||
int curCount = GetWeakRefCount();
|
||||
if (curCount > 0) {
|
||||
@@ -237,7 +237,7 @@ RefBase::RefBase() : refs_(new RefCounter())
|
||||
refs_->SetCallback(std::bind(&RefBase::RefPtrCallback, this));
|
||||
}
|
||||
|
||||
RefBase::RefBase(const RefBase &/*other*/)
|
||||
RefBase::RefBase(const RefBase & /* other */)
|
||||
{
|
||||
refs_ = new RefCounter();
|
||||
if (refs_ != nullptr) {
|
||||
@@ -257,7 +257,7 @@ void RefBase::RefPtrCallback()
|
||||
* RISK: If there is a reference count on the left of the equal sign,
|
||||
* it may cause a reference count exception
|
||||
*/
|
||||
RefBase &RefBase::operator=(const RefBase &/*other*/)
|
||||
RefBase &RefBase::operator=(const RefBase & /* other */)
|
||||
{
|
||||
if (refs_ != nullptr) {
|
||||
refs_->RemoveCallback();
|
||||
@@ -426,16 +426,16 @@ bool RefBase::IsExtendLifeTimeSet()
|
||||
return refs_->IsLifeTimeExtended();
|
||||
}
|
||||
|
||||
void RefBase::OnFirstStrongRef(const void* /*objectId*/)
|
||||
void RefBase::OnFirstStrongRef(const void* /* objectId */)
|
||||
{}
|
||||
|
||||
void RefBase::OnLastStrongRef(const void* /*objectId*/)
|
||||
void RefBase::OnLastStrongRef(const void* /* objectId */)
|
||||
{}
|
||||
|
||||
void RefBase::OnLastWeakRef(const void* /*objectId*/)
|
||||
void RefBase::OnLastWeakRef(const void* /* objectId */)
|
||||
{}
|
||||
|
||||
bool RefBase::OnAttemptPromoted(const void* /*objectId*/)
|
||||
bool RefBase::OnAttemptPromoted(const void* /* objectId */)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ class IRemoteObject : public virtual RefBase {
|
||||
public:
|
||||
IRemoteObject() { ExtendObjectLifetime(); };
|
||||
virtual bool IsProxyObject() = 0;
|
||||
~IRemoteObject(){};
|
||||
~IRemoteObject() {};
|
||||
};
|
||||
|
||||
class RefBaseTestTracker : public RefBase {
|
||||
@@ -205,7 +205,7 @@ public:
|
||||
tracker->TrackObject(this);
|
||||
tracker->TrackNewObject(this);
|
||||
};
|
||||
~IPCObjectProxy(){};
|
||||
~IPCObjectProxy() {};
|
||||
void RefPtrCallback() override;
|
||||
void OnLastStrongRef(const void *objectId) override;
|
||||
void OnFirstStrongRef(const void *objectId) override;
|
||||
|
||||
@@ -28,8 +28,8 @@ public:
|
||||
void* GetObjAddr() { return (void*)this; }
|
||||
};
|
||||
|
||||
DelayedSingletonDeclearTest::~DelayedSingletonDeclearTest(){};
|
||||
DelayedSingletonDeclearTest::DelayedSingletonDeclearTest(){};
|
||||
DelayedSingletonDeclearTest::~DelayedSingletonDeclearTest() {};
|
||||
DelayedSingletonDeclearTest::DelayedSingletonDeclearTest() {};
|
||||
|
||||
class SingletonDeclearTest {
|
||||
DECLARE_SINGLETON(SingletonDeclearTest);
|
||||
@@ -37,8 +37,8 @@ public:
|
||||
void* GetObjAddr() { return (void*)this; }
|
||||
};
|
||||
|
||||
SingletonDeclearTest::~SingletonDeclearTest(){};
|
||||
SingletonDeclearTest::SingletonDeclearTest(){};
|
||||
SingletonDeclearTest::~SingletonDeclearTest() {};
|
||||
SingletonDeclearTest::SingletonDeclearTest() {};
|
||||
|
||||
class SingletonTest: public Singleton<SingletonTest> {
|
||||
public:
|
||||
@@ -57,8 +57,8 @@ public:
|
||||
void* GetObjAddr() { return (void*)this; }
|
||||
};
|
||||
|
||||
DelayedRefSingletonDeclearTest::DelayedRefSingletonDeclearTest(){};
|
||||
DelayedRefSingletonDeclearTest::~DelayedRefSingletonDeclearTest(){};
|
||||
DelayedRefSingletonDeclearTest::DelayedRefSingletonDeclearTest() {};
|
||||
DelayedRefSingletonDeclearTest::~DelayedRefSingletonDeclearTest() {};
|
||||
|
||||
class DelayedRefSingletonTest: public DelayedRefSingleton<DelayedRefSingletonTest> {
|
||||
public:
|
||||
|
||||
@@ -120,13 +120,13 @@ HWTEST_F(UtilsThreadPoolTest, test_05, TestSize.Level0)
|
||||
EXPECT_EQ((int)pool.GetThreadsNum(), 5);
|
||||
EXPECT_EQ((int)pool.GetCurTaskNum(), 0);
|
||||
|
||||
for ( int i = 0; i < 3; ++i )
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
auto task = std::bind(TestFuncAddOneTime, i);
|
||||
pool.AddTask(task);
|
||||
}
|
||||
|
||||
for ( int i = 0; i < 2; ++i )
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
auto task = std::bind(TestFuncSubOneTime, i);
|
||||
pool.AddTask(task);
|
||||
@@ -150,13 +150,13 @@ HWTEST_F(UtilsThreadPoolTest, test_06, TestSize.Level0)
|
||||
|
||||
pool.SetMaxTaskNum(10);
|
||||
|
||||
for ( int i = 0; i < 8; ++i )
|
||||
for (int i = 0; i < 8; ++i)
|
||||
{
|
||||
auto task = std::bind(TestFuncAddOneTime, i);
|
||||
pool.AddTask(task);
|
||||
}
|
||||
|
||||
for ( int i = 0; i < 7; ++i )
|
||||
for (int i = 0; i < 7; ++i)
|
||||
{
|
||||
auto task = std::bind(TestFuncSubOneTime, i);
|
||||
pool.AddTask(task);
|
||||
@@ -175,7 +175,7 @@ void TestFuncAddWait(int& i)
|
||||
++g_times;
|
||||
printf("after func:%s0%d called, :%d\n", __func__, i, g_times);
|
||||
std::unique_lock<std::mutex> lk(g_mutex);
|
||||
g_cv.wait(lk, []{return g_ready;});
|
||||
g_cv.wait(lk, [] {return g_ready;});
|
||||
printf("func:%s0%d received ready signal!\n", __func__, i);
|
||||
}
|
||||
|
||||
@@ -184,7 +184,7 @@ void TestFuncSubWait(int& i)
|
||||
--g_times;
|
||||
printf("after func:%s0%d called, :%d\n", __func__, i, g_times);
|
||||
std::unique_lock<std::mutex> lk(g_mutex);
|
||||
g_cv.wait(lk, []{return g_ready;});
|
||||
g_cv.wait(lk, [] {return g_ready;});
|
||||
printf("func:%s0%d received ready signal!\n", __func__, i);
|
||||
}
|
||||
|
||||
@@ -198,13 +198,13 @@ HWTEST_F(UtilsThreadPoolTest, test_07, TestSize.Level0)
|
||||
EXPECT_EQ((int)pool.GetThreadsNum(), 5);
|
||||
EXPECT_EQ((int)pool.GetCurTaskNum(), 0);
|
||||
|
||||
for ( int i = 0; i < 3; ++i )
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
auto task = std::bind(TestFuncAddWait, i);
|
||||
pool.AddTask(task);
|
||||
}
|
||||
|
||||
for ( int i = 0; i < 2; ++i )
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
auto task = std::bind(TestFuncSubWait, i);
|
||||
pool.AddTask(task);
|
||||
@@ -236,13 +236,13 @@ HWTEST_F(UtilsThreadPoolTest, test_08, TestSize.Level0)
|
||||
pool.SetMaxTaskNum(10);
|
||||
|
||||
// ADD 15 tasks
|
||||
for ( int i = 0; i < 8; ++i )
|
||||
for (int i = 0; i < 8; ++i)
|
||||
{
|
||||
auto task = std::bind(TestFuncAddWait, i);
|
||||
pool.AddTask(task);
|
||||
}
|
||||
|
||||
for ( int i = 0; i < 7; ++i )
|
||||
for (int i = 0; i < 7; ++i)
|
||||
{
|
||||
auto task = std::bind(TestFuncSubWait, i);
|
||||
pool.AddTask(task);
|
||||
|
||||
@@ -25,9 +25,8 @@ using namespace std;
|
||||
static int times = 0;
|
||||
using ThreadRunFunc = bool (*)(int& data);
|
||||
|
||||
class UtilsThreadTest : public testing::Test
|
||||
{
|
||||
public :
|
||||
class UtilsThreadTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void);
|
||||
static void TearDownTestCase(void);
|
||||
void SetUp();
|
||||
@@ -66,7 +65,7 @@ int GetThreadPriority(const pthread_t& thread)
|
||||
|
||||
// scheduling parameters of target thread
|
||||
ret = pthread_getschedparam (thread, &policy, ¶m);
|
||||
if (ret != 0){
|
||||
if (ret != 0) {
|
||||
printf("pthread_getschedparam failed! thread:%lu, ret:%d\n", thread, ret);
|
||||
return -1;
|
||||
}
|
||||
@@ -103,14 +102,14 @@ bool TestRun03(int& data)
|
||||
constexpr int DEFAULT_PRIO = 0;
|
||||
const std::string& DEFAULT_THREAD_NAME = "default";
|
||||
|
||||
class TestThread : public OHOS::Thread{
|
||||
class TestThread : public OHOS::Thread {
|
||||
public:
|
||||
TestThread(const int data, const bool readyToWork, ThreadRunFunc runFunc)
|
||||
: data_(data), priority_(DEFAULT_PRIO), name_(DEFAULT_THREAD_NAME), readyToWork_(readyToWork), runFunc_(runFunc)
|
||||
{};
|
||||
|
||||
TestThread() = delete;
|
||||
~TestThread(){};
|
||||
~TestThread() {};
|
||||
|
||||
bool ReadyToWork() override;
|
||||
|
||||
@@ -158,7 +157,7 @@ HWTEST_F(UtilsThreadTest, testThread001, TestSize.Level0)
|
||||
pthread_t thread = test->GetThread();
|
||||
|
||||
// pthread_equal return non-zero if equal
|
||||
EXPECT_EQ(pthread_equal(thread ,-1) != 0, (test->IsRunning() ? false : true));
|
||||
EXPECT_EQ(pthread_equal(thread, -1) != 0, (test->IsRunning() ? false : true));
|
||||
|
||||
// ReadyToWork return false, RUN will not be called!
|
||||
EXPECT_EQ(test->priority_, DEFAULT_PRIO);
|
||||
@@ -170,7 +169,7 @@ HWTEST_F(UtilsThreadTest, testThread001, TestSize.Level0)
|
||||
EXPECT_EQ(times, 0);
|
||||
test->NotifyExitSync();
|
||||
sleep(1);
|
||||
EXPECT_EQ(pthread_equal(test->GetThread() ,-1) != 0, (test->IsRunning() ? false : true));
|
||||
EXPECT_EQ(pthread_equal(test->GetThread(), -1) != 0, (test->IsRunning() ? false : true));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -188,7 +187,7 @@ HWTEST_F(UtilsThreadTest, testThread002, TestSize.Level0)
|
||||
sleep(1); // let the new thread has chance to run
|
||||
|
||||
// pthread_equal return non-zero if equal, RUN return false,may exit already
|
||||
EXPECT_EQ(pthread_equal(test->GetThread() ,-1) != 0, (test->IsRunning() ? false : true));
|
||||
EXPECT_EQ(pthread_equal(test->GetThread(), -1) != 0, (test->IsRunning() ? false : true));
|
||||
|
||||
// ReadyToWork return true, RUN will be called!
|
||||
EXPECT_EQ(test->priority_, THREAD_PROI_LOW);
|
||||
@@ -198,7 +197,7 @@ HWTEST_F(UtilsThreadTest, testThread002, TestSize.Level0)
|
||||
EXPECT_EQ(times, 0);
|
||||
test->NotifyExitSync();
|
||||
sleep(1);
|
||||
EXPECT_EQ(pthread_equal(test->GetThread() ,-1) != 0, (test->IsRunning() ? false : true));
|
||||
EXPECT_EQ(pthread_equal(test->GetThread(), -1) != 0, (test->IsRunning() ? false : true));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -225,7 +224,7 @@ HWTEST_F(UtilsThreadTest, testThread003, TestSize.Level0)
|
||||
EXPECT_EQ(times, 0);
|
||||
test->NotifyExitSync();
|
||||
sleep(1);
|
||||
EXPECT_EQ(pthread_equal(test->GetThread() ,-1) != 0, (test->IsRunning() ? false : true));
|
||||
EXPECT_EQ(pthread_equal(test->GetThread(), -1) != 0, (test->IsRunning() ? false : true));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -243,7 +242,7 @@ HWTEST_F(UtilsThreadTest, testThread004, TestSize.Level0)
|
||||
sleep(1); // let the new thread has chance to run
|
||||
|
||||
// pthread_equal return non-zero if equal, RUN return false,may exit already
|
||||
EXPECT_EQ(pthread_equal(test->GetThread() ,-1) != 0, (test->IsRunning() ? false : true));
|
||||
EXPECT_EQ(pthread_equal(test->GetThread(), -1) != 0, (test->IsRunning() ? false : true));
|
||||
|
||||
// ReadyToWork return true, RUN will be called!
|
||||
EXPECT_EQ(test->priority_, THREAD_PROI_LOW);
|
||||
@@ -253,7 +252,7 @@ HWTEST_F(UtilsThreadTest, testThread004, TestSize.Level0)
|
||||
EXPECT_EQ(times, 0);
|
||||
test->NotifyExitSync();
|
||||
sleep(1);
|
||||
EXPECT_EQ(pthread_equal(test->GetThread() ,-1) != 0, (test->IsRunning() ? false : true));
|
||||
EXPECT_EQ(pthread_equal(test->GetThread(), -1) != 0, (test->IsRunning() ? false : true));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -280,7 +279,7 @@ HWTEST_F(UtilsThreadTest, testThread005, TestSize.Level0)
|
||||
EXPECT_EQ(times, 0);
|
||||
test->NotifyExitSync();
|
||||
sleep(1);
|
||||
EXPECT_EQ(pthread_equal(test->GetThread() ,-1) != 0, (test->IsRunning() ? false : true));
|
||||
EXPECT_EQ(pthread_equal(test->GetThread(), -1) != 0, (test->IsRunning() ? false : true));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -298,7 +297,7 @@ HWTEST_F(UtilsThreadTest, testThread006, TestSize.Level0)
|
||||
sleep(1); // let the new thread has chance to run
|
||||
|
||||
// pthread_equal return non-zero if equal, RUN return false,may exit already
|
||||
EXPECT_EQ(pthread_equal(test->GetThread() ,-1) != 0, (test->IsRunning() ? false : true));
|
||||
EXPECT_EQ(pthread_equal(test->GetThread(), -1) != 0, (test->IsRunning() ? false : true));
|
||||
|
||||
// ReadyToWork return true, RUN will be called!
|
||||
EXPECT_EQ(test->priority_, THREAD_PROI_LOW);
|
||||
@@ -308,11 +307,11 @@ HWTEST_F(UtilsThreadTest, testThread006, TestSize.Level0)
|
||||
EXPECT_EQ(times, 0);
|
||||
|
||||
times = 100;
|
||||
EXPECT_GT(test->data_, 10);
|
||||
EXPECT_GT(test->data_, 10);
|
||||
|
||||
sleep(1); // let the new thread has chance to run
|
||||
|
||||
// times > 10, TestRun03 return false, thread exit
|
||||
EXPECT_EQ(pthread_equal(test->GetThread() ,-1) != 0, (test->IsRunning() ? false : true));
|
||||
EXPECT_EQ(pthread_equal(test->GetThread(), -1) != 0, (test->IsRunning() ? false : true));
|
||||
}
|
||||
|
||||
|
||||
@@ -145,7 +145,7 @@ HWTEST_F(UtilsTimerTest, testTimer004, TestSize.Level0)
|
||||
|
||||
class A {
|
||||
public:
|
||||
explicit A(int data) : data_(data), timer_("ATimer"){}
|
||||
explicit A(int data) : data_(data), timer_("ATimer") {}
|
||||
~A() = default;
|
||||
bool Init();
|
||||
bool StartTimer(int milliseconds, bool once);
|
||||
|
||||
Reference in New Issue
Block a user