From 247750abcbf6760bbc52aa5d64fc375d6fbee8a3 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Sun, 6 Dec 2020 19:28:06 +0900 Subject: Renaming of files in preparation for code style tools. Signed-off-by: Michele Calgaro (cherry picked from commit 00d4f92b717fbcbed6f9eee361975d6ee5380d59) --- tests/README.test | 4 +- tests/testanyref.cc | 97 --------------------- tests/testanyref.cpp | 97 +++++++++++++++++++++ tests/testbuffer.cc | 139 ----------------------------- tests/testbuffer.cpp | 139 +++++++++++++++++++++++++++++ tests/testchangenotify.cc | 195 ----------------------------------------- tests/testchangenotify.cpp | 195 +++++++++++++++++++++++++++++++++++++++++ tests/testdispatcher.cc | 41 --------- tests/testdispatcher.cpp | 41 +++++++++ tests/testflowsystem.cc | 83 ------------------ tests/testflowsystem.cpp | 83 ++++++++++++++++++ tests/testifacerepo.cc | 84 ------------------ tests/testifacerepo.cpp | 84 ++++++++++++++++++ tests/testnotification.cc | 146 ------------------------------- tests/testnotification.cpp | 146 +++++++++++++++++++++++++++++++ tests/testremote.cc | 176 ------------------------------------- tests/testremote.cpp | 176 +++++++++++++++++++++++++++++++++++++ tests/testwrapper.cc | 211 --------------------------------------------- tests/testwrapper.cpp | 211 +++++++++++++++++++++++++++++++++++++++++++++ tests/value_impl.cc | 94 -------------------- tests/value_impl.cpp | 94 ++++++++++++++++++++ 21 files changed, 1268 insertions(+), 1268 deletions(-) delete mode 100644 tests/testanyref.cc create mode 100644 tests/testanyref.cpp delete mode 100644 tests/testbuffer.cc create mode 100644 tests/testbuffer.cpp delete mode 100644 tests/testchangenotify.cc create mode 100644 tests/testchangenotify.cpp delete mode 100644 tests/testdispatcher.cc create mode 100644 tests/testdispatcher.cpp delete mode 100644 tests/testflowsystem.cc create mode 100644 tests/testflowsystem.cpp delete mode 100644 tests/testifacerepo.cc create mode 100644 tests/testifacerepo.cpp delete mode 100644 tests/testnotification.cc create mode 100644 tests/testnotification.cpp delete mode 100644 tests/testremote.cc create mode 100644 tests/testremote.cpp delete mode 100644 tests/testwrapper.cc create mode 100644 tests/testwrapper.cpp delete mode 100644 tests/value_impl.cc create mode 100644 tests/value_impl.cpp (limited to 'tests') diff --git a/tests/README.test b/tests/README.test index d605c21..f4fcb34 100644 --- a/tests/README.test +++ b/tests/README.test @@ -23,7 +23,7 @@ likely at least. How to add a new set of tests: ============================== -1. create a new .cc file, for this example we'll suppose testarithmetic.cc +1. create a new .cpp file, for this example we'll suppose testarithmetic.cpp 2. #include "test.h" 3. create a struct which will hold all your tests @@ -67,6 +67,6 @@ TESTMAIN(TestArithmetic); 7. add the following to the Makefile.am (you may want to add more source files, as required) -testarithmetic_SOURCES = testarithmetic.cc +testarithmetic_SOURCES = testarithmetic.cpp 8. add it to check_PROGRAMS diff --git a/tests/testanyref.cc b/tests/testanyref.cc deleted file mode 100644 index 861291b..0000000 --- a/tests/testanyref.cc +++ /dev/null @@ -1,97 +0,0 @@ - /* - - Copyright (C) 2000 Stefan Westerfeld - stefan@space.twc.de - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include "common.h" -#include "test.h" - -using namespace Arts; -using namespace std; - -struct TestAnyRef : public TestCase -{ - TESTCASE(TestAnyRef); - - Dispatcher dispatcher; - Buffer *buffer, *buffer2; - Any any; - - void setUp() { - buffer = new Buffer(); - any.type = ""; - any.value.clear(); - } - void tearDown() { - delete buffer; buffer = 0; - } - void copy(AnyRef& src, AnyRef& dest) - { - Buffer tmp; - src.write(&tmp); - tmp.rewind(); - dest.read(&tmp); - } - TEST(ioAnyFloat) { - // create a buffer with a float and a end-of-buffer delimiter - float f = 1.1; - buffer->writeFloat(f); - buffer->writeLong(12345678); - buffer->rewind(); - - // see if reading it as float reads the *only* the float - any.type = "float"; - - AnyRef ref(any); - ref.read(buffer); - testEquals(12345678,buffer->readLong()); - testEquals(4, any.value.size()); - - // check if the value is all right by copying it to a "real" float - float f2; - AnyRef ref2(f2); - copy(ref,ref2); - testEquals(f,f2); - } - TEST(ioAnyType) { - // do the same again with a complex structured type - Arts::InterfaceDef objInterface = - Dispatcher::the()->interfaceRepo().queryInterface("Arts::Object"); - testEquals("Arts::Object", objInterface.name); - - objInterface.writeType(*buffer); - buffer->writeLong(12345678); - buffer->rewind(); - - vector objInterfaceRaw; - buffer->read(objInterfaceRaw, buffer->remaining() - 4); - buffer->rewind(); - testAssert(objInterfaceRaw.size() > 50); - - any.type = "Arts::InterfaceDef"; - AnyRef ref(any); - ref.read(buffer); - testEquals(12345678,buffer->readLong()); - testAssert(objInterfaceRaw == any.value); - } - -}; - -TESTMAIN(TestAnyRef); diff --git a/tests/testanyref.cpp b/tests/testanyref.cpp new file mode 100644 index 0000000..861291b --- /dev/null +++ b/tests/testanyref.cpp @@ -0,0 +1,97 @@ + /* + + Copyright (C) 2000 Stefan Westerfeld + stefan@space.twc.de + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include "common.h" +#include "test.h" + +using namespace Arts; +using namespace std; + +struct TestAnyRef : public TestCase +{ + TESTCASE(TestAnyRef); + + Dispatcher dispatcher; + Buffer *buffer, *buffer2; + Any any; + + void setUp() { + buffer = new Buffer(); + any.type = ""; + any.value.clear(); + } + void tearDown() { + delete buffer; buffer = 0; + } + void copy(AnyRef& src, AnyRef& dest) + { + Buffer tmp; + src.write(&tmp); + tmp.rewind(); + dest.read(&tmp); + } + TEST(ioAnyFloat) { + // create a buffer with a float and a end-of-buffer delimiter + float f = 1.1; + buffer->writeFloat(f); + buffer->writeLong(12345678); + buffer->rewind(); + + // see if reading it as float reads the *only* the float + any.type = "float"; + + AnyRef ref(any); + ref.read(buffer); + testEquals(12345678,buffer->readLong()); + testEquals(4, any.value.size()); + + // check if the value is all right by copying it to a "real" float + float f2; + AnyRef ref2(f2); + copy(ref,ref2); + testEquals(f,f2); + } + TEST(ioAnyType) { + // do the same again with a complex structured type + Arts::InterfaceDef objInterface = + Dispatcher::the()->interfaceRepo().queryInterface("Arts::Object"); + testEquals("Arts::Object", objInterface.name); + + objInterface.writeType(*buffer); + buffer->writeLong(12345678); + buffer->rewind(); + + vector objInterfaceRaw; + buffer->read(objInterfaceRaw, buffer->remaining() - 4); + buffer->rewind(); + testAssert(objInterfaceRaw.size() > 50); + + any.type = "Arts::InterfaceDef"; + AnyRef ref(any); + ref.read(buffer); + testEquals(12345678,buffer->readLong()); + testAssert(objInterfaceRaw == any.value); + } + +}; + +TESTMAIN(TestAnyRef); diff --git a/tests/testbuffer.cc b/tests/testbuffer.cc deleted file mode 100644 index e469710..0000000 --- a/tests/testbuffer.cc +++ /dev/null @@ -1,139 +0,0 @@ - /* - - Copyright (C) 2000 Stefan Westerfeld - stefan@space.twc.de - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include "buffer.h" -#include "test.h" - -using namespace Arts; -using namespace std; - -struct TestBuffer : public TestCase -{ - TESTCASE(TestBuffer); - - Arts::Buffer *buffer, *buffer1234; - - void setUp() { - buffer = new Buffer(); - buffer1234 = new Buffer(); - buffer1234->writeByte(1); - buffer1234->writeByte(2); - buffer1234->writeByte(3); - buffer1234->writeByte(4); - } - void tearDown() { - delete buffer; buffer = 0; - delete buffer1234; buffer1234 = 0; - } - TEST(writeByte) { - buffer->writeByte(0x42); - - testEquals("42",buffer->toString("")); - testEquals(0x42,buffer->readByte()); - } - TEST(writeLong) { - buffer->writeLong(10001025); - - testEquals("00989a81",buffer->toString("")); - testEquals(10001025, buffer->readLong()); - } - TEST(writeString) { - buffer->writeString("hello"); - - /* __size__ h e l l o \0 */ - testEquals("00000006""68656c6c6f00",buffer->toString("")); - - string s; - buffer->readString(s); - testEquals("hello", s); - } - TEST(writeBool) { - buffer->writeBool(true); - buffer->writeBool(false); - - testEquals("0100",buffer->toString("")); - testEquals(true, buffer->readBool()); - testEquals(false, buffer->readBool()); - } - TEST(writeFloat) { - float f = 2.15; - buffer->writeFloat(f); - - testEquals("4009999a",buffer->toString("")); - testEquals(f,buffer->readFloat()); - } - TEST(write) { - vector b; - b.push_back(1); - b.push_back(2); - - buffer->write(b); - - testEquals("0102",buffer->toString("")); - - char c[2] = { 3,4 }; - buffer->write(c,2); - - testEquals("01020304",buffer->toString("")); - } - TEST(read) { - vector bytes; - buffer1234->read(bytes,4); - - testEquals(4, bytes.size()); - testEquals(1, bytes[0]); - testEquals(2, bytes[1]); - testEquals(3, bytes[2]); - testEquals(4, bytes[3]); - - // read shall overwrite the vector it gets as parameter - buffer1234->rewind(); - buffer1234->read(bytes,3); - testEquals(3, bytes.size()); - } - TEST(errorHandling) - { - testEquals(false, buffer1234->readError()); - testEquals(4, buffer1234->size()); - testEquals(4, buffer1234->remaining()); - buffer1234->readLong(); - testEquals(4, buffer1234->size()); - testEquals(0, buffer1234->remaining()); - testEquals(false, buffer1234->readError()); - buffer1234->readByte(); - testEquals(4, buffer1234->size()); - testEquals(0, buffer1234->remaining()); - testEquals(true, buffer1234->readError()); - - testEquals(false, buffer->readError()); - buffer->writeLong(0xdddddddd); - buffer->writeLong(0x12345678); - - // check that it terminates properly upon reading broken data - string s; - testEquals(false,buffer->readError()); - buffer->readString(s); - testEquals(true, buffer->readError()); - } -}; - -TESTMAIN(TestBuffer); diff --git a/tests/testbuffer.cpp b/tests/testbuffer.cpp new file mode 100644 index 0000000..e469710 --- /dev/null +++ b/tests/testbuffer.cpp @@ -0,0 +1,139 @@ + /* + + Copyright (C) 2000 Stefan Westerfeld + stefan@space.twc.de + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include "buffer.h" +#include "test.h" + +using namespace Arts; +using namespace std; + +struct TestBuffer : public TestCase +{ + TESTCASE(TestBuffer); + + Arts::Buffer *buffer, *buffer1234; + + void setUp() { + buffer = new Buffer(); + buffer1234 = new Buffer(); + buffer1234->writeByte(1); + buffer1234->writeByte(2); + buffer1234->writeByte(3); + buffer1234->writeByte(4); + } + void tearDown() { + delete buffer; buffer = 0; + delete buffer1234; buffer1234 = 0; + } + TEST(writeByte) { + buffer->writeByte(0x42); + + testEquals("42",buffer->toString("")); + testEquals(0x42,buffer->readByte()); + } + TEST(writeLong) { + buffer->writeLong(10001025); + + testEquals("00989a81",buffer->toString("")); + testEquals(10001025, buffer->readLong()); + } + TEST(writeString) { + buffer->writeString("hello"); + + /* __size__ h e l l o \0 */ + testEquals("00000006""68656c6c6f00",buffer->toString("")); + + string s; + buffer->readString(s); + testEquals("hello", s); + } + TEST(writeBool) { + buffer->writeBool(true); + buffer->writeBool(false); + + testEquals("0100",buffer->toString("")); + testEquals(true, buffer->readBool()); + testEquals(false, buffer->readBool()); + } + TEST(writeFloat) { + float f = 2.15; + buffer->writeFloat(f); + + testEquals("4009999a",buffer->toString("")); + testEquals(f,buffer->readFloat()); + } + TEST(write) { + vector b; + b.push_back(1); + b.push_back(2); + + buffer->write(b); + + testEquals("0102",buffer->toString("")); + + char c[2] = { 3,4 }; + buffer->write(c,2); + + testEquals("01020304",buffer->toString("")); + } + TEST(read) { + vector bytes; + buffer1234->read(bytes,4); + + testEquals(4, bytes.size()); + testEquals(1, bytes[0]); + testEquals(2, bytes[1]); + testEquals(3, bytes[2]); + testEquals(4, bytes[3]); + + // read shall overwrite the vector it gets as parameter + buffer1234->rewind(); + buffer1234->read(bytes,3); + testEquals(3, bytes.size()); + } + TEST(errorHandling) + { + testEquals(false, buffer1234->readError()); + testEquals(4, buffer1234->size()); + testEquals(4, buffer1234->remaining()); + buffer1234->readLong(); + testEquals(4, buffer1234->size()); + testEquals(0, buffer1234->remaining()); + testEquals(false, buffer1234->readError()); + buffer1234->readByte(); + testEquals(4, buffer1234->size()); + testEquals(0, buffer1234->remaining()); + testEquals(true, buffer1234->readError()); + + testEquals(false, buffer->readError()); + buffer->writeLong(0xdddddddd); + buffer->writeLong(0x12345678); + + // check that it terminates properly upon reading broken data + string s; + testEquals(false,buffer->readError()); + buffer->readString(s); + testEquals(true, buffer->readError()); + } +}; + +TESTMAIN(TestBuffer); diff --git a/tests/testchangenotify.cc b/tests/testchangenotify.cc deleted file mode 100644 index 0447e7c..0000000 --- a/tests/testchangenotify.cc +++ /dev/null @@ -1,195 +0,0 @@ - /* - - Copyright (C) 2000 Stefan Westerfeld stefan@space.twc.de - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - Permission is also granted to link this program with the Qt - library, treating Qt like a library that normally accompanies the - operating system kernel, whether or not that is in fact the case. - - */ - -#include "value.h" -#include "connect.h" -#include "test.h" -#include -#include - -using namespace std; -using namespace Arts; - -struct TestChangeNotify : public TestCase -{ - TESTCASE(TestChangeNotify); - - Arts::Dispatcher dispatcher; - float zero, three, four; - - void setUp() - { - zero = 0.0; - three = 3.0; - four = 4.0; - } - - void process() - { - dispatcher.ioManager()->processOneEvent(false); - } - - TEST(floatValue) - { - FloatValue f; - - testEquals(zero, f.value()); - - f.value(three); - testEquals(three, f.value()); - } - TEST(stringValue) - { - StringValue s; - - testEquals("",s.value()); - - s.value("hello"); - testEquals("hello", s.value()); - } - TEST(floatNotify) - { - FloatValue f1, f2; - - connect(f1,"value_changed",f2,"value"); - f1.value(three); - - process(); - testEquals(three, f2.value()); - } - TEST(floatMultiNotify) - { - FloatValue f1, f2, f3; - - connect(f1,"value_changed",f2,"value"); - connect(f1,"value_changed",f3,"value"); - f1.value(three); - - process(); - testEquals(three, f2.value()); - testEquals(three, f3.value()); - } - TEST(floatCrossNotify) - { - FloatValue f1, f2; - - connect(f1,"value_changed",f2,"value"); - connect(f2,"value_changed",f1,"value"); - f1.value(three); - - process(); - testEquals(three, f1.value()); - testEquals(three, f2.value()); - - f2.value(four); - - process(); - testEquals(four, f1.value()); - testEquals(four, f2.value()); - } - TEST(stringNotify) - { - StringValue s1, s2; - - connect(s1,"value_changed",s2,"value"); - s1.value("hello"); - - process(); - testEquals("hello", s2.value()); - } - TEST(stringMultiNotify) - { - StringValue s1, s2, s3; - - connect(s1,"value_changed",s2,"value"); - connect(s1,"value_changed",s3,"value"); - s1.value("hello"); - - process(); - testEquals("hello", s2.value()); - testEquals("hello", s3.value()); - } - TEST(stringCrossNotify) - { - StringValue s1, s2; - - connect(s1,"value_changed",s2,"value"); - connect(s2,"value_changed",s1,"value"); - s1.value("world"); - - process(); - testEquals("world", s1.value()); - testEquals("world", s2.value()); - - s2.value("test"); - - process(); - testEquals("test", s1.value()); - testEquals("test", s2.value()); - } - TEST(floatSenderToValue1) - { - FloatSender sender; - FloatValue f; - - connect(sender,"outstream",f,"value"); - vector data; - data.push_back(three); - sender.send(data); - - process(); - testEquals(three,f.value()); - } - TEST(floatSenderToValue2) - { - FloatSender sender; - FloatValue f; - - connect(sender,"outstream",f,"value"); - vector data; - data.push_back(three); - data.push_back(four); - sender.send(data); - - process(); - testEquals(four,f.value()); - } - TEST(myEnumNotify) - { - MyEnumValue e1, e2; - - connect(e1,"value_changed",e2,"value"); - - testEquals(meIdle, e1.value()); - testEquals(meIdle, e2.value()); - - e1.value(meHelloWorld); - process(); - - testEquals(meHelloWorld, e1.value()); - testEquals(meHelloWorld, e2.value()); - } -}; - -TESTMAIN(TestChangeNotify); diff --git a/tests/testchangenotify.cpp b/tests/testchangenotify.cpp new file mode 100644 index 0000000..0447e7c --- /dev/null +++ b/tests/testchangenotify.cpp @@ -0,0 +1,195 @@ + /* + + Copyright (C) 2000 Stefan Westerfeld stefan@space.twc.de + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Permission is also granted to link this program with the Qt + library, treating Qt like a library that normally accompanies the + operating system kernel, whether or not that is in fact the case. + + */ + +#include "value.h" +#include "connect.h" +#include "test.h" +#include +#include + +using namespace std; +using namespace Arts; + +struct TestChangeNotify : public TestCase +{ + TESTCASE(TestChangeNotify); + + Arts::Dispatcher dispatcher; + float zero, three, four; + + void setUp() + { + zero = 0.0; + three = 3.0; + four = 4.0; + } + + void process() + { + dispatcher.ioManager()->processOneEvent(false); + } + + TEST(floatValue) + { + FloatValue f; + + testEquals(zero, f.value()); + + f.value(three); + testEquals(three, f.value()); + } + TEST(stringValue) + { + StringValue s; + + testEquals("",s.value()); + + s.value("hello"); + testEquals("hello", s.value()); + } + TEST(floatNotify) + { + FloatValue f1, f2; + + connect(f1,"value_changed",f2,"value"); + f1.value(three); + + process(); + testEquals(three, f2.value()); + } + TEST(floatMultiNotify) + { + FloatValue f1, f2, f3; + + connect(f1,"value_changed",f2,"value"); + connect(f1,"value_changed",f3,"value"); + f1.value(three); + + process(); + testEquals(three, f2.value()); + testEquals(three, f3.value()); + } + TEST(floatCrossNotify) + { + FloatValue f1, f2; + + connect(f1,"value_changed",f2,"value"); + connect(f2,"value_changed",f1,"value"); + f1.value(three); + + process(); + testEquals(three, f1.value()); + testEquals(three, f2.value()); + + f2.value(four); + + process(); + testEquals(four, f1.value()); + testEquals(four, f2.value()); + } + TEST(stringNotify) + { + StringValue s1, s2; + + connect(s1,"value_changed",s2,"value"); + s1.value("hello"); + + process(); + testEquals("hello", s2.value()); + } + TEST(stringMultiNotify) + { + StringValue s1, s2, s3; + + connect(s1,"value_changed",s2,"value"); + connect(s1,"value_changed",s3,"value"); + s1.value("hello"); + + process(); + testEquals("hello", s2.value()); + testEquals("hello", s3.value()); + } + TEST(stringCrossNotify) + { + StringValue s1, s2; + + connect(s1,"value_changed",s2,"value"); + connect(s2,"value_changed",s1,"value"); + s1.value("world"); + + process(); + testEquals("world", s1.value()); + testEquals("world", s2.value()); + + s2.value("test"); + + process(); + testEquals("test", s1.value()); + testEquals("test", s2.value()); + } + TEST(floatSenderToValue1) + { + FloatSender sender; + FloatValue f; + + connect(sender,"outstream",f,"value"); + vector data; + data.push_back(three); + sender.send(data); + + process(); + testEquals(three,f.value()); + } + TEST(floatSenderToValue2) + { + FloatSender sender; + FloatValue f; + + connect(sender,"outstream",f,"value"); + vector data; + data.push_back(three); + data.push_back(four); + sender.send(data); + + process(); + testEquals(four,f.value()); + } + TEST(myEnumNotify) + { + MyEnumValue e1, e2; + + connect(e1,"value_changed",e2,"value"); + + testEquals(meIdle, e1.value()); + testEquals(meIdle, e2.value()); + + e1.value(meHelloWorld); + process(); + + testEquals(meHelloWorld, e1.value()); + testEquals(meHelloWorld, e2.value()); + } +}; + +TESTMAIN(TestChangeNotify); diff --git a/tests/testdispatcher.cc b/tests/testdispatcher.cc deleted file mode 100644 index 41808ed..0000000 --- a/tests/testdispatcher.cc +++ /dev/null @@ -1,41 +0,0 @@ - /* - - Copyright (C) 2000 Stefan Westerfeld - stefan@space.twc.de - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include "dispatcher.h" -#include "test.h" - -using namespace Arts; -using namespace std; - -struct TestDispatcher : public TestCase -{ - TESTCASE(TestDispatcher); - - TEST(newDispatcher) { - for(int i = 0;i < 10; i++) { - Dispatcher *dispatcher = new Dispatcher(); - delete dispatcher; - } - } -}; - -TESTMAIN(TestDispatcher); diff --git a/tests/testdispatcher.cpp b/tests/testdispatcher.cpp new file mode 100644 index 0000000..41808ed --- /dev/null +++ b/tests/testdispatcher.cpp @@ -0,0 +1,41 @@ + /* + + Copyright (C) 2000 Stefan Westerfeld + stefan@space.twc.de + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include "dispatcher.h" +#include "test.h" + +using namespace Arts; +using namespace std; + +struct TestDispatcher : public TestCase +{ + TESTCASE(TestDispatcher); + + TEST(newDispatcher) { + for(int i = 0;i < 10; i++) { + Dispatcher *dispatcher = new Dispatcher(); + delete dispatcher; + } + } +}; + +TESTMAIN(TestDispatcher); diff --git a/tests/testflowsystem.cc b/tests/testflowsystem.cc deleted file mode 100644 index 392a844..0000000 --- a/tests/testflowsystem.cc +++ /dev/null @@ -1,83 +0,0 @@ - /* - - Copyright (C) 2000 Stefan Westerfeld - stefan@space.twc.de - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include "flowsystem.h" -#include "connect.h" -#include "value.h" -#include "test.h" - -using namespace Arts; -using namespace std; - -struct TestFlowSystem : public TestCase -{ - TESTCASE(TestFlowSystem); - - Dispatcher dispatcher; - StringValue v1, v2; - - void process() { - dispatcher.ioManager()->processOneEvent(false); - } - void setUp() { - /* initialize v1, v2 with values */ - v1 = StringValue(); v1.value("v1"); - v2 = StringValue(); v2.value("v2"); - } - void tearDown() { - v1 = StringValue::null(); - v2 = StringValue::null(); - } - TEST(connectObject) { - dispatcher.flowSystem()->connectObject(v1,"value_changed",v2,"value"); - - testEquals("v1",v1.value()); - testEquals("v2",v2.value()); - - v1.value("test"); - process(); - - testEquals("test",v1.value()); - testEquals("test",v2.value()); - } - // at the time of writing, this fails: disconnectObject is not implemented - TEST(disconnectObject) { - connect(v1,"value_changed",v2,"value"); - - /* here we have a connection, so this should be sent */ - v1.value("sendThis"); - process(); - testEquals("sendThis", v2.value()); - - dispatcher.flowSystem()->disconnectObject(v1,"value_changed", - v2,"value"); - - /* here we don't have a connection, so this should not be sent */ - v1.value("v1only"); - process(); - - testEquals("v1only", v1.value()); - testEquals("sendThis", v2.value()); - } -}; - -TESTMAIN(TestFlowSystem); diff --git a/tests/testflowsystem.cpp b/tests/testflowsystem.cpp new file mode 100644 index 0000000..392a844 --- /dev/null +++ b/tests/testflowsystem.cpp @@ -0,0 +1,83 @@ + /* + + Copyright (C) 2000 Stefan Westerfeld + stefan@space.twc.de + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include "flowsystem.h" +#include "connect.h" +#include "value.h" +#include "test.h" + +using namespace Arts; +using namespace std; + +struct TestFlowSystem : public TestCase +{ + TESTCASE(TestFlowSystem); + + Dispatcher dispatcher; + StringValue v1, v2; + + void process() { + dispatcher.ioManager()->processOneEvent(false); + } + void setUp() { + /* initialize v1, v2 with values */ + v1 = StringValue(); v1.value("v1"); + v2 = StringValue(); v2.value("v2"); + } + void tearDown() { + v1 = StringValue::null(); + v2 = StringValue::null(); + } + TEST(connectObject) { + dispatcher.flowSystem()->connectObject(v1,"value_changed",v2,"value"); + + testEquals("v1",v1.value()); + testEquals("v2",v2.value()); + + v1.value("test"); + process(); + + testEquals("test",v1.value()); + testEquals("test",v2.value()); + } + // at the time of writing, this fails: disconnectObject is not implemented + TEST(disconnectObject) { + connect(v1,"value_changed",v2,"value"); + + /* here we have a connection, so this should be sent */ + v1.value("sendThis"); + process(); + testEquals("sendThis", v2.value()); + + dispatcher.flowSystem()->disconnectObject(v1,"value_changed", + v2,"value"); + + /* here we don't have a connection, so this should not be sent */ + v1.value("v1only"); + process(); + + testEquals("v1only", v1.value()); + testEquals("sendThis", v2.value()); + } +}; + +TESTMAIN(TestFlowSystem); diff --git a/tests/testifacerepo.cc b/tests/testifacerepo.cc deleted file mode 100644 index a5c5962..0000000 --- a/tests/testifacerepo.cc +++ /dev/null @@ -1,84 +0,0 @@ - /* - - Copyright (C) 2000 Stefan Westerfeld - stefan@space.twc.de - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include -#include "common.h" -#include "test.h" - -using namespace Arts; -using namespace std; - -struct TestInterfaceRepo : public TestCase -{ - TESTCASE(TestInterfaceRepo); - - Arts::Dispatcher dispatcher; - Arts::InterfaceRepo interfaceRepo; - - void setUp() { - interfaceRepo = Arts::Dispatcher::the()->interfaceRepo(); - } - TEST(queryInterface) { - InterfaceDef def = interfaceRepo.queryInterface("Arts::InterfaceRepo"); - - testEquals("Arts::InterfaceRepo",def.name); - } - TEST(queryType) { - TypeDef def = interfaceRepo.queryType("Arts::MethodDef"); - - testEquals("Arts::MethodDef",def.name); - } - TEST(queryEnum) { - EnumDef def = interfaceRepo.queryEnum("Arts::AttributeType"); - - testEquals("Arts::AttributeType",def.name); - } - bool contains(vector& sequence, const string& element) - { - vector::iterator it; - it = find(sequence.begin(),sequence.end(), element); - return (it != sequence.end()); - } - TEST(queryInterfaces) { - vector *interfaces = interfaceRepo.queryInterfaces(); - - testAssert(contains(*interfaces,"Arts::InterfaceRepo")); - testAssert(!contains(*interfaces,"Arts::MethodDef")); - delete interfaces; - } - TEST(queryTypes) { - vector *types = interfaceRepo.queryTypes(); - - testAssert(contains(*types,"Arts::MethodDef")); - testAssert(!contains(*types,"Arts::AttributeType")); - delete types; - } - TEST(queryEnums) { - vector *enums = interfaceRepo.queryEnums(); - - testAssert(contains(*enums,"Arts::AttributeType")); - testAssert(!contains(*enums,"Arts::InterfaceRepo")); - delete enums; - } -}; - -TESTMAIN(TestInterfaceRepo); diff --git a/tests/testifacerepo.cpp b/tests/testifacerepo.cpp new file mode 100644 index 0000000..a5c5962 --- /dev/null +++ b/tests/testifacerepo.cpp @@ -0,0 +1,84 @@ + /* + + Copyright (C) 2000 Stefan Westerfeld + stefan@space.twc.de + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include +#include "common.h" +#include "test.h" + +using namespace Arts; +using namespace std; + +struct TestInterfaceRepo : public TestCase +{ + TESTCASE(TestInterfaceRepo); + + Arts::Dispatcher dispatcher; + Arts::InterfaceRepo interfaceRepo; + + void setUp() { + interfaceRepo = Arts::Dispatcher::the()->interfaceRepo(); + } + TEST(queryInterface) { + InterfaceDef def = interfaceRepo.queryInterface("Arts::InterfaceRepo"); + + testEquals("Arts::InterfaceRepo",def.name); + } + TEST(queryType) { + TypeDef def = interfaceRepo.queryType("Arts::MethodDef"); + + testEquals("Arts::MethodDef",def.name); + } + TEST(queryEnum) { + EnumDef def = interfaceRepo.queryEnum("Arts::AttributeType"); + + testEquals("Arts::AttributeType",def.name); + } + bool contains(vector& sequence, const string& element) + { + vector::iterator it; + it = find(sequence.begin(),sequence.end(), element); + return (it != sequence.end()); + } + TEST(queryInterfaces) { + vector *interfaces = interfaceRepo.queryInterfaces(); + + testAssert(contains(*interfaces,"Arts::InterfaceRepo")); + testAssert(!contains(*interfaces,"Arts::MethodDef")); + delete interfaces; + } + TEST(queryTypes) { + vector *types = interfaceRepo.queryTypes(); + + testAssert(contains(*types,"Arts::MethodDef")); + testAssert(!contains(*types,"Arts::AttributeType")); + delete types; + } + TEST(queryEnums) { + vector *enums = interfaceRepo.queryEnums(); + + testAssert(contains(*enums,"Arts::AttributeType")); + testAssert(!contains(*enums,"Arts::InterfaceRepo")); + delete enums; + } +}; + +TESTMAIN(TestInterfaceRepo); diff --git a/tests/testnotification.cc b/tests/testnotification.cc deleted file mode 100644 index 1f7a026..0000000 --- a/tests/testnotification.cc +++ /dev/null @@ -1,146 +0,0 @@ - /* - - Copyright (C) 2001 Stefan Westerfeld - stefan@space.twc.de - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include "notification.h" -#include "dispatcher.h" -#include "test.h" - -using namespace Arts; -using namespace std; - -static string messagesReceived; -static long messagesAlive; - -static void destroyString(const Notification& n) -{ - messagesAlive--; - delete (string *)n.data; -} - -class Receiver : public NotificationClient { -private: - long alive; - -public: - Receiver() { alive = 42; } - virtual ~Receiver() { - NotificationManager::the()->removeClient(this); - alive = 0; - } - - void notify(const Notification& n) { - if(alive != 42) messagesReceived += ""; - - string *data = (string *)n.data; - messagesReceived += *data; - destroyString(n); - - if(alive != 42) messagesReceived += ""; - } -}; - -struct TestNotification : public TestCase -{ - TESTCASE(TestNotification); - - Dispatcher dispatcher; - - void setUp() { - messagesReceived = ""; - messagesAlive = 0; - } - void tearDown() { - } - void sendNotification(Receiver& r, string text) - { - messagesAlive++; - Notification n; - n.receiver = &r; - n.data = new string(text); - n.internal = 0; - n.setDestroy(destroyString); - NotificationManager::the()->send(n); - } - - /* sending a notification (should be asynchronous) */ - TEST(send) { - Receiver r1; - sendNotification(r1,"r1"); - - testEquals(1,messagesAlive); - testEquals("",messagesReceived); - testEquals(true, NotificationManager::the()->pending()); - - NotificationManager::the()->run(); - - testEquals("r1",messagesReceived); - testEquals(false, NotificationManager::the()->pending()); - testEquals(0,messagesAlive); - } - - /* order of sending notifications (first-in-first-out) */ - TEST(sendOrder) { - Receiver r1,r2; - - sendNotification(r1,"r1"); - sendNotification(r2,"r2"); - - testEquals(2,messagesAlive); - testEquals("",messagesReceived); - testEquals(true, NotificationManager::the()->pending()); - - NotificationManager::the()->run(); - - testEquals(false, NotificationManager::the()->pending()); - testEquals(0,messagesAlive); - testEquals("r1r2",messagesReceived); - } - - /* deletion of unprocessed notifications once a client dies */ - TEST(clientDeletion) { - Receiver *r1 = new Receiver, - *r2 = new Receiver, - *r3 = new Receiver, - *r4 = new Receiver; - - sendNotification(*r1,"r1"); - sendNotification(*r2,"r2"); - sendNotification(*r3,"r3"); - sendNotification(*r4,"r4"); - - testEquals(4,messagesAlive); - testEquals("",messagesReceived); - - delete r2; - delete r4; - - testEquals(2,messagesAlive); - testEquals("",messagesReceived); - - NotificationManager::the()->run(); - - testEquals("r1r3",messagesReceived); - testEquals(0,messagesAlive); - } -}; - -TESTMAIN(TestNotification); diff --git a/tests/testnotification.cpp b/tests/testnotification.cpp new file mode 100644 index 0000000..1f7a026 --- /dev/null +++ b/tests/testnotification.cpp @@ -0,0 +1,146 @@ + /* + + Copyright (C) 2001 Stefan Westerfeld + stefan@space.twc.de + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include "notification.h" +#include "dispatcher.h" +#include "test.h" + +using namespace Arts; +using namespace std; + +static string messagesReceived; +static long messagesAlive; + +static void destroyString(const Notification& n) +{ + messagesAlive--; + delete (string *)n.data; +} + +class Receiver : public NotificationClient { +private: + long alive; + +public: + Receiver() { alive = 42; } + virtual ~Receiver() { + NotificationManager::the()->removeClient(this); + alive = 0; + } + + void notify(const Notification& n) { + if(alive != 42) messagesReceived += ""; + + string *data = (string *)n.data; + messagesReceived += *data; + destroyString(n); + + if(alive != 42) messagesReceived += ""; + } +}; + +struct TestNotification : public TestCase +{ + TESTCASE(TestNotification); + + Dispatcher dispatcher; + + void setUp() { + messagesReceived = ""; + messagesAlive = 0; + } + void tearDown() { + } + void sendNotification(Receiver& r, string text) + { + messagesAlive++; + Notification n; + n.receiver = &r; + n.data = new string(text); + n.internal = 0; + n.setDestroy(destroyString); + NotificationManager::the()->send(n); + } + + /* sending a notification (should be asynchronous) */ + TEST(send) { + Receiver r1; + sendNotification(r1,"r1"); + + testEquals(1,messagesAlive); + testEquals("",messagesReceived); + testEquals(true, NotificationManager::the()->pending()); + + NotificationManager::the()->run(); + + testEquals("r1",messagesReceived); + testEquals(false, NotificationManager::the()->pending()); + testEquals(0,messagesAlive); + } + + /* order of sending notifications (first-in-first-out) */ + TEST(sendOrder) { + Receiver r1,r2; + + sendNotification(r1,"r1"); + sendNotification(r2,"r2"); + + testEquals(2,messagesAlive); + testEquals("",messagesReceived); + testEquals(true, NotificationManager::the()->pending()); + + NotificationManager::the()->run(); + + testEquals(false, NotificationManager::the()->pending()); + testEquals(0,messagesAlive); + testEquals("r1r2",messagesReceived); + } + + /* deletion of unprocessed notifications once a client dies */ + TEST(clientDeletion) { + Receiver *r1 = new Receiver, + *r2 = new Receiver, + *r3 = new Receiver, + *r4 = new Receiver; + + sendNotification(*r1,"r1"); + sendNotification(*r2,"r2"); + sendNotification(*r3,"r3"); + sendNotification(*r4,"r4"); + + testEquals(4,messagesAlive); + testEquals("",messagesReceived); + + delete r2; + delete r4; + + testEquals(2,messagesAlive); + testEquals("",messagesReceived); + + NotificationManager::the()->run(); + + testEquals("r1r3",messagesReceived); + testEquals(0,messagesAlive); + } +}; + +TESTMAIN(TestNotification); diff --git a/tests/testremote.cc b/tests/testremote.cc deleted file mode 100644 index 85bdfb2..0000000 --- a/tests/testremote.cc +++ /dev/null @@ -1,176 +0,0 @@ - /* - - Copyright (C) 2000 Stefan Westerfeld stefan@space.twc.de - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - Permission is also granted to link this program with the Qt - library, treating Qt like a library that normally accompanies the - operating system kernel, whether or not that is in fact the case. - - */ - -#include "remotetest.h" -#include "value.h" -#include "test.h" -#include "connect.h" -#include -#include - -using namespace std; -using namespace Arts; - -class RemoteTest_impl: virtual public RemoteTest_skel { -private: - bool alive; - -public: - RemoteTest_impl() - { - alive = true; - _copy(); - } - ~RemoteTest_impl() - { - Dispatcher::the()->terminate(); - } - - Object createObject(const string& name) - { - return SubClass(name); - } - long fortyTwo() - { - return 42; - } - void die() - { - if(alive) - { - _release(); - alive = false; - } - } -}; - -REGISTER_IMPLEMENTATION(RemoteTest_impl); - -/* name of the remote object - should be sufficiently unique */ -char objectName[60]; - -struct TestRemote : public TestCase -{ - TESTCASE(TestRemote); - - Arts::Dispatcher dispatcher; - RemoteTest remoteTest; - - void setUp() { - string globalRef = "global:"; - globalRef += objectName; - - remoteTest = Arts::Reference(globalRef); - } - void tearDown() { - remoteTest = RemoteTest::null(); - } - - void process() - { - dispatcher.ioManager()->processOneEvent(false); - } - - - /* test whether the server is running, and we could connect ok */ - TEST(connected) { - testEquals(false, remoteTest.isNull()); - } - - /* test method call */ - TEST(fortyTwo) { - testEquals(42, remoteTest.fortyTwo()); - } - - /* test remote change notifications */ - TEST(remoteChangeNotify) { - StringValue local; - local.value("local"); - testEquals("local", local.value()); - - Object o = remoteTest.createObject("StringValue"); - testAssert(!o.isNull()); - - StringValue remote = Arts::DynamicCast(o); - testAssert(!remote.isNull()); - remote.value("remote"); - testEquals("remote", remote.value()); - - connect(local,"value_changed",remote,"value"); - local.value("transferme"); - - process(); - sleep(1); /* change notifications are asynchronous */ - - testEquals("transferme", local.value()); - testEquals("transferme", remote.value()); - - disconnect(local,"value_changed",remote,"value"); - - local.value("notransfer"); - - testEquals("notransfer", local.value()); - testEquals("transferme", remote.value()); - } - - /* terminate server */ - TEST(die) { - remoteTest.die(); - remoteTest = RemoteTest::null(); - sleep(1); - } - - /* check if server is dead now */ - TEST(dead) { - testEquals(true, remoteTest.isNull()); - } -}; - -TESTMAINFUNC(TestRemote,performTests); - -/* - * this test case is a bit tricky because we need a client and a server - * - * we create the server in a fork()ed process, and then evaluate the test - * inside the client - */ -int main() -{ - /* create unique object name for test server/test client */ - sprintf(objectName, "RemoteTest_%d_%ld", getpid(), time(0)); - - int pid = fork(); - if(pid == 0) /* child process - we play the server here */ - { - Dispatcher dispatcher(0, Dispatcher::startUnixServer); - ObjectManager::the()->addGlobalReference(RemoteTest(), objectName); - dispatcher.run(); - return 0; - } - else if(pid >= 0) /* parent process - do the test here */ - { - sleep(1); - return performTests(); - } -} diff --git a/tests/testremote.cpp b/tests/testremote.cpp new file mode 100644 index 0000000..85bdfb2 --- /dev/null +++ b/tests/testremote.cpp @@ -0,0 +1,176 @@ + /* + + Copyright (C) 2000 Stefan Westerfeld stefan@space.twc.de + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Permission is also granted to link this program with the Qt + library, treating Qt like a library that normally accompanies the + operating system kernel, whether or not that is in fact the case. + + */ + +#include "remotetest.h" +#include "value.h" +#include "test.h" +#include "connect.h" +#include +#include + +using namespace std; +using namespace Arts; + +class RemoteTest_impl: virtual public RemoteTest_skel { +private: + bool alive; + +public: + RemoteTest_impl() + { + alive = true; + _copy(); + } + ~RemoteTest_impl() + { + Dispatcher::the()->terminate(); + } + + Object createObject(const string& name) + { + return SubClass(name); + } + long fortyTwo() + { + return 42; + } + void die() + { + if(alive) + { + _release(); + alive = false; + } + } +}; + +REGISTER_IMPLEMENTATION(RemoteTest_impl); + +/* name of the remote object - should be sufficiently unique */ +char objectName[60]; + +struct TestRemote : public TestCase +{ + TESTCASE(TestRemote); + + Arts::Dispatcher dispatcher; + RemoteTest remoteTest; + + void setUp() { + string globalRef = "global:"; + globalRef += objectName; + + remoteTest = Arts::Reference(globalRef); + } + void tearDown() { + remoteTest = RemoteTest::null(); + } + + void process() + { + dispatcher.ioManager()->processOneEvent(false); + } + + + /* test whether the server is running, and we could connect ok */ + TEST(connected) { + testEquals(false, remoteTest.isNull()); + } + + /* test method call */ + TEST(fortyTwo) { + testEquals(42, remoteTest.fortyTwo()); + } + + /* test remote change notifications */ + TEST(remoteChangeNotify) { + StringValue local; + local.value("local"); + testEquals("local", local.value()); + + Object o = remoteTest.createObject("StringValue"); + testAssert(!o.isNull()); + + StringValue remote = Arts::DynamicCast(o); + testAssert(!remote.isNull()); + remote.value("remote"); + testEquals("remote", remote.value()); + + connect(local,"value_changed",remote,"value"); + local.value("transferme"); + + process(); + sleep(1); /* change notifications are asynchronous */ + + testEquals("transferme", local.value()); + testEquals("transferme", remote.value()); + + disconnect(local,"value_changed",remote,"value"); + + local.value("notransfer"); + + testEquals("notransfer", local.value()); + testEquals("transferme", remote.value()); + } + + /* terminate server */ + TEST(die) { + remoteTest.die(); + remoteTest = RemoteTest::null(); + sleep(1); + } + + /* check if server is dead now */ + TEST(dead) { + testEquals(true, remoteTest.isNull()); + } +}; + +TESTMAINFUNC(TestRemote,performTests); + +/* + * this test case is a bit tricky because we need a client and a server + * + * we create the server in a fork()ed process, and then evaluate the test + * inside the client + */ +int main() +{ + /* create unique object name for test server/test client */ + sprintf(objectName, "RemoteTest_%d_%ld", getpid(), time(0)); + + int pid = fork(); + if(pid == 0) /* child process - we play the server here */ + { + Dispatcher dispatcher(0, Dispatcher::startUnixServer); + ObjectManager::the()->addGlobalReference(RemoteTest(), objectName); + dispatcher.run(); + return 0; + } + else if(pid >= 0) /* parent process - do the test here */ + { + sleep(1); + return performTests(); + } +} diff --git a/tests/testwrapper.cc b/tests/testwrapper.cc deleted file mode 100644 index 9be8c35..0000000 --- a/tests/testwrapper.cc +++ /dev/null @@ -1,211 +0,0 @@ - /* - - Copyright (C) 2000 Stefan Westerfeld stefan@space.twc.de - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - Permission is also granted to link this program with the Qt - library, treating Qt like a library that normally accompanies the - operating system kernel, whether or not that is in fact the case. - - */ - -#include "wrapper.h" -#include "test.h" -#include -#include - -using namespace std; -using namespace Arts; - -int active_d_objects = 0; - -class D_impl: virtual public D_skel { -private: - long _value; -public: - void value(long newVal) { _value = newVal; } - long value() { return _value; } - - D_impl() :_value(0) { active_d_objects++; } - ~D_impl() { active_d_objects--; } - string a() { return "a"; } - string b() { return "b"; } - string c() { return "c"; } - string d() { return "d"; } - void dummy() { } - - long sum(A v1, A v2) { return v1.value() + v2.value(); } - D self() { return D::_from_base(_copy()); } -}; - -REGISTER_IMPLEMENTATION(D_impl); - -class B_impl: virtual public B_skel { -private: - long _value; -public: - void value(long newVal) { _value = newVal; } - long value() { return _value; } - B_impl() :_value(0) {} - string a() { return "a"; } - string b() { return "b"; } -}; -REGISTER_IMPLEMENTATION(B_impl); - - -struct TestWrapper : public TestCase -{ - TESTCASE(TestWrapper); - - Arts::Dispatcher dispatcher; - - /* - generic inheritance test, tests that using a D object, you - can call the a,b,c,d methods without problems - */ - TEST(genericInheritance) - { - D d; - - /* implications of lazy creation */ - testEquals(0, active_d_objects); - - C c = d; - testEquals(0, active_d_objects); - - string abcd = A(d).a()+d.b()+c.c()+d.d(); - testEquals("abcd",abcd); - - /* - should be exactly one here, not more than one through the various - assignments - */ - testEquals(1, active_d_objects); - - Object o = d; - - /* dynamic casting tests */ - c = DynamicCast(o); // operator - testEquals(false, c.isNull()); - testEquals("c", c.c()); - - C cc = DynamicCast(o); // constructor - testEquals(false, cc.isNull()); - testEquals("c", cc.c()); - - A a = Reference(d.toString()); - cc = DynamicCast(a); - testEquals(false, cc.isNull()); - testEquals("c", cc.c()); - - /* isNull() and error() */ - testEquals(false, d.isNull()); - testEquals(false, d.error()); - - d = D::null(); - testEquals(true, d.isNull()); - testEquals(false, c.isNull()); - testEquals(false, d.error()); - - /* reference counting */ - c = C::null(); - o = Object::null(); - cc = C::null(); - a = A::null(); - testEquals(0, active_d_objects); - } - TEST(nullInAssign) { - B b; - B b2 = b; - b = B::null(); - testEquals(true, b.isNull()); - testEquals(false, b2.isNull()); - } - TEST(coreference) { - B b3; - B b4=b3; - b3.value(3); - testEquals(3, b4.value()); - } - - D afunc(D arg) - { - arg.value(42); - return arg; - } - - TEST(cacheAndArgs) { - /* test cache invalidation */ - B b; - b.value(3); // stores 3 using parent method - testEquals(0, active_d_objects); - - D d; - d.value(6); - testEquals(1, active_d_objects); - - b = d; // uses operator, not constructor. should invalidate A::cacheOK - testEquals(6, b.value()); - testEquals(1, active_d_objects); - - A a = afunc(d); - testEquals(1, active_d_objects); - testEquals(42, a.value()); - testEquals(42, b.value()); - testEquals(42, d.value()); - } - - TEST(dynamicCastNull) { - D normalD; - D nullD = D::null(); - A aNormalD = normalD; - A aNullD = nullD; - D d; - - d = DynamicCast(aNormalD); - testEquals(false, d.isNull()); - - d = DynamicCast(aNullD); - testEquals(true, d.isNull()); - } - - TEST(stringification) { - D d; - d.value(5); - - string s = d.toString(); - - D anotherD = Arts::Reference(s); - testEquals(false, anotherD.isNull()); - testEquals(5, anotherD.value()); - } - /* - unfortunately, this currently fails, because resolving a reference to a - non-existing object is not handled properly by the dispatcher - I am not - sure whether it is worth fixing it (which might be complicated) - - TEST(stringificationFailures) { - D d; - d.value(5); - string s = d.toString(); - d = D::null(); - - D anotherD = Arts::Reference(s); - testEquals(true, anotherD.isNull()); - }*/ -}; - -TESTMAIN(TestWrapper); diff --git a/tests/testwrapper.cpp b/tests/testwrapper.cpp new file mode 100644 index 0000000..9be8c35 --- /dev/null +++ b/tests/testwrapper.cpp @@ -0,0 +1,211 @@ + /* + + Copyright (C) 2000 Stefan Westerfeld stefan@space.twc.de + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Permission is also granted to link this program with the Qt + library, treating Qt like a library that normally accompanies the + operating system kernel, whether or not that is in fact the case. + + */ + +#include "wrapper.h" +#include "test.h" +#include +#include + +using namespace std; +using namespace Arts; + +int active_d_objects = 0; + +class D_impl: virtual public D_skel { +private: + long _value; +public: + void value(long newVal) { _value = newVal; } + long value() { return _value; } + + D_impl() :_value(0) { active_d_objects++; } + ~D_impl() { active_d_objects--; } + string a() { return "a"; } + string b() { return "b"; } + string c() { return "c"; } + string d() { return "d"; } + void dummy() { } + + long sum(A v1, A v2) { return v1.value() + v2.value(); } + D self() { return D::_from_base(_copy()); } +}; + +REGISTER_IMPLEMENTATION(D_impl); + +class B_impl: virtual public B_skel { +private: + long _value; +public: + void value(long newVal) { _value = newVal; } + long value() { return _value; } + B_impl() :_value(0) {} + string a() { return "a"; } + string b() { return "b"; } +}; +REGISTER_IMPLEMENTATION(B_impl); + + +struct TestWrapper : public TestCase +{ + TESTCASE(TestWrapper); + + Arts::Dispatcher dispatcher; + + /* + generic inheritance test, tests that using a D object, you + can call the a,b,c,d methods without problems + */ + TEST(genericInheritance) + { + D d; + + /* implications of lazy creation */ + testEquals(0, active_d_objects); + + C c = d; + testEquals(0, active_d_objects); + + string abcd = A(d).a()+d.b()+c.c()+d.d(); + testEquals("abcd",abcd); + + /* + should be exactly one here, not more than one through the various + assignments + */ + testEquals(1, active_d_objects); + + Object o = d; + + /* dynamic casting tests */ + c = DynamicCast(o); // operator + testEquals(false, c.isNull()); + testEquals("c", c.c()); + + C cc = DynamicCast(o); // constructor + testEquals(false, cc.isNull()); + testEquals("c", cc.c()); + + A a = Reference(d.toString()); + cc = DynamicCast(a); + testEquals(false, cc.isNull()); + testEquals("c", cc.c()); + + /* isNull() and error() */ + testEquals(false, d.isNull()); + testEquals(false, d.error()); + + d = D::null(); + testEquals(true, d.isNull()); + testEquals(false, c.isNull()); + testEquals(false, d.error()); + + /* reference counting */ + c = C::null(); + o = Object::null(); + cc = C::null(); + a = A::null(); + testEquals(0, active_d_objects); + } + TEST(nullInAssign) { + B b; + B b2 = b; + b = B::null(); + testEquals(true, b.isNull()); + testEquals(false, b2.isNull()); + } + TEST(coreference) { + B b3; + B b4=b3; + b3.value(3); + testEquals(3, b4.value()); + } + + D afunc(D arg) + { + arg.value(42); + return arg; + } + + TEST(cacheAndArgs) { + /* test cache invalidation */ + B b; + b.value(3); // stores 3 using parent method + testEquals(0, active_d_objects); + + D d; + d.value(6); + testEquals(1, active_d_objects); + + b = d; // uses operator, not constructor. should invalidate A::cacheOK + testEquals(6, b.value()); + testEquals(1, active_d_objects); + + A a = afunc(d); + testEquals(1, active_d_objects); + testEquals(42, a.value()); + testEquals(42, b.value()); + testEquals(42, d.value()); + } + + TEST(dynamicCastNull) { + D normalD; + D nullD = D::null(); + A aNormalD = normalD; + A aNullD = nullD; + D d; + + d = DynamicCast(aNormalD); + testEquals(false, d.isNull()); + + d = DynamicCast(aNullD); + testEquals(true, d.isNull()); + } + + TEST(stringification) { + D d; + d.value(5); + + string s = d.toString(); + + D anotherD = Arts::Reference(s); + testEquals(false, anotherD.isNull()); + testEquals(5, anotherD.value()); + } + /* + unfortunately, this currently fails, because resolving a reference to a + non-existing object is not handled properly by the dispatcher - I am not + sure whether it is worth fixing it (which might be complicated) + + TEST(stringificationFailures) { + D d; + d.value(5); + string s = d.toString(); + d = D::null(); + + D anotherD = Arts::Reference(s); + testEquals(true, anotherD.isNull()); + }*/ +}; + +TESTMAIN(TestWrapper); diff --git a/tests/value_impl.cc b/tests/value_impl.cc deleted file mode 100644 index 9f9f83c..0000000 --- a/tests/value_impl.cc +++ /dev/null @@ -1,94 +0,0 @@ - /* - - Copyright (C) 2000-2001 Stefan Westerfeld - stefan@space.twc.de - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. - - */ - -#include "value.h" - -using namespace std; - -class FloatValue_impl : virtual public FloatValue_skel { -private: - float _value; -public: - FloatValue_impl() : _value(0) { }; - void value(float newvalue) - { - if(newvalue != _value) - { - _value = newvalue; - value_changed(_value); - } - } - float value() { return _value; } -}; - -REGISTER_IMPLEMENTATION(FloatValue_impl); - -class StringValue_impl : virtual public StringValue_skel { -private: - string _value; -public: - StringValue_impl() { }; - void value(const string& newvalue) - { - if(newvalue != _value) - { - _value = newvalue; - value_changed(_value); - } - } - string value() { return _value; } -}; - -REGISTER_IMPLEMENTATION(StringValue_impl); - -class FloatSender_impl : virtual public FloatSender_skel { -public: - void send(const vector& data) - { - Arts::DataPacket *packet = outstream.allocPacket(data.size()); - copy(data.begin(), data.end(), packet->contents); - packet->size = data.size(); - packet->send(); - } -}; - -REGISTER_IMPLEMENTATION(FloatSender_impl); - -class MyEnumValue_impl : virtual public MyEnumValue_skel { -private: - MyEnum _value; -public: - MyEnumValue_impl() : _value(meIdle) { }; - void value(MyEnum newvalue) - { - if(newvalue != _value) - { - _value = newvalue; - value_changed(_value); - } - } - MyEnum value() { return _value; } -}; - -REGISTER_IMPLEMENTATION(MyEnumValue_impl); - - diff --git a/tests/value_impl.cpp b/tests/value_impl.cpp new file mode 100644 index 0000000..9f9f83c --- /dev/null +++ b/tests/value_impl.cpp @@ -0,0 +1,94 @@ + /* + + Copyright (C) 2000-2001 Stefan Westerfeld + stefan@space.twc.de + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. + + */ + +#include "value.h" + +using namespace std; + +class FloatValue_impl : virtual public FloatValue_skel { +private: + float _value; +public: + FloatValue_impl() : _value(0) { }; + void value(float newvalue) + { + if(newvalue != _value) + { + _value = newvalue; + value_changed(_value); + } + } + float value() { return _value; } +}; + +REGISTER_IMPLEMENTATION(FloatValue_impl); + +class StringValue_impl : virtual public StringValue_skel { +private: + string _value; +public: + StringValue_impl() { }; + void value(const string& newvalue) + { + if(newvalue != _value) + { + _value = newvalue; + value_changed(_value); + } + } + string value() { return _value; } +}; + +REGISTER_IMPLEMENTATION(StringValue_impl); + +class FloatSender_impl : virtual public FloatSender_skel { +public: + void send(const vector& data) + { + Arts::DataPacket *packet = outstream.allocPacket(data.size()); + copy(data.begin(), data.end(), packet->contents); + packet->size = data.size(); + packet->send(); + } +}; + +REGISTER_IMPLEMENTATION(FloatSender_impl); + +class MyEnumValue_impl : virtual public MyEnumValue_skel { +private: + MyEnum _value; +public: + MyEnumValue_impl() : _value(meIdle) { }; + void value(MyEnum newvalue) + { + if(newvalue != _value) + { + _value = newvalue; + value_changed(_value); + } + } + MyEnum value() { return _value; } +}; + +REGISTER_IMPLEMENTATION(MyEnumValue_impl); + + -- cgit v1.2.3