HugeGemBlockTest.cpp

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 2006-2007 by Peter Dimov.
00004 
00005 This file is part of Calitko (http://www.calitko.org).
00006 
00007 Calitko is free software; you can redistribute it and/or modify
00008 it under the terms of the GNU General Public License as published by
00009 the Free Software Foundation; either version 2 of the License, or
00010 (at your option) any later version.
00011 
00012 Calitko is distributed in the hope that it will be useful,
00013 but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 GNU General Public License for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Calitko; if not, write to the Free Software
00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020 
00021 */
00022 
00023 #include "Qt.h"
00024 #include "../HugeGemBlock.h"
00025 #include "../Ggeps/Unknown.h"
00026 #include "Imports.cpp"
00027 
00028 namespace Protocols {
00029 namespace Gnutella {
00030 namespace Packets {
00031 namespace Extensions {
00032 namespace Testing {
00033 
00034 class HugeGemBlockTest : public CppUnit::TestFixture
00035 {
00036     CPPUNIT_TEST_SUITE(HugeGemBlockTest);
00037     CPPUNIT_TEST(testOperatorEqualXmlsDifferent);
00038     CPPUNIT_TEST(testOperatorEqualUrnsDifferent);
00039     CPPUNIT_TEST(testOperatorEqualGgepBlockDifferent);
00040     CPPUNIT_TEST(testOperatorEqualUnknownsDifferent);
00041     CPPUNIT_TEST(testOperatorEqualRealEqual);
00042     CPPUNIT_TEST_SUITE_END();
00043 
00044     HugeGemBlock    extension1, extension2;
00045 
00046 public:
00047     HugeGemBlockTest() : extension1(), extension2() {}
00048 
00049     void scenarioOperatorEqual (const HugeGemBlock::Urn     &urn1,
00050                                 const HugeGemBlock::Urn &urn2,
00051                                 const HugeGemBlock::Xml &xml1,
00052                                 const HugeGemBlock::Xml &xml2,
00053                                 const HugeGemBlock::Unknown &unknown1,
00054                                 const HugeGemBlock::Unknown &unknown2,
00055                                 const GgepBlock &ggepBlock1,
00056                                 const GgepBlock &ggepBlock2,
00057                                 bool areEqual)
00058     {
00059         extension1.urnList += urn1;
00060         extension1.xmlList += xml1;
00061         extension1.unknownList += unknown1;
00062         extension1.ggepBlock = ggepBlock1;
00063         extension2.urnList += urn2;
00064         extension2.xmlList += xml2;
00065         extension2.unknownList += unknown2;
00066         extension2.ggepBlock = ggepBlock2;
00067         CPPUNIT_ASSERT ((extension1 == extension2) == areEqual);
00068     }
00069 
00070     void testOperatorEqualXmlsDifferent()
00071     {
00072         scenarioOperatorEqual ("<xmltest/>", "{xmltest2/}", "", "", "", "",
00073                                GgepBlock(), GgepBlock(), false);
00074     }
00075     void testOperatorEqualUrnsDifferent()
00076     {
00077         scenarioOperatorEqual ("", "", "urn:urn1","urn:urn2", "", "",
00078                                GgepBlock(), GgepBlock(), false);
00079     }
00080     void testOperatorEqualGgepBlockDifferent()
00081     {
00082         scenarioOperatorEqual ("", "", "", "", "", "",
00083             GgepBlock().addExtension(Ggeps::Unknown ("un","fortest1")),
00084             GgepBlock().addExtension(Ggeps::Unknown ("un","fortest2")), false);
00085     }
00086     void testOperatorEqualUnknownsDifferent()
00087     {
00088         scenarioOperatorEqual ("", "", "", "", "dunno1", "dunno2",
00089                                GgepBlock(), GgepBlock(), false);
00090     }
00091     void testOperatorEqualRealEqual()
00092     {
00093         scenarioOperatorEqual (
00094                     "<xmltest/>", "<xmltest/>",
00095                     "urn:urntest", "urn:urntest", "dunnotest", "dunnotest",
00096                     GgepBlock().addExtension(Ggeps::Unknown ("un","fortest")),
00097                     GgepBlock().addExtension(Ggeps::Unknown ("un","fortest")),
00098                     true);
00099     }
00100 };
00101 
00102 CPPUNIT_TEST_SUITE_REGISTRATION(HugeGemBlockTest);
00103 
00104 } // namespace Testing
00105 } // namespace Extensions
00106 } // namespace Packets
00107 } // namespace Gnutella
00108 } // namespace Protocols