Permalink
Browse files

Fix some issues with the Properties class and add a Unit test for it …

…to help increase the code coverage of the tests and prevent errors from getting in again.

git-svn-id: https://svn.apache.org/repos/asf/activemq/activemq-cpp/trunk@777310 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent ed54658 commit 0ca1f1319f631cb1e228394211f8bcf3ca9d950d Timothy A. Bish committed May 21, 2009
@@ -603,7 +603,7 @@ EXCLUDE_PATTERNS =
# wildcard * is used, a substring. Examples: ANamespace, AClass,
# AClass::ANamespace, ANamespace::*Test
-EXCLUDE_SYMBOLS =
+EXCLUDE_SYMBOLS = DECAF_UNUSED, AMQCPP_UNUSED
# The EXAMPLE_PATH tag can be used to specify one or more files or
# directories that contain example code fragments that are included (see
@@ -1339,12 +1339,12 @@ CLASS_GRAPH = YES
# indirect implementation dependencies (inheritance, containment, and
# class references variables) of the class with other documented classes.
-COLLABORATION_GRAPH = YES
+COLLABORATION_GRAPH = NO
# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen
# will generate a graph for groups, showing the direct groups dependencies
-GROUP_GRAPHS = YES
+GROUP_GRAPHS = NO
# If the UML_LOOK tag is set to YES doxygen will generate inheritance and
# collaboration diagrams in a style similar to the OMG's Unified Modeling
@@ -1362,14 +1362,14 @@ TEMPLATE_RELATIONS = NO
# file showing the direct and indirect include dependencies of the file with
# other documented files.
-INCLUDE_GRAPH = YES
+INCLUDE_GRAPH = NO
# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and
# HAVE_DOT tags are set to YES then doxygen will generate a graph for each
# documented header file showing the documented files that directly or
# indirectly include this file.
-INCLUDED_BY_GRAPH = YES
+INCLUDED_BY_GRAPH = NO
# If the CALL_GRAPH and HAVE_DOT options are set to YES then
# doxygen will generate a call dependency graph for every global function
@@ -1390,14 +1390,14 @@ CALLER_GRAPH = NO
# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen
# will graphical hierarchy of all classes instead of a textual one.
-GRAPHICAL_HIERARCHY = YES
+GRAPHICAL_HIERARCHY = NO
# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES
# then doxygen will show the dependencies a directory has on other directories
# in a graphical way. The dependency relations are determined by the #include
# relations between the files in the directories.
-DIRECTORY_GRAPH = YES
+DIRECTORY_GRAPH = NO
# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images
# generated by dot. Possible values are png, jpg, or gif
@@ -21,7 +21,7 @@
#include <sstream>
#include <decaf/util/Date.h>
#include <decaf/lang/exceptions/UnsupportedOperationException.h>
-#include <decaf/util/concurrent/Mutex.h>
+#include <decaf/util/StlMap.h>
using namespace decaf;
using namespace decaf::util;
@@ -36,8 +36,7 @@ namespace util{
class PropertiesInternal{
public:
- std::map< std::string, std::string > properties;
- decaf::util::concurrent::Mutex mutex;
+ decaf::util::StlMap< std::string, std::string > properties;
};
@@ -51,7 +50,7 @@ Properties::Properties() {
////////////////////////////////////////////////////////////////////////////////
Properties::Properties( const Properties& src ) {
this->internal.reset( new PropertiesInternal() );
- this->internal->properties = src.internal->properties;
+ this->internal->properties.copy( src.internal->properties );
if( src.defaults.get() != NULL ) {
this->defaults.reset( src.defaults->clone() );
@@ -63,47 +62,43 @@ Properties::~Properties() {
}
////////////////////////////////////////////////////////////////////////////////
-Properties& Properties::operator= ( const Properties& src ) {
+Properties& Properties::operator= ( const Properties& source ) {
- if( this == &src ) {
+ if( this == &source ) {
return *this;
}
- synchronized( &( internal->mutex ) ) {
- this->internal.reset( new PropertiesInternal() );
-
- synchronized( &( src.internal->mutex ) ) {
- this->internal->properties = src.internal->properties;
- }
-
- if( src.defaults.get() != NULL ) {
- this->defaults.reset( src.defaults->clone() );
- }
- }
+ this->copy( source );
return *this;
}
////////////////////////////////////////////////////////////////////////////////
bool Properties::isEmpty() const {
- synchronized( &( internal->mutex ) ) {
- return internal->properties.empty();
+ synchronized( &( internal->properties ) ) {
+ return internal->properties.isEmpty();
}
return false;
}
////////////////////////////////////////////////////////////////////////////////
+std::size_t Properties::size() const {
+
+ synchronized( &( internal->properties ) ) {
+ return internal->properties.size();
+ }
+
+ return 0;
+}
+
+////////////////////////////////////////////////////////////////////////////////
const char* Properties::getProperty( const std::string& name ) const{
- synchronized( &( internal->mutex ) ) {
- std::map< std::string, std::string >::const_iterator iter =
- internal->properties.find( name );
- if( iter == internal->properties.end() ){
- return NULL;
+ synchronized( &( internal->properties ) ) {
+ if( this->internal->properties.containsKey( name ) ) {
+ return this->internal->properties.get( name ).c_str();
}
-
- return iter->second.c_str();
}
return NULL;
@@ -113,11 +108,9 @@ const char* Properties::getProperty( const std::string& name ) const{
std::string Properties::getProperty( const std::string& name,
const std::string& defaultValue ) const {
- synchronized( &( internal->mutex ) ) {
- std::map< std::string, std::string >::const_iterator iter =
- internal->properties.find( name );
- if( iter != internal->properties.end() ){
- return iter->second;
+ synchronized( &( internal->properties ) ) {
+ if( this->internal->properties.containsKey( name ) ) {
+ return this->internal->properties.get( name );
}
}
@@ -128,27 +121,27 @@ std::string Properties::getProperty( const std::string& name,
void Properties::setProperty( const std::string& name,
const std::string& value ){
- synchronized( &( internal->mutex ) ) {
- internal->properties[name] = value;
+ synchronized( &( internal->properties ) ) {
+ internal->properties.put( name, value );
}
}
////////////////////////////////////////////////////////////////////////////////
bool Properties::hasProperty( const std::string& name ) const {
- synchronized( &( internal->mutex ) ) {
- if( internal->properties.find(name) != internal->properties.end() ) {
- return true;
- }
+ synchronized( &( internal->properties ) ) {
+ return this->internal->properties.containsKey( name );
}
return false;
}
////////////////////////////////////////////////////////////////////////////////
void Properties::remove( const std::string& name ){
- synchronized( &( internal->mutex ) ) {
- internal->properties.erase( name );
+ synchronized( &( internal->properties ) ) {
+ if( this->internal->properties.containsKey( name ) ) {
+ this->internal->properties.remove( name );
+ }
}
}
@@ -157,8 +150,14 @@ std::vector< std::pair< std::string, std::string > > Properties::toArray() const
std::vector< std::pair<std::string, std::string> > result;
- synchronized( &( internal->mutex ) ) {
- result.assign( internal->properties.begin(), internal->properties.end() );
+ synchronized( &( internal->properties ) ) {
+ std::vector<std::string> keys = this->internal->properties.keySet();
+ std::vector<std::string>::const_iterator iter = keys.begin();
+
+ for( ; iter != keys.end(); ++iter ) {
+ result.push_back(
+ std::make_pair( *iter, this->internal->properties.get( *iter ) ) );
+ }
}
return result;
@@ -171,26 +170,31 @@ void Properties::copy( const Properties& source ){
return;
}
- synchronized( &( internal->mutex ) ) {
- *this = source;
+ synchronized( &( this->internal->properties ) ) {
+
+ synchronized( &( source.internal->properties ) ) {
+ this->internal->properties.copy( source.internal->properties );
+
+ if( source.defaults.get() != NULL ) {
+ this->defaults.reset( source.defaults->clone() );
+ }
+ }
}
}
////////////////////////////////////////////////////////////////////////////////
Properties* Properties::clone() const{
Properties* props = new Properties();
-
- *props = *this;
-
+ props->internal->properties.copy( this->internal->properties );
return props;
}
////////////////////////////////////////////////////////////////////////////////
void Properties::clear(){
- synchronized( &( internal->mutex ) ) {
- internal->properties.clear();
+ synchronized( &( internal->properties ) ) {
+ this->internal->properties.clear();
}
}
@@ -202,10 +206,13 @@ std::string Properties::toString() const {
stream << "Begin Class decaf::util::Properties:" << std::endl;
- synchronized( &( internal->mutex ) ) {
- for( iter = internal->properties.begin(); iter != internal->properties.end(); ++iter ){
- stream << " property[" << iter->first << "] = "
- << iter->second << std::endl;
+ synchronized( &( internal->properties ) ) {
+ std::vector<std::string> keys = this->internal->properties.keySet();
+ std::vector<std::string>::const_iterator iter = keys.begin();
+
+ for( iter = keys.begin(); iter != keys.end(); ++iter ){
+ stream << " property[" << *iter << "] = "
+ << this->internal->properties.get( *iter ) << std::endl;
}
}
@@ -85,6 +85,11 @@ namespace util{
bool isEmpty() const;
/**
+ * @return The number of Properties in this Properties Object.
+ */
+ std::size_t size() const;
+
+ /**
* Looks up the value for the given property.
* @param name The name of the property to be looked up.
* @return the value of the property with the given name, if it
@@ -45,6 +45,7 @@ cc_sources = \
decaf/util/ListTest.cpp \
decaf/util/StlMapTest.cpp \
decaf/util/SetTest.cpp \
+ decaf/util/PropertiesTest.cpp \
decaf/util/UUIDTest.cpp \
decaf/internal/util/ByteArrayAdapterTest.cpp \
decaf/internal/nio/ShortArrayBufferTest.cpp \
@@ -156,6 +157,7 @@ h_sources = \
decaf/util/concurrent/atomic/AtomicIntegerTest.h \
decaf/util/concurrent/TimeUnitTest.h \
decaf/util/DateTest.h \
+ decaf/util/PropertiesTest.h \
decaf/util/Endian.h \
decaf/util/SetTest.h \
decaf/util/RandomTest.h \
Oops, something went wrong.

0 comments on commit 0ca1f13

Please sign in to comment.