summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2011-12-04 01:19:09 -0800
committerPixel <pixel@nobis-crew.org>2011-12-04 01:20:10 -0800
commitd440c3f50a918a932293ad98bcec96eaa4683222 (patch)
tree33e8e42a8e4506ae9da70cdb44dd133bde7f7219 /tests
parente5577eb7a643ce7885e5d14660a6d24254161622 (diff)
Reworked some things in the architecture, mainly exceptions and asserts.
-) Removed Assert() -) Added AAssert(), IAssert(), RAssert(), TAssert() and Failure() -) Reworked all asserts in the code, and added meaningful messages to them. -) Changed the way the startup code is generated; BALAU_STARTUP is no longer necessary.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-Handles.cc56
-rw-r--r--tests/test-Http.cc11
-rw-r--r--tests/test-Lua.cc12
-rw-r--r--tests/test-Regex.cc12
-rw-r--r--tests/test-Sanity.cc8
-rw-r--r--tests/test-Sockets.cc16
-rw-r--r--tests/test-String.cc52
-rw-r--r--tests/test-Tasks.cc14
-rw-r--r--tests/test-Threads.cc3
9 files changed, 84 insertions, 100 deletions
diff --git a/tests/test-Handles.cc b/tests/test-Handles.cc
index f185b60..c872e9f 100644
--- a/tests/test-Handles.cc
+++ b/tests/test-Handles.cc
@@ -14,8 +14,6 @@ void ctime_r(const time_t * t, char * str) {
}
#endif
-BALAU_STARTUP;
-
using namespace Balau;
void MainTask::Do() {
@@ -28,7 +26,7 @@ void MainTask::Do() {
catch (ENoEnt e) {
failed = true;
}
- Assert(failed);
+ TAssert(failed);
IO<Handle> i(new Input("tests/rtest.txt"));
Printer::log(M_STATUS, "Opened file %s:", i->getName());
Printer::log(M_STATUS, " - size = %lli", i->getSize());
@@ -39,71 +37,71 @@ void MainTask::Do() {
char * nl = strrchr(mtimestr, '\n');
if (nl)
*nl = 0;
- Printer::log(M_STATUS, " - mtime = %i (%s)", mtime, mtimestr);
+ Printer::log(M_STATUS, " - mtime = %li (%s)", mtime, mtimestr);
off_t s = i->rtell();
- Assert(s == 0);
+ TAssert(s == 0);
i->rseek(0, SEEK_END);
s = i->rtell();
- Assert(s == i->getSize());
+ TAssert(s == i->getSize());
i->rseek(0, SEEK_SET);
char * buf1 = (char *) malloc(i->getSize());
ssize_t r = i->read(buf1, s + 15);
- Printer::log(M_STATUS, "Read %i bytes (instead of %i)", r, s + 15);
- Assert(i->isEOF())
+ Printer::log(M_STATUS, "Read %li bytes (instead of %lli)", r, s + 15);
+ TAssert(i->isEOF())
char * buf2 = (char *) malloc(i->getSize());
i->rseek(0, SEEK_SET);
- Assert(!i->isEOF());
- Assert(i->rtell() == 0);
+ TAssert(!i->isEOF());
+ TAssert(i->rtell() == 0);
r = i->read(buf2, 5);
- Assert(r == 5);
- Assert(i->rtell() == 5);
+ TAssert(r == 5);
+ TAssert(i->rtell() == 5);
r = i->read(buf2 + 5, s - 5);
- Assert(r == (s - 5));
- Assert(memcmp(buf1, buf2, s) == 0);
+ TAssert(r == (s - 5));
+ TAssert(memcmp(buf1, buf2, s) == 0);
IO<Handle> o(new Output("tests/out.txt"));
s = o->wtell();
- Assert(s == 0);
+ TAssert(s == 0);
s = o->getSize();
- Assert(s == 0);
+ TAssert(s == 0);
o->writeString("foo\n");
IO<Handle> b(new Buffer());
s = b->rtell();
- Assert(s == 0);
+ TAssert(s == 0);
s = b->wtell();
- Assert(s == 0);
+ TAssert(s == 0);
b->writeString("foo\n");
s = b->rtell();
- Assert(s == 0);
+ TAssert(s == 0);
s = b->wtell();
- Assert(s == 4);
+ TAssert(s == 4);
b->writeString("bar\r\n");
s = b->rtell();
- Assert(s == 0);
+ TAssert(s == 0);
s = b->wtell();
- Assert(s == 9);
+ TAssert(s == 9);
b->writeString("eof");
s = b->rtell();
- Assert(s == 0);
+ TAssert(s == 0);
s = b->wtell();
- Assert(s == 12);
+ TAssert(s == 12);
IO<BStream> strm(new BStream(b));
String str;
str = strm->readString();
- Assert(str == "foo");
+ TAssert(str == "foo");
str = strm->readString();
- Assert(str == "bar");
+ TAssert(str == "bar");
str = strm->readString();
- Assert(str == "eof");
+ TAssert(str == "eof");
s = b->rtell();
- Assert(s == 12);
- Assert(b->isEOF());
+ TAssert(s == 12);
+ TAssert(b->isEOF());
Printer::log(M_STATUS, "Test::Handles passed.");
}
diff --git a/tests/test-Http.cc b/tests/test-Http.cc
index 15ef7de..e6ba38d 100644
--- a/tests/test-Http.cc
+++ b/tests/test-Http.cc
@@ -1,7 +1,6 @@
#include <Main.h>
#include <HttpServer.h>
-
-BALAU_STARTUP;
+#include <TaskMan.h>
#define DAEMON_NAME "Balau/1.0"
@@ -48,13 +47,15 @@ bool TestFailure::Do(HttpServer * server, Http::Request & req, HttpServer::Actio
throw GeneralException("Test...");
}
+#define NTHREADS 4
+
void MainTask::Do() {
Printer::enable(M_DEBUG);
Printer::log(M_STATUS, "Test::Http running.");
- Thread * tms[4];
+ Thread * tms[NTHREADS];
- for (int i = 0; i < 4; i++)
+ for (int i = 0; i < NTHREADS; i++)
tms[i] = TaskMan::createThreadedTaskMan();
HttpServer * s = new HttpServer();
@@ -70,7 +71,7 @@ void MainTask::Do() {
s->stop();
- for (int i = 0; i < 4; i++)
+ for (int i = 0; i < NTHREADS; i++)
tms[i]->join();
Printer::log(M_STATUS, "Test::Http passed.");
diff --git a/tests/test-Lua.cc b/tests/test-Lua.cc
index 86baffb..8ba3785 100644
--- a/tests/test-Lua.cc
+++ b/tests/test-Lua.cc
@@ -1,8 +1,6 @@
#include <Main.h>
#include <BLua.h>
-BALAU_STARTUP;
-
using namespace Balau;
void MainTask::Do() {
@@ -11,7 +9,7 @@ void MainTask::Do() {
Lua L;
// yeah, they really should be the same thing.
- Assert(sizeof(L) == sizeof(lua_State *));
+ TAssert(sizeof(L) == sizeof(lua_State *));
L.open_base();
L.open_table();
@@ -21,13 +19,13 @@ void MainTask::Do() {
L.open_bit();
L.open_jit();
- Assert(L.gettop() == 0);
+ TAssert(L.gettop() == 0);
L.load("return 42");
- Assert(L.gettop() == 1);
+ TAssert(L.gettop() == 1);
int r = L.tonumber();
- Assert(r == 42);
+ TAssert(r == 42);
L.pop();
- Assert(L.gettop() == 0);
+ TAssert(L.gettop() == 0);
Printer::log(M_STATUS, "Test::Lua passed.");
}
diff --git a/tests/test-Regex.cc b/tests/test-Regex.cc
index b656445..082afd2 100644
--- a/tests/test-Regex.cc
+++ b/tests/test-Regex.cc
@@ -1,8 +1,6 @@
#include <Main.h>
#include <BRegex.h>
-BALAU_STARTUP;
-
using namespace Balau;
void MainTask::Do() {
@@ -11,11 +9,11 @@ void MainTask::Do() {
Regex reg("http://([^/ ]+)/([^? ]+)(\\?([^ ]+))?");
Regex::Captures c = reg.match("some url: http://www.test.com/uri?var1=val1 that should match");
- Assert(c[0] == "http://www.test.com/uri?var1=val1");
- Assert(c[1] == "www.test.com");
- Assert(c[2] == "uri");
- Assert(c[3] == "?var1=val1");
- Assert(c[4] == "var1=val1");
+ TAssert(c[0] == "http://www.test.com/uri?var1=val1");
+ TAssert(c[1] == "www.test.com");
+ TAssert(c[2] == "uri");
+ TAssert(c[3] == "?var1=val1");
+ TAssert(c[4] == "var1=val1");
Printer::log(M_STATUS, "Test::Regex passed");
}
diff --git a/tests/test-Sanity.cc b/tests/test-Sanity.cc
index 9ed9b4e..22120ab 100644
--- a/tests/test-Sanity.cc
+++ b/tests/test-Sanity.cc
@@ -1,15 +1,13 @@
#include <Main.h>
-BALAU_STARTUP;
-
using namespace Balau;
void MainTask::Do() {
Printer::log(M_STATUS, "Test::Sanity running.");
- Assert(sizeof(off_t) == 8);
- Assert(sizeof(size_t) == 4);
- Assert(sizeof(time_t) == 4);
+ TAssert(sizeof(off_t) == 8);
+ TAssert(sizeof(size_t) == 4);
+ TAssert(sizeof(time_t) == 4);
Printer::log(M_STATUS, "Test::Sanity passed.");
}
diff --git a/tests/test-Sockets.cc b/tests/test-Sockets.cc
index 87d557b..073548a 100644
--- a/tests/test-Sockets.cc
+++ b/tests/test-Sockets.cc
@@ -1,8 +1,6 @@
#include <Main.h>
#include <Socket.h>
-BALAU_STARTUP;
-
using namespace Balau;
class Worker : public Task {
@@ -28,11 +26,11 @@ void Worker::Do() {
int r;
r = m_io->read(&x, 1);
- Assert(x == 'x');
- Assert(r == 1);
+ TAssert(x == 'x');
+ TAssert(r == 1);
y = 'y';
r = m_io->write(&y, 1);
- Assert(r == 1);
+ TAssert(r == 1);
}
Listener<Worker> * listener;
@@ -48,14 +46,14 @@ class Client : public Task {
char x, y;
IO<Socket> s(new Socket());
bool c = s->connect("localhost", 1234);
- Assert(c);
+ TAssert(c);
x = 'x';
int r;
r = s->write(&x, 1);
- Assert(r == 1);
+ TAssert(r == 1);
r = s->read(&y, 1);
- Assert(y == 'y');
- Assert(r == 1);
+ TAssert(y == 'y');
+ TAssert(r == 1);
listener->stop();
}
};
diff --git a/tests/test-String.cc b/tests/test-String.cc
index 1f7efc0..9637911 100644
--- a/tests/test-String.cc
+++ b/tests/test-String.cc
@@ -1,54 +1,52 @@
#include <BString.h>
#include <Main.h>
-BALAU_STARTUP;
-
using namespace Balau;
void MainTask::Do() {
Printer::log(M_STATUS, "Test::String running.");
String x = "foobar";
- Assert(x == "foobar");
- Assert(x != "barfoo");
+ TAssert(x == "foobar");
+ TAssert(x != "barfoo");
String y = "xyz";
- x = "abcdef"; Assert(x < y); Assert(x + y == "abcdefxyz");
- x.set("x:%i", 42); Assert(x == "x:42");
+ x = "abcdef"; TAssert(x < y); TAssert(x + y == "abcdefxyz");
+ x.set("x:%i", 42); TAssert(x == "x:42");
- x = "foobar"; Assert(x == "foobar");
+ x = "foobar"; TAssert(x == "foobar");
- y = x.extract(3); Assert(y == "bar");
- y = x.extract(1, 3); Assert(y == "oob");
+ y = x.extract(3); TAssert(y == "bar");
+ y = x.extract(1, 3); TAssert(y == "oob");
y = " foo bar ";
- x = y; x.do_ltrim(); Assert(x == "foo bar ");
- x = y; x.do_rtrim(); Assert(x == " foo bar");
- x = y; x.do_trim(); Assert(x == "foo bar");
+ x = y; x.do_ltrim(); TAssert(x == "foo bar ");
+ x = y; x.do_rtrim(); TAssert(x == " foo bar");
+ x = y; x.do_trim(); TAssert(x == "foo bar");
y = " ";
- x = y; x.do_ltrim(); Assert(x == "");
- x = y; x.do_rtrim(); Assert(x == "");
- x = y; x.do_trim(); Assert(x == "");
+ x = y; x.do_ltrim(); TAssert(x == "");
+ x = y; x.do_rtrim(); TAssert(x == "");
+ x = y; x.do_trim(); TAssert(x == "");
- x = "42"; Assert(x.to_int() == 42);
- x = "0x42"; Assert(x.to_int() == 0x42);
- x = "42"; Assert(x.to_int(16) == 0x42);
- x = "4.2"; Assert(x.to_double() == 4.2);
+ x = "42"; TAssert(x.to_int() == 42);
+ x = "0x42"; TAssert(x.to_int() == 0x42);
+ x = "42"; TAssert(x.to_int(16) == 0x42);
+ x = "4.2"; TAssert(x.to_double() == 4.2);
x = "foobar";
- Assert(x[0] == 'f');
- Assert(x[5] == 'r');
- Assert(x.strlen() == 6);
- Assert(x.strchr('o') == 1);
- Assert(x.strrchr('o') == 2);
- Assert(x.strchrcnt('o') == 2);
- Assert(x.strstr("bar") == 3);
+ TAssert(x[0] == 'f');
+ TAssert(x[5] == 'r');
+ TAssert(x.strlen() == 6);
+ TAssert(x.strchr('o') == 1);
+ TAssert(x.strrchr('o') == 2);
+ TAssert(x.strchrcnt('o') == 2);
+ TAssert(x.strstr("bar") == 3);
x = "\xc3\xa9";
y = x.iconv("UTF-8", "Latin1");
- Assert(((unsigned char) y[0]) == 0xe9);
+ TAssert(((unsigned char) y[0]) == 0xe9);
Printer::log(M_STATUS, "Test::String passed.");
}
diff --git a/tests/test-Tasks.cc b/tests/test-Tasks.cc
index 8677fb7..4b26406 100644
--- a/tests/test-Tasks.cc
+++ b/tests/test-Tasks.cc
@@ -2,8 +2,6 @@
#include <Task.h>
#include <TaskMan.h>
-BALAU_STARTUP;
-
using namespace Balau;
class CustomPrinter : public Printer {
@@ -25,7 +23,7 @@ class TestTask : public Task {
static void yieldingFunction() {
Events::Timeout timeout(0.2);
Task::yield(&timeout);
- Assert(timeout.gotSignal());
+ TAssert(timeout.gotSignal());
}
void MainTask::Do() {
@@ -35,22 +33,22 @@ void MainTask::Do() {
Task * testTask = Balau::createTask(new TestTask());
Events::TaskEvent taskEvt(testTask);
waitFor(&taskEvt);
- Assert(!taskEvt.gotSignal());
+ TAssert(!taskEvt.gotSignal());
yield();
- Assert(taskEvt.gotSignal());
+ TAssert(taskEvt.gotSignal());
taskEvt.ack();
Events::Timeout timeout(0.1);
waitFor(&timeout);
- Assert(!timeout.gotSignal());
+ TAssert(!timeout.gotSignal());
yield();
- Assert(timeout.gotSignal());
+ TAssert(timeout.gotSignal());
timeout.set(0.1);
timeout.reset();
waitFor(&timeout);
yieldingFunction();
- Assert(timeout.gotSignal());
+ TAssert(timeout.gotSignal());
Printer::log(M_STATUS, "Test::Tasks passed.");
Printer::log(M_DEBUG, "You shouldn't see that message.");
diff --git a/tests/test-Threads.cc b/tests/test-Threads.cc
index 1005906..50cc741 100644
--- a/tests/test-Threads.cc
+++ b/tests/test-Threads.cc
@@ -1,12 +1,9 @@
#include <Main.h>
#include <Threads.h>
-BALAU_STARTUP;
-
using namespace Balau;
class TestThread : public Thread {
- private:
virtual void * proc();
};