summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am8
-rw-r--r--tests/queue_test.cpp47
-rw-r--r--tests/thread_test.cpp16
3 files changed, 69 insertions, 2 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0732d07..2389628 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,8 +1,12 @@
if BUILD_TESTS
-AM_CXXFLAGS = -I..
-bin_PROGRAMS = path_test
+AM_CXXFLAGS = -I.. -lpthread
+bin_PROGRAMS = path_test thread_test queue_test
+
+thread_test_LDADD = ../src/libraul.la
path_test_SOURCES = path_test.cpp
+thread_test_SOURCES = thread_test.cpp
+queue_test_SOURCES = queue_test.cpp
endif
diff --git a/tests/queue_test.cpp b/tests/queue_test.cpp
new file mode 100644
index 0000000..c39d156
--- /dev/null
+++ b/tests/queue_test.cpp
@@ -0,0 +1,47 @@
+#include <iostream>
+#include <string>
+#include "raul/Queue.h"
+
+using std::string; using std::cerr; using std::cout; using std::endl;
+
+
+int main()
+{
+ Queue<int> q(10);
+
+ cout << "New queue. Should be empty: " << q.is_empty() << endl;
+ cout << "Capacity: " << q.capacity() << endl;
+ cout << "Fill: " << q.fill() << endl;
+
+ for (uint i=0; i < 5; ++i) {
+ q.push(i);
+ assert(!q.is_full());
+ q.pop();
+ }
+ cout << "Pushed and popped 5 elements. Queue should be empty: " << q.is_empty() << endl;
+ cout << "Fill: " << q.fill() << endl;
+
+ for (uint i=10; i < 20; ++i) {
+ q.push(i);
+ }
+ cout << "Pushed 10 elements. Queue should be full: " << q.is_full() << endl;
+ cout << "Fill: " << q.fill() << endl;
+
+ cout << "The digits 10->19 should print: " << endl;
+ while (!q.is_empty()) {
+ int foo = q.pop();
+ cout << "Popped: " << foo << endl;
+ }
+ cout << "Queue should be empty: " << q.is_empty() << endl;
+ cout << "Fill: " << q.fill() << endl;
+
+ cout << "Attempting to add eleven elements to queue of size 10. Only first 10 should succeed:" << endl;
+ for (uint i=20; i <= 39; ++i) {
+ cout << i;
+ cout << " - Fill: " << q.fill();
+ cout << ", is full: " << q.is_full();
+ cout << ", succeeded: " << q.push(i) << endl;
+ }
+
+ return 0;
+}
diff --git a/tests/thread_test.cpp b/tests/thread_test.cpp
new file mode 100644
index 0000000..7a4d875
--- /dev/null
+++ b/tests/thread_test.cpp
@@ -0,0 +1,16 @@
+#include <iostream>
+#include <raul/Thread.h>
+
+using namespace std;
+
+int
+main()
+{
+ Thread& this_thread = Thread::get();
+ this_thread.set_name("Main");
+
+ cerr << "Thread name: " << Thread::get().name() << endl;
+
+ return 0;
+}
+