switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Utils / Console / ParsedCommand.test.cc
index 8a4a7bb..c8808f8 100644 (file)
@@ -1,24 +1,29 @@
 // $Id$
 //
-// Copyright (C) 2008 
+// Copyright (C) 2008
 // Fraunhofer Institute for Open Communication Systems (FOKUS)
-// Competence Center NETwork research (NET), St. Augustin, GERMANY
-//     Stefan Bund <g0dil@berlios.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.
+// The contents of this file are subject to the Fraunhofer FOKUS Public License
+// Version 1.0 (the "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at 
+// http://senf.berlios.de/license.html
 //
-// 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.
+// The Fraunhofer FOKUS Public License Version 1.0 is based on, 
+// but modifies the Mozilla Public License Version 1.1.
+// See the full license text for the amendments.
 //
-// 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.,
-// 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+// Software distributed under the License is distributed on an "AS IS" basis, 
+// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
+// for the specific language governing rights and limitations under the License.
+//
+// The Original Code is Fraunhofer FOKUS code.
+//
+// The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
+// (registered association), Hansastraße 27 c, 80686 Munich, Germany.
+// All Rights Reserved.
+//
+// Contributor(s):
+//   Stefan Bund <g0dil@berlios.de>
 
 /** \file
     \brief ParsedCommand unit tests */
@@ -35,7 +40,7 @@
 #include <boost/test/test_tools.hpp>
 
 #define prefix_
-///////////////////////////////cc.p////////////////////////////////////////
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
 
 namespace {
 
@@ -45,7 +50,7 @@ namespace {
     std::string cb4(std::ostream & os) { os << "text\n"; return "value"; }
     void cb5(std::ostream & os, std::string const & v) { os << "Value: " << v << "\n"; }
 
-    struct TestParser 
+    struct TestParser
     {
         void operator()(senf::console::ParseCommandInfo::TokensRange const &,
                         std::string & out) const
@@ -56,8 +61,10 @@ namespace {
     { os << "formatter"; }
 }
 
-BOOST_AUTO_UNIT_TEST(parsedCommand)
+SENF_AUTO_UNIT_TEST(parsedCommand)
 {
+    namespace fty = senf::console::factory;
+
     senf::console::Executor executor;
     senf::console::CommandParser parser;
     senf::console::ScopedDirectory<> dir;
@@ -65,15 +72,15 @@ BOOST_AUTO_UNIT_TEST(parsedCommand)
 
     {
         std::stringstream ss;
-        dir.add("cb1", &cb1);
-        parser.parse("test/cb1 2 3.2", 
+        dir.add("cb1", fty::Command(&cb1));
+        parser.parse("test/cb1 2 3.2",
                      boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 ));
         BOOST_CHECK_EQUAL( ss.str(), "5\n" );
     }
 
     {
         std::stringstream ss;
-        dir.add("cb2", &cb2);
+        dir.add("cb2", fty::Command(&cb2));
         parser.parse("test/cb2",
                      boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 ));
         BOOST_CHECK_EQUAL( ss.str(), "1.2\n" );
@@ -81,7 +88,7 @@ BOOST_AUTO_UNIT_TEST(parsedCommand)
 
     {
         std::stringstream ss;
-        dir.add("cb3", &cb3);
+        dir.add("cb3", fty::Command(&cb3));
         parser.parse("test/cb3 234",
                      boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 ));
         BOOST_CHECK_EQUAL( ss.str(), "" );
@@ -89,7 +96,7 @@ BOOST_AUTO_UNIT_TEST(parsedCommand)
 
     {
         std::stringstream ss;
-        dir.add("cb4", &cb4);
+        dir.add("cb4", fty::Command(&cb4));
         parser.parse("test/cb4",
                      boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 ));
         BOOST_CHECK_EQUAL( ss.str(), "text\n" "value\n" );
@@ -97,7 +104,7 @@ BOOST_AUTO_UNIT_TEST(parsedCommand)
 
     {
         std::stringstream ss;
-        dir.add("cb5", &cb5);
+        dir.add("cb5", fty::Command(&cb5));
         parser.parse("test/cb5 1234",
                      boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 ));
         BOOST_CHECK_EQUAL( ss.str(), "Value: 1234\n" );
@@ -106,18 +113,18 @@ BOOST_AUTO_UNIT_TEST(parsedCommand)
     {
         std::stringstream ss;
 
-        BOOST_CHECK_THROW( 
-            parser.parse("test/cb1 2 3.2 foo", 
+        BOOST_CHECK_THROW(
+            parser.parse("test/cb1 2 3.2 foo",
                          boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 )),
             senf::console::SyntaxErrorException );
 
         BOOST_CHECK_THROW(
-            parser.parse("test/cb1 2", 
+            parser.parse("test/cb1 2",
                          boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 )),
             senf::console::SyntaxErrorException );
 
         BOOST_CHECK_THROW(
-            parser.parse("test/cb1 2 foo", 
+            parser.parse("test/cb1 2 foo",
                          boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 )),
             senf::console::SyntaxErrorException );
     }
@@ -127,8 +134,10 @@ BOOST_AUTO_UNIT_TEST(parsedCommand)
         std::stringstream ss;
 
         // Just for the fun of it, use a functor and not a function pointer as parser ...
-        dir.add("cb6", &cb5)
-            .arg( kw::parser = TestParser() );
+        dir.add("cb6",
+                fty::Command(&cb5)
+                    .arg( kw::parser = TestParser() )
+            );
         SENF_CHECK_NO_THROW(
             parser.parse("test/cb6 false",
                          boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 )) );
@@ -138,10 +147,12 @@ BOOST_AUTO_UNIT_TEST(parsedCommand)
     {
         std::stringstream ss;
 
-        // This tests adding boost::function objects and at the same time validates, that 
+        // This tests adding boost::function objects and at the same time validates, that
         // compatible types also work
-        dir.add("cb7", boost::function<float()>(&cb2))
-            .formatter( &testFormatter );
+        dir.add("cb7",
+                fty::Command(boost::function<float()>(&cb2))
+                    .formatter( &testFormatter )
+            );
         SENF_CHECK_NO_THROW(
             parser.parse("test/cb7",
                          boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 )) );
@@ -153,7 +164,7 @@ BOOST_AUTO_UNIT_TEST(parsedCommand)
 
         using namespace senf::console::kw;
 
-        dir.add("cb", &cb1)
+        dir.add("cb", fty::Command(&cb1)
             .doc(
                 "Ops fortunate, ops me ut orgia vociferatio contumax per, rudo re loco emitto\n"
                 "intolerabiliter ita iugo. Subcribo gravo. Devenio luna fonticulus Castanea\n"
@@ -171,21 +182,23 @@ BOOST_AUTO_UNIT_TEST(parsedCommand)
 
             .arg( description   = "Bar didelfrump di desgorb. Nu widsoflar brimeldrgf." )
 
-            .arg( name          = "checkup", 
+            .arg( name          = "checkup",
                   type_name     = "number",
                   description   = "Florgel, dargel and durgel",
                   default_value = 2.1,
-                  default_doc   = "(double) 2.1" );
+                  default_doc   = "(double) 2.1" )
+            );
 
         senf::console::OverloadedCommandNode & cbNode (
-            dir.add("cb", &cb5)
+            dir.add("cb", fty::Command(&cb5)
                 .overloadDoc(
                     "Uus Primordia fundo falsidicus corium, diurnitas humo pro leto. Sui Ueraciter\n"
                     "hio eruca lenis qua Agalmate ut fors penitentia. Iugum obdormio anxio nuncupo\n"
-                    "iam, in vos nam Custodi." ) 
-                .arg( "text", default_value = "" ) );
+                    "iam, in vos nam Custodi." )
+                .arg( "text", default_value = "" ) )
+            );
 
-        (void) cbNode;
+        senf::IGNORE( cbNode );
 
         SENF_CHECK_NO_THROW(
             parser.parse("test/cb 111 222.4",
@@ -208,8 +221,8 @@ BOOST_AUTO_UNIT_TEST(parsedCommand)
     {
         std::stringstream ss;
         senf::console::root()["test"]("cb").help(ss);
-        BOOST_CHECK_EQUAL( 
-            ss.str(), 
+        BOOST_CHECK_EQUAL(
+            ss.str(),
             "Usage:\n"
             "    1- cb arg11:int [checkup:number]\n"
             "    2- cb [text:string]\n"
@@ -240,14 +253,14 @@ BOOST_AUTO_UNIT_TEST(parsedCommand)
 }
 
 namespace {
-
-    struct Test 
+    struct Test
     {
         senf::console::ScopedDirectory<Test> dir;
         std::string name_;
 
         Test(std::string const & name) : dir(this), name_ (name) {
-            dir.add("name", &Test::name);
+            dir.add("name", senf::console::factory::Command(
+                        SENF_MEMBINDFNP(std::string, Test, name, (std::string const &))));
         }
 
         std::string name(std::string const & suffix) {
@@ -257,17 +270,17 @@ namespace {
 
 }
 
-BOOST_AUTO_UNIT_TEST(memberParsedCommand)
+SENF_AUTO_UNIT_TEST(memberParsedCommand)
 {
     senf::console::Executor executor;
     senf::console::CommandParser parser;
     senf::console::ScopedDirectory<> dir;
     senf::console::root().add("test", dir);
-    
+
     {
         Test obj ("bar");
         dir.add("obj", obj.dir);
-        
+
         std::stringstream ss;
         parser.parse("test/obj/name \": foo\"",
                      boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 ));
@@ -277,34 +290,38 @@ BOOST_AUTO_UNIT_TEST(memberParsedCommand)
 
 namespace {
 
-    senf::console::DirectoryNode::ptr dircb() 
+    senf::console::DirectoryNode::ptr dircb()
     {
+        namespace fty = senf::console::factory;
+
         senf::console::DirectoryNode & dir (
-            senf::console::root()["test"].mkdir("dircb"));
-        dir.add("cb1", &cb1);
+            senf::console::root()["test"].add("dircb", fty::Directory()));
+        dir.add("cb1", fty::Command(&cb1));
         return dir.thisptr();
     }
 
 }
 
-BOOST_AUTO_UNIT_TEST(directoryReturn)
+SENF_AUTO_UNIT_TEST(directoryReturn)
 {
+    namespace fty = senf::console::factory;
+
     senf::console::Executor executor;
     senf::console::CommandParser parser;
     senf::console::ScopedDirectory<> dir;
     senf::console::root().add("test", dir);
-    dir.add("test", &dircb);
+    dir.add("test", fty::Command(&dircb));
 
     {
         std::stringstream ss;
         SENF_CHECK_NO_THROW(
             parser.parse("test/test { ll; }",
                          boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 )) );
-        BOOST_CHECK_EQUAL( ss.str(), 
+        BOOST_CHECK_EQUAL( ss.str(),
                            "<Directory at '/test/dircb'>\n"
                            "cb1                         \n" );
     }
-    
+
 }
 
 #ifdef COMPILE_CHECK
@@ -331,8 +348,8 @@ COMPILE_FAIL(defaultDoc)
 }
 
 #endif
-    
-///////////////////////////////cc.e////////////////////////////////////////
+
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
 #undef prefix_
 
 \f