diff options
Diffstat (limited to 'utests')
-rw-r--r-- | utests/Makefile.am | 12 | ||||
-rw-r--r-- | utests/biginttest.cpp | 82 | ||||
-rw-r--r-- | utests/biginttest.h | 42 | ||||
-rw-r--r-- | utests/dhtmsgparsetest.cpp | 108 | ||||
-rw-r--r-- | utests/dhtmsgparsetest.h | 44 | ||||
-rw-r--r-- | utests/difflehellmantest.cpp | 58 | ||||
-rw-r--r-- | utests/difflehellmantest.h | 44 | ||||
-rw-r--r-- | utests/main.cpp | 52 | ||||
-rw-r--r-- | utests/rc4test.cpp | 95 | ||||
-rw-r--r-- | utests/rc4test.h | 46 | ||||
-rw-r--r-- | utests/testrunner.cpp | 76 | ||||
-rw-r--r-- | utests/testrunner.h | 45 | ||||
-rw-r--r-- | utests/unittest.cpp | 33 | ||||
-rw-r--r-- | utests/unittest.h | 47 | ||||
-rw-r--r-- | utests/upnpparsedescriptiontest.cpp | 433 | ||||
-rw-r--r-- | utests/upnpparsedescriptiontest.h | 44 | ||||
-rw-r--r-- | utests/upnpparseresponsetest.cpp | 66 | ||||
-rw-r--r-- | utests/upnpparseresponsetest.h | 44 |
18 files changed, 1371 insertions, 0 deletions
diff --git a/utests/Makefile.am b/utests/Makefile.am new file mode 100644 index 0000000..eb25f53 --- /dev/null +++ b/utests/Makefile.am @@ -0,0 +1,12 @@ +INCLUDES = -I$(srcdir)/../libktorrent -I$(srcdir)/.. $(all_includes) +METASOURCES = AUTO +noinst_HEADERS = unittest.h testrunner.h upnpparsedescriptiontest.h \ + upnpparseresponsetest.h dhtmsgparsetest.h biginttest.h rc4test.h difflehellmantest.h +bin_PROGRAMS = ktutester +ktutester_LDFLAGS = $(KDE_RPATH) $(all_libraries) +ktutester_SOURCES = unittest.cpp testrunner.cpp main.cpp \ + upnpparsedescriptiontest.cpp upnpparseresponsetest.cpp dhtmsgparsetest.cpp biginttest.cpp \ + rc4test.cpp difflehellmantest.cpp +ktutester_LDADD = ../plugins/upnp/libktupnp.la \ + ../libktorrent/libktorrent.la +KDE_CXXFLAGS = $(USE_EXCEPTIONS) $(USE_RTTI) diff --git a/utests/biginttest.cpp b/utests/biginttest.cpp new file mode 100644 index 0000000..fc8f105 --- /dev/null +++ b/utests/biginttest.cpp @@ -0,0 +1,82 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * joris.guisson@gmail.com * + * * + * 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. * + ***************************************************************************/ +#include <stdio.h> +#include <mse/bigint.h> +#include <util/log.h> +#include <torrent/globals.h> +#include "biginttest.h" + +using namespace bt; +using namespace mse; + +namespace utest +{ + + BigIntTest::BigIntTest() : UnitTest("BigIntTest") + {} + + + BigIntTest::~BigIntTest() + {} + + static void PrintBigInt(BigInt & b) + { + Uint8 buf[10]; + memset(buf,0,10); + b.toBuffer(buf,10); + for (Uint32 i = 0;i < 10;i++) + { + Out() << QString("0x%1 ").arg(buf[i],0,16); + } + Out() << endl; + } + + bool BigIntTest::doTest() + { + Out() << "First test : " << endl; + BigInt a("0x1E"); + BigInt b("0x42"); + BigInt c("0xFFFFEE"); + BigInt d = BigInt::powerMod(a,b,c); + PrintBigInt(a); + PrintBigInt(b); + PrintBigInt(c); + PrintBigInt(d); + Out() << "Second test : " << endl; + Uint8 test[] = {0xAB,0x12,0x34,0xE4,0xF6}; + a = BigInt::fromBuffer(test,5); + PrintBigInt(a); + Uint8 foobar[5]; + a.toBuffer(foobar,5); + for (Uint32 i = 0;i < 5;i++) + { + Out() << QString("0x%1 ").arg(foobar[i],0,16); + } + Out() << endl; + Out() << "Third test" << endl; + a = BigInt("0xABCD1234"); + PrintBigInt(a); + a.toBuffer(foobar,4); + c = BigInt::fromBuffer(foobar,4); + PrintBigInt(c); + return true; + } + +} diff --git a/utests/biginttest.h b/utests/biginttest.h new file mode 100644 index 0000000..2e4073b --- /dev/null +++ b/utests/biginttest.h @@ -0,0 +1,42 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * joris.guisson@gmail.com * + * * + * 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. * + ***************************************************************************/ +#ifndef UTESTBIGINTTEST_H +#define UTESTBIGINTTEST_H + +#include "unittest.h" + +namespace utest +{ + + /** + @author Joris Guisson <joris.guisson@gmail.com> + */ + class BigIntTest : public UnitTest + { + public: + BigIntTest(); + virtual ~BigIntTest(); + + virtual bool doTest(); + }; + +} + +#endif diff --git a/utests/dhtmsgparsetest.cpp b/utests/dhtmsgparsetest.cpp new file mode 100644 index 0000000..44e0338 --- /dev/null +++ b/utests/dhtmsgparsetest.cpp @@ -0,0 +1,108 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * joris.guisson@gmail.com * + * * + * 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. * + ***************************************************************************/ +#include <torrent/bdecoder.h> +#include <torrent/bnode.h> +#include <kademlia/rpcmsg.h> +#include <util/log.h> +#include <torrent/globals.h> +#include "dhtmsgparsetest.h" + +using namespace dht; +using namespace bt; + +namespace utest +{ + + + DHTMsgParseTest::DHTMsgParseTest() : UnitTest("DHTMsgParseTest") + {} + + + DHTMsgParseTest::~DHTMsgParseTest() + {} + + bool DHTMsgParseTest::doTest(const QString & data,int method) + { + QByteArray bdata(data.length()); + + for (int i = 0;i < data.length();i++) + { + bdata[i] = data[i]; + } + + BDecoder bdec(bdata,false); + + BNode* n = bdec.decode(); + if (n->getType() != BNode::DICT) + { + delete n; + Out() << "Packet does not contain a dictionary" << endl; + return false; + } + + MsgBase* msg = MakeRPCMsgTest((BDictNode*)n,(dht::Method)method); + if (!msg) + { + delete n; + Out() << "Error parsing message : " << endl; + return false; + } + delete msg; + delete n; + return true; + } + + + + bool DHTMsgParseTest::doTest() + { + + QString test_str[] = { + "d1:rd2:id20:####################5:token20:####################6:valuesl6:######6:######6:######6:######6:######6:######6:######6:######ee1:t1:#1:y1:re", + + "d1:ad2:id20:####################9:info_hash20:####################e1:q9:get_peers1:t1:#1:y1:qe", + + "d1:rd2:id20:####################5:nodes208:################################################################################################################################################################################################################5:token20:####################e1:t1:#1:y1:re", + + QString::null + }; + + int types[] = {dht::GET_PEERS,dht::NONE,dht::GET_PEERS}; + + int i = 0; + while (!test_str[i].isNull()) + { + // read and decode the packet + if (!doTest(test_str[i],types[i])) + { + Out() << "Testing packet " << i << " : Failed" << endl; + return false; + } + else + { + Out() << "Testing packet " << i << " : OK" << endl; + } + i++; + } + + return true; + } + +} diff --git a/utests/dhtmsgparsetest.h b/utests/dhtmsgparsetest.h new file mode 100644 index 0000000..c88ec72 --- /dev/null +++ b/utests/dhtmsgparsetest.h @@ -0,0 +1,44 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * joris.guisson@gmail.com * + * * + * 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. * + ***************************************************************************/ +#ifndef UTESTDHTMSGPARSETEST_H +#define UTESTDHTMSGPARSETEST_H + +#include <unittest.h> + +namespace utest +{ + + /** + @author Joris Guisson <joris.guisson@gmail.com> + */ + class DHTMsgParseTest : public UnitTest + { + public: + DHTMsgParseTest(); + virtual ~DHTMsgParseTest(); + + virtual bool doTest(); + private: + bool doTest(const QString & data,int method); + }; + +} + +#endif diff --git a/utests/difflehellmantest.cpp b/utests/difflehellmantest.cpp new file mode 100644 index 0000000..b261d5a --- /dev/null +++ b/utests/difflehellmantest.cpp @@ -0,0 +1,58 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * joris.guisson@gmail.com * + * * + * 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. * + ***************************************************************************/ + +#include <stdio.h> +#include <mse/bigint.h> +#include <mse/functions.h> +#include <util/log.h> +#include <torrent/globals.h> +#include "difflehellmantest.h" + +using namespace bt; +using namespace mse; + +namespace utest +{ + + DiffleHellmanTest::DiffleHellmanTest() + : UnitTest("DiffleHellman") + {} + + + DiffleHellmanTest::~DiffleHellmanTest() + {} + + + bool DiffleHellmanTest::doTest() + { + BigInt xa,ya,xb,yb; + mse::GeneratePublicPrivateKey(xa,ya); + mse::GeneratePublicPrivateKey(xb,yb); + mse::DumpBigInt("Xa",xa); + mse::DumpBigInt("Ya",ya); + mse::DumpBigInt("Xb",xb); + mse::DumpBigInt("Yb",yb); + + mse::DumpBigInt("Sa",mse::DHSecret(xa,yb)); + mse::DumpBigInt("Sb",mse::DHSecret(xb,ya)); + return true; + } + +} diff --git a/utests/difflehellmantest.h b/utests/difflehellmantest.h new file mode 100644 index 0000000..c065894 --- /dev/null +++ b/utests/difflehellmantest.h @@ -0,0 +1,44 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * joris.guisson@gmail.com * + * * + * 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. * + ***************************************************************************/ +#ifndef UTESTDIFFLEHELLMANTEST_H +#define UTESTDIFFLEHELLMANTEST_H + +#include "unittest.h" + +namespace utest +{ + + /** + @author Joris Guisson <joris.guisson@gmail.com> + */ + class DiffleHellmanTest : public UnitTest + { + public: + DiffleHellmanTest(); + + ~DiffleHellmanTest(); + + virtual bool doTest(); + + }; + +} + +#endif diff --git a/utests/main.cpp b/utests/main.cpp new file mode 100644 index 0000000..7618cac --- /dev/null +++ b/utests/main.cpp @@ -0,0 +1,52 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * joris.guisson@gmail.com * + * * + * 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. * + ***************************************************************************/ +#include <stdio.h> +#include <stdlib.h> +#include <libktorrent/util/log.h> +#include <libktorrent/torrent/globals.h> +#include "testrunner.h" +#include "upnpparsedescriptiontest.h" +#include "upnpparseresponsetest.h" +#include "dhtmsgparsetest.h" +#include "biginttest.h" +#include "rc4test.h" +#include "difflehellmantest.h" + +using namespace kt; +using namespace bt; +using namespace utest; + + + +int main(int argc,char** argv) +{ + Globals::instance().setDebugMode(true); + Globals::instance().initLog("ktutester.log"); + TestRunner tr; + tr.addTest(new UPnPParseDescriptionTest()); + tr.addTest(new UPnPParseResponseTest()); + tr.addTest(new DHTMsgParseTest()); + tr.addTest(new BigIntTest()); + tr.addTest(new RC4Test()); + tr.addTest(new DiffleHellmanTest()); + tr.doAllTests(); + Globals::cleanup(); + return 0; +} diff --git a/utests/rc4test.cpp b/utests/rc4test.cpp new file mode 100644 index 0000000..ef5e7c4 --- /dev/null +++ b/utests/rc4test.cpp @@ -0,0 +1,95 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * joris.guisson@gmail.com * + * * + * 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. * + ***************************************************************************/ +#include <stdio.h> +#include <mse/rc4encryptor.h> +#include <util/log.h> +#include <torrent/globals.h> +#include "rc4test.h" + +using namespace bt; +using namespace mse; + +namespace utest +{ + + RC4Test::RC4Test() : UnitTest("RC4") + {} + + + RC4Test::~RC4Test() + {} + + + bool RC4Test::doTest() + { + bool ret1 = firstTest(); + bool ret2 = secondTest(); + return ret1 && ret2; + } + + bool RC4Test::firstTest() + { + Out() << "First RC4 test" << endl; + SHA1Hash a = SHA1Hash::generate((Uint8*)"keyA",4); + SHA1Hash b = SHA1Hash::generate((Uint8*)"keyB",4); + + RC4Encryptor as(b,a); + RC4Encryptor bs(a,b); + char* test = "Dit is een test"; + int tlen = strlen(test); + Uint8* dec = (Uint8*)as.encrypt((Uint8*)test,tlen); + bs.decrypt(dec,tlen); + if (memcmp(dec,test,tlen) == 0) + { + Out() << "Test succesfull" << endl; + Out() << QString(test) << endl; + Out() << QString((char*)dec) << endl; + return true; + } + else + { + Out() << "Test not succesfull" << endl; + Out() << QString(test) << endl; + Out() << QString((char*)dec) << endl; + return false; + } + } + + bool RC4Test::secondTest() + { + Out() << "Second RC4 test" << endl; + Uint8 output[100]; + Uint8 result[] = {0xbb,0xf3,0x16, 0xe8 , 0xd9, 0x40, 0xaf,0x0a ,0xd3 }; + // RC4( "Key", "Plaintext" ) == "bbf316e8 d940af0a d3" + char* key = "Key"; + char* pt = "Plaintext"; + RC4 enc((const Uint8*)key,3); + enc.process((const Uint8*)pt,output,strlen(pt)); + + for (Uint32 i = 0;i < strlen(pt);i++) + { + if (output[i] != result[i]) + return false; + } + + return true; + } + +} diff --git a/utests/rc4test.h b/utests/rc4test.h new file mode 100644 index 0000000..b92afae --- /dev/null +++ b/utests/rc4test.h @@ -0,0 +1,46 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * joris.guisson@gmail.com * + * * + * 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. * + ***************************************************************************/ +#ifndef UTESTRC4TEST_H +#define UTESTRC4TEST_H + +#include "unittest.h" + +namespace utest +{ + + /** + @author Joris Guisson <joris.guisson@gmail.com> + */ + class RC4Test : public UnitTest + { + public: + RC4Test(); + virtual ~RC4Test(); + + virtual bool doTest(); + + private: + bool firstTest(); + bool secondTest(); + }; + +} + +#endif diff --git a/utests/testrunner.cpp b/utests/testrunner.cpp new file mode 100644 index 0000000..d518c17 --- /dev/null +++ b/utests/testrunner.cpp @@ -0,0 +1,76 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * joris.guisson@gmail.com * + * * + * 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. * + ***************************************************************************/ +#include <util/log.h> +#include <util/error.h> +#include <torrent/globals.h> +#include "testrunner.h" + +using namespace bt; + +namespace utest +{ + + TestRunner::TestRunner() + { + tests.setAutoDelete(true); + } + + + TestRunner::~TestRunner() + {} + + void TestRunner::addTest(UnitTest* ut) + { + tests.append(ut); + } + + void TestRunner::doAllTests() + { + int succes = 0; + int failure = 0; + QPtrList<UnitTest>::iterator i = tests.begin(); + while (i != tests.end()) + { + Out() << "======================" << endl; + UnitTest* t = *i; + bool res = false; + try + { + res = t->doTest(); + } + catch (bt::Error & err) + { + Out() << "Caught Error : " << err.toString() << endl; + res = false; + } + bt::Out() << "Doing test " << t->getName() << " : " << (res ? "SUCCES" : "FAILURE") << endl; + if (res) + succes++; + else + failure++; + i++; + } + + Out() << "======================" << endl; + Out() << "Summary : " << endl; + Out() << "\t" << succes << " succesfull tests" << endl; + Out() << "\t" << failure << " failed tests" << endl; + } +} diff --git a/utests/testrunner.h b/utests/testrunner.h new file mode 100644 index 0000000..c4e7623 --- /dev/null +++ b/utests/testrunner.h @@ -0,0 +1,45 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * joris.guisson@gmail.com * + * * + * 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. * + ***************************************************************************/ +#ifndef UTESTTESTRUNNER_H +#define UTESTTESTRUNNER_H + +#include <qptrlist.h> +#include "unittest.h" + +namespace utest +{ + + /** + @author Joris Guisson <joris.guisson@gmail.com> + */ + class TestRunner + { + QPtrList<UnitTest> tests; + public: + TestRunner(); + virtual ~TestRunner(); + + void addTest(UnitTest* ut); + void doAllTests(); + }; + +} + +#endif diff --git a/utests/unittest.cpp b/utests/unittest.cpp new file mode 100644 index 0000000..458ff8b --- /dev/null +++ b/utests/unittest.cpp @@ -0,0 +1,33 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * joris.guisson@gmail.com * + * * + * 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. * + ***************************************************************************/ +#include "unittest.h" + +namespace utest +{ + + UnitTest::UnitTest(const QString & name) : name(name) + {} + + + UnitTest::~UnitTest() + {} + + +} diff --git a/utests/unittest.h b/utests/unittest.h new file mode 100644 index 0000000..6fd46d8 --- /dev/null +++ b/utests/unittest.h @@ -0,0 +1,47 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * joris.guisson@gmail.com * + * * + * 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. * + ***************************************************************************/ +#ifndef UTESTUNITTEST_H +#define UTESTUNITTEST_H + +#include <qstring.h> + +namespace utest +{ + + /** + @author Joris Guisson <joris.guisson@gmail.com> + + Base class for all unit tests + */ + class UnitTest + { + QString name; + public: + UnitTest(const QString & name); + virtual ~UnitTest(); + + QString getName() const {return name;} + + virtual bool doTest() = 0; + }; + +} + +#endif diff --git a/utests/upnpparsedescriptiontest.cpp b/utests/upnpparsedescriptiontest.cpp new file mode 100644 index 0000000..bbccfdd --- /dev/null +++ b/utests/upnpparsedescriptiontest.cpp @@ -0,0 +1,433 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * joris.guisson@gmail.com * + * * + * 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. * + ***************************************************************************/ +#include <qfile.h> +#include <plugins/upnp/upnprouter.h> +#include <plugins/upnp/upnpdescriptionparser.h> +#include <util/fileops.h> +#include <util/error.h> +#include <util/log.h> +#include <torrent/globals.h> +#include "upnpparsedescriptiontest.h" + +using namespace kt; +using namespace bt; + +namespace utest +{ + static char* test_data1 = "<?xml version=\"1.0\"?>\n" + "<root xmlns=\"urn:schemas-upnp-org:device-1-0\">\n" + "<specVersion>\n" + "<major>1</major>\n" + "<minor>0</minor>\n" + "</specVersion>\n" + "<URLBase>http://192.168.0.1:5678</URLBase>\n" + "<device>\n" + "<deviceType>urn:schemas-upnp-org:device:InternetGatewayDevice:1</deviceType>\n" + "<presentationURL>http://192.168.0.1:80</presentationURL>\n" + "<friendlyName>D-Link Router</friendlyName>\n" + "<manufacturer>D-Link</manufacturer>\n" + "<manufacturerURL>http://www.dlink.com</manufacturerURL>\n" + "<modelDescription>Internet Access Router</modelDescription>\n" + "<modelName>D-Link Router</modelName>\n" + "<UDN>uuid:upnp-InternetGatewayDevice-1_0-12345678900001</UDN>\n" + "<UPC>123456789001</UPC>\n" + "<serviceList>\n" + "<service>\n" + "<serviceType>urn:schemas-upnp-org:service:Layer3Forwarding:1</serviceType>\n" + "<serviceId>urn:upnp-org:serviceId:L3Forwarding1</serviceId>\n" + "<controlURL>/Layer3Forwarding</controlURL>\n" + "<eventSubURL>/Layer3Forwarding</eventSubURL>\n" + "<SCPDURL>/Layer3Forwarding.xml</SCPDURL>\n" + "</service>\n" + "</serviceList>\n" + "<deviceList>\n" + "<device>\n" + "<deviceType>urn:schemas-upnp-org:device:WANDevice:1</deviceType>\n" + "<friendlyName>WANDevice</friendlyName>\n" + "<manufacturer>D-Link</manufacturer>\n" + "<manufacturerURL>http://www.dlink.com</manufacturerURL>\n" + "<modelDescription>Internet Access Router</modelDescription>\n" + "<modelName>D-Link Router</modelName>\n" + "<modelNumber>1</modelNumber>\n" + "<modelURL>http://support.dlink.com</modelURL>\n" + "<serialNumber>12345678900001</serialNumber>\n" + "<UDN>uuid:upnp-WANDevice-1_0-12345678900001</UDN>\n" + "<UPC>123456789001</UPC>\n" + "<serviceList>\n" + "<service>\n" + "<serviceType>urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1</serviceType>\n" + "<serviceId>urn:upnp-org:serviceId:WANCommonInterfaceConfig</serviceId>\n" + "<controlURL>/WANCommonInterfaceConfig</controlURL>\n" + "<eventSubURL>/WANCommonInterfaceConfig</eventSubURL>\n" + "<SCPDURL>/WANCommonInterfaceConfig.xml</SCPDURL>\n" + "</service>\n" + "</serviceList>\n" + "<deviceList>\n" + "<device>\n" + "<deviceType>urn:schemas-upnp-org:device:WANConnectionDevice:1</deviceType>\n" + "<friendlyName>WAN Connection Device</friendlyName>\n" + "<manufacturer>D-Link</manufacturer>\n" + "<manufacturerURL>http://www.dlink.com</manufacturerURL>\n" + "<modelDescription>Internet Access Router</modelDescription>\n" + "<modelName>D-Link Router</modelName> \n" + "<modelNumber>1</modelNumber>\n" + "<modelURL>http://support.dlink.com</modelURL>\n" + "<serialNumber>12345678900001</serialNumber>\n" + "<UDN>uuid:upnp-WANConnectionDevice-1_0-12345678900001</UDN>\n" + "<UPC>123456789001</UPC>\n" + "<serviceList>\n" + "<service>\n" + "<serviceType>urn:schemas-upnp-org:service:WANIPConnection:1</serviceType>\n" + "<serviceId>urn:upnp-org:serviceId:WANIPConnection</serviceId> \n" + "<controlURL>/WANIPConnection</controlURL>\n" + "<eventSubURL>/WANIPConnection</eventSubURL>\n" + "<SCPDURL>/WANIPConnection.xml</SCPDURL>\n" + "</service>\n" + "</serviceList>\n" + "</device>\n" + "</deviceList>\n" + "</device>\n" + "</deviceList>\n" + "</device>\n" + "</root>"; + + static const char* test_data2 = "<?xml version=\"1.0\"?> \n" + "<root xmlns=\"urn:schemas-upnp-org:device-1-0\"> \n" + "<specVersion> \n" + "<major>1</major> \n" + "<minor>0</minor> \n" + "</specVersion> \n" + "<URLBase>http://192.168.1.1:52869</URLBase> \n" + "<device> \n" + "<deviceType>urn:schemas-upnp-org:device:InternetGatewayDevice:1</deviceType> \n" + "<friendlyName>DLINK Internet Gateway Device</friendlyName> \n" + "<manufacturer>DLINK</manufacturer> \n" + "<manufacturerURL>http://www.dlink.com</manufacturerURL> \n" + "<modelName>DLINK IGD</modelName> \n" + "<UDN>uuid:75802409-bccb-40e7-8e6c-fa095ecce13e</UDN> \n" + "<iconList> \n" + "<icon> \n" + "<mimetype>image/gif</mimetype> \n" + "<width>118</width> \n" + "<height>119</height> \n" + "<depth>8</depth> \n" + "<url>/ligd.gif</url> \n" + "</icon> \n" + "</iconList> \n" + "<serviceList> \n" + "<service> \n" + "<serviceType>urn:schemas-microsoft-com:service:OSInfo:1</serviceType> \n" + "<serviceId>urn:microsoft-com:serviceId:OSInfo1</serviceId> \n" + "<controlURL>/upnp/control/OSInfo1</controlURL> \n" + "<eventSubURL>/upnp/event/OSInfo1</eventSubURL> \n" + "<SCPDURL>/gateinfoSCPD.xml</SCPDURL> \n" + "</service> \n" + "</serviceList> \n" + "<deviceList> \n" + "<device> \n" + "<deviceType>urn:schemas-upnp-org:device:WANDevice:1</deviceType> \n" + "<friendlyName>WANDevice</friendlyName> \n" + "<manufacturer>DLINK</manufacturer> \n" + "<manufacturerURL>http://www.dlink.com</manufacturerURL> \n" + "<modelDescription>WAN Device on DLINK IGD</modelDescription> \n" + "<modelName>DLINK IGD</modelName> \n" + "<modelNumber>0.92</modelNumber> \n" + "<modelURL>http://www.dlink.com</modelURL> \n" + "<serialNumber>0.92</serialNumber> \n" + "<UDN>uuid:75802409-bccb-40e7-8e6c-fa095ecce13e</UDN> \n" + "<UPC>DLINK IGD</UPC> \n" + "<serviceList> \n" + "<service> \n" + "<serviceType>urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1</serviceType> \n" + "<serviceId>urn:upnp-org:serviceId:WANCommonIFC1</serviceId> \n" + "<controlURL>/upnp/control/WANCommonIFC1</controlURL> \n" + "<eventSubURL>/upnp/control/WANCommonIFC1</eventSubURL> \n" + "<SCPDURL>/gateicfgSCPD.xml</SCPDURL> \n" + "</service> \n" + "</serviceList> \n" + "<deviceList> \n" + "<device> \n" + "<deviceType>urn:schemas-upnp-org:device:WANConnectionDevice:1</deviceType> \n" + "<friendlyName>WANConnectionDevice</friendlyName> \n" + "<manufacturer>DLINK</manufacturer> \n" + "<manufacturerURL>http://www.dlink.com</manufacturerURL> \n" + "<modelDescription>WanConnectionDevice on DLINK IGD</modelDescription> \n" + "<modelName>DLINK IGD</modelName> \n" + "<modelNumber>0.92</modelNumber> \n" + "<modelURL>http://www.dlink.com</modelURL> \n" + "<serialNumber>0.92</serialNumber> \n" + "<UDN>uuid:75802409-bccb-40e7-8e6c-fa095ecce13e</UDN> \n" + "<UPC>DLINK IGD</UPC> \n" + "<serviceList> \n" + "<service> \n" + "<serviceType>urn:schemas-upnp-org:service:WANIPConnection:1</serviceType> \n" + "<serviceId>urn:upnp-org:serviceId:WANIPConn1</serviceId> \n" + "<controlURL>/upnp/control/WANIPConn1</controlURL> \n" + "<eventSubURL>/upnp/control/WANIPConn1</eventSubURL> \n" + "<SCPDURL>/gateconnSCPD.xml</SCPDURL> \n" + "</service> \n" + "</serviceList> \n" + "</device> \n" + "</deviceList> \n" + "</device> \n" + "</deviceList> \n" + "<presentationURL>http://192.168.1.1/</presentationURL> \n" + "</device> \n" + "</root> "; + + static const char* test_data3 = "<?xml version=\"1.0\"?> \ + <root xmlns=\"urn:schemas-upnp-org:device-1-0\"> \ + <specVersion> \ + <major>1</major> \ + <minor>0</minor> \ + </specVersion> \ + <URLBase>http://192.168.0.5:5431/</URLBase> \ + <device> \ + <deviceType>urn:schemas-upnp-org:device:InternetGatewayDevice:1</deviceType> \ + <presentationURL>http://192.168.0.5:80/</presentationURL> \ + <friendlyName>Dynalink Wireless ADSL Router</friendlyName> \ + <manufacturer>Danalink</manufacturer> \ + <manufacturerURL>http://www.dynalink.co.nz/</manufacturerURL> \ + <modelDescription>Broadcom single-chip ADSL router</modelDescription> \ + <modelName>BCM6345+BCM4306</modelName> \ + <modelNumber>1.0</modelNumber> \ + <modelURL>http://www.dynalink.co.nz/</modelURL> \ + <UDN>uuid:10740000-0000-1000-b710-107c0032dca6</UDN> \ + <serviceList> \ + <service> \ + <serviceType>urn:schemas-upnp-org:service:Layer3Forwarding:1</serviceType> \ + <serviceId>urn:upnp-org:serviceId:Layer3Forwarding:11</serviceId> \ + <controlURL>/uuid:10740000-0000-1000-b710-107c0032dca6/Layer3Forwarding:1</controlURL> \ + <eventSubURL>/uuid:10740000-0000-1000-b710-107c0032dca6/Layer3Forwarding:1</eventSubURL> \ + <SCPDURL>/dynsvc/Layer3Forwarding:1.xml</SCPDURL> \ + </service> \ + </serviceList> \ + <deviceList> \ + <device> \ + <deviceType>urn:schemas-upnp-org:device:WANDevice:1</deviceType> \ + <friendlyName>urn:schemas-upnp-org:device:WANDevice:1</friendlyName> \ + <manufacturer>Danalink</manufacturer> \ + <manufacturerURL>http://www.dynalink.co.nz/</manufacturerURL> \ + <modelDescription>Broadcom single-chip ADSL router</modelDescription> \ + <modelName>BCM6345+BCM4306</modelName> \ + <modelNumber>1.0</modelNumber> \ + <modelURL>http://www.dynalink.co.nz/</modelURL> \ + <UDN>uuid:10740000-0000-1000-b710-107c0132dca6</UDN> \ + <serviceList> \ + <service> \ + <serviceType>urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1</serviceType> \ + <serviceId>urn:upnp-org:serviceId:WANCommonIFC1</serviceId> \ + <controlURL>/uuid:10740000-0000-1000-b710-107c0132dca6/WANCommonInterfaceConfig:1</controlURL> \ + <eventSubURL>/uuid:10740000-0000-1000-b710-107c0132dca6/WANCommonInterfaceConfig:1</eventSubURL> \ + <SCPDURL>/dynsvc/WANCommonInterfaceConfig:1.xml</SCPDURL> \ + </service> \ + </serviceList> \ + <deviceList> \ + <device> \ + <deviceType>urn:schemas-upnp-org:device:WANConnectionDevice:1</deviceType> \ + <friendlyName>urn:schemas-upnp-org:device:WANConnectionDevice:1</friendlyName> \ + <manufacturer>Danalink</manufacturer> \ + <manufacturerURL>http://www.dynalink.co.nz/</manufacturerURL> \ + <modelDescription>Broadcom single-chip ADSL router</modelDescription> \ + <modelName>BCM6345+BCM4306</modelName> \ + <modelNumber>1.0</modelNumber> \ + <modelURL>http://www.dynalink.co.nz/</modelURL> \ + <UDN>uuid:10740000-0000-1000-b710-107c0232dca6</UDN> \ + <serviceList> \ + <service> \ + <serviceType>urn:schemas-upnp-org:service:WANPPPConnection:1</serviceType> \ + <serviceId>urn:upnp-org:serviceId:WANPPPConn1</serviceId> \ + <controlURL>/uuid:10740000-0000-1000-b710-107c0232dca6/WANPPPConnection:1</controlURL> \ + <eventSubURL>/uuid:10740000-0000-1000-b710-107c0232dca6/WANPPPConnection:1</eventSubURL> \ + <SCPDURL>/dynsvc/WANPPPConnection:1.xml</SCPDURL> \ + </service> \ + </serviceList> \ + </device> \ + </deviceList> \ + </device> \ + </deviceList> \ + </device> \ + </root> "; + + const char* test_data4 = "<?xml version=\"1.0\"?> \ + <root xmlns=\"urn:schemas-upnp-org:device-1-0\"> \ + <specVersion> \ + <major>1</major> \ + <minor>0</minor> \ + </specVersion> \ + <URLBase>http://192.168.1.1:2869</URLBase> \ + <device> \ + <deviceType>urn:schemas-upnp-org:device:InternetGatewayDevice:1</deviceType> \ + <friendlyName>OpenWrt Linux Internet Gateway Device</friendlyName> \ + <manufacturer>OpenWrt Project</manufacturer> \ + <manufacturerURL>http://www.openwrt.org</manufacturerURL> \ + <modelName>WRT54G(S)</modelName> \ + <UDN>uuid:75802409-bccb-40e7-8e6c-fa095ecce13e</UDN> \ + <iconList> \ + <icon> \ + <mimetype>image/gif</mimetype> \ + <width>118</width> \ + <height>119</height>\ + <depth>8</depth> \ + <url>/ligd.gif</url> \ + </icon> \ + </iconList> \ + <serviceList> \ + <service> \ + <serviceType>urn:schemas-microsoft-com:service:OSInfo:1</serviceType> \ + <serviceId>urn:microsoft-com:serviceId:OSInfo1</serviceId> \ + <controlURL>/upnp/control/OSInfo1</controlURL> \ + <eventSubURL>/upnp/event/OSInfo1</eventSubURL> \ + <SCPDURL>/gateinfoSCPD.xml</SCPDURL> \ + </service> \ + </serviceList> \ + <deviceList> \ + <device> \ + <deviceType>urn:schemas-upnp-org:device:WANDevice:1</deviceType> \ + <friendlyName>WANDevice</friendlyName> \ + <manufacturer>OpenWrt Project</manufacturer> \ + <manufacturerURL>http://www.openwrt.org</manufacturerURL> \ + <modelDescription>WAN Device on OpenWrt Router</modelDescription> \ + <modelName>WRT54G(S)</modelName> \ + <modelNumber>1.0</modelNumber> \ + <modelURL>http://www.linksys.com</modelURL> \ + <serialNumber>XXXXXXXXXX</serialNumber> \ + <UDN>uuid:75802409-bccb-40e7-8e6c-fa095ecce13e</UDN> \ + <UPC>Linux IGD</UPC> \ + <serviceList> \ + <service> \ + <serviceType>urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1</serviceType> \ + <serviceId>urn:upnp-org:serviceId:WANCommonIFC1</serviceId> \ + <controlURL>/upnp/control/WANCommonIFC1</controlURL> \ + <eventSubURL>/upnp/control/WANCommonIFC1</eventSubURL> \ + <SCPDURL>/gateicfgSCPD.xml</SCPDURL> \ + </service> \ + </serviceList> \ + <deviceList> \ + <device> \ + <deviceType>urn:schemas-upnp-org:device:WANConnectionDevice:1</deviceType> \ + <friendlyName>WANConnectionDevice</friendlyName> \ + <manufacturer>OpenWrt Project</manufacturer> \ + <manufacturerURL>http://www.openwrt.org</manufacturerURL> \ + <modelDescription>WanConnectionDevice on OpenWrt Router</modelDescription> \ + <modelName>WRT54G(S)</modelName> \ + <modelNumber>1.0</modelNumber> \ + <modelURL>http://www.linksys.com</modelURL> \ + <serialNumber>XXXXXXXXXX</serialNumber> \ + <UDN>uuid:75802409-bccb-40e7-8e6c-fa095ecce13e</UDN> \ + <UPC>Linux IGD</UPC> \ + <serviceList> \ + <service> \ + <serviceType>urn:schemas-upnp-org:service:WANIPConnection:1</serviceType> \ + <serviceId>urn:upnp-org:serviceId:WANIPConn1</serviceId> \ + <controlURL>/upnp/control/WANIPConn1</controlURL> \ + <eventSubURL>/upnp/control/WANIPConn1</eventSubURL> \ + <SCPDURL>/gateconnSCPD.xml</SCPDURL> \ + </service> \ + </serviceList> \ + </device> \ + </deviceList> \ + </device> \ + </deviceList> \ + <presentationURL>http://192.168.1.1/</presentationURL> \ + </device> \ + </root> "; + + + UPnPParseDescriptionTest::UPnPParseDescriptionTest() : UnitTest("UPnPParseDescriptionTest") + {} + + + UPnPParseDescriptionTest::~UPnPParseDescriptionTest() + {} + + bool UPnPParseDescriptionTest::doParse(const char* data,bool forward_test) + { + QString fn = "/tmp/UPnPParseDescriptionTest"; + QFile fptr(fn); + if (!fptr.open(IO_WriteOnly)) + { + Out() << "Cannot open " << fn << " : " << fptr.errorString() << endl; + return false; + } + fptr.writeBlock(data,strlen(data)); + fptr.close(); + + kt::UPnPRouter router(QString::null,"http://foobar.com"); + kt::UPnPDescriptionParser dp; + + if (!dp.parse(fn,&router)) + { + bt::Delete(fn,true); + return false; + } + else + { + Out() << "Succesfully parsed the UPnP contents" << endl; + bt::Delete(fn,true); + if (forward_test) + { + try + { + Out() << "Attempting to forward port 9999" << endl; + router.forward(net::Port(9999,net::TCP,true)); + } + catch (Error & e) + { + Out() << "Error forwarding : "<< e.toString() << endl; + return false; + } + } + // router.debugPrintData(); + return true; + } + } + + bool UPnPParseDescriptionTest::doTest() + { + bool ret = true; + if (!doParse(test_data1,false)) + { + Out() << "Test data 1 failed" << endl; + ret = false; + } + + if (!doParse(test_data2,false)) + { + Out() << "Test data 2 failed" << endl; + ret = false; + } + + if (!doParse(test_data3,false)) + { + Out() << "Test data 3 failed" << endl; + ret = false; + } + + if (!doParse(test_data4,false)) + { + Out() << "Test data 4 failed" << endl; + ret = false; + } + + return ret; + } + +} diff --git a/utests/upnpparsedescriptiontest.h b/utests/upnpparsedescriptiontest.h new file mode 100644 index 0000000..29d4e1e --- /dev/null +++ b/utests/upnpparsedescriptiontest.h @@ -0,0 +1,44 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * joris.guisson@gmail.com * + * * + * 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. * + ***************************************************************************/ +#ifndef UTESTUPNPPARSEDESCRIPTIONTEST_H +#define UTESTUPNPPARSEDESCRIPTIONTEST_H + +#include <unittest.h> + +namespace utest +{ + + /** + @author Joris Guisson <joris.guisson@gmail.com> + */ + class UPnPParseDescriptionTest : public UnitTest + { + public: + UPnPParseDescriptionTest(); + virtual ~UPnPParseDescriptionTest(); + + virtual bool doTest(); + private: + bool doParse(const char* data,bool forward_test); + }; + +} + +#endif diff --git a/utests/upnpparseresponsetest.cpp b/utests/upnpparseresponsetest.cpp new file mode 100644 index 0000000..0198ec7 --- /dev/null +++ b/utests/upnpparseresponsetest.cpp @@ -0,0 +1,66 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * joris.guisson@gmail.com * + * * + * 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. * + ***************************************************************************/ +#include <plugins/upnp/upnprouter.h> +#include <plugins/upnp/upnpdescriptionparser.h> +#include <plugins/upnp/upnpmcastsocket.h> +#include "upnpparseresponsetest.h" + +using namespace kt; +using namespace bt; + +namespace utest +{ + + UPnPParseResponseTest::UPnPParseResponseTest() : UnitTest("UPnPParseResponseTest") + {} + + + UPnPParseResponseTest::~UPnPParseResponseTest() + {} + + + bool UPnPParseResponseTest::doTest() + { + static const char* test_ps = "M-SEARCH * HTTP/1.1\r\n" + "HOST: 239.255.255.250:1900\r\n" + "ST:urn:schemas-upnp-org:device:InternetGatewayDevice:1\r\n" + "MAN:\"ssdp:discover\"\r\n" + "MX:3\r\n" + "HTTP/1.1 200 OK\r\n" + "CACHE-CONTROL: max-age=1800\r\n" + "DATE: Mon, 13 Mar 2006 19:55:10 GMT \r\n" + "EXT:\r\n" + "LOCATION: http://192.168.1.1:52869/gatedesc.xml\r\n" + "SERVER: Linux/2.4.17_mvl21-malta-mips_fp_le, UPnP/1.0, Intel SDK for UPnP devices /1.2\r\n" + "ST: urn:schemas-upnp-org:device:InternetGatewayDevice:1\r\n" + "USN: uuid:75802409-bccb-40e7-8e6c-fa095ecce13e::urn:schemas-upnp-org:device:InternetGatewayDevice:1\r\n\r\n"; + + UPnPMCastSocket mcast; + UPnPRouter* r = mcast.parseResponse(QCString(test_ps)); + if (r) + { + delete r; + return true; + } + + return false; + } + +} diff --git a/utests/upnpparseresponsetest.h b/utests/upnpparseresponsetest.h new file mode 100644 index 0000000..5186fd5 --- /dev/null +++ b/utests/upnpparseresponsetest.h @@ -0,0 +1,44 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * joris.guisson@gmail.com * + * * + * 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. * + ***************************************************************************/ +#ifndef UTESTUPNPPARSERESPONSETEST_H +#define UTESTUPNPPARSERESPONSETEST_H + +#include <unittest.h> + +namespace utest +{ + + /** + @author Joris Guisson <joris.guisson@gmail.com> + */ + class UPnPParseResponseTest : public UnitTest + { + public: + UPnPParseResponseTest(); + + ~UPnPParseResponseTest(); + + virtual bool doTest(); + + }; + +} + +#endif |