diff options
author | David Robillard <d@drobilla.net> | 2010-01-07 21:27:39 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2010-01-07 21:27:39 +0000 |
commit | 0d009a4e980e40dc8a9c9b5e3d25c3fafb363e95 (patch) | |
tree | 4d41dea009f1647519af8df10f114cd7a6165792 | |
parent | 61ac4a41f0aea63f45d7b27be3ef2e0554e93ece (diff) | |
download | raul-0d009a4e980e40dc8a9c9b5e3d25c3fafb363e95.tar.gz raul-0d009a4e980e40dc8a9c9b5e3d25c3fafb363e95.tar.bz2 raul-0d009a4e980e40dc8a9c9b5e3d25c3fafb363e95.zip |
Move unit testing and coverage framework into autowaf.
Make raul tests return 0 on success, 1 on failure.
Test coverage for Raul.
git-svn-id: http://svn.drobilla.net/lad/trunk/raul@2368 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r-- | test/atomic_test.cpp (renamed from tests/atomic_test.cpp) | 0 | ||||
-rw-r--r-- | test/list_test.cpp | 141 | ||||
-rw-r--r-- | test/midi_ringbuffer_test.cpp (renamed from tests/midi_ringbuffer_test.cpp) | 33 | ||||
-rw-r--r-- | test/path_test.cpp | 68 | ||||
-rw-r--r-- | test/quantize_test.cpp | 25 | ||||
-rw-r--r-- | test/queue_test.cpp (renamed from tests/queue_test.cpp) | 74 | ||||
-rw-r--r-- | test/ringbuffer_test.cpp (renamed from tests/ringbuffer_test.cpp) | 0 | ||||
-rw-r--r-- | test/smf_test.cpp (renamed from tests/smf_test.cpp) | 0 | ||||
-rw-r--r-- | test/table_test.cpp (renamed from tests/table_test.cpp) | 19 | ||||
-rw-r--r-- | test/thread_test.cpp (renamed from tests/thread_test.cpp) | 0 | ||||
-rw-r--r-- | test/time_test.cpp (renamed from tests/time_test.cpp) | 0 | ||||
-rw-r--r-- | tests/list_test.cpp | 168 | ||||
-rw-r--r-- | tests/path_test.cpp | 46 | ||||
-rw-r--r-- | tests/quantize_test.cpp | 31 | ||||
-rw-r--r-- | tests/wscript | 25 | ||||
-rw-r--r-- | wscript | 49 |
16 files changed, 325 insertions, 354 deletions
diff --git a/tests/atomic_test.cpp b/test/atomic_test.cpp index 6611c91..6611c91 100644 --- a/tests/atomic_test.cpp +++ b/test/atomic_test.cpp diff --git a/test/list_test.cpp b/test/list_test.cpp new file mode 100644 index 0000000..664ca5b --- /dev/null +++ b/test/list_test.cpp @@ -0,0 +1,141 @@ +#include <iostream> +#include <cstddef> +#include "raul/log.hpp" +#include "raul/List.hpp" + +using namespace std; +using namespace Raul; + +int +main() +{ +#define CHECK(cond) \ + do { if (!(cond)) { \ + error << "Test at " << __FILE__ << ":" << __LINE__ << " failed: " << __STRING(cond) << endl; \ + return 1; \ + } } while (0) + + List<int> l; + + l.push_back(new List<int>::Node(1)); + l.push_back(new List<int>::Node(2)); + l.push_back(new List<int>::Node(3)); + l.push_back(new List<int>::Node(4)); + l.push_back(new List<int>::Node(5)); + l.push_back(new List<int>::Node(6)); + l.push_back(new List<int>::Node(7)); + l.push_back(new List<int>::Node(8)); + + /*cout << "List:" << endl; + for (List<int>::iterator i = l.begin(); i != l.end(); ++i) { + cout << *i << endl; + } + cout << endl;*/ + + // Remove 4 + for (List<int>::iterator i = l.begin(); i != l.end(); ++i) { + if ((*i) == 4) { + l.erase(i); + break; + } + } + + // Check + int idx = 0; + for (List<int>::iterator i = l.begin(); i != l.end(); ++i, ++idx) { + if (idx < 3) + CHECK(*i == idx + 1); + else + CHECK(*i == idx + 2); + } + + // Remove 1 (head) + for (List<int>::iterator i = l.begin(); i != l.end(); ++i) { + if ((*i) == 1) { + l.erase(i); + break; + } + } + + // Check + idx = 0; + for (List<int>::iterator i = l.begin(); i != l.end(); ++i, ++idx) { + if (idx < 2) + CHECK(*i == idx + 2); + else + CHECK(*i == idx + 3); + } + + // Remove 8 (tail) + for (List<int>::iterator i = l.begin(); i != l.end(); ++i) { + if ((*i) == 8) { + l.erase(i); + break; + } + } + + // Check + idx = 0; + for (List<int>::iterator i = l.begin(); i != l.end(); ++i, ++idx) { + if (idx < 2) + CHECK(*i == idx + 2); + else if (idx < 4) + CHECK(*i == idx + 3); + else + CHECK(*i == 7); + } + + // Create, push, erase (should get empty list) + List<int> r; + r.push_back(new List<int>::Node(9)); + r.erase(r.begin()); + CHECK(r.size() == 0); + CHECK(r.empty()); + + // Appending to an empty list + l.clear(); + CHECK(l.size() == 0); + CHECK(l.empty()); + + List<int> l2; + l2.push_back(new List<int>::Node(0)); + l2.push_back(new List<int>::Node(2)); + l2.push_back(new List<int>::Node(4)); + l2.push_back(new List<int>::Node(6)); + + l.append(l2); + idx = 0; + for (List<int>::iterator i = l.begin(); i != l.end(); ++i, ++idx) { + CHECK(*i == idx * 2); + } + + // Appending non-empty lists + l2.push_back(new List<int>::Node(5)); + l2.push_back(new List<int>::Node(6)); + l2.push_back(new List<int>::Node(7)); + l2.push_back(new List<int>::Node(8)); + + l.append(l2); + idx = 0; + for (List<int>::iterator i = l.begin(); i != l.end(); ++i, ++idx) { + if (idx < 4) + CHECK(*i == idx * 2); + else + CHECK(*i == idx + 1); + } + + + // Appending an empty list + l2.clear(); + l.append(l2); + + idx = 0; + for (List<int>::iterator i = l.begin(); i != l.end(); ++i, ++idx) { + if (idx < 4) + CHECK(*i == idx * 2); + else + CHECK(*i == idx + 1); + } + + return 0; +} diff --git a/tests/midi_ringbuffer_test.cpp b/test/midi_ringbuffer_test.cpp index 1e55caf..f75cfd5 100644 --- a/tests/midi_ringbuffer_test.cpp +++ b/test/midi_ringbuffer_test.cpp @@ -1,35 +1,31 @@ -#include "raul/TimeStamp.hpp" -#include "raul/EventRingBuffer.hpp" #include <iostream> #include <cstring> #include <cstdio> -#include "raul/midi_names.h" #include <stdio.h> +#include "raul/TimeStamp.hpp" +#include "raul/EventRingBuffer.hpp" +#include "raul/midi_names.h" + using namespace std; using namespace Raul; -void +int read_write_test(EventRingBuffer& rb, unsigned offset) { TimeStamp t(TimeUnit(TimeUnit::FRAMES, 48000), 0, 0); size_t size; - unsigned char buf[5]; + unsigned char write_buf[5]; + unsigned char read_buf[5]; - snprintf((char*)buf, 5, "%d", offset); - size = strlen((char*)buf); + snprintf((char*)write_buf, 5, "%d", offset); + size = strlen((char*)write_buf); -#ifndef NDEBUG - size_t written = rb.write(t, size, buf); -#endif + const size_t written = rb.write(t, size, write_buf); assert(written == size); - for (size_t i=0; i < 4; ++i) - buf[i] = 0; - - rb.read(&t, &size, buf); - - cout << "t=" << t << ", s=" << size << ", b='" << buf << "'" << endl; + rb.read(&t, &size, read_buf); + return (strncmp((const char*)write_buf, (const char*)read_buf, size)); } @@ -38,8 +34,9 @@ main() { EventRingBuffer rb(32); - for (size_t i=0; i < 9999; ++i) - read_write_test(rb, i); + for (size_t i = 0; i < 1000000; ++i) + if (read_write_test(rb, i)) + return 1; return 0; } diff --git a/test/path_test.cpp b/test/path_test.cpp new file mode 100644 index 0000000..099b463 --- /dev/null +++ b/test/path_test.cpp @@ -0,0 +1,68 @@ +#include <iostream> +#include <list> +#include "raul/log.hpp" +#include "raul/Path.hpp" + +using namespace std; +using namespace Raul; + +int +main() +{ +#define CHECK(cond) \ + do { if (!(cond)) { \ + error << "Test failed: " << (cond) << endl; \ + return 1; \ + } } while (0) + + list<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"); + + for (list<string>::iterator i = names.begin(); i != names.end(); ++i) { + CHECK(Symbol::is_valid(Path::nameify(*i))); + CHECK(Symbol::is_valid(Symbol::symbolify(*i))); + } + + CHECK(Path("/foo/bar").parent() == Path("/foo")); + CHECK(Path("/foo").parent() == Path("/")); + CHECK(Path("/").parent() == Path("/")); + + CHECK(Path("/").is_parent_of(Path("/foo"))); + CHECK(Path("/foo").is_parent_of(Path("/foo/bar"))); + CHECK(!(Path("/foo").is_parent_of(Path("/foo2")))); + + CHECK(!Path::is_valid("")); + CHECK(!Path::is_valid("hello")); + CHECK(!Path::is_valid("/foo/bar/")); + CHECK(!Path::is_valid("/foo//bar")); + CHECK(!Path::is_valid("/foo/bar/d*s")); + CHECK(Path::is_valid("/")); + CHECK(!Path::is_valid("/foo/3foo/bar")); + + CHECK(Path::descendant_comparator("/", "/foo")); + CHECK(Path::descendant_comparator("/foo", "/foo/bar")); + CHECK(Path::descendant_comparator("/foo", "/foo")); + CHECK(Path::descendant_comparator("/", "/")); + CHECK(!Path::descendant_comparator("/baz", "/")); + CHECK(!Path::descendant_comparator("/foo", "/bar")); + CHECK(!Path::descendant_comparator("/foo/bar", "/foo")); + + CHECK(!Symbol::is_valid("")); + CHECK(!Symbol::is_valid("/I/have/slashes")); + CHECK(!Symbol::is_valid("!illegalchar")); + CHECK(!Symbol::is_valid("0illegalleadingdigit")); + CHECK(Symbol::is_valid(Symbol::symbolify(""))); + CHECK(Symbol::is_valid(Symbol::symbolify("1hello"))); + + return 0; +} diff --git a/test/quantize_test.cpp b/test/quantize_test.cpp new file mode 100644 index 0000000..39ba899 --- /dev/null +++ b/test/quantize_test.cpp @@ -0,0 +1,25 @@ +#include "raul/Quantizer.hpp" +#include <iostream> + +using namespace std; +using namespace Raul; + + +int +main() +{ + TimeStamp q(TimeUnit(TimeUnit::BEATS, 19200), 0.25); + + for (double in = 0.0; in < 32; in += 0.23) { + TimeStamp beats(TimeUnit(TimeUnit::BEATS, 19200), in); + + cout << "Q(" << in << ", 1/4) = " + << Quantizer::quantize(q, beats) << endl; + + if (Quantizer::quantize(q, beats).subticks() % (19200/4) != 0) + return 1; + } + + return 0; +} + diff --git a/tests/queue_test.cpp b/test/queue_test.cpp index 28d06d8..49ba6f2 100644 --- a/tests/queue_test.cpp +++ b/test/queue_test.cpp @@ -4,8 +4,6 @@ #include <algorithm> #include <stdio.h> #include <stdlib.h> -#include <fcntl.h> -#include <termios.h> #include "raul/SRSWQueue.hpp" #include "raul/SRMWQueue.hpp" #include "raul/Thread.hpp" @@ -15,9 +13,9 @@ using namespace std; using namespace Raul; static const unsigned NUM_DATA = 10; -static const unsigned QUEUE_SIZE = 1024*1024; +static const unsigned QUEUE_SIZE = 128; static const unsigned NUM_WRITERS = 2; -static const unsigned PUSHES_PER_ITERATION = 2; +static const unsigned PUSHES_PER_ITERATION = 3; // Data to read/write using actions pumped through the queue struct Record { @@ -32,18 +30,13 @@ Record data[NUM_DATA]; // Actions pumped through the queue to manipulate data struct WriteAction { - WriteAction(unsigned idx) - : index(idx)/*, has_read(false)*/ {} + WriteAction(unsigned idx) : index(idx) {} inline void read() const { - //cout << "READ " << index << "\r\n"; - //assert(!has_read); ++(data[index].read_count); - //has_read = true; }; unsigned index; - //bool has_read; }; @@ -54,11 +47,8 @@ SRMWQueue<WriteAction> queue(QUEUE_SIZE); class WriteThread : public Thread { protected: void _run() { - - cout << "Writer starting.\r\n"; - // Wait for everything to get ready - sleep(2); + sleep(1); while (true) { for (unsigned j=0; j < PUSHES_PER_ITERATION; ++j) { @@ -67,17 +57,12 @@ protected: ++(data[i].write_count); //cout << "WRITE " << i << "\r\n"; } else { - cerr << "FAILED WRITE\r\n"; + //cerr << "FAILED WRITE\r\n"; } } - // FIXME: remove! - //if (rand() % 20) - // usleep(1); - // This thread will never cancel without this here since - // all the stuff about is cancellation point free - // (good! RT safe) + // this loop is hard RT safe and thus cancellation point free pthread_testcancel(); } @@ -92,7 +77,7 @@ unsigned data_is_sane() { unsigned ret = 0; - for (unsigned i=0; i < NUM_DATA; ++i) { + for (unsigned i = 0; i < NUM_DATA; ++i) { unsigned diff = abs(data[i].read_count.get() - data[i].write_count.get()); ret += diff; } @@ -104,7 +89,7 @@ data_is_sane() void dump_data() { - for (unsigned i=0; i < NUM_DATA; ++i) { + for (unsigned i = 0; i < NUM_DATA; ++i) { cout << i << ":\t" << data[i].read_count.get() << "\t : \t" << data[i].write_count.get(); if (data[i].read_count.get() == data[i].write_count.get()) @@ -115,8 +100,8 @@ dump_data() } - -int main() +int +main() { unsigned long total_processed = 0; @@ -138,7 +123,7 @@ int main() } } - for (unsigned i=0; i < queue.capacity(); ++i) + for (unsigned i = 0; i < queue.capacity(); ++i) queue.pop(); if (!queue.empty()) { @@ -149,23 +134,16 @@ int main() cout << "Testing concurrent reading/writing" << endl; vector<WriteThread*> writers(NUM_WRITERS, new WriteThread()); - struct termios orig_term; - struct termios raw_term; - - cfmakeraw(&raw_term); - if (tcgetattr(0, &orig_term) != 0) return 1; //save terminal settings - if (tcsetattr(0, TCSANOW, &raw_term) != 0) return 1; //set to raw - fcntl(0, F_SETFL, O_NONBLOCK); //set to nonblocking IO on stdin - - for (unsigned i=0; i < NUM_WRITERS; ++i) { writers[i]->set_name(string("Writer ") + (char)('0' + i)); writers[i]->start(); } + sleep(1); + // Read - while (getchar() == -1) { - unsigned count = 0; + unsigned count = 0; + for (unsigned i = 0; i < 10000000; ++i) { while (count < queue.capacity() && !queue.empty()) { WriteAction action = queue.front(); queue.pop(); @@ -176,21 +154,19 @@ int main() /*if (count > 0) cout << "Processed " << count << " requests\t\t" - << "(total " << total_processed << ")\r\n";*/ + << "(total " << total_processed << ")\r\n"; - //if (total_processed > 0 && total_processed % 128l == 0) - // cout << "Total processed: " << total_processed << "\r\n"; + if (total_processed > 0 && total_processed % 128l == 0) + cout << "Total processed: " << total_processed << "\r\n";*/ } - if (tcsetattr(0, TCSANOW, &orig_term) != 0) return 1; //restore - - cout << "Finishing." << endl; + cout << "Processed " << total_processed << " requests" << endl; // Stop the writers for (unsigned i=0; i < NUM_WRITERS; ++i) writers[i]->stop(); - cout << "\n\n****************** DONE *********************\n\n"; + //cout << "\n\n****************** DONE *********************\n\n"; unsigned leftovers = 0; @@ -207,7 +183,7 @@ int main() cout << "Processed " << leftovers << " leftovers." << endl; - cout << "\n\n*********************************************\n\n"; + //cout << "\n\n*********************************************\n\n"; cout << "Total processed: " << total_processed << endl; if (total_processed > INT_MAX) @@ -216,16 +192,16 @@ int main() cout << "(Counter did NOT have to wrap)" << endl; - unsigned diff = data_is_sane(); + const unsigned diff = data_is_sane(); if (diff == 0) { - cout << "PASS" << endl; + return EXIT_SUCCESS; } else { cout << "FAILED BY " << diff << endl; - // dump_data(); + return EXIT_FAILURE; } - dump_data(); + //dump_data(); return 0; } diff --git a/tests/ringbuffer_test.cpp b/test/ringbuffer_test.cpp index 87b81c6..87b81c6 100644 --- a/tests/ringbuffer_test.cpp +++ b/test/ringbuffer_test.cpp diff --git a/tests/smf_test.cpp b/test/smf_test.cpp index 40465ed..40465ed 100644 --- a/tests/smf_test.cpp +++ b/test/smf_test.cpp diff --git a/tests/table_test.cpp b/test/table_test.cpp index 5e83479..882873a 100644 --- a/tests/table_test.cpp +++ b/test/table_test.cpp @@ -162,10 +162,6 @@ main(int argc, char** argv) /* **** */ - cout << "\nAssuming you built with debugging, if this continues to run " - << "and chews your CPU without dying, everything's good." << endl; - - Table<string, string> st; st.insert(make_pair("apple", "core")); @@ -180,7 +176,7 @@ main(int argc, char** argv) cout << i->first << " "; cout << endl; - while (true) { + for (int i = 0; i < 1000; ++i) { Table<int, int> t; size_t table_size = (rand() % 1000) + 1; @@ -198,14 +194,13 @@ main(int argc, char** argv) /*cout << "CONTENTS:" << endl; - for (Table<int,int>::const_iterator i = t.begin(); i != t.end(); ++i) { - cout << i->first << ": " << i->second << endl; - } + for (Table<int,int>::const_iterator i = t.begin(); i != t.end(); ++i) { + cout << i->first << ": " << i->second << endl; + } - Table<int,int>::iterator i = t.find(7); - if (i != t.end()) - cout << "Find: 7: " << i->second << endl; - */ + Table<int,int>::iterator i = t.find(7); + if (i != t.end()) + cout << "Find: 7: " << i->second << endl;*/ } return 0; diff --git a/tests/thread_test.cpp b/test/thread_test.cpp index fd7a411..fd7a411 100644 --- a/tests/thread_test.cpp +++ b/test/thread_test.cpp diff --git a/tests/time_test.cpp b/test/time_test.cpp index 2b53207..2b53207 100644 --- a/tests/time_test.cpp +++ b/test/time_test.cpp diff --git a/tests/list_test.cpp b/tests/list_test.cpp deleted file mode 100644 index ae139ce..0000000 --- a/tests/list_test.cpp +++ /dev/null @@ -1,168 +0,0 @@ -#include <iostream> -#include <cstddef> -#include "raul/List.hpp" - -using namespace std; -using namespace Raul; - - -int main() -{ - List<int> l; - - l.push_back(new List<int>::Node(1)); - l.push_back(new List<int>::Node(2)); - l.push_back(new List<int>::Node(3)); - l.push_back(new List<int>::Node(4)); - l.push_back(new List<int>::Node(5)); - l.push_back(new List<int>::Node(6)); - l.push_back(new List<int>::Node(7)); - l.push_back(new List<int>::Node(8)); - - cout << "List:" << endl; - for (List<int>::iterator i = l.begin(); i != l.end(); ++i) { - cout << *i << endl; - } - cout << endl; - - - for (List<int>::iterator i = l.begin(); i != l.end(); ++i) { - if ((*i) == 4) { - l.erase(i); - break; - } - } - - cout << "Removed 4 (by iterator)...\n"; - for (List<int>::iterator i = l.begin(); i != l.end(); ++i) { - cout << *i << endl; - } - cout << endl; - - /*l.remove(1); - - cout << "Removed 1 (head) (by value)...\n"; - for (List<int>::iterator i = l.begin(); i != l.end(); ++i) { - cout << *i << endl; - } - cout << endl; - */ - - for (List<int>::iterator i = l.begin(); i != l.end(); ++i) { - if ((*i) == 2) { - l.erase(i); - break; - } - } - - cout << "Removed 2 (head) (by iterator)...\n"; - for (List<int>::iterator i = l.begin(); i != l.end(); ++i) { - cout << *i << endl; - } - cout << endl; - - /*l.remove(5); - - cout << "Removed 5 (by value)...\n"; - for (List<int>::iterator i = l.begin(); i != l.end(); ++i) { - cout << *i << endl; - } - cout << endl; - - l.remove(8); - - cout << "Removed 8 (tail) (by value)...\n"; - for (List<int>::iterator i = l.begin(); i != l.end(); ++i) { - cout << *i << endl; - } - cout << endl; - */ - for (List<int>::iterator i = l.begin(); i != l.end(); ++i) { - if ((*i) == 7) { - l.erase(i); - break; - } - } - - cout << "Removed 7 (tail) (by iterator)...\n"; - for (List<int>::iterator i = l.begin(); i != l.end(); ++i) { - cout << *i << endl; - } - cout << endl; - - List<int> r; - r.push_back(new List<int>::Node(9)); - r.erase(r.begin()); - cout << "Should not see ANY numbers:\n"; - for (List<int>::iterator i = r.begin(); i != r.end(); ++i) { - cout << *i << endl; - } - - cout << "\n\nTesting appending to an empty list:\n"; - l.clear(); - - List<int> l2; - l2.push_back(new List<int>::Node(1)); - l2.push_back(new List<int>::Node(2)); - l2.push_back(new List<int>::Node(3)); - l2.push_back(new List<int>::Node(4)); - - cout << "l1:\n"; - for (List<int>::iterator i = l.begin(); i != l.end(); ++i) { - cout << *i << endl; - } - - cout << "l2:\n"; - for (List<int>::iterator i = l2.begin(); i != l2.end(); ++i) { - cout << *i << endl; - } - - l.append(l2); - cout << "l1.append(l2):\n"; - for (List<int>::iterator i = l.begin(); i != l.end(); ++i) { - cout << *i << endl; - } - - cout << "\n\nAppending non-empty lists:\n"; - l2.push_back(new List<int>::Node(5)); - l2.push_back(new List<int>::Node(6)); - l2.push_back(new List<int>::Node(7)); - l2.push_back(new List<int>::Node(8)); - - cout << "l1:\n"; - for (List<int>::iterator i = l.begin(); i != l.end(); ++i) { - cout << *i << endl; - } - - cout << "l2:\n"; - for (List<int>::iterator i = l2.begin(); i != l2.end(); ++i) { - cout << *i << endl; - } - - l.append(l2); - cout << "l1.append(l2):\n"; - for (List<int>::iterator i = l.begin(); i != l.end(); ++i) { - cout << *i << endl; - } - - - cout << "\n\nAppending an empty list:\n"; - - cout << "l1:\n"; - for (List<int>::iterator i = l.begin(); i != l.end(); ++i) { - cout << *i << endl; - } - - cout << "l2:\n"; - for (List<int>::iterator i = l2.begin(); i != l2.end(); ++i) { - cout << *i << endl; - } - - l.append(l2); - cout << "l1.append(l2):\n"; - for (List<int>::iterator i = l.begin(); i != l.end(); ++i) { - cout << *i << endl; - } - - return 0; -} diff --git a/tests/path_test.cpp b/tests/path_test.cpp deleted file mode 100644 index 20d6705..0000000 --- a/tests/path_test.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include <iostream> -#include <list> -#include "raul/Path.hpp" - -using namespace std; -using namespace Raul; - -int -main() -{ - list<string> names; - 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"); - - cerr << "Nameification:" << endl; - for (list<string>::iterator i = names.begin(); i != names.end(); ++i) - cerr << *i << " -> " << Path::nameify(*i) << endl; - - cerr << endl; - cerr << Path("/foo/bar") << " parent = " << Path("/foo/bar").parent() << endl; - cerr << Path("/foo") << " parent = " << Path("/foo").parent() << endl; - cerr << Path("/") << " parent = " << Path("/").parent() << endl; - - cerr << "1's are good..." << endl << endl; - - cerr << (Path("/").is_parent_of(Path("/foo"))) << endl; - cerr << (Path("/foo").is_parent_of(Path("/foo/bar"))) << endl; - cerr << !(Path("/foo").is_parent_of(Path("/foo2"))) << endl; - - cerr << endl << endl << "Descendants..." << endl; - cerr << "/ /foo " << Path::descendant_comparator("/", "/foo") << endl; - cerr << "/foo /foo/bar " << Path::descendant_comparator("/foo", "/foo/bar") << endl; - cerr << "/foo /foo " << Path::descendant_comparator("/foo", "/foo") << endl; - cerr << "/ / " << Path::descendant_comparator("/", "/") << endl; - cerr << "/baz / " << Path::descendant_comparator("/baz", "/") << endl; - - return 0; -} diff --git a/tests/quantize_test.cpp b/tests/quantize_test.cpp deleted file mode 100644 index cc10505..0000000 --- a/tests/quantize_test.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "raul/Quantizer.hpp" -#include <iostream> - -using namespace std; -using namespace Raul; - - -int -main() -{ - double in = 0; - - cout << "Quantization: "; - cin >> in; - cout << endl; - - TimeStamp q(TimeUnit(TimeUnit::BEATS, 19200), in); - - while (true) { - cout << "Beats: "; - cin >> in; - - TimeStamp beats(TimeUnit(TimeUnit::BEATS, 19200), in); - - cout << "Quantized: "; - cout << Quantizer::quantize(q, beats) << endl << endl; - } - - return 0; -} - diff --git a/tests/wscript b/tests/wscript deleted file mode 100644 index 1997c1a..0000000 --- a/tests/wscript +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env python - -def build(bld): - tests = ''' - path_test - thread_test - queue_test - ringbuffer_test - midi_ringbuffer_test - atomic_test - list_test - time_test - quantize_test - smf_test - table_test - ''' - if bld.env['BUILD_TESTS']: - for i in tests.split(): - obj = bld.new_task_gen('cxx', 'program') - obj.source = i + '.cpp' - obj.includes = '..' - obj.uselib_local = 'libraul' - obj.target = i - obj.install_path = '' - @@ -59,6 +59,20 @@ def configure(conf): autowaf.print_summary(conf) autowaf.display_msg(conf, "Unit tests", str(conf.env['BUILD_TESTS'])) print + +tests = ''' + test/path_test + test/thread_test + test/queue_test + test/ringbuffer_test + test/midi_ringbuffer_test + test/atomic_test + test/list_test + test/time_test + test/quantize_test + test/smf_test + test/table_test +''' def build(bld): # Headers @@ -68,9 +82,7 @@ def build(bld): # Pkgconfig file autowaf.build_pc(bld, 'RAUL', RAUL_VERSION, 'GLIBMM GTHREAD') - # Library - obj = bld.new_task_gen('cxx', 'shlib') - obj.source = ''' + lib_source = ''' src/Configuration.cpp src/Maid.cpp src/Path.cpp @@ -80,21 +92,48 @@ def build(bld): src/Thread.cpp src/log.cpp ''' + + # Library + obj = bld.new_task_gen('cxx', 'shlib') obj.export_incdirs = ['.'] + obj.source = lib_source obj.includes = ['.', './src'] obj.name = 'libraul' obj.target = 'raul' obj.uselib = 'GLIBMM GTHREAD' obj.install_path = '${LIBDIR}' obj.vnum = RAUL_LIB_VERSION + + if bld.env['BUILD_TESTS']: + # Static library (for unit test code coverage) + obj = bld.new_task_gen('cxx', 'staticlib') + obj.source = lib_source + obj.includes = ['.', './src'] + obj.name = 'libraul_static' + obj.target = 'raul_static' + obj.uselib = 'GLIBMM GTHREAD' + obj.install_path = '' + obj.cxxflags = [ '-fprofile-arcs', '-ftest-coverage' ] - # Unit tests - bld.add_subdirs('tests') + # Unit tests + for i in tests.split(): + obj = bld.new_task_gen('cxx', 'program') + obj.source = i + '.cpp' + obj.includes = '..' + obj.uselib_local = 'libraul_static' + obj.uselib = 'GLIB GLIBMM' + obj.libs = 'gcov' + obj.target = i + obj.install_path = '' + obj.cxxflags = [ '-fprofile-arcs', '-ftest-coverage' ] # Documentation autowaf.build_dox(bld, 'RAUL', RAUL_VERSION, srcdir, blddir) bld.install_files('${HTMLDIR}', blddir + '/default/doc/html/*') +def test(ctx): + autowaf.run_tests(APPNAME, tests.split()) + def shutdown(): autowaf.shutdown() |