summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/maid_test.cpp10
-rw-r--r--test/queue_test.cpp36
-rw-r--r--test/ringbuffer_test.cpp25
-rw-r--r--test/thread_test.cpp6
-rw-r--r--test/uri_test.cpp4
5 files changed, 45 insertions, 36 deletions
diff --git a/test/maid_test.cpp b/test/maid_test.cpp
index 8bf4f45..e21ba04 100644
--- a/test/maid_test.cpp
+++ b/test/maid_test.cpp
@@ -33,10 +33,10 @@ static std::atomic<size_t> n_finished_threads(0);
class Junk : public Maid::Disposable {
public:
- explicit Junk(int v) : val(v) { ++n_junk; }
+ explicit Junk(size_t v) : val(v) { ++n_junk; }
~Junk() { --n_junk; }
- int val;
+ size_t val;
};
static void
@@ -57,9 +57,9 @@ test()
// Check basic single-threaded correctness
{
assert(n_junk == 0);
- Maid::managed_ptr<Junk> a = maid.make_managed<Junk>(1);
+ Maid::managed_ptr<Junk> a = maid.make_managed<Junk>(1U);
assert(n_junk == 1);
- Maid::managed_ptr<Junk> b = maid.make_managed<Junk>(2);
+ Maid::managed_ptr<Junk> b = maid.make_managed<Junk>(2U);
assert(n_junk == 2);
}
@@ -111,7 +111,7 @@ test()
assert(n_junk == 0);
// Allocate a new object, then let it and the Maid go out of scope
- Maid::managed_ptr<Junk> c = maid.make_managed<Junk>(5);
+ Maid::managed_ptr<Junk> c = maid.make_managed<Junk>(5U);
assert(n_junk == 1);
}
diff --git a/test/queue_test.cpp b/test/queue_test.cpp
index 55b8c76..8f9ab61 100644
--- a/test/queue_test.cpp
+++ b/test/queue_test.cpp
@@ -31,10 +31,12 @@
using namespace std;
using namespace Raul;
-static const unsigned NUM_DATA = 10;
-static const unsigned QUEUE_SIZE = 128;
-static const unsigned NUM_WRITERS = 2;
-static const unsigned PUSHES_PER_ITERATION = 3;
+namespace {
+
+const unsigned NUM_DATA = 10;
+const unsigned QUEUE_SIZE = 128;
+const unsigned NUM_WRITERS = 2;
+const unsigned PUSHES_PER_ITERATION = 3;
// Data to read/write using actions pumped through the queue
struct Record {
@@ -52,7 +54,7 @@ struct WriteAction {
inline void read() const {
++(data[index].read_count);
- };
+ }
unsigned index;
};
@@ -60,12 +62,12 @@ struct WriteAction {
// The victim
SRMWQueue<WriteAction> queue(QUEUE_SIZE);
-static void
+void
test_write(bool* exit_flag)
{
while (!*exit_flag) {
for (unsigned j=0; j < PUSHES_PER_ITERATION; ++j) {
- unsigned i = rand() % NUM_DATA;
+ unsigned i = unsigned(rand()) % NUM_DATA;
if (queue.push(WriteAction(i))) {
++(data[i].write_count);
//cout << "WRITE " << i << "\r\n";
@@ -76,29 +78,31 @@ test_write(bool* exit_flag)
}
cout << "Writer exiting." << endl;
-};
+}
// Returns 0 if all read count/write count pairs are equal,
// otherwise how far off total count was
-static unsigned
+unsigned
data_is_sane()
{
unsigned ret = 0;
for (unsigned i = 0; i < NUM_DATA; ++i) {
- unsigned diff = abs(data[i].read_count.load() - data[i].write_count.load());
- ret += diff;
+ ret += unsigned(abs(data[i].read_count.load() -
+ data[i].write_count.load()));
}
return ret;
}
+} // namespace
+
int
main()
{
size_t total_processed = 0;
cout << "Testing size" << endl;
- for (size_t i=0; i < queue.capacity(); ++i) {
+ for (unsigned i = 0; i < queue.capacity(); ++i) {
queue.push(i);
if (i == queue.capacity()-1) {
if (!queue.full()) {
@@ -185,15 +189,11 @@ main()
cout << "(Counter did NOT have to wrap)" << endl;
const unsigned diff = data_is_sane();
-
- if (diff == 0) {
- return EXIT_SUCCESS;
- } else {
+ if (diff != 0) {
cout << "FAILED BY " << diff << endl;
- return EXIT_FAILURE;
}
- return 0;
+ return diff == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
#if 0
diff --git a/test/ringbuffer_test.cpp b/test/ringbuffer_test.cpp
index 7537c85..ee80e6a 100644
--- a/test/ringbuffer_test.cpp
+++ b/test/ringbuffer_test.cpp
@@ -19,6 +19,7 @@
#include <cstdlib>
#include <cstring>
#include <iostream>
+#include <string>
#include "raul/RingBuffer.hpp"
@@ -27,11 +28,13 @@ using namespace Raul;
#define MSG_SIZE 20
+namespace {
+
Raul::RingBuffer* ring = 0;
size_t n_writes = 0;
bool ring_error = false;
-static int
+int
gen_msg(int* msg, int start)
{
for (int i = 0; i < MSG_SIZE; ++i) {
@@ -41,7 +44,7 @@ gen_msg(int* msg, int start)
return start;
}
-static int
+int
cmp_msg(int* msg1, int* msg2)
{
for (int i = 0; i < MSG_SIZE; ++i) {
@@ -54,7 +57,7 @@ cmp_msg(int* msg1, int* msg2)
return 1;
}
-static void*
+void*
reader(void* arg)
{
printf("Reader starting\n");
@@ -85,7 +88,7 @@ reader(void* arg)
return NULL;
}
-static void*
+void*
writer(void* arg)
{
printf("Writer starting\n");
@@ -108,6 +111,8 @@ writer(void* arg)
return NULL;
}
+} // namespace
+
int
main(int argc, char** argv)
{
@@ -116,21 +121,21 @@ main(int argc, char** argv)
return 1;
}
- int size = 1024;
+ size_t size = 1024;
if (argc > 1) {
- size = atoi(argv[1]);
+ size = std::stoul(argv[1]);
}
n_writes = size * 1024;
if (argc > 2) {
- n_writes = atoi(argv[2]);
+ n_writes = std::stoul(argv[2]);
}
- printf("Testing %zu writes of %d ints to a %d int ring...\n",
+ printf("Testing %zu writes of %u ints to a %zu int ring...\n",
n_writes, MSG_SIZE, size);
- ring = new Raul::RingBuffer(size);
- if (ring->capacity() < (unsigned)size - 1) {
+ ring = new Raul::RingBuffer(uint32_t(size));
+ if (ring->capacity() < size - 1) {
fprintf(stderr, "Ring capacity is smaller than expected\n");
return 1;
}
diff --git a/test/thread_test.cpp b/test/thread_test.cpp
index 3d1fc8b..9012b4c 100644
--- a/test/thread_test.cpp
+++ b/test/thread_test.cpp
@@ -23,10 +23,12 @@
using namespace std;
using namespace Raul;
+namespace {
+
thread_local int var(0);
std::atomic<int> n_errors(0);
-static void
+void
wait_for_sem(Semaphore* sem)
{
var = 41;
@@ -40,6 +42,8 @@ wait_for_sem(Semaphore* sem)
}
}
+} // namespace
+
int
main()
{
diff --git a/test/uri_test.cpp b/test/uri_test.cpp
index 19debab..5e1a648 100644
--- a/test/uri_test.cpp
+++ b/test/uri_test.cpp
@@ -46,7 +46,7 @@ main()
bool valid = true;
try {
URI uri("not/a/uri");
- } catch (const URI::BadURI& e) {
+ } catch (const URI::BadURI&) {
valid = false;
}
CHECK(!valid);
@@ -54,7 +54,7 @@ main()
valid = true;
try {
URI uri(std::string("/this/is/a/path"));
- } catch (const URI::BadURI& e) {
+ } catch (const URI::BadURI&) {
valid = false;
}
CHECK(!valid);