[Cppunit-cvs] cppunit2/include/opentest forwards.h,1.7,1.8 interfaces.h,1.3,1.4 properties.h,1.13,1.
Brought to you by:
blep
From: Baptiste L. <bl...@us...> - 2005-11-07 22:43:25
|
Update of /cvsroot/cppunit/cppunit2/include/opentest In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30871/include/opentest Modified Files: forwards.h interfaces.h properties.h serializer.h Log Message: - replaced usage of OpenTest::Properties with Json::Value. Json::Value provides a simpler interface and a standard *simple* serialization format. - jsoncpp has been inlined in CppTL to make deploy easier and remove an external dependency. Index: forwards.h =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/opentest/forwards.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** forwards.h 6 Sep 2005 07:31:42 -0000 1.7 --- forwards.h 7 Nov 2005 22:43:07 -0000 1.8 *************** *** 3,15 **** # include <opentest/config.h> # include <cpptl/enumerator.h> # include <cpptl/sharedptr.h> namespace OpenTest { ! class Property; ! class PropertyPath; ! class Properties; ! class PropertiesAccessor; class ResourceList; class TestDeclarator; --- 3,17 ---- # include <opentest/config.h> + # include <cpptl/forwards.h> # include <cpptl/enumerator.h> # include <cpptl/sharedptr.h> + # include <json/forwards.h> namespace OpenTest { ! typedef Json::Value Value; ! typedef Value Properties; ! typedef CppTL::ConstString String; ! class ResourceList; class TestDeclarator; *************** *** 18,23 **** class TestPlans; class TestRunTracker; - class Value; - class ValueBadCast; class RemoteMessage; --- 20,23 ---- Index: serializer.h =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/opentest/serializer.h,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** serializer.h 6 Sep 2005 07:31:42 -0000 1.7 --- serializer.h 7 Nov 2005 22:43:07 -0000 1.8 *************** *** 5,8 **** --- 5,9 ---- # include <opentest/properties.h> # include <map> + # include <deque> # include <vector> *************** *** 193,197 **** Stream &operator <<( const String &str ); Stream &operator <<( const Properties &properties ); - Stream &operator <<( const Value &value ); Stream &operator >>( bool &value ); --- 194,197 ---- *************** *** 205,209 **** Stream &operator >>( String &str ); Stream &operator >>( Properties &properties ); - Stream &operator >>( Value &value ); bool inError() const; --- 205,208 ---- *************** *** 227,230 **** --- 226,234 ---- void write( Byte byte ); static bool isNamedPropertyControl( Byte control ); + void unserializeArrayValue( Value &value ); + void unserializeObjectValue( Byte control, + Value &value ); + void serializeArrayValue( const Value &value ); + void serializeObjectValue( const Value &value ); private: Index: properties.h =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/opentest/properties.h,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** properties.h 1 Jul 2005 20:32:05 -0000 1.13 --- properties.h 7 Nov 2005 22:43:07 -0000 1.14 *************** *** 3,397 **** # include <opentest/forwards.h> # include <cpptl/conststring.h> - # include <cpptl/enumerator.h> - # include <stdexcept> - # include <deque> - # include <vector> - # include <typeinfo> // for std::bad_cast - - namespace OpenTest { - - class OPENTEST_API ValueBadCast : public std::bad_cast - { - public: // overriden from std::bad_cast - const char * what() const throw() - { - return "ValueBadCast: " - "Value can not be converted to the specified type."; - } - }; - - - /// Value wrapper for basic type. - /// - strong exception guaranty. - /// - copy constructor is thread-safe - /// ? should we provide conversion of numeric type to string ? - class OPENTEST_API Value - { - public: - enum Type - { - vtNone = 0, - vtBoolean, - vtSignedInteger, - vtUnsignedInteger, - vtReal, - vtString, - vtProperties - }; - - # ifdef CPPTL_NO_INT64 - typedef int StorageInt; - typedef unsigned int StorageUInt; - # else - typedef CppTL::int64_t StorageInt; - typedef CppTL::uint64_t StorageUInt; - # endif - - Value(); - - Value( bool value ); - - Value( int value ); - - Value( unsigned int value ); - - # ifndef CPPTL_NO_INT64 - Value( CppTL::int64_t value ); - - Value( CppTL::uint64_t value ); - # endif - - Value( float value ); - - Value( double value ); - - Value( const char *value ); - - Value( const CppTL::ConstString &value ); - - Value( const Properties &value ); - - Value( const Value &other ); - - Value &operator =( const Value &other ); - - ~Value(); - - void swap( Value &other ); - - bool asBool() const; - - int asInt() const; - - unsigned int asUInt() const; - - # ifndef CPPTL_NO_INT64 - StorageInt asInt64() const; - - StorageUInt asUInt64() const; - # endif - - double asReal() const; - - CppTL::ConstString asString() const; - - const Properties &asProperties() const; - - Properties &asProperties(); - - bool isNone() const; - - bool isBoolean() const; - - bool isInteger() const; - - bool isSignedInteger() const; - - bool isUnsignedInteger() const; - - bool isReal() const; - - bool isString() const; - - bool isProperties() const; - - bool isConvertibleTo( Type type ) const; - - Type type() const; - - /// Delegates to Properties[] if the value is a Properties. - Value &operator[]( unsigned int index ); - - /// Delegates to Properties[] if the value is a Properties. - Value &operator[]( const PropertyPath &path ); - - /// Delegates to Properties[] if the value is a Properties. - const Value &operator[]( unsigned int index ) const; - - /// Delegates to Properties[] if the value is a Properties. - const Value &operator[]( const PropertyPath &path ) const; - - /// Delegates to Properties::append if the value is a Properties. - Properties &append( const Value &value ); - - CppTL::ConstString toString() const; - - bool operator ==( const Value &other ) const; - bool operator !=( const Value &other ) const; - - private: - - struct Storage - { - Type type_; - - union - { - bool boolValue_; - StorageInt intValue_; - StorageUInt uintValue_; - double realValue_; - char *stringValue_; - Properties *propertiesValue_; - }; - }; - - void throwBadCast() const; - - Storage guts_; - }; - - - class OPENTEST_API PropertyPath - { - public: - typedef CppTL::AnyEnumerator<CppTL::ConstString> NamesEnum; - - PropertyPath( const CppTL::ConstString &path, - char separator = '/' ); - - PropertyPath( const char *path, - char separator = '/' ); - - NamesEnum names() const; - - PropertyPath &add( const CppTL::ConstString &name ); - - PropertyPath &addPath( const PropertyPath &path ); - - PropertyPath parent() const; - - const CppTL::ConstString &name() const; - - bool isEmpty() const; - - private: - typedef std::deque<CppTL::ConstString> PropertyNames; - - PropertyPath( const PropertyNames &names ); - - void initialize( const char *path, - char separator ); - - private: - PropertyNames names_; - }; - - class OPENTEST_API Property - { - public: - Property( const CppTL::ConstString &name, - const Value &value ); - - const CppTL::ConstString &name() const; - - const Value &value() const; - - Value &value(); - - bool operator ==( const Property &other ) const; - bool operator !=( const Property &other ) const; - - private: - CppTL::ConstString name_; - Value value_; - }; - - - /* - Properties properties; - properties["result"]["status"]["general"] = "pass"; // pass, fail, skip - properties["result/status/general"] = "pass"; // pass, fail, skip - properties["result"]["status"]["detail"] = "success"; - properties["result"]["duration"] = 163.5; - properties["log"].append( "log line 1" ); - */ - class OPENTEST_API Properties - { - public: - typedef CppTL::AnyEnumerator<Value> ValueEnum; - typedef CppTL::AnyEnumerator<Property> PropertyEnum; - typedef CppTL::AnyEnumerator<CppTL::ConstString> NameEnum; - - Properties(); - - Properties( const Property &property ); - - Properties( const Properties &other ); - - Properties &operator =( const Properties &other ); - - ~Properties(); - - void swap( Properties &other ); - - void clear(); - - Properties &set( const Property &property ); - - Properties &set( const CppTL::ConstString &name, - const Value &value ); - - Properties &setIfNew( const Property &property ); - - Properties &setIfNew( const CppTL::ConstString &name, - const Value &value ); - - Properties &mergeReplacingExisting( const Properties &properties ); - - Properties &mergePreservingExisting( const Properties &properties ); - - bool has( const PropertyPath &path ) const; - - const Property &getProperty( const PropertyPath &path ) const; - - const Value &getValue( const PropertyPath &path ) const; - - const Value &at( unsigned int index ) const; - - Value getValue( const PropertyPath &path, - const Value &defaultValue ) const; - - Value at( unsigned int index, - const Value &defaultValue ) const; - - const Value &operator[]( unsigned int index ) const; - - const Value &operator[]( const PropertyPath &path ) const; - - Value &operator[]( unsigned int index ); - - /// If there no property named 'name' then create it and initialize it to - /// an empty Properties => allow chaining ["a"]["b"] to create a tree. - Value &operator[]( const PropertyPath &path ); - - Properties &remove( unsigned int index ); - - Properties &remove( const PropertyPath &path ); - - Properties &append( const Value &value ); - - unsigned int listSize() const; - - bool hasList() const; - - PropertiesAccessor accessor() const; - - ValueEnum listValues() const; - - NameEnum names() const; - - PropertyEnum properties() const; - - CppTL::ConstString toString() const; - - bool operator ==( const Properties &other ) const; - bool operator !=( const Properties &other ) const; - - private: - // Notes: can not use std::map because VC++6 implementation is buggy and cause - // crash when exposed in DLL. - typedef std::vector<Property> PropertyList; - typedef std::deque<Value> IndexedProperties; - - struct NameAdaptor - { - typedef CppTL::ConstString result_type; - - CppTL::ConstString operator()( const Property &property ) const - { - return property.name(); - } - }; - - PropertyList::iterator find( const CppTL::ConstString &name ); - - PropertyList::const_iterator find( const CppTL::ConstString &name ) const; - - PropertyList::const_iterator resolvePath( const PropertyPath &path ) const; - - Properties *tryGetProperties( const PropertyPath &path ); - - const Properties *tryGetProperties( const PropertyPath &path ) const; - - Properties &makeProperties( const PropertyPath &path ); - - void checkPathNotEmpty( const PropertyPath &path ) const; - - CppTL::ConstString toString( const CppTL::ConstString &prefix ) const; - - PropertyList properties_; - IndexedProperties indexedProperties_; - }; - - - - /// Helper to navigate the property tree in read-only mode and - /// avoid testing if every single node exist. - class OPENTEST_API PropertiesAccessor - { - public: - PropertiesAccessor( const Properties *properties = 0 ); - - PropertiesAccessor operator[]( unsigned int index ) const; - - PropertiesAccessor operator[]( const PropertyPath &path ) const; - - const Properties &properties() const; - - bool isValid() const; - - bool has( const PropertyPath &path ) const; - - const Property &getProperty( const PropertyPath &path ) const; - - /// If the current node is valid then returns the value of the property - /// named 'name', otherwise returns an empty value. - Value getValue( const PropertyPath &path ) const; - - Value at( unsigned int index ) const; - - /// If current node is valid and has a property named 'name' returns its - /// values, otherwise returns the 'defaultValue'. - Value getValue( const PropertyPath &path, - const Value &defaultValue ) const; - - /// If current node is valid and has a indexed value at the specified - //// index returns its values, otherwise returns the 'defaultValue'. - Value at( unsigned int index, - const Value &defaultValue ) const; - - Properties::ValueEnum listValues() const; - - unsigned int listSize() const; - - bool hasList() const; - - private: - const Properties *properties_; - }; - - } // namespace OpenTest #endif // OPENTEST_PROPERTIES_H_INCLUDED --- 3,8 ---- # include <opentest/forwards.h> + # include <json/value.h> # include <cpptl/conststring.h> #endif // OPENTEST_PROPERTIES_H_INCLUDED Index: interfaces.h =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/opentest/interfaces.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** interfaces.h 6 Sep 2005 07:31:42 -0000 1.3 --- interfaces.h 7 Nov 2005 22:43:07 -0000 1.4 *************** *** 5,8 **** --- 5,9 ---- # include <opentest/properties.h> # include <map> + # include <deque> # include <vector> |