summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/maid_test.cpp8
-rw-r--r--test/path_test.cpp3
-rw-r--r--test/ringbuffer_test.cpp51
-rw-r--r--test/symbol_test.cpp29
-rw-r--r--test/time_test.cpp3
5 files changed, 48 insertions, 46 deletions
diff --git a/test/maid_test.cpp b/test/maid_test.cpp
index ba4086a..94e09c6 100644
--- a/test/maid_test.cpp
+++ b/test/maid_test.cpp
@@ -28,8 +28,8 @@
using Raul::Maid;
-static const size_t n_threads = 8;
-static const size_t n_junk_per_thread = 1 << 18;
+static const size_t n_threads = 8U;
+static const size_t n_junk_per_thread = 1U << 18U;
static std::atomic<size_t> n_junk(0);
static std::atomic<size_t> n_finished_threads(0);
@@ -37,7 +37,7 @@ static std::atomic<size_t> n_finished_threads(0);
class Junk : public Maid::Disposable {
public:
explicit Junk(size_t v) : val(v) { ++n_junk; }
- ~Junk() { --n_junk; }
+ ~Junk() override { --n_junk; }
size_t val;
};
@@ -79,7 +79,7 @@ test()
// Create some threads to produce garbage
std::vector<std::thread> litterers;
for (size_t i = 0; i < n_threads; ++i) {
- litterers.push_back(std::thread(litter, &maid));
+ litterers.emplace_back(litter, &maid);
}
// Wait for some garbage to show up if necessary (unlikely)
diff --git a/test/path_test.cpp b/test/path_test.cpp
index 9391063..538a262 100644
--- a/test/path_test.cpp
+++ b/test/path_test.cpp
@@ -78,8 +78,7 @@ main()
CHECK(!strcmp(Path("/").symbol(), ""));
Path original(std::string("/foo/bar"));
- Path copy(original);
- CHECK(original == copy);
+ CHECK(original == Path(original));
bool valid = true;
try {
diff --git a/test/ringbuffer_test.cpp b/test/ringbuffer_test.cpp
index aeebacd..daae419 100644
--- a/test/ringbuffer_test.cpp
+++ b/test/ringbuffer_test.cpp
@@ -28,9 +28,13 @@
namespace {
-Raul::RingBuffer* ring = 0;
-size_t n_writes = 0;
-bool ring_error = false;
+using RingBuffer = Raul::RingBuffer;
+
+struct Context {
+ std::unique_ptr<RingBuffer> ring;
+ size_t n_writes{0};
+ size_t ring_errors{0};
+};
int
gen_msg(int* msg, int start)
@@ -56,7 +60,7 @@ cmp_msg(int* msg1, int* msg2)
}
void
-reader()
+reader(Context& ctx)
{
printf("Reader starting\n");
@@ -64,17 +68,17 @@ reader()
int read_msg[MSG_SIZE]; // Read from ring
size_t count = 0;
int start = gen_msg(ref_msg, 0);
- for (size_t i = 0; i < n_writes; ++i) {
- if (ring->read_space() >= MSG_SIZE * sizeof(int)) {
- const uint32_t n_read = ring->read(MSG_SIZE * sizeof(int), read_msg);
+ for (size_t i = 0; i < ctx.n_writes; ++i) {
+ if (ctx.ring->read_space() >= MSG_SIZE * sizeof(int)) {
+ const uint32_t n_read = ctx.ring->read(MSG_SIZE * sizeof(int), read_msg);
if (n_read != MSG_SIZE * sizeof(int)) {
fprintf(stderr, "FAIL: Read size incorrect\n");
- ring_error = true;
+ ++ctx.ring_errors;
return;
}
if (!cmp_msg(ref_msg, read_msg)) {
fprintf(stderr, "FAIL: Message %zu is corrupt\n", count);
- ring_error = true;
+ ++ctx.ring_errors;
return;
}
start = gen_msg(ref_msg, start);
@@ -86,18 +90,18 @@ reader()
}
void
-writer()
+writer(Context& ctx)
{
printf("Writer starting\n");
int write_msg[MSG_SIZE]; // Written to ring
int start = gen_msg(write_msg, 0);
- for (size_t i = 0; i < n_writes; ++i) {
- if (ring->write_space() >= MSG_SIZE * sizeof(int)) {
- const uint32_t n_write = ring->write(MSG_SIZE * sizeof(int), write_msg);
+ for (size_t i = 0; i < ctx.n_writes; ++i) {
+ if (ctx.ring->write_space() >= MSG_SIZE * sizeof(int)) {
+ const uint32_t n_write = ctx.ring->write(MSG_SIZE * sizeof(int), write_msg);
if (n_write != MSG_SIZE * sizeof(int)) {
fprintf(stderr, "FAIL: Write size incorrect\n");
- ring_error = true;
+ ++ctx.ring_errors;
return;
}
start = gen_msg(write_msg, start);
@@ -117,20 +121,24 @@ main(int argc, char** argv)
return 1;
}
+ Context ctx;
+
size_t size = 1024;
if (argc > 1) {
size = std::stoul(argv[1]);
}
- n_writes = size * 1024;
+ ctx.n_writes = size * 1024;
if (argc > 2) {
- n_writes = std::stoul(argv[2]);
+ ctx.n_writes = std::stoul(argv[2]);
}
printf("Testing %zu writes of %u ints to a %zu int ring...\n",
- n_writes, MSG_SIZE, size);
+ ctx.n_writes, MSG_SIZE, size);
+
+ ctx.ring = std::unique_ptr<RingBuffer>(new RingBuffer(uint32_t(size)));
- ring = new Raul::RingBuffer(uint32_t(size));
+ auto& ring = ctx.ring;
if (ring->capacity() < size - 1) {
fprintf(stderr, "Ring capacity is smaller than expected\n");
return 1;
@@ -187,17 +195,16 @@ main(int argc, char** argv)
ring->reset();
- std::thread reader_thread(reader);
- std::thread writer_thread(writer);
+ std::thread reader_thread(reader, std::ref(ctx));
+ std::thread writer_thread(writer, std::ref(ctx));
reader_thread.join();
writer_thread.join();
- if (ring_error) {
+ if (ctx.ring_errors) {
fprintf(stderr, "FAIL: Error occurred\n");
return 1;
}
- delete ring;
return 0;
}
diff --git a/test/symbol_test.cpp b/test/symbol_test.cpp
index 0fa0039..4af598b 100644
--- a/test/symbol_test.cpp
+++ b/test/symbol_test.cpp
@@ -32,27 +32,26 @@ main()
} } while (0)
std::list<std::string> names;
- names.push_back("Dry/Wet Balance");
- names.push_back("foo+1bar(baz)");
- names.push_back("ThisCRAR");
- names.push_back("NAME");
- names.push_back("thing with a bunch of spaces");
- names.push_back("thing-with-a-bunch-of-dashes");
- names.push_back("CamelCaseABC");
- names.push_back("Signal Level [dB]");
- names.push_back("Gain dB");
- names.push_back("Dry/Wet Balance");
- names.push_back("Phaser1 - Similar to CSound's phaser1 by Sean Costello");
- names.push_back("1");
- names.push_back("");
+ names.emplace_back("Dry/Wet Balance");
+ names.emplace_back("foo+1bar(baz)");
+ names.emplace_back("ThisCRAR");
+ names.emplace_back("NAME");
+ names.emplace_back("thing with a bunch of spaces");
+ names.emplace_back("thing-with-a-bunch-of-dashes");
+ names.emplace_back("CamelCaseABC");
+ names.emplace_back("Signal Level [dB]");
+ names.emplace_back("Gain dB");
+ names.emplace_back("Dry/Wet Balance");
+ names.emplace_back("Phaser1 - Similar to CSound's phaser1 by Sean Costello");
+ names.emplace_back("1");
+ names.emplace_back("");
for (const auto& name : names) {
CHECK(!Symbol::symbolify(name).empty());
}
Symbol original("sym");
- Symbol copy(original);
- CHECK(original == copy);
+ CHECK(original == Symbol(original));
bool valid = true;
try {
diff --git a/test/time_test.cpp b/test/time_test.cpp
index 61b9b9a..4b72feb 100644
--- a/test/time_test.cpp
+++ b/test/time_test.cpp
@@ -20,9 +20,6 @@
#include <cstdint>
#include <iostream>
-using namespace std;
-using namespace Raul;
-
int
main()
{