Boost logo

Boost-Commit :

From: jmcintyre_at_[hidden]
Date: 2008-01-28 19:17:17


Author: jared
Date: 2008-01-28 19:17:16 EST (Mon, 28 Jan 2008)
New Revision: 43004
URL: http://svn.boost.org/trac/boost/changeset/43004

Log:
fix and properly test find.hpp
Add find.hpp to pinhole.hpp
Added:
   sandbox/pinhole/libs/pinhole/test/test_find.cpp (contents, props changed)
Text files modified:
   sandbox/pinhole/boost/pinhole.hpp | 3 +
   sandbox/pinhole/boost/pinhole/find.hpp | 70 ++++++++++++++++++++++-----------------
   sandbox/pinhole/libs/pinhole/test/Jamfile.v2 | 4 +
   3 files changed, 44 insertions(+), 33 deletions(-)

Modified: sandbox/pinhole/boost/pinhole.hpp
==============================================================================
--- sandbox/pinhole/boost/pinhole.hpp (original)
+++ sandbox/pinhole/boost/pinhole.hpp 2008-01-28 19:17:16 EST (Mon, 28 Jan 2008)
@@ -1,6 +1,6 @@
 // Pinhole pinhole.hpp file
 //
-// Copyright Jared McIntyre 2007.
+// Copyright Jared McIntyre 2007-2008.
 // Distributed under the Boost Software License, Version 1.0.
 // (See accompanying file LICENSE_1_0.txt or copy at
 // http://www.boost.org/LICENSE_1_0.txt)
@@ -10,5 +10,6 @@
 
 #include "pinhole/config.hpp"
 #include "pinhole/property_group.hpp"
+#include "pinhole/find.hpp"
 
 #endif //BOOST_PROPERTY_PINHOLE
\ No newline at end of file

Modified: sandbox/pinhole/boost/pinhole/find.hpp
==============================================================================
--- sandbox/pinhole/boost/pinhole/find.hpp (original)
+++ sandbox/pinhole/boost/pinhole/find.hpp 2008-01-28 19:17:16 EST (Mon, 28 Jan 2008)
@@ -1,6 +1,6 @@
 // Pinhole Find.hpp file
 //
-// Copyright Jared McIntyre 2007.
+// Copyright Jared McIntyre 2007-2008.
 // Distributed under the Boost Software License, Version 1.0.
 // (See accompanying file LICENSE_1_0.txt or copy at
 // http://www.boost.org/LICENSE_1_0.txt)
@@ -8,24 +8,26 @@
 #ifndef BOOST_FIND
 #define BOOST_FIND
 
-#include "property_manager.hpp"
+#include <vector>
 
 namespace boost { namespace pinhole
 {
     namespace detail
     {
- property_group* search_single_property_group_based_on_name( children_collection* current_property_group_collection,
- const string& property_group_name)
+ inline
+ boost::pinhole::property_group*
+ search_single_property_group_based_on_name( boost::pinhole::children_collection* current_property_group_collection,
+ const std::string& property_group_name)
         {
- property_group* property_group_found = 0;
+ boost::pinhole::property_group* property_group_found = 0;
             for( children_collection::iterator iter = current_property_group_collection->begin(); iter != current_property_group_collection->end(); iter++)
             {
- property_group* current_property_group = *iter;
+ boost::pinhole::property_group* current_property_group = *iter;
                 if(current_property_group->get_name() == property_group_name)
                 {
                     if(property_group_found != 0)
                     {
- string strError = "Multiple " + property_group_name + " are found in property_manager::selectSingleNode";
+ std::string strError = "Multiple " + property_group_name + " are found in property_manager::selectSingleNode";
                         throw multiple_property_groups(strError.c_str());
                     }
                     property_group_found = current_property_group;
@@ -38,20 +40,22 @@
             return property_group_found;
         }
 
- property_group* search_single_property_group_based_on_property_value( children_collection* current_property_group_collection,
- const string& property_group_name,
- const string& property_name,
- const string& property_value )
+ inline
+ boost::pinhole::property_group*
+ search_single_property_group_based_on_property_value( boost::pinhole::children_collection* current_property_group_collection,
+ const std::string& property_group_name,
+ const std::string& property_name,
+ const std::string& property_value )
         {
- property_group* property_group_found = 0;
- for(children_collection::iterator iter = current_property_group_collection->begin(); iter != current_property_group_collection->end(); iter++)
+ boost::pinhole::property_group* property_group_found = 0;
+ for(boost::pinhole::children_collection::iterator iter = current_property_group_collection->begin(); iter != current_property_group_collection->end(); iter++)
             {
- property_group* current_property_group = *iter;
+ boost::pinhole::property_group* current_property_group = *iter;
                 if((current_property_group->get_name() == property_group_name) && (current_property_group->get_as_string(property_name) == property_value))
                 {
                     if(property_group_found != 0)
                     {
- string strError = "Multiple " + property_group_name + "." + property_name + "=" + property_value + " are found in property_manager::selectSingleNode";
+ std::string strError = "Multiple " + property_group_name + "." + property_name + "=" + property_value + " are found in property_manager::selectSingleNode";
                         throw multiple_property_groups(strError.c_str());
                     }
                     property_group_found = current_property_group;
@@ -93,23 +97,27 @@
      * @throw invalid_path The path does not meet the requirements for a valid path.
      * @throw multiple_property_groups There were multiple property groups matching this path.
      */
- property_group* select_single_node(property_group* current_property_group, const string& path)
+ inline boost::pinhole::property_group* select_single_node(boost::pinhole::property_group* current_property_group, const std::string& path)
     {
- children_collection* current_property_group_collection = NULL;
+ boost::pinhole::children_collection* current_property_group_collection = NULL;
         if( NULL != current_property_group )
         {
             current_property_group_collection = &current_property_group->get_children_collection();
         }
- children_collection* root_property_group_collection = 0; //The root collection might not be needed if it is not referred.
+ else if( path.length() > 0 && path[0] != '/' )
+ {
+ throw boost::pinhole::invalid_path("A relative path was requested, but no property_group to search from was given.");
+ }
+ boost::pinhole::children_collection* root_property_group_collection = 0; //The root collection might not be needed if it is not referred.
         
- typedef vector< string > split_vector_type;
+ typedef std::vector< std::string > split_vector_type;
         split_vector_type vecproperty_groups;
         boost::split( vecproperty_groups, path, boost::is_any_of("/") ); //Note: "/" is the separator for a property group
         try
         {
             for(split_vector_type::const_iterator iter_property_group = vecproperty_groups.begin(); iter_property_group != vecproperty_groups.end(); iter_property_group++)
             {
- string strproperty_group = *iter_property_group;
+ std::string strproperty_group = *iter_property_group;
                 split_vector_type properties;
                 boost::split( properties, strproperty_group, boost::is_any_of(".=") );
                 //Note: "." is the separator between Property group name and Property name.
@@ -120,14 +128,14 @@
                 {
                     case 1:
                     {
- string strItem = properties[0]; //It either is "/" or the property group name.
+ std::string strItem = properties[0]; //It either is "/" or the property group name.
                         boost::trim(strItem);
                         if(strItem.empty()) //It is "/"
                         {
- property_manager *manager = property_manager::instance();
- root_property_group_collection = new children_collection();
- property_manager::iterator iter = manager->begin();
- property_manager::iterator iterEnd = manager->end();
+ boost::pinhole::property_manager::instance_type manager = boost::pinhole::property_manager::instance();
+ root_property_group_collection = new boost::pinhole::children_collection();
+ boost::pinhole::property_manager::iterator iter = manager->begin();
+ boost::pinhole::property_manager::iterator iterEnd = manager->end();
                             for( ; iter != iterEnd; iter++)
                             {
                                 root_property_group_collection->push_back(*iter);
@@ -145,13 +153,13 @@
                         break;
                     case 3:
                     {
- string property_group_name = properties[0];
+ std::string property_group_name = properties[0];
                         boost::trim(property_group_name);
                         
- string property_name = properties[1];
+ std::string property_name = properties[1];
                         boost::trim(property_name);
                         
- string property_value = properties[2];
+ std::string property_value = properties[2];
                         boost::trim(property_value);
                         current_property_group = detail::search_single_property_group_based_on_property_value(current_property_group_collection, property_group_name, property_name, property_value);
                         current_property_group_collection = &current_property_group->get_children_collection();
@@ -159,7 +167,7 @@
                         break;
                     default:
                     {
- string strError = path + " is not a valid path. Details: " + strproperty_group + " should be either A.B=C or A format";
+ std::string strError = path + " is not a valid path. Details: " + strproperty_group + " should be either A.B=C or A format";
                         throw invalid_path(strError.c_str());
                     }
                 }
@@ -174,7 +182,7 @@
         return current_property_group;
     }
 
- property_group* select_single_node(property_group& current_property_group, const string& path)
+ inline property_group* select_single_node(boost::pinhole::property_group& current_property_group, const std::string& path)
     {
         return select_single_node(&current_property_group, path);
     }
@@ -198,7 +206,7 @@
     * @throw invalid_path The path does not meet the requirements for a valid path.
     * @throw multiple_property_groups There were multiple property groups matching this path.
     */
- property_group* select_single_node(const string& path)
+ inline property_group* select_single_node(const std::string& path)
     {
         return select_single_node(NULL, path);
     }

Modified: sandbox/pinhole/libs/pinhole/test/Jamfile.v2
==============================================================================
--- sandbox/pinhole/libs/pinhole/test/Jamfile.v2 (original)
+++ sandbox/pinhole/libs/pinhole/test/Jamfile.v2 2008-01-28 19:17:16 EST (Mon, 28 Jan 2008)
@@ -1,6 +1,6 @@
 # Boost.Pinhole Library
 
-# Copyright Jared McIntyre 2007. Use, modification and
+# Copyright Jared McIntyre 2007-2008. Use, modification and
 # distribution is subject to the Boost Software License, Version
 # 1.0. (See accompanying file LICENSE_1_0.txt or copy at
 # http://www.boost.org/LICENSE_1_0.txt)
@@ -30,5 +30,7 @@
   [ run test_string_properties.cpp ]
   
   [ run test_actions.cpp ]
+
+ [ run test_find.cpp ]
  ;
 }

Added: sandbox/pinhole/libs/pinhole/test/test_find.cpp
==============================================================================
--- (empty file)
+++ sandbox/pinhole/libs/pinhole/test/test_find.cpp 2008-01-28 19:17:16 EST (Mon, 28 Jan 2008)
@@ -0,0 +1,148 @@
+// Boost.Pinhole library
+
+// Copyright Jared McIntyre 2008. Use, modification and
+// distribution is subject to the Boost Software License, Version
+// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+// For more information, see http://www.boost.org
+
+#define BOOST_TEST_MODULE PinholeLib
+#include <boost/test/unit_test.hpp>
+#include <boost/pinhole.hpp>
+
+using namespace std;
+using namespace boost;
+using namespace boost::pinhole;
+
+class TestPropertyGroup : public property_group
+{
+public:
+ TestPropertyGroup( int level, int id, property_group *pParentGroup) :
+ property_group( lexical_cast<string>(level), pParentGroup ),
+ m_int(id)
+ {
+ add_property("ID", "ID", BOOST_SETTER_NONE, BOOST_GETTER_VAR(m_int));
+ }
+
+ int m_int;
+};
+
+class TestPropertyManagerGuard
+{
+public:
+ TestPropertyManagerGuard()
+ {
+ property_manager::delete_instance();
+ }
+
+ ~TestPropertyManagerGuard()
+ {
+ property_manager::delete_instance();
+ }
+};
+
+BOOST_AUTO_TEST_CASE( TestSimplePath_RootSearch )
+{
+ TestPropertyGroup group1(1, 1, NULL);
+ TestPropertyGroup group2(2, 2, &group1);
+ TestPropertyGroup group3(3, 3, &group2);
+ TestPropertyGroup group4(4, 4, &group3);
+
+ BOOST_CHECK( &group1 == select_single_node("/1") );
+ BOOST_CHECK( &group2 == select_single_node("/1/2") );
+ BOOST_CHECK( &group3 == select_single_node("/1/2/3") );
+ BOOST_CHECK( &group4 == select_single_node("/1/2/3/4") );
+}
+
+BOOST_AUTO_TEST_CASE( TestSimplePath_RelativeSearch )
+{
+ TestPropertyGroup group1(1, 1, NULL);
+ TestPropertyGroup group2(2, 2, &group1);
+ TestPropertyGroup group3(3, 3, &group2);
+ TestPropertyGroup group4(4, 4, &group3);
+
+ BOOST_CHECK( &group2 == select_single_node(group1, "2") );
+ BOOST_CHECK( &group3 == select_single_node(group1, "2/3") );
+ BOOST_CHECK( &group4 == select_single_node(group1, "2/3/4") );
+}
+
+BOOST_AUTO_TEST_CASE( TestRelativePathWithNoPropertyGroup )
+{
+ TestPropertyGroup group1(1, 1, NULL);
+ TestPropertyGroup group2(2, 2, &group1);
+ TestPropertyGroup group3(3, 3, &group2);
+ TestPropertyGroup group4(4, 4, &group3);
+
+ BOOST_CHECK_THROW( select_single_node("1"), boost::pinhole::invalid_path );
+}
+
+BOOST_AUTO_TEST_CASE( TestNonExistantRootPath )
+{
+ TestPropertyGroup group1(1, 1, NULL);
+ TestPropertyGroup group2(2, 2, &group1);
+ TestPropertyGroup group3(3, 3, &group2);
+ TestPropertyGroup group4(4, 4, &group3);
+
+ BOOST_CHECK( NULL == select_single_node("/error") );
+ BOOST_CHECK( NULL == select_single_node("/1/error") );
+}
+
+BOOST_AUTO_TEST_CASE( TestNonExistantVariablePath )
+{
+ TestPropertyGroup group1(1, 1, NULL);
+ TestPropertyGroup group2(2, 2, &group1);
+ TestPropertyGroup group3(3, 3, &group2);
+ TestPropertyGroup group4(4, 4, &group3);
+
+ BOOST_CHECK( NULL == select_single_node(group1, "error") );
+ BOOST_CHECK( NULL == select_single_node(group1, "2/error") );
+}
+
+BOOST_AUTO_TEST_CASE( TestFindByValue_RootSearch )
+{
+ TestPropertyGroup group1a(1, 1, NULL);
+ TestPropertyGroup group1b(1, 2, NULL);
+ TestPropertyGroup group2a(2, 1, &group1a);
+ TestPropertyGroup group2b(2, 2, &group1a);
+ TestPropertyGroup group3a(3, 1, &group2a);
+ TestPropertyGroup group3b(3, 2, &group2a);
+
+ BOOST_CHECK( &group1a == select_single_node("/1.ID=1") );
+ BOOST_CHECK( &group1b == select_single_node("/1.ID=2") );
+
+ BOOST_CHECK( &group2a == select_single_node("/1.ID=1/2.ID=1") );
+ BOOST_CHECK( &group2b == select_single_node("/1.ID=1/2.ID=2") );
+
+ BOOST_CHECK( &group3a == select_single_node("/1.ID=1/2.ID=1/3.ID=1") );
+ BOOST_CHECK( &group3b == select_single_node("/1.ID=1/2.ID=1/3.ID=2") );
+}
+
+BOOST_AUTO_TEST_CASE( TestFindByValue_VariableSearch )
+{
+ TestPropertyGroup group1a(1, 1, NULL);
+ TestPropertyGroup group1b(1, 2, NULL);
+ TestPropertyGroup group2a(2, 1, &group1a);
+ TestPropertyGroup group2b(2, 2, &group1a);
+ TestPropertyGroup group3a(3, 1, &group2a);
+ TestPropertyGroup group3b(3, 2, &group2a);
+
+ BOOST_CHECK( &group2a == select_single_node(group1a, "2.ID=1") );
+ BOOST_CHECK( &group2b == select_single_node(group1a, "2.ID=2") );
+
+ BOOST_CHECK( &group3a == select_single_node(group1a, "2.ID=1/3.ID=1") );
+ BOOST_CHECK( &group3b == select_single_node(group1a, "2.ID=1/3.ID=2") );
+}
+
+BOOST_AUTO_TEST_CASE( TestFindMultiples )
+{
+ TestPropertyGroup group1a(1, 1, NULL);
+ TestPropertyGroup group1b(1, 2, NULL);
+ TestPropertyGroup group2a(2, 1, &group1a);
+ TestPropertyGroup group2b(2, 2, &group1a);
+ TestPropertyGroup group3a(3, 1, &group2a);
+ TestPropertyGroup group3b(3, 2, &group2a);
+
+ BOOST_CHECK_THROW( select_single_node("/1"), boost::pinhole::multiple_property_groups );
+ BOOST_CHECK_THROW( select_single_node("/1.ID=1/2"), boost::pinhole::multiple_property_groups );
+}
\ No newline at end of file


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk