Skip to content

Commit

Permalink
CF::PropertyListType::FromPropertyListData
Browse files Browse the repository at this point in the history
  • Loading branch information
macmade committed Dec 21, 2015
1 parent 884494c commit b485abc
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
17 changes: 13 additions & 4 deletions CF++/include/CF++/CFPP-PropertyListType-Definition.hpp
Expand Up @@ -66,17 +66,26 @@ namespace CF

template < class T >
T PropertyListType< T >::FromPropertyListString( const std::string & plist )
{
if( plist.length() == 0 )
{
return static_cast< CFTypeRef >( NULL );
}

return FromPropertyListData( Data( plist ) );
}

template < class T >
T PropertyListType< T >::FromPropertyListData( const Data & plist )
{
AutoPointer ap;
Data data;

if( plist.length() == 0 )
if( plist.GetLength() == 0 )
{
return static_cast< CFTypeRef >( NULL );
}

data = CF::Data( plist );
ap = CFPropertyListCreateWithData( static_cast< CFAllocatorRef >( NULL ), data, 0, NULL, NULL );
ap = CFPropertyListCreateWithData( static_cast< CFAllocatorRef >( NULL ), plist, 0, NULL, NULL );

return ap.As< T >();
}
Expand Down
1 change: 1 addition & 0 deletions CF++/include/CF++/CFPP-PropertyListType.hpp
Expand Up @@ -54,6 +54,7 @@ namespace CF

static T FromPropertyList( const std::string & path );
static T FromPropertyListString( const std::string & plist );
static T FromPropertyListData( const Data & plist );
bool ToPropertyList( const std::string & path, PropertyListFormat format = PropertyListFormatXML ) const;
Data ToPropertyList( PropertyListFormat format = PropertyListFormatXML ) const;
};
Expand Down
34 changes: 34 additions & 0 deletions Unit-Tests/Test-CFPP-PropertyListType.cpp
Expand Up @@ -100,6 +100,40 @@ TEST( CFPP_PropertyListType, FromPropertyListString )
}
}

TEST( CFPP_PropertyListType, FromPropertyListData )
{
CF::Dictionary d;

d = CF::Dictionary::FromPropertyListData( std::string( __plist ) );

ASSERT_TRUE( d.IsValid() );
ASSERT_EQ( d.GetCount(), 1 );
ASSERT_EQ( CF::String( d[ "hello" ] ), "world" );

d = CF::Dictionary::FromPropertyListData( std::string( "" ) );

ASSERT_FALSE( d.IsValid() );

{
CF::ReadStream stream;
CF::Data data;

stream.Open( "/System/Library/Frameworks/CoreFoundation.framework/Versions/A/Resources/Info.plist" );

data = stream.Read();

stream.Close();

ASSERT_TRUE( data.IsValid() );
ASSERT_TRUE( data.GetLength() > 0 );

d = CF::Dictionary::FromPropertyListData( data );

ASSERT_TRUE( d.IsValid() );
ASSERT_TRUE( d.GetCount() > 0 );
}
}

TEST( CFPP_PropertyListType, ToPropertyList_STDString_PropertyListFormat )
{
CF::Dictionary d1;
Expand Down

0 comments on commit b485abc

Please sign in to comment.