mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-07 01:06:45 +08:00
(void) => ()
This commit is contained in:
parent
eb2e75d5b7
commit
9c9ca8f5c4
@ -12,19 +12,19 @@ QVector<QObject*>* suites__ = nullptr;
|
|||||||
|
|
||||||
} // internal-linkage
|
} // internal-linkage
|
||||||
|
|
||||||
TestSuite::TestSuite(void) {
|
TestSuite::TestSuite() {
|
||||||
static struct __ {
|
static struct __ {
|
||||||
QVector<QObject*> suites_;
|
QVector<QObject*> suites_;
|
||||||
__(void) { suites__ = &suites_; }
|
__() { suites__ = &suites_; }
|
||||||
} _;
|
} _;
|
||||||
_.suites_ << this;
|
_.suites_ << this;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* TestSuite::name(void) const {
|
const char* TestSuite::name() const {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestSuite::initTestCase(void) {
|
void TestSuite::initTestCase() {
|
||||||
qDebug() << QString("#### Start: %1 ####").arg(name());
|
qDebug() << QString("#### Start: %1 ####").arg(name());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -7,11 +7,11 @@ class TestSuite : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit TestSuite(void);
|
explicit TestSuite();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual const char* name(void) const;
|
virtual const char* name() const;
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
virtual void initTestCase(void);
|
virtual void initTestCase();
|
||||||
};
|
};
|
||||||
|
|||||||
@ -17,21 +17,21 @@ namespace {
|
|||||||
class Unit : public TestSuite {
|
class Unit : public TestSuite {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
const char* name(void) const {
|
const char* name() const {
|
||||||
return "test_circ";
|
return "test_circ";
|
||||||
}
|
}
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void initTestCase(void);
|
void initTestCase();
|
||||||
void cleanupTestCase(void);
|
void cleanupTestCase();
|
||||||
|
|
||||||
void test_inst(void);
|
void test_inst();
|
||||||
void test_prod_cons_1v1(void);
|
void test_prod_cons_1v1();
|
||||||
void test_prod_cons_1v3(void);
|
void test_prod_cons_1v3();
|
||||||
void test_prod_cons_3v1(void);
|
void test_prod_cons_3v1();
|
||||||
void test_prod_cons_performance(void);
|
void test_prod_cons_performance();
|
||||||
|
|
||||||
void test_queue(void);
|
void test_queue();
|
||||||
} unit__;
|
} unit__;
|
||||||
|
|
||||||
#include "test_circ.moc"
|
#include "test_circ.moc"
|
||||||
@ -41,16 +41,16 @@ cq_t* cq__;
|
|||||||
|
|
||||||
constexpr int LoopCount = 1000000;
|
constexpr int LoopCount = 1000000;
|
||||||
|
|
||||||
void Unit::initTestCase(void) {
|
void Unit::initTestCase() {
|
||||||
TestSuite::initTestCase();
|
TestSuite::initTestCase();
|
||||||
cq__ = new cq_t;
|
cq__ = new cq_t;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Unit::cleanupTestCase(void) {
|
void Unit::cleanupTestCase() {
|
||||||
delete cq__;
|
delete cq__;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Unit::test_inst(void) {
|
void Unit::test_inst() {
|
||||||
std::cout << "cq_t::head_size = " << cq_t::head_size << std::endl;
|
std::cout << "cq_t::head_size = " << cq_t::head_size << std::endl;
|
||||||
std::cout << "cq_t::data_size = " << cq_t::data_size << std::endl;
|
std::cout << "cq_t::data_size = " << cq_t::data_size << std::endl;
|
||||||
std::cout << "cq_t::elem_size = " << cq_t::elem_size << std::endl;
|
std::cout << "cq_t::elem_size = " << cq_t::elem_size << std::endl;
|
||||||
@ -77,7 +77,7 @@ struct test_stopwatch {
|
|||||||
capo::stopwatch<> sw_;
|
capo::stopwatch<> sw_;
|
||||||
std::atomic_flag started_ = ATOMIC_FLAG_INIT;
|
std::atomic_flag started_ = ATOMIC_FLAG_INIT;
|
||||||
|
|
||||||
void start(void) {
|
void start() {
|
||||||
if (!started_.test_and_set()) {
|
if (!started_.test_and_set()) {
|
||||||
sw_.start();
|
sw_.start();
|
||||||
}
|
}
|
||||||
@ -101,7 +101,7 @@ struct test_verify {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
~test_verify(void) {
|
~test_verify() {
|
||||||
delete [] list_;
|
delete [] list_;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,7 +152,7 @@ struct test_cq<ipc::circ::elem_array<D>> {
|
|||||||
::new (ca) ca_t;
|
::new (ca) ca_t;
|
||||||
}
|
}
|
||||||
|
|
||||||
cn_t connect(void) {
|
cn_t connect() {
|
||||||
auto cur = ca_->cursor();
|
auto cur = ca_->cursor();
|
||||||
ca_->connect();
|
ca_->connect();
|
||||||
return cur;
|
return cur;
|
||||||
@ -201,7 +201,7 @@ struct test_cq<ipc::circ::queue<T>> {
|
|||||||
::new (ca_) ca_t;
|
::new (ca_) ca_t;
|
||||||
}
|
}
|
||||||
|
|
||||||
cn_t connect(void) {
|
cn_t connect() {
|
||||||
cn_t queue;
|
cn_t queue;
|
||||||
[&] {
|
[&] {
|
||||||
queue.attach(ca_);
|
queue.attach(ca_);
|
||||||
@ -284,25 +284,25 @@ void test_prod_cons(T* cq) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <int N, int M, bool V = true, int Loops = LoopCount>
|
template <int N, int M, bool V = true, int Loops = LoopCount>
|
||||||
void test_prod_cons(void) {
|
void test_prod_cons() {
|
||||||
test_prod_cons<N, M, V, Loops>(cq__);
|
test_prod_cons<N, M, V, Loops>(cq__);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Unit::test_prod_cons_1v1(void) {
|
void Unit::test_prod_cons_1v1() {
|
||||||
test_prod_cons<1, 1>();
|
test_prod_cons<1, 1>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Unit::test_prod_cons_1v3(void) {
|
void Unit::test_prod_cons_1v3() {
|
||||||
test_prod_cons<1, 3>();
|
test_prod_cons<1, 3>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Unit::test_prod_cons_3v1(void) {
|
void Unit::test_prod_cons_3v1() {
|
||||||
test_prod_cons<3, 1>();
|
test_prod_cons<3, 1>();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <int P, int C>
|
template <int P, int C>
|
||||||
struct test_performance {
|
struct test_performance {
|
||||||
static void start(void) {
|
static void start() {
|
||||||
test_performance<P - 1, C - 1>::start();
|
test_performance<P - 1, C - 1>::start();
|
||||||
test_prod_cons<P, C, false>();
|
test_prod_cons<P, C, false>();
|
||||||
}
|
}
|
||||||
@ -310,7 +310,7 @@ struct test_performance {
|
|||||||
|
|
||||||
template <int C>
|
template <int C>
|
||||||
struct test_performance<1, C> {
|
struct test_performance<1, C> {
|
||||||
static void start(void) {
|
static void start() {
|
||||||
test_performance<1, C - 1>::start();
|
test_performance<1, C - 1>::start();
|
||||||
test_prod_cons<1, C, false>();
|
test_prod_cons<1, C, false>();
|
||||||
}
|
}
|
||||||
@ -318,7 +318,7 @@ struct test_performance<1, C> {
|
|||||||
|
|
||||||
template <int P>
|
template <int P>
|
||||||
struct test_performance<P, 1> {
|
struct test_performance<P, 1> {
|
||||||
static void start(void) {
|
static void start() {
|
||||||
test_performance<P - 1, 1>::start();
|
test_performance<P - 1, 1>::start();
|
||||||
test_prod_cons<P, 1, false>();
|
test_prod_cons<P, 1, false>();
|
||||||
}
|
}
|
||||||
@ -326,19 +326,19 @@ struct test_performance<P, 1> {
|
|||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct test_performance<1, 1> {
|
struct test_performance<1, 1> {
|
||||||
static void start(void) {
|
static void start() {
|
||||||
test_prod_cons<1, 1, false>();
|
test_prod_cons<1, 1, false>();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void Unit::test_prod_cons_performance(void) {
|
void Unit::test_prod_cons_performance() {
|
||||||
test_performance<1 , 10>::start();
|
test_performance<1 , 10>::start();
|
||||||
test_performance<10, 1 >::start();
|
test_performance<10, 1 >::start();
|
||||||
test_performance<10, 10>::start();
|
test_performance<10, 10>::start();
|
||||||
test_prod_cons <3 , 3 >(); // test & verify
|
test_prod_cons <3 , 3 >(); // test & verify
|
||||||
}
|
}
|
||||||
|
|
||||||
void Unit::test_queue(void) {
|
void Unit::test_queue() {
|
||||||
ipc::circ::queue<msg_t> queue;
|
ipc::circ::queue<msg_t> queue;
|
||||||
queue.push(1, 2);
|
queue.push(1, 2);
|
||||||
QVERIFY_EXCEPTION_THROWN(queue.pop(), std::exception);
|
QVERIFY_EXCEPTION_THROWN(queue.pop(), std::exception);
|
||||||
|
|||||||
@ -6,17 +6,18 @@ namespace {
|
|||||||
class Unit : public TestSuite {
|
class Unit : public TestSuite {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
const char* name(void) const {
|
const char* name() const {
|
||||||
return "test_ipc";
|
return "test_ipc";
|
||||||
}
|
}
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void test_send_recv(void);
|
void test_send_recv();
|
||||||
|
void test_rw_lock();
|
||||||
} unit__;
|
} unit__;
|
||||||
|
|
||||||
#include "test_ipc.moc"
|
#include "test_ipc.moc"
|
||||||
|
|
||||||
void Unit::test_send_recv(void) {
|
void Unit::test_send_recv() {
|
||||||
auto h = ipc::connect("my-ipc");
|
auto h = ipc::connect("my-ipc");
|
||||||
QVERIFY(h != nullptr);
|
QVERIFY(h != nullptr);
|
||||||
char data[] = "hello ipc!";
|
char data[] = "hello ipc!";
|
||||||
@ -26,4 +27,8 @@ void Unit::test_send_recv(void) {
|
|||||||
ipc::disconnect(h);
|
ipc::disconnect(h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Unit::test_rw_lock() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
} // internal-linkage
|
} // internal-linkage
|
||||||
|
|||||||
@ -12,23 +12,23 @@ namespace {
|
|||||||
class Unit : public TestSuite {
|
class Unit : public TestSuite {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
const char* name(void) const {
|
const char* name() const {
|
||||||
return "test_shm";
|
return "test_shm";
|
||||||
}
|
}
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void test_acquire(void);
|
void test_acquire();
|
||||||
void test_release(void);
|
void test_release();
|
||||||
void test_get(void);
|
void test_get();
|
||||||
void test_hello(void);
|
void test_hello();
|
||||||
void test_mt(void);
|
void test_mt();
|
||||||
} unit__;
|
} unit__;
|
||||||
|
|
||||||
#include "test_shm.moc"
|
#include "test_shm.moc"
|
||||||
|
|
||||||
handle shm_hd__;
|
handle shm_hd__;
|
||||||
|
|
||||||
void Unit::test_acquire(void) {
|
void Unit::test_acquire() {
|
||||||
QVERIFY(!shm_hd__.valid());
|
QVERIFY(!shm_hd__.valid());
|
||||||
|
|
||||||
QVERIFY(shm_hd__.acquire("my-test-1", 1024));
|
QVERIFY(shm_hd__.acquire("my-test-1", 1024));
|
||||||
@ -44,13 +44,13 @@ void Unit::test_acquire(void) {
|
|||||||
QCOMPARE(shm_hd__.name(), "my-test-3");
|
QCOMPARE(shm_hd__.name(), "my-test-3");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Unit::test_release(void) {
|
void Unit::test_release() {
|
||||||
QVERIFY(shm_hd__.valid());
|
QVERIFY(shm_hd__.valid());
|
||||||
shm_hd__.release();
|
shm_hd__.release();
|
||||||
QVERIFY(!shm_hd__.valid());
|
QVERIFY(!shm_hd__.valid());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Unit::test_get(void) {
|
void Unit::test_get() {
|
||||||
QVERIFY(shm_hd__.get() == nullptr);
|
QVERIFY(shm_hd__.get() == nullptr);
|
||||||
QVERIFY(shm_hd__.acquire("my-test", 1024));
|
QVERIFY(shm_hd__.acquire("my-test", 1024));
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ void Unit::test_get(void) {
|
|||||||
QVERIFY(mem == shm_hd__.get());
|
QVERIFY(mem == shm_hd__.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Unit::test_hello(void) {
|
void Unit::test_hello() {
|
||||||
auto mem = shm_hd__.get();
|
auto mem = shm_hd__.get();
|
||||||
QVERIFY(mem != nullptr);
|
QVERIFY(mem != nullptr);
|
||||||
|
|
||||||
@ -76,7 +76,7 @@ void Unit::test_hello(void) {
|
|||||||
QCOMPARE((char*)shm_hd__.get(), hello);
|
QCOMPARE((char*)shm_hd__.get(), hello);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Unit::test_mt(void) {
|
void Unit::test_mt() {
|
||||||
std::thread {
|
std::thread {
|
||||||
[] {
|
[] {
|
||||||
handle shm_mt(shm_hd__.name(), shm_hd__.size());
|
handle shm_mt(shm_hd__.name(), shm_hd__.size());
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user