00001 /*!@file TestSuite/whitebox-Channels.C */ 00002 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005 // 00005 // by the University of Southern California (USC) and the iLab at USC. // 00006 // See http://iLab.usc.edu for information about this project. // 00007 // //////////////////////////////////////////////////////////////////// // 00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00010 // in Visual Environments, and Applications'' by Christof Koch and // 00011 // Laurent Itti, California Institute of Technology, 2001 (patent // 00012 // pending; application number 09/912,225 filed July 23, 2001; see // 00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00014 // //////////////////////////////////////////////////////////////////// // 00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00016 // // 00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00018 // redistribute it and/or modify it under the terms of the GNU General // 00019 // Public License as published by the Free Software Foundation; either // 00020 // version 2 of the License, or (at your option) any later version. // 00021 // // 00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00025 // PURPOSE. See the GNU General Public License for more details. // 00026 // // 00027 // You should have received a copy of the GNU General Public License // 00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00030 // Boston, MA 02111-1307 USA. // 00031 // //////////////////////////////////////////////////////////////////// // 00032 // 00033 // Primary maintainer for this file: Rob Peters <rjpeters at usc dot edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/TestSuite/whitebox-Channels.C $ 00035 // $Id: whitebox-Channels.C 9992 2008-07-28 19:10:59Z lior $ 00036 // 00037 00038 #ifndef TESTSUITE_WHITEBOX_CHANNELS_C_DEFINED 00039 #define TESTSUITE_WHITEBOX_CHANNELS_C_DEFINED 00040 00041 #include "Channels/ChannelFacet.H" 00042 #include "Channels/ComplexChannel.H" 00043 #include "Channels/SingleChannel.H" 00044 #include "Component/ModelManager.H" 00045 #include "Component/ParamMap.H" 00046 #include "TestSuite/TestSuite.H" 00047 00048 #include <sstream> 00049 00050 namespace 00051 { 00052 class DummyFacet : public ChannelFacet 00053 { 00054 public: 00055 DummyFacet(int m) : magic(m) {} 00056 00057 virtual ~DummyFacet() {} 00058 00059 virtual void writeTo(ParamMap& pmap) const 00060 { 00061 pmap.putIntParam("magic", magic); 00062 } 00063 00064 virtual void readFrom(const ParamMap& pmap) 00065 { 00066 pmap.queryIntParam("magic", magic); 00067 } 00068 00069 int magic; 00070 }; 00071 } 00072 00073 static void Channels_xx_facets_xx_1(TestSuite& suite) 00074 { 00075 ModelManager m(""); 00076 00077 nub::ref<SingleChannel> c 00078 (new SingleChannel 00079 (m, "dummy", "dummy", UNKNOWN, 00080 rutz::make_shared(new GaussianPyrBuilder<float>(5)))); 00081 00082 m.addSubComponent(c); 00083 m.exportOptions(MC_RECURSE); 00084 00085 m.start(); 00086 00087 REQUIRE_EQ(c->hasFacet<DummyFacet>(), false); 00088 REQUIRE_EQ(c->hasFacet<int>(), false); 00089 00090 rutz::shared_ptr<DummyFacet> f(new DummyFacet(42)); 00091 00092 c->setFacet(f); 00093 00094 REQUIRE_EQ(c->hasFacet<DummyFacet>(), true); 00095 REQUIRE_EQ(c->hasFacet<int>(), false); 00096 REQUIRE_EQ(c->getFacet<DummyFacet>()->magic, 42); 00097 00098 ParamMap pmap; 00099 c->writeTo(pmap); 00100 std::ostringstream oss; 00101 pmap.format(oss); 00102 00103 REQUIRE_EQ(oss.str(), 00104 std::string("(anonymous\\ namespace)::DummyFacet {\n" 00105 "\tmagic 42\n" 00106 "}\n" 00107 "descriptivename dummy\n")); 00108 00109 f->magic = 39; 00110 REQUIRE_EQ(f->magic, 39); 00111 00112 ParamMap pmap2; 00113 std::istringstream iss(oss.str()); 00114 pmap2.load(iss); 00115 c->readFrom(pmap2); 00116 REQUIRE_EQ(f->magic, 42); 00117 } 00118 00119 /////////////////////////////////////////////////////////////////////// 00120 // 00121 // main 00122 // 00123 /////////////////////////////////////////////////////////////////////// 00124 00125 int main(int argc, const char** argv) 00126 { 00127 TestSuite suite; 00128 00129 suite.ADD_TEST(Channels_xx_facets_xx_1); 00130 00131 suite.parseAndRun(argc, argv); 00132 00133 return 0; 00134 } 00135 00136 // ###################################################################### 00137 /* So things look consistent in everyone's emacs... */ 00138 /* Local Variables: */ 00139 /* mode: c++ */ 00140 /* indent-tabs-mode: nil */ 00141 /* End: */ 00142 00143 #endif // TESTSUITE_WHITEBOX_CHANNELS_C_DEFINED