diff options
Diffstat (limited to 'qa/libcmis-c')
-rw-r--r-- | qa/libcmis-c/Makefile.am | 48 | ||||
-rw-r--r-- | qa/libcmis-c/test-allowable-actions.cxx | 82 | ||||
-rw-r--r-- | qa/libcmis-c/test-api.cxx | 39 | ||||
-rw-r--r-- | qa/libcmis-c/test-build.c | 36 | ||||
-rw-r--r-- | qa/libcmis-c/test-document.cxx | 621 | ||||
-rw-r--r-- | qa/libcmis-c/test-dummies.cxx | 633 | ||||
-rw-r--r-- | qa/libcmis-c/test-dummies.hxx | 223 | ||||
-rw-r--r-- | qa/libcmis-c/test-folder.cxx | 433 | ||||
-rw-r--r-- | qa/libcmis-c/test-object-type.cxx | 377 | ||||
-rw-r--r-- | qa/libcmis-c/test-object.cxx | 425 | ||||
-rw-r--r-- | qa/libcmis-c/test-property-type.cxx | 251 | ||||
-rw-r--r-- | qa/libcmis-c/test-property.cxx | 242 | ||||
-rw-r--r-- | qa/libcmis-c/test-repository.cxx | 205 | ||||
-rw-r--r-- | qa/libcmis-c/test-session.cxx | 88 |
14 files changed, 3703 insertions, 0 deletions
diff --git a/qa/libcmis-c/Makefile.am b/qa/libcmis-c/Makefile.am new file mode 100644 index 0000000..c0de5ad --- /dev/null +++ b/qa/libcmis-c/Makefile.am @@ -0,0 +1,48 @@ +check_PROGRAMS = \ + test-api \ + test-c-build + +test_api_SOURCES = \ + test-allowable-actions.cxx \ + test-api.cxx \ + test-document.cxx \ + test-dummies.cxx \ + test-dummies.hxx \ + test-folder.cxx \ + test-object-type.cxx \ + test-object.cxx \ + test-property-type.cxx \ + test-property.cxx \ + test-repository.cxx \ + test-session.cxx + +test_api_CXXFLAGS = \ + -I$(top_srcdir)/inc \ + -I$(top_srcdir)/src/libcmis-c/ \ + $(XML2_CFLAGS) \ + $(BOOST_CPPFLAGS) + +test_api_LDADD = \ + $(top_builddir)/src/libcmis-c/libcmis-c-@LIBCMIS_API_VERSION@.la \ + $(top_builddir)/src/libcmis/libcmis-@LIBCMIS_API_VERSION@.la \ + $(XML2_LIBS) \ + $(CURL_LIBS) \ + $(CPPUNIT_LIBS) \ + $(BOOST_DATE_TIME_LIBS) + +test_c_build_SOURCES = \ + test-build.c + +test_c_build_CFLAGS = \ + -I$(top_srcdir)/inc \ + $(XML2_CFLAGS) + +test_c_build_LDADD = \ + $(top_builddir)/src/libcmis-c/libcmis-c-@LIBCMIS_API_VERSION@.la \ + $(top_builddir)/src/libcmis/libcmis-@LIBCMIS_API_VERSION@.la \ + $(XML2_LIBS) \ + $(CURL_LIBS) \ + $(CPPUNIT_LIBS) \ + $(BOOST_DATE_TIME_LIBS) + +TESTS = test-api diff --git a/qa/libcmis-c/test-allowable-actions.cxx b/qa/libcmis-c/test-allowable-actions.cxx new file mode 100644 index 0000000..19332d4 --- /dev/null +++ b/qa/libcmis-c/test-allowable-actions.cxx @@ -0,0 +1,82 @@ +/* libcmis + * Version: MPL 1.1 / GPLv2+ / LGPLv2+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License or as specified alternatively below. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * 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. + * + * Major Contributor(s): + * Copyright (C) 2011 SUSE <cbosdonnat@suse.com> + * + * + * All Rights Reserved. + * + * For minor contributions see the git repository. + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPLv2+"), or + * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"), + * in which case the provisions of the GPLv2+ or the LGPLv2+ are applicable + * instead of those above. + */ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/TestFixture.h> +#include <cppunit/TestAssert.h> + +#include <libcmis-c/allowable-actions.h> + +#include "internals.hxx" +#include "test-dummies.hxx" + +using namespace std; + +class AllowableActionsTest : public CppUnit::TestFixture +{ + private: + libcmis_AllowableActionsPtr getTested( ); + + public: + void isDefinedTest( ); + void isAllowedTest( ); + + CPPUNIT_TEST_SUITE( AllowableActionsTest ); + CPPUNIT_TEST( isDefinedTest ); + CPPUNIT_TEST( isAllowedTest ); + CPPUNIT_TEST_SUITE_END( ); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION( AllowableActionsTest ); + +libcmis_AllowableActionsPtr AllowableActionsTest::getTested( ) +{ + libcmis_AllowableActionsPtr result = new libcmis_allowable_actions( ); + libcmis::AllowableActionsPtr handle( new dummies::AllowableActions( ) ); + result->handle = handle; + + return result; +} + +void AllowableActionsTest::isDefinedTest( ) +{ + libcmis_AllowableActionsPtr allowableActions = getTested( ); + CPPUNIT_ASSERT( !libcmis_allowable_actions_isDefined( allowableActions, libcmis_DeleteObject ) ); + CPPUNIT_ASSERT( libcmis_allowable_actions_isDefined( allowableActions, libcmis_GetFolderParent ) ); + + libcmis_allowable_actions_free( allowableActions ); +} + +void AllowableActionsTest::isAllowedTest( ) +{ + libcmis_AllowableActionsPtr allowableActions = getTested( ); + CPPUNIT_ASSERT( libcmis_allowable_actions_isAllowed( allowableActions, libcmis_GetProperties ) ); + CPPUNIT_ASSERT( !libcmis_allowable_actions_isAllowed( allowableActions, libcmis_GetFolderParent ) ); + + libcmis_allowable_actions_free( allowableActions ); +} diff --git a/qa/libcmis-c/test-api.cxx b/qa/libcmis-c/test-api.cxx new file mode 100644 index 0000000..45b2daf --- /dev/null +++ b/qa/libcmis-c/test-api.cxx @@ -0,0 +1,39 @@ +/* libcmis + * Version: MPL 1.1 / GPLv2+ / LGPLv2+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License or as specified alternatively below. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * 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. + * + * Major Contributor(s): + * Copyright (C) 2011 SUSE <cbosdonnat@suse.com> + * + * + * All Rights Reserved. + * + * For minor contributions see the git repository. + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPLv2+"), or + * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"), + * in which case the provisions of the GPLv2+ or the LGPLv2+ are applicable + * instead of those above. + */ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/ui/text/TestRunner.h> + +int main( int, char** ) +{ + CppUnit::TextUi::TestRunner runner; + CppUnit::TestFactoryRegistry ®istry = CppUnit::TestFactoryRegistry::getRegistry(); + runner.addTest( registry.makeTest() ); + bool wasSuccess = runner.run( "", false ); + return !wasSuccess; +} diff --git a/qa/libcmis-c/test-build.c b/qa/libcmis-c/test-build.c new file mode 100644 index 0000000..52ac44d --- /dev/null +++ b/qa/libcmis-c/test-build.c @@ -0,0 +1,36 @@ +/* libcmis + * Version: MPL 1.1 / GPLv2+ / LGPLv2+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License or as specified alternatively below. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * 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. + * + * Major Contributor(s): + * Copyright (C) 2011 SUSE <cbosdonnat@suse.com> + * + * + * All Rights Reserved. + * + * For minor contributions see the git repository. + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPLv2+"), or + * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"), + * in which case the provisions of the GPLv2+ or the LGPLv2+ are applicable + * instead of those above. + */ + +#include <libcmis-c/libcmis-c.h> + +int main ( int argc, char ** argv ) +{ + ( void )argc; + ( void )argv; + return 0; +} diff --git a/qa/libcmis-c/test-document.cxx b/qa/libcmis-c/test-document.cxx new file mode 100644 index 0000000..525cbaa --- /dev/null +++ b/qa/libcmis-c/test-document.cxx @@ -0,0 +1,621 @@ +/* libcmis + * Version: MPL 1.1 / GPLv2+ / LGPLv2+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License or as specified alternatively below. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * 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. + * + * Major Contributor(s): + * Copyright (C) 2011 SUSE <cbosdonnat@suse.com> + * + * + * All Rights Reserved. + * + * For minor contributions see the git repository. + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPLv2+"), or + * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"), + * in which case the provisions of the GPLv2+ or the LGPLv2+ are applicable + * instead of those above. + */ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/TestFixture.h> +#include <cppunit/TestAssert.h> + +#include <libcmis-c/error.h> +#include <libcmis-c/folder.h> +#include <libcmis-c/document.h> +#include <libcmis-c/object.h> +#include <libcmis-c/object-type.h> +#include <libcmis-c/property.h> +#include <libcmis-c/property-type.h> +#include <libcmis-c/vectors.h> + +#include "internals.hxx" +#include "test-dummies.hxx" + +using namespace std; + +extern bool isOutOfMemory; + +namespace +{ + string lcl_readFile( FILE* file ) + { + // Get the size + fseek( file, 0, SEEK_END ); + long size = ftell( file ); + rewind( file ); + + char* buf = new char[size + 1]; + size_t readbytes = fread( buf, 1, size, file ); + buf[ readbytes ] = '\0'; + + string result( buf ); + delete[] buf; + + return result; + } +} + +class DocumentTest : public CppUnit::TestFixture +{ + private: + libcmis_DocumentPtr getTested( bool isFiled, bool triggersFaults ); + dummies::Document* getTestedImplementation( libcmis_DocumentPtr document ); + + public: + void objectCastTest( ); + void objectCastFailureTest( ); + void objectFunctionsTest( ); + void getParentsTest( ); + void getParentsUnfiledTest( ); + void getParentsErrorTest( ); + void getContentStreamTest( ); + void getContentStreamErrorTest( ); + void getContentStreamBadAllocTest( ); + void setContentStreamTest( ); + void setContentStreamErrorTest( ); + void getContentTypeTest( ); + void getContentFilenameTest( ); + void getContentLengthTest( ); + void checkOutTest( ); + void checkOutErrorTest( ); + void cancelCheckoutTest( ); + void cancelCheckoutErrorTest( ); + void checkInTest( ); + void checkInErrorTest( ); + void getAllVersionsTest( ); + void getAllVersionsErrorTest( ); + + CPPUNIT_TEST_SUITE( DocumentTest ); + CPPUNIT_TEST( objectCastTest ); + CPPUNIT_TEST( objectCastFailureTest ); + CPPUNIT_TEST( objectFunctionsTest ); + CPPUNIT_TEST( getParentsTest ); + CPPUNIT_TEST( getParentsUnfiledTest ); + CPPUNIT_TEST( getParentsErrorTest ); + CPPUNIT_TEST( getContentStreamTest ); + CPPUNIT_TEST( getContentStreamErrorTest ); + CPPUNIT_TEST( getContentStreamBadAllocTest ); + CPPUNIT_TEST( setContentStreamTest ); + CPPUNIT_TEST( setContentStreamErrorTest ); + CPPUNIT_TEST( getContentTypeTest ); + CPPUNIT_TEST( getContentFilenameTest ); + CPPUNIT_TEST( getContentLengthTest ); + CPPUNIT_TEST( checkOutTest ); + CPPUNIT_TEST( checkOutErrorTest ); + CPPUNIT_TEST( cancelCheckoutTest ); + CPPUNIT_TEST( cancelCheckoutErrorTest ); + CPPUNIT_TEST( checkInTest ); + CPPUNIT_TEST( checkInErrorTest ); + CPPUNIT_TEST( getAllVersionsTest ); + CPPUNIT_TEST( getAllVersionsErrorTest ); + CPPUNIT_TEST_SUITE_END( ); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION( DocumentTest ); + +libcmis_DocumentPtr DocumentTest::getTested( bool isFiled, bool triggersFaults ) +{ + // Create the document + libcmis_DocumentPtr result = new libcmis_document( ); + libcmis::DocumentPtr handle( new dummies::Document( isFiled, triggersFaults ) ); + result->handle = handle; + + return result; +} + +dummies::Document* DocumentTest::getTestedImplementation( libcmis_DocumentPtr document ) +{ + dummies::Document* impl = dynamic_cast< dummies::Document* >( document->handle.get( ) ); + return impl; +} + +void DocumentTest::objectCastTest( ) +{ + // Create the test object to cast + libcmis_ObjectPtr tested = new libcmis_object( ); + libcmis::DocumentPtr handle( new dummies::Document( true, false ) ); + tested->handle = handle; + + // Test libcmis_is_document + CPPUNIT_ASSERT( libcmis_is_document( tested ) ); + + // Actually cast to a document + libcmis_DocumentPtr actual = libcmis_document_cast( tested ); + + // Check the result + CPPUNIT_ASSERT( NULL != actual ); + + // Check that the libcmis_object-* functions are working with the cast result + char* actualId = libcmis_object_getId( tested ); + CPPUNIT_ASSERT_EQUAL( string( "Document::Id" ), string( actualId ) ); + free( actualId ); + + // Free it all + libcmis_document_free( actual ); + libcmis_object_free( tested ); +} + +void DocumentTest::objectCastFailureTest( ) +{ + // Create the test object to cast + libcmis_ObjectPtr tested = new libcmis_object( ); + libcmis::FolderPtr handle( new dummies::Folder( false, false ) ); + tested->handle = handle; + + // Test libcmis_is_document + CPPUNIT_ASSERT( !libcmis_is_document( tested ) ); + + // Actually cast to a document + libcmis_DocumentPtr actual = libcmis_document_cast( tested ); + + // Check the result + CPPUNIT_ASSERT( NULL == actual ); + + libcmis_object_free( tested ); +} + +void DocumentTest::objectFunctionsTest( ) +{ + libcmis_DocumentPtr tested = getTested( true, false ); + char* actual = libcmis_object_getId( tested ); + CPPUNIT_ASSERT_EQUAL( string( "Document::Id" ), string( actual ) ); + free( actual ); + libcmis_document_free( tested ); +} + +void DocumentTest::getParentsTest( ) +{ + libcmis_DocumentPtr tested = getTested( true, false ); + libcmis_ErrorPtr error = libcmis_error_create( ); + + // get the parent folders (tested method) + libcmis_vector_folder_Ptr actual = libcmis_document_getParents( tested, error ); + + // Check + CPPUNIT_ASSERT_EQUAL( size_t( 2 ), libcmis_vector_folder_size( actual ) ); + + // Free it all + libcmis_vector_folder_free( actual ); + libcmis_error_free( error ); + libcmis_document_free( tested ); +} + +void DocumentTest::getParentsUnfiledTest( ) +{ + libcmis_DocumentPtr tested = getTested( false, false ); + libcmis_ErrorPtr error = libcmis_error_create( ); + + // get the parent folders (tested method) + libcmis_vector_folder_Ptr actual = libcmis_document_getParents( tested, error ); + + // Check + CPPUNIT_ASSERT_EQUAL( size_t( 0 ), libcmis_vector_folder_size( actual ) ); + + // Free it all + libcmis_vector_folder_free( actual ); + libcmis_error_free( error ); + libcmis_document_free( tested ); +} + +void DocumentTest::getParentsErrorTest( ) +{ + libcmis_DocumentPtr tested = getTested( true, true ); + libcmis_ErrorPtr error = libcmis_error_create( ); + + // get the parent folders (tested method) + libcmis_vector_folder_Ptr actual = libcmis_document_getParents( tested, error ); + + // Check + CPPUNIT_ASSERT( NULL == actual ); + CPPUNIT_ASSERT( !string( libcmis_error_getMessage( error ) ).empty( ) ); + + // Free it all + libcmis_vector_folder_free( actual ); + libcmis_error_free( error ); + libcmis_document_free( tested ); +} + +void DocumentTest::getContentStreamTest( ) +{ + libcmis_DocumentPtr tested = getTested( true, false ); + libcmis_ErrorPtr error = libcmis_error_create( ); + + // get the content into a temporary file (tested method) + FILE* tmp = tmpfile( ); + libcmis_document_getContentStream( tested, + ( libcmis_writeFn )fwrite, tmp, error ); + + // Check + string expected = getTestedImplementation( tested )->getContentString( ); + + string actual = lcl_readFile( tmp ); + fclose( tmp ); + CPPUNIT_ASSERT( NULL == libcmis_error_getMessage( error ) ); + CPPUNIT_ASSERT_EQUAL( expected, actual ); + + // Free it all + libcmis_error_free( error ); + libcmis_document_free( tested ); +} + +void DocumentTest::getContentStreamErrorTest( ) +{ + libcmis_DocumentPtr tested = getTested( true, true ); + libcmis_ErrorPtr error = libcmis_error_create( ); + + // get the content into a temporary file (tested method) + FILE* tmp = tmpfile( ); + libcmis_document_getContentStream( tested, + ( libcmis_writeFn )fwrite, tmp, error ); + + // Check + string actual = lcl_readFile( tmp ); + fclose( tmp ); + CPPUNIT_ASSERT_EQUAL( string( ), actual ); + CPPUNIT_ASSERT( !string( libcmis_error_getMessage( error ) ).empty( ) ); + + // Free it all + libcmis_error_free( error ); + libcmis_document_free( tested ); +} + +void DocumentTest::getContentStreamBadAllocTest( ) +{ + libcmis_DocumentPtr tested = getTested( true, false ); + libcmis_ErrorPtr error = libcmis_error_create( ); + + // get the content into a temporary file (tested method) + FILE* tmp = tmpfile( ); + + isOutOfMemory= true; + libcmis_document_getContentStream( tested, + ( libcmis_writeFn )fwrite, tmp, error ); + isOutOfMemory = false; + + // Check + string actual = lcl_readFile( tmp ); + fclose( tmp ); + CPPUNIT_ASSERT( !string( libcmis_error_getMessage( error ) ).empty() ); + CPPUNIT_ASSERT_EQUAL( string( ), actual ); + + // Free it all + libcmis_error_free( error ); + libcmis_document_free( tested ); +} + +void DocumentTest::setContentStreamTest( ) +{ + libcmis_DocumentPtr tested = getTested( true, false ); + libcmis_ErrorPtr error = libcmis_error_create( ); + + // Prepare the content to set + FILE* tmp = tmpfile( ); + string expected( "New Content Stream" ); + fwrite( expected.c_str( ), 1, expected.size( ), tmp ); + rewind( tmp ); + + // get the content into a temporary file (tested method) + const char* contentType = "content/type"; + const char* filename = "name.txt"; + libcmis_document_setContentStream( tested, + ( libcmis_readFn )fread, tmp, contentType, filename, true, error ); + fclose( tmp ); + + // Check + string actual = getTestedImplementation( tested )->getContentString( ); + CPPUNIT_ASSERT( NULL == libcmis_error_getMessage( error ) ); + CPPUNIT_ASSERT_EQUAL( expected, actual ); + + // Free it all + libcmis_error_free( error ); + libcmis_document_free( tested ); +} + +void DocumentTest::setContentStreamErrorTest( ) +{ + libcmis_DocumentPtr tested = getTested( true, true ); + libcmis_ErrorPtr error = libcmis_error_create( ); + + string expected = getTestedImplementation( tested )->getContentString( ); + + // Prepare the content to set + FILE* tmp = tmpfile( ); + string newContent( "New Content Stream" ); + fwrite( newContent.c_str( ), 1, newContent.size( ), tmp ); + rewind( tmp ); + + // get the content into a temporary file (tested method) + const char* contentType = "content/type"; + const char* filename = "name.txt"; + libcmis_document_setContentStream( tested, + ( libcmis_readFn )fread, tmp, contentType, filename, true, error ); + fclose( tmp ); + + // Check + string actual = getTestedImplementation( tested )->getContentString( ); + CPPUNIT_ASSERT( !string( libcmis_error_getMessage( error ) ).empty( ) ); + CPPUNIT_ASSERT_EQUAL( expected, actual ); + + // Free it all + libcmis_error_free( error ); + libcmis_document_free( tested ); +} + +void DocumentTest::getContentTypeTest( ) +{ + libcmis_DocumentPtr tested = getTested( true, false ); + char* actual = libcmis_document_getContentType( tested ); + CPPUNIT_ASSERT_EQUAL( string( "Document::ContentType" ), string( actual ) ); + free( actual ); + libcmis_document_free( tested ); +} + +void DocumentTest::getContentFilenameTest( ) +{ + libcmis_DocumentPtr tested = getTested( true, false ); + char* actual = libcmis_document_getContentFilename( tested ); + CPPUNIT_ASSERT_EQUAL( string( "Document::ContentFilename" ), string( actual ) ); + free( actual ); + libcmis_document_free( tested ); +} + +void DocumentTest::getContentLengthTest( ) +{ + libcmis_DocumentPtr tested = getTested( true, false ); + long actual = libcmis_document_getContentLength( tested ); + CPPUNIT_ASSERT( 0 != actual ); + libcmis_document_free( tested ); +} + +void DocumentTest::checkOutTest( ) +{ + libcmis_DocumentPtr tested = getTested( true, false ); + libcmis_ErrorPtr error = libcmis_error_create( ); + + // checkout a private working copy (tested method) + libcmis_DocumentPtr actual = libcmis_document_checkOut( tested, error ); + + // Check + CPPUNIT_ASSERT( NULL != actual ); + + // Free it all + libcmis_document_free( actual ); + libcmis_error_free( error ); + libcmis_document_free( tested ); +} + +void DocumentTest::checkOutErrorTest( ) +{ + libcmis_DocumentPtr tested = getTested( true, true ); + libcmis_ErrorPtr error = libcmis_error_create( ); + + // checkout a private working copy (tested method) + libcmis_DocumentPtr actual = libcmis_document_checkOut( tested, error ); + + // Check + CPPUNIT_ASSERT( NULL == actual ); + CPPUNIT_ASSERT( !string( libcmis_error_getMessage( error ) ).empty( ) ); + + // Free it all + libcmis_document_free( actual ); + libcmis_error_free( error ); + libcmis_document_free( tested ); +} + +void DocumentTest::cancelCheckoutTest( ) +{ + libcmis_DocumentPtr tested = getTested( true, false ); + libcmis_ErrorPtr error = libcmis_error_create( ); + + // checkout a private working copy (tested method) + libcmis_document_cancelCheckout( tested, error ); + + // Check + CPPUNIT_ASSERT( 0 != libcmis_object_getRefreshTimestamp( tested ) ); + + // Free it all + libcmis_error_free( error ); + libcmis_document_free( tested ); +} + +void DocumentTest::cancelCheckoutErrorTest( ) +{ + libcmis_DocumentPtr tested = getTested( true, true ); + libcmis_ErrorPtr error = libcmis_error_create( ); + + // checkout a private working copy (tested method) + libcmis_document_cancelCheckout( tested, error ); + + // Check + CPPUNIT_ASSERT( 0 == libcmis_object_getRefreshTimestamp( tested ) ); + CPPUNIT_ASSERT( !string( libcmis_error_getMessage( error ) ).empty( ) ); + + // Free it all + libcmis_error_free( error ); + libcmis_document_free( tested ); +} + +void DocumentTest::checkInTest( ) +{ + libcmis_DocumentPtr tested = getTested( true, false ); + libcmis_ErrorPtr error = libcmis_error_create( ); + + // Prepare the content to set + FILE* tmp = tmpfile( ); + string expected( "New Content Stream" ); + fwrite( expected.c_str( ), 1, expected.size( ), tmp ); + rewind( tmp ); + + // Create the properties for the new version + libcmis_vector_property_Ptr properties = libcmis_vector_property_create( ); + libcmis_ObjectTypePtr objectType = libcmis_object_getTypeDescription( tested ); + const char* id = "Property1"; + libcmis_PropertyTypePtr propertyType = libcmis_object_type_getPropertyType( objectType, id ); + size_t size = 2; + const char** values = new const char*[size]; + values[0] = "Value 1"; + values[1] = "Value 2"; + libcmis_PropertyPtr property = libcmis_property_create( propertyType, values, size ); + delete[] values; + libcmis_vector_property_append( properties, property ); + + // get the content into a temporary file (tested method) + const char* contentType = "content/type"; + const char* comment = "Version comment"; + const char* filename = "filename.txt"; + libcmis_DocumentPtr newVersion = libcmis_document_checkIn( + tested, true, comment, properties, + ( libcmis_readFn )fread, tmp, contentType, filename, error ); + fclose( tmp ); + + // Check + CPPUNIT_ASSERT( NULL != newVersion ); + + string actual = getTestedImplementation( tested )->getContentString( ); + CPPUNIT_ASSERT( NULL == libcmis_error_getMessage( error ) ); + CPPUNIT_ASSERT_EQUAL( expected, actual ); + + libcmis_PropertyPtr checkedProperty = libcmis_object_getProperty( tested, "Property1" ); + libcmis_vector_string_Ptr newValues = libcmis_property_getStrings( checkedProperty ); + CPPUNIT_ASSERT_EQUAL( size_t( 2 ), libcmis_vector_string_size( newValues ) ); + + // Free it all + libcmis_vector_string_free( newValues ); + libcmis_property_free( checkedProperty ); + libcmis_document_free( newVersion ); + libcmis_property_free( property ); + libcmis_property_type_free( propertyType ); + libcmis_object_type_free( objectType ); + libcmis_vector_property_free( properties ); + libcmis_error_free( error ); + libcmis_document_free( tested ); +} + +void DocumentTest::checkInErrorTest( ) +{ + libcmis_DocumentPtr tested = getTested( true, true ); + libcmis_ErrorPtr error = libcmis_error_create( ); + + string expected = getTestedImplementation( tested )->getContentString( ); + + // Prepare the content to set + FILE* tmp = tmpfile( ); + string newContent( "New Content Stream" ); + fwrite( newContent.c_str( ), 1, newContent.size( ), tmp ); + rewind( tmp ); + + // Create the properties for the new version + libcmis_vector_property_Ptr properties = libcmis_vector_property_create( ); + libcmis_ObjectTypePtr objectType = libcmis_object_getTypeDescription( tested ); + const char* id = "Property1"; + libcmis_PropertyTypePtr propertyType = libcmis_object_type_getPropertyType( objectType, id ); + size_t size = 2; + const char** values = new const char*[size]; + values[0] = "Value 1"; + values[1] = "Value 2"; + libcmis_PropertyPtr property = libcmis_property_create( propertyType, values, size ); + delete[] values; + libcmis_vector_property_append( properties, property ); + + // get the content into a temporary file (tested method) + const char* contentType = "content/type"; + const char* comment = "Version comment"; + const char* filename = "filename.txt"; + libcmis_DocumentPtr newVersion = libcmis_document_checkIn( + tested, true, comment, properties, + ( libcmis_readFn )fread, tmp, contentType, filename, error ); + fclose( tmp ); + + // Check + CPPUNIT_ASSERT( NULL == newVersion ); + + string actual = getTestedImplementation( tested )->getContentString( ); + CPPUNIT_ASSERT( !string( libcmis_error_getMessage( error ) ).empty( ) ); + CPPUNIT_ASSERT_EQUAL( expected, actual ); + + libcmis_PropertyPtr checkedProperty = libcmis_object_getProperty( tested, "Property1" ); + libcmis_vector_string_Ptr newValues = libcmis_property_getStrings( checkedProperty ); + CPPUNIT_ASSERT_EQUAL( size_t( 1 ), libcmis_vector_string_size( newValues ) ); + + // Free it all + libcmis_vector_string_free( newValues ); + libcmis_property_free( checkedProperty ); + libcmis_document_free( newVersion ); + libcmis_property_free( property ); + libcmis_property_type_free( propertyType ); + libcmis_object_type_free( objectType ); + libcmis_vector_property_free( properties ); + libcmis_error_free( error ); + libcmis_document_free( tested ); +} + +void DocumentTest::getAllVersionsTest( ) +{ + libcmis_DocumentPtr tested = getTested( true, false ); + libcmis_ErrorPtr error = libcmis_error_create( ); + + // get all versions (tested method) + libcmis_vector_document_Ptr versions = libcmis_document_getAllVersions( tested, error ); + + // Check + CPPUNIT_ASSERT_EQUAL( size_t( 2 ), libcmis_vector_document_size( versions ) ); + libcmis_DocumentPtr actualVersion = libcmis_vector_document_get( versions, 0 ); + char* actualId = libcmis_object_getId( actualVersion ); + CPPUNIT_ASSERT( actualId != NULL ); + free( actualId ); + + // Free it all + libcmis_document_free( actualVersion ); + libcmis_vector_document_free( versions ); + libcmis_error_free( error ); + libcmis_document_free( tested ); +} + +void DocumentTest::getAllVersionsErrorTest( ) +{ + libcmis_DocumentPtr tested = getTested( true, true ); + libcmis_ErrorPtr error = libcmis_error_create( ); + + // get all versions (tested method) + libcmis_vector_document_Ptr versions = libcmis_document_getAllVersions( tested, error ); + + // Check + CPPUNIT_ASSERT( NULL == versions ); + CPPUNIT_ASSERT( !string( libcmis_error_getMessage( error ) ).empty( ) ); + + // Free it all + libcmis_vector_document_free( versions ); + libcmis_error_free( error ); + libcmis_document_free( tested ); +} diff --git a/qa/libcmis-c/test-dummies.cxx b/qa/libcmis-c/test-dummies.cxx new file mode 100644 index 0000000..5056bcf --- /dev/null +++ b/qa/libcmis-c/test-dummies.cxx @@ -0,0 +1,633 @@ +/* libcmis + * Version: MPL 1.1 / GPLv2+ / LGPLv2+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License or as specified alternatively below. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * 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. + * + * Major Contributor(s): + * Copyright (C) 2011 SUSE <cbosdonnat@suse.com> + * + * + * All Rights Reserved. + * + * For minor contributions see the git repository. + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPLv2+"), or + * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"), + * in which case the provisions of the GPLv2+ or the LGPLv2+ are applicable + * instead of those above. + */ + +#include "test-dummies.hxx" + +using namespace std; +using libcmis::PropertyPtrMap; + +bool isOutOfMemory = false; + +/// Ignore all tests results depending on this when running in valgrind +void * operator new ( size_t requestedSize ) +{ + if ( isOutOfMemory ) + { + throw bad_alloc( ); + } + + return malloc( requestedSize ); +} + +void operator delete ( void* ptr ) throw ( ) +{ + free( ptr ); +} + +#if __cplusplus > 201103L +void operator delete ( void* ptr, std::size_t ) throw ( ) +{ + free( ptr ); +} +#endif + +namespace dummies +{ + Session::Session( ) + { + } + + Session::~Session( ) + { + } + + libcmis::RepositoryPtr Session::getRepository( ) + { + libcmis::RepositoryPtr repo( new Repository( ) ); + return repo; + } + + + bool Session::setRepository( std::string ) + { + return true; + } + + vector< libcmis::RepositoryPtr > Session::getRepositories( ) + { + vector< libcmis::RepositoryPtr > repos; + libcmis::RepositoryPtr repo1( new Repository( ) ); + libcmis::RepositoryPtr repo2( new Repository( ) ); + repos.push_back( repo1 ); + repos.push_back( repo2 ); + return repos; + } + + libcmis::FolderPtr Session::getRootFolder() + { + libcmis::FolderPtr root( new Folder( true, false ) ); + return root; + } + + libcmis::ObjectPtr Session::getObject( string id ) + { + return getFolder( id ); + } + + libcmis::ObjectPtr Session::getObjectByPath( string path ) + { + return getFolder( path ); + } + + libcmis::FolderPtr Session::getFolder( string ) + { + libcmis::FolderPtr result( new Folder( false, false ) ); + return result; + } + + libcmis::ObjectTypePtr Session::getType( string ) + { + libcmis::ObjectTypePtr type( new ObjectType( true, false ) ); + return type; + } + + vector< libcmis::ObjectTypePtr > Session::getBaseTypes( ) + { + vector< libcmis::ObjectTypePtr > types; + libcmis::ObjectTypePtr type( new ObjectType( true, false ) ); + types.push_back( type ); + return types; + } + + std::string Session::getRefreshToken( ) + { + return string( ); + } + + Repository::Repository( ) : + libcmis::Repository( ) + { + m_id = string( "Repository::Id" ); + m_name = string( "Repository::Name" ); + m_description = string( "Repository::Description" ); + m_vendorName = string( "Repository::VendorName" ); + m_productName = string( "Repository::ProductName" ); + m_productVersion = string( "Repository::ProductVersion" ); + m_rootId = string( "Repository::RootId" ); + m_cmisVersionSupported = string( "Repository::CmisVersionSupported" ); + m_thinClientUri.reset( new string( "Repository::ThinClientUri" ) ); + m_principalAnonymous.reset( new string( "Repository::PrincipalAnonymous" ) ); + m_principalAnyone.reset( new string( "Repository::PrincipalAnyone" ) ); + } + + Repository::~Repository( ) + { + } + + PropertyType::PropertyType( string id, string xmlType ) : + libcmis::PropertyType( ) + { + setId( id ); + setLocalName( string( "PropertyType::LocalName" ) ); + setLocalNamespace( string( "PropertyType::LocalNamespace" ) ); + setDisplayName( string( "PropertyType::DisplayName" ) ); + setQueryName( string( "PropertyType::QueryName" ) ); + setTypeFromXml( xmlType ); + + // Setting true for the tests to see a difference with + // the default false result of the tested functions + setMultiValued( true ); + setUpdatable( true ); + setInherited( true ); + setRequired( true ); + setQueryable( true ); + setOrderable( true ); + setOpenChoice( true ); + } + + PropertyType::~PropertyType( ) + { + } + + AllowableActions::AllowableActions( ) : + libcmis::AllowableActions( ) + { + m_states.insert( pair< libcmis::ObjectAction::Type, bool >( libcmis::ObjectAction::GetProperties, true ) ); + m_states.insert( pair< libcmis::ObjectAction::Type, bool >( libcmis::ObjectAction::GetFolderParent, false ) ); + } + + AllowableActions::~AllowableActions( ) + { + } + + ObjectType::ObjectType( ) : + libcmis::ObjectType( ), + m_typeId( ), + m_childrenIds( ), + m_triggersFaults( false ) + { + } + + ObjectType::ObjectType( bool rootType, bool triggersFaults ) : + libcmis::ObjectType( ), + m_typeId( ), + m_childrenIds( ), + m_triggersFaults( triggersFaults ) + { + if ( rootType ) + m_typeId = "RootType"; + else + { + m_typeId = "ObjectType"; + m_parentTypeId = "ParentType"; + m_childrenIds.push_back( "ChildType1" ); + m_childrenIds.push_back( "ChildType2" ); + } + + m_baseTypeId = "RootType"; + libcmis::PropertyTypePtr propType1( new PropertyType( "Property1", "string" ) ); + m_propertiesTypes.insert( pair< string, libcmis::PropertyTypePtr >( propType1->getId( ), propType1 ) ); + libcmis::PropertyTypePtr propType2( new PropertyType( "Property2", "string" ) ); + m_propertiesTypes.insert( pair< string, libcmis::PropertyTypePtr >( propType2->getId( ), propType2 ) ); + libcmis::PropertyTypePtr propType3( new PropertyType( "Property3", "string" ) ); + m_propertiesTypes.insert( pair< string, libcmis::PropertyTypePtr >( propType3->getId( ), propType3 ) ); + + initMembers( ); + } + + void ObjectType::initMembers( ) + { + + m_id = m_typeId + "::Id"; + m_localName = m_typeId + "::LocalName"; + m_localNamespace = m_typeId + "::LocalNamespace"; + m_displayName = m_typeId + "::DisplayName"; + m_queryName = m_typeId + "::QueryName"; + m_description = m_typeId + "::Description"; + + m_creatable = true; + m_fileable = true; + m_queryable = true; + m_fulltextIndexed = true; + m_includedInSupertypeQuery = true; + m_controllablePolicy = true; + m_controllableAcl = true; + m_versionable = true; + m_contentStreamAllowed = libcmis::ObjectType::Allowed; + } + + ObjectType::~ObjectType( ) + { + } + + libcmis::ObjectTypePtr ObjectType::getParentType( ) + { + if ( m_triggersFaults ) + throw libcmis::Exception( "Fault triggered" ); + + ObjectType* parent = NULL; + if ( !m_parentTypeId.empty( ) ) + { + parent = new ObjectType( ); + parent->m_typeId = m_parentTypeId; + parent->m_parentTypeId = m_baseTypeId; + parent->m_baseTypeId = m_baseTypeId; + parent->m_childrenIds.push_back( m_id ); + parent->m_triggersFaults = m_triggersFaults; + parent->m_propertiesTypes = m_propertiesTypes; + + parent->initMembers( ); + } + + libcmis::ObjectTypePtr result( parent ); + return result; + } + + libcmis::ObjectTypePtr ObjectType::getBaseType( ) + { + if ( m_triggersFaults ) + throw libcmis::Exception( "Fault triggered" ); + + ObjectType* base = this; + if ( m_typeId != m_baseTypeId ) + { + base = new ObjectType( ); + base->m_typeId = m_baseTypeId; + base->m_baseTypeId = m_baseTypeId; + base->m_childrenIds.push_back( m_id ); + base->m_triggersFaults = m_triggersFaults; + base->m_propertiesTypes = m_propertiesTypes; + + base->initMembers( ); + } + + libcmis::ObjectTypePtr result( base ); + return result; + } + + vector< libcmis::ObjectTypePtr > ObjectType::getChildren( ) + { + if ( m_triggersFaults ) + throw libcmis::Exception( "Fault triggered" ); + + vector< libcmis::ObjectTypePtr > children; + + for ( vector< string >::iterator it = m_childrenIds.begin( ); it != m_childrenIds.end( ); ++it ) + { + ObjectType* child = new ObjectType( ); + child->m_typeId = *it; + child->m_parentTypeId = m_typeId; + child->m_baseTypeId = m_baseTypeId; + child->m_triggersFaults = m_triggersFaults; + child->m_propertiesTypes = m_propertiesTypes; + + child->initMembers( ); + + libcmis::ObjectTypePtr result( child ); + children.push_back( result ); + } + + return children; + } + + string ObjectType::toString( ) + { + return m_typeId + "::toString"; + } + + Object::Object( bool triggersFaults, string type ): + libcmis::Object( NULL ), + m_type( type ), + m_triggersFaults( triggersFaults ) + { + libcmis::PropertyTypePtr propertyType( new PropertyType( "Property1", "string" ) ); + vector< string > values; + values.push_back( "Value1" ); + libcmis::PropertyPtr property( new libcmis::Property( propertyType, values ) ); + m_properties.insert( pair< string, libcmis::PropertyPtr >( propertyType->getId( ), property ) ); + } + + string Object::getId( ) + { + return m_type + "::Id"; + } + + string Object::getName( ) + { + return m_type + "::Name"; + } + + vector< string > Object::getPaths( ) + { + vector< string > paths; + paths.push_back( string( "/Path1/" ) ); + paths.push_back( string( "/Path2/" ) ); + + return paths; + } + + string Object::getBaseType( ) + { + return m_type + "::BaseType"; + } + + string Object::getType( ) + { + return m_type + "::Type"; + } + + boost::posix_time::ptime Object::getCreationDate( ) + { + boost::posix_time::ptime now( boost::posix_time::second_clock::local_time( ) ); + return now; + } + + boost::posix_time::ptime Object::getLastModificationDate( ) + { + boost::posix_time::ptime now( boost::posix_time::second_clock::local_time( ) ); + return now; + } + + libcmis::ObjectPtr Object::updateProperties( + const PropertyPtrMap& ) + { + if ( m_triggersFaults ) + throw libcmis::Exception( "Fault triggered" ); + + time( &m_refreshTimestamp ); + libcmis::ObjectPtr result( new Object( false ) ); + return result; + } + + libcmis::ObjectTypePtr Object::getTypeDescription( ) + { + libcmis::ObjectTypePtr type( new ObjectType( false, m_triggersFaults ) ); + return type; + } + + libcmis::AllowableActionsPtr Object::getAllowableActions( ) + { + libcmis::AllowableActionsPtr allowableActions( new AllowableActions( ) ); + return allowableActions; + } + + void Object::refresh( ) + { + if ( m_triggersFaults ) + throw libcmis::Exception( "Fault triggered" ); + + time( &m_refreshTimestamp ); + } + + void Object::remove( bool ) + { + if ( m_triggersFaults ) + throw libcmis::Exception( "Fault triggered" ); + + time( &m_refreshTimestamp ); + } + + void Object::move( libcmis::FolderPtr, libcmis::FolderPtr ) + { + if ( m_triggersFaults ) + throw libcmis::Exception( "Fault triggered" ); + + time( &m_refreshTimestamp ); + } + + void Object::toXml( xmlTextWriterPtr ) + { + } + + Folder::Folder( bool isRoot, bool triggersFaults ) : + libcmis::Object( NULL ), + libcmis::Folder( NULL ), + dummies::Object( triggersFaults, "Folder" ), + m_isRoot( isRoot ) + { + } + + libcmis::FolderPtr Folder::getFolderParent( ) + { + if ( m_triggersFaults ) + throw libcmis::Exception( "Fault triggered" ); + + libcmis::FolderPtr parent; + + if ( !m_isRoot ) + parent.reset( new Folder( true, m_triggersFaults ) ); + + return parent; + } + + vector< libcmis::ObjectPtr > Folder::getChildren( ) + { + if ( m_triggersFaults ) + throw libcmis::Exception( "Fault triggered" ); + + vector< libcmis::ObjectPtr > children; + + libcmis::ObjectPtr child1( new Object( m_triggersFaults ) ); + children.push_back( child1 ); + libcmis::ObjectPtr child2( new Object( m_triggersFaults ) ); + children.push_back( child2 ); + + return children; + } + + string Folder::getPath( ) + { + return string( "/Path/" ); + } + + bool Folder::isRootFolder( ) + { + return m_isRoot; + } + + libcmis::FolderPtr Folder::createFolder( const PropertyPtrMap& ) + { + if ( m_triggersFaults ) + throw libcmis::Exception( "Fault triggered" ); + + libcmis::FolderPtr created( new Folder( true, m_triggersFaults ) ); + return created; + } + + libcmis::DocumentPtr Folder::createDocument( const PropertyPtrMap& properties, + boost::shared_ptr< ostream > os, string contentType, string filename ) + { + if ( m_triggersFaults ) + throw libcmis::Exception( "Fault triggered" ); + + dummies::Document* document = new dummies::Document( true, false ); + + PropertyPtrMap propertiesCopy( properties ); + document->getProperties( ).swap( propertiesCopy ); + document->setContentStream( os, contentType, filename ); + + libcmis::DocumentPtr created( document ); + return created; + } + + vector< string > Folder::removeTree( bool, libcmis::UnfileObjects::Type, + bool ) + { + if ( m_triggersFaults ) + throw libcmis::Exception( "Fault triggered" ); + + time( &m_refreshTimestamp ); + + vector< string > failed; + failed.push_back( "failed 1" ); + return failed; + } + + Document::Document( bool isFiled, bool triggersFaults ) : + libcmis::Object( NULL ), + libcmis::Document( NULL ), + dummies::Object( triggersFaults, "Document" ), + m_isFiled( isFiled ), + m_contentString( "Document::ContentStream" ) + { + } + + vector< libcmis::FolderPtr > Document::getParents( ) + { + if ( m_triggersFaults ) + throw libcmis::Exception( "Fault triggered" ); + + vector< libcmis::FolderPtr > parents; + if ( m_isFiled ) + { + libcmis::FolderPtr parent1( new Folder( true, m_triggersFaults ) ); + parents.push_back( parent1 ); + libcmis::FolderPtr parent2( new Folder( false, m_triggersFaults ) ); + parents.push_back( parent2 ); + } + + return parents; + } + + boost::shared_ptr< istream > Document::getContentStream( string /*streamId*/ ) + { + if ( m_triggersFaults ) + throw libcmis::Exception( "Fault triggered" ); + + bool oldOutOfMem = isOutOfMemory; + isOutOfMemory = false; + boost::shared_ptr< istream > stream( new stringstream( m_contentString ) ); + isOutOfMemory = oldOutOfMem; + return stream; + } + + void Document::setContentStream( boost::shared_ptr< ostream > os, string, string, bool ) + { + if ( m_triggersFaults ) + throw libcmis::Exception( "Fault triggered" ); + + istream is( os->rdbuf( ) ); + stringstream out; + is.seekg( 0 ); + int bufSize = 2048; + char* buf = new char[ bufSize ]; + while ( !is.eof( ) ) + { + is.read( buf, bufSize ); + size_t read = is.gcount( ); + out.write( buf, read ); + } + delete[] buf; + + m_contentString = out.str( ); + + time( &m_refreshTimestamp ); + } + + string Document::getContentType( ) + { + return "Document::ContentType"; + } + + string Document::getContentFilename( ) + { + return "Document::ContentFilename"; + } + + long Document::getContentLength( ) + { + return long( 12345 ); + } + + libcmis::DocumentPtr Document::checkOut( ) + { + if ( m_triggersFaults ) + throw libcmis::Exception( "Fault triggered" ); + + time( &m_refreshTimestamp ); + + libcmis::DocumentPtr result( new Document( true, m_triggersFaults ) ); + return result; + } + + void Document::cancelCheckout( ) + { + if ( m_triggersFaults ) + throw libcmis::Exception( "Fault triggered" ); + + time( &m_refreshTimestamp ); + } + + libcmis::DocumentPtr Document::checkIn( bool, string, const PropertyPtrMap& properties, + boost::shared_ptr< ostream > os, string contentType, string filename ) + { + if ( m_triggersFaults ) + throw libcmis::Exception( "Fault triggered" ); + + m_properties = properties; + setContentStream( os, contentType, filename ); + time( &m_refreshTimestamp ); + + return libcmis::DocumentPtr( new Document( true, false ) ); + } + + vector< libcmis::DocumentPtr > Document::getAllVersions( ) + { + if ( m_triggersFaults ) + throw libcmis::Exception( "Fault triggered" ); + + vector< libcmis::DocumentPtr > versions; + + libcmis::DocumentPtr version1( new Document( true, false ) ); + versions.push_back( version1 ); + libcmis::DocumentPtr version2( new Document( true, false ) ); + versions.push_back( version2 ); + + return versions; + } +} diff --git a/qa/libcmis-c/test-dummies.hxx b/qa/libcmis-c/test-dummies.hxx new file mode 100644 index 0000000..161c813 --- /dev/null +++ b/qa/libcmis-c/test-dummies.hxx @@ -0,0 +1,223 @@ +/* libcmis + * Version: MPL 1.1 / GPLv2+ / LGPLv2+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License or as specified alternatively below. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * 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. + * + * Major Contributor(s): + * Copyright (C) 2011 SUSE <cbosdonnat@suse.com> + * + * + * All Rights Reserved. + * + * For minor contributions see the git repository. + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPLv2+"), or + * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"), + * in which case the provisions of the GPLv2+ or the LGPLv2+ are applicable + * instead of those above. + */ +#ifndef _LIBCMIS_TEST_DUMMIES_HXX_ +#define _LIBCMIS_TEST_DUMMIES_HXX_ + + +#include <libcmis/allowable-actions.hxx> +#include <libcmis/document.hxx> +#include <libcmis/folder.hxx> +#include <libcmis/object.hxx> +#include <libcmis/object-type.hxx> +#include <libcmis/property-type.hxx> +#include <libcmis/repository.hxx> +#include <libcmis/session.hxx> + +/** This namespace contains dummy classes to simulate the libcmis layer + in the libcmis-c unit tests. + */ +namespace dummies +{ + class Session : public libcmis::Session + { + public: + Session( ); + ~Session( ); + + virtual libcmis::RepositoryPtr getRepository( ); + virtual bool setRepository( std::string repositoryId ); + virtual std::vector< libcmis::RepositoryPtr > getRepositories( ); + virtual libcmis::FolderPtr getRootFolder(); + virtual libcmis::ObjectPtr getObject( std::string id ); + virtual libcmis::ObjectPtr getObjectByPath( std::string path ); + virtual libcmis::FolderPtr getFolder( std::string id ); + virtual libcmis::ObjectTypePtr getType( std::string id ); + virtual std::vector< libcmis::ObjectTypePtr > getBaseTypes( ); + virtual std::string getRefreshToken( ); + virtual void setNoSSLCertificateCheck( bool /*noCheck*/ ) { } + }; + + class Repository : public libcmis::Repository + { + public: + Repository( ); + ~Repository( ); + }; + + class PropertyType : public libcmis::PropertyType + { + public: + PropertyType( std::string id, std::string xmlType ); + ~PropertyType( ); + }; + + /** Dummy for testing the C API for allowable actions. The dummy has only the + following actions defined: + \li \c GetProperties, defined to \c true + \li \c GetFolderParent, defined to \c false + */ + class AllowableActions : public libcmis::AllowableActions + { + public: + AllowableActions( ); + ~AllowableActions( ); + }; + + class ObjectType : public libcmis::ObjectType + { + private: + std::string m_typeId; + std::vector< std::string > m_childrenIds; + bool m_triggersFaults; + + ObjectType( ); + void initMembers( ); + + public: + ObjectType( bool rootType, bool triggersFaults ); + ~ObjectType( ); + + virtual boost::shared_ptr< libcmis::ObjectType > getParentType( ); + virtual boost::shared_ptr< libcmis::ObjectType > getBaseType( ); + virtual std::vector< boost::shared_ptr< libcmis::ObjectType > > getChildren( ); + + virtual std::string toString( ); + }; + + class Object : public virtual libcmis::Object + { + public: + std::string m_type; + bool m_triggersFaults; + + public: + Object( bool triggersFaults, std::string m_type = "Object" ); + ~Object( ) { } + + virtual std::string getId( ); + virtual std::string getName( ); + + virtual std::vector< std::string > getPaths( ); + + virtual std::string getBaseType( ); + virtual std::string getType( ); + + virtual std::string getCreatedBy( ) { return m_type + "::CreatedBy"; } + virtual boost::posix_time::ptime getCreationDate( ); + virtual std::string getLastModifiedBy( ) { return m_type + "::LastModifiedBy"; } + virtual boost::posix_time::ptime getLastModificationDate( ); + + virtual std::string getChangeToken( ) { return m_type + "::ChangeToken"; } + virtual bool isImmutable( ) { return true; }; + + virtual libcmis::ObjectPtr updateProperties( + const std::map< std::string, libcmis::PropertyPtr >& properties ); + + virtual libcmis::ObjectTypePtr getTypeDescription( ); + virtual libcmis::AllowableActionsPtr getAllowableActions( ); + + virtual void refresh( ); + + virtual void remove( bool allVersions = true ); + + virtual void move( libcmis::FolderPtr source, libcmis::FolderPtr destination ); + + virtual std::string toString( ) { return m_type + "::toString"; } + + virtual void toXml( xmlTextWriterPtr writer ); + }; + + class Folder : public libcmis::Folder, public Object + { + private: + bool m_isRoot; + + public: + Folder( bool isRoot, bool triggersFaults ); + ~Folder( ) { } + + virtual libcmis::FolderPtr getFolderParent( ); + virtual std::vector< libcmis::ObjectPtr > getChildren( ); + virtual std::string getPath( ); + + virtual bool isRootFolder( ); + + virtual libcmis::FolderPtr createFolder( const std::map< std::string, libcmis::PropertyPtr >& properties ); + virtual libcmis::DocumentPtr createDocument( const std::map< std::string, libcmis::PropertyPtr >& properties, + boost::shared_ptr< std::ostream > os, std::string contentType, std::string filename ); + + virtual std::vector< std::string > removeTree( bool allVersion = true, + libcmis::UnfileObjects::Type unfile = libcmis::UnfileObjects::Delete, + bool continueOnError = false ); + + virtual std::vector< std::string > getPaths( ) { return dummies::Object::getPaths( ); } + virtual std::string toString( ) { return dummies::Object::toString( ); } + }; + + class Document : public libcmis::Document, public Object + { + private: + bool m_isFiled; + std::string m_contentString; + + public: + Document( bool isFiled, bool triggersFaults ); + ~Document( ) { } + + std::string getContentString( ) { return m_contentString; } + + virtual std::vector< libcmis::FolderPtr > getParents( ); + + virtual boost::shared_ptr< std::istream > getContentStream( std::string streamId = std::string( ) ); + + virtual void setContentStream( boost::shared_ptr< std::ostream > os, std::string contentType, + std::string fileName, bool overwrite = true ); + + virtual std::string getContentType( ); + + virtual std::string getContentFilename( ); + + virtual long getContentLength( ); + + virtual libcmis::DocumentPtr checkOut( ); + + virtual void cancelCheckout( ); + + virtual libcmis::DocumentPtr checkIn( bool isMajor, std::string comment, + const std::map< std::string, libcmis::PropertyPtr >& properties, + boost::shared_ptr< std::ostream > stream, + std::string contentType, std::string filename ); + + virtual std::vector< libcmis::DocumentPtr > getAllVersions( ); + + virtual std::vector< std::string > getPaths( ) { return dummies::Object::getPaths( ); } + virtual std::string toString( ) { return dummies::Object::toString( ); } + }; +} + +#endif diff --git a/qa/libcmis-c/test-folder.cxx b/qa/libcmis-c/test-folder.cxx new file mode 100644 index 0000000..171c57d --- /dev/null +++ b/qa/libcmis-c/test-folder.cxx @@ -0,0 +1,433 @@ +/* libcmis + * Version: MPL 1.1 / GPLv2+ / LGPLv2+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License or as specified alternatively below. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * 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. + * + * Major Contributor(s): + * Copyright (C) 2011 SUSE <cbosdonnat@suse.com> + * + * + * All Rights Reserved. + * + * For minor contributions see the git repository. + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPLv2+"), or + * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"), + * in which case the provisions of the GPLv2+ or the LGPLv2+ are applicable + * instead of those above. + */ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/TestFixture.h> +#include <cppunit/TestAssert.h> + +#include <libcmis-c/document.h> +#include <libcmis-c/error.h> +#include <libcmis-c/folder.h> +#include <libcmis-c/object.h> +#include <libcmis-c/object-type.h> +#include <libcmis-c/property.h> +#include <libcmis-c/property-type.h> +#include <libcmis-c/vectors.h> + +#include "internals.hxx" +#include "test-dummies.hxx" + +using namespace std; + +class FolderTest : public CppUnit::TestFixture +{ + private: + libcmis_FolderPtr getTested( bool isRoot, bool triggersFaults ); + dummies::Document* getDocumentImplementation( libcmis_DocumentPtr document ); + + public: + void objectCastTest( ); + void objectCastFailureTest( ); + void objectFunctionsTest( ); + void getParentTest( ); + void getParentRootTest( ); + void getParentErrorTest( ); + void getChildrenTest( ); + void getChildrenErrorTest( ); + void getPathTest( ); + void createFolderTest( ); + void createFolderErrorTest( ); + void createDocumentTest( ); + void createDocumentErrorTest( ); + void removeTreeTest( ); + void removeTreeErrorTest( ); + + CPPUNIT_TEST_SUITE( FolderTest ); + CPPUNIT_TEST( objectCastTest ); + CPPUNIT_TEST( objectCastFailureTest ); + CPPUNIT_TEST( objectFunctionsTest ); + CPPUNIT_TEST( getParentTest ); + CPPUNIT_TEST( getParentRootTest ); + CPPUNIT_TEST( getParentErrorTest ); + CPPUNIT_TEST( getChildrenTest ); + CPPUNIT_TEST( getChildrenErrorTest ); + CPPUNIT_TEST( getPathTest ); + CPPUNIT_TEST( createFolderTest ); + CPPUNIT_TEST( createFolderErrorTest ); + CPPUNIT_TEST( createDocumentTest ); + CPPUNIT_TEST( createDocumentErrorTest ); + CPPUNIT_TEST( removeTreeTest ); + CPPUNIT_TEST( removeTreeErrorTest ); + CPPUNIT_TEST_SUITE_END( ); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION( FolderTest ); + +libcmis_FolderPtr FolderTest::getTested( bool isRoot, bool triggersFaults ) +{ + libcmis_FolderPtr result = new libcmis_folder( ); + libcmis::FolderPtr handle( new dummies::Folder( isRoot, triggersFaults ) ); + result->handle = handle; + + return result; +} + +dummies::Document* FolderTest::getDocumentImplementation( libcmis_DocumentPtr document ) +{ + dummies::Document* impl = dynamic_cast< dummies::Document* >( document->handle.get( ) ); + return impl; +} + +void FolderTest::objectCastTest( ) +{ + // Create the test object to cast + libcmis_ObjectPtr tested = new libcmis_object( ); + libcmis::FolderPtr handle( new dummies::Folder( false, false ) ); + tested->handle = handle; + + // Test libcmis_is_folder + CPPUNIT_ASSERT( libcmis_is_folder( tested ) ); + + // Actually cast to a folder + libcmis_FolderPtr actual = libcmis_folder_cast( tested ); + + // Check the result + CPPUNIT_ASSERT( NULL != actual ); + + // Check that the libcmis_object-* functions are working with the cast result + char* actualId = libcmis_object_getId( tested ); + CPPUNIT_ASSERT_EQUAL( string( "Folder::Id" ), string( actualId ) ); + free( actualId ); + + // Free it all + libcmis_folder_free( actual ); + libcmis_object_free( tested ); +} + +void FolderTest::objectCastFailureTest( ) +{ + // Create the test object to cast + libcmis_ObjectPtr tested = new libcmis_object( ); + libcmis::DocumentPtr handle( new dummies::Document( true, false ) ); + tested->handle = handle; + + // Test libcmis_is_folder + CPPUNIT_ASSERT( !libcmis_is_folder( tested ) ); + + // Actually cast to a folder + libcmis_FolderPtr actual = libcmis_folder_cast( tested ); + + // Check the result + CPPUNIT_ASSERT( NULL == actual ); + + libcmis_object_free( tested ); +} + +void FolderTest::objectFunctionsTest( ) +{ + libcmis_FolderPtr tested = getTested( false, false ); + char* actual = libcmis_object_getId( tested ); + CPPUNIT_ASSERT_EQUAL( string( "Folder::Id" ), string( actual ) ); + free( actual ); + libcmis_folder_free( tested ); +} + +void FolderTest::getParentTest( ) +{ + libcmis_FolderPtr tested = getTested( false, false ); + libcmis_ErrorPtr error = libcmis_error_create( ); + libcmis_FolderPtr parent = libcmis_folder_getParent( tested, error ); + CPPUNIT_ASSERT( NULL != parent ); + CPPUNIT_ASSERT( !libcmis_folder_isRootFolder( tested ) ); + libcmis_folder_free( parent ); + libcmis_error_free( error ); + libcmis_folder_free( tested ); +} + +void FolderTest::getParentRootTest( ) +{ + libcmis_FolderPtr tested = getTested( true, false ); + libcmis_ErrorPtr error = libcmis_error_create( ); + libcmis_FolderPtr parent = libcmis_folder_getParent( tested, error ); + CPPUNIT_ASSERT( NULL == parent ); + CPPUNIT_ASSERT( libcmis_folder_isRootFolder( tested ) ); + libcmis_error_free( error ); + libcmis_folder_free( tested ); +} + +void FolderTest::getParentErrorTest( ) +{ + libcmis_FolderPtr tested = getTested( false, true ); + libcmis_ErrorPtr error = libcmis_error_create( ); + libcmis_FolderPtr parent = libcmis_folder_getParent( tested, error ); + CPPUNIT_ASSERT( NULL == parent ); + const char* actualMessage = libcmis_error_getMessage( error ); + CPPUNIT_ASSERT( !string( actualMessage ).empty( ) ); + libcmis_error_free( error ); + libcmis_folder_free( tested ); +} + +void FolderTest::getChildrenTest( ) +{ + libcmis_FolderPtr tested = getTested( false, false ); + libcmis_ErrorPtr error = libcmis_error_create( ); + + libcmis_vector_object_Ptr children = libcmis_folder_getChildren( tested, error ); + CPPUNIT_ASSERT_EQUAL( size_t( 2 ), libcmis_vector_object_size( children ) ); + libcmis_vector_object_free( children ); + libcmis_error_free( error ); + libcmis_folder_free( tested ); +} + +void FolderTest::getChildrenErrorTest( ) +{ + libcmis_FolderPtr tested = getTested( false, true ); + libcmis_ErrorPtr error = libcmis_error_create( ); + + libcmis_vector_object_Ptr children = libcmis_folder_getChildren( tested, error ); + CPPUNIT_ASSERT( NULL == children ); + const char* actualMessage = libcmis_error_getMessage( error ); + CPPUNIT_ASSERT( !string( actualMessage ).empty( ) ); + libcmis_error_free( error ); + libcmis_folder_free( tested ); +} + +void FolderTest::getPathTest( ) +{ + libcmis_FolderPtr tested = getTested( false, false ); + char* actual = libcmis_folder_getPath( tested ); + CPPUNIT_ASSERT_EQUAL( string( "/Path/" ), string( actual ) ); + free( actual ); + libcmis_folder_free( tested ); +} + +void FolderTest::createFolderTest( ) +{ + libcmis_FolderPtr tested = getTested( false, false ); + libcmis_ErrorPtr error = libcmis_error_create( ); + + // Create the properties for the new folder + libcmis_vector_property_Ptr properties = libcmis_vector_property_create( ); + libcmis_ObjectTypePtr objectType = libcmis_object_getTypeDescription( tested ); + const char* id = "Property1"; + libcmis_PropertyTypePtr propertyType = libcmis_object_type_getPropertyType( objectType, id ); + size_t size = 2; + const char** values = new const char*[size]; + values[0] = "Value 1"; + values[1] = "Value 2"; + libcmis_PropertyPtr property = libcmis_property_create( propertyType, values, size ); + delete[] values; + libcmis_vector_property_append( properties, property ); + + // Create the new folder (method to test) + libcmis_FolderPtr created = libcmis_folder_createFolder( tested, properties, error ); + + // Check + CPPUNIT_ASSERT( NULL != created ); + + // Free everything + libcmis_folder_free( created ); + libcmis_property_free( property ); + libcmis_property_type_free( propertyType ); + libcmis_object_type_free( objectType ); + libcmis_vector_property_free( properties ); + libcmis_error_free( error ); + libcmis_folder_free( tested ); +} + +void FolderTest::createFolderErrorTest( ) +{ + libcmis_FolderPtr tested = getTested( false, true ); + libcmis_ErrorPtr error = libcmis_error_create( ); + + // Create the properties for the new folder + libcmis_vector_property_Ptr properties = libcmis_vector_property_create( ); + libcmis_ObjectTypePtr objectType = libcmis_object_getTypeDescription( tested ); + const char* id = "Property1"; + libcmis_PropertyTypePtr propertyType = libcmis_object_type_getPropertyType( objectType, id ); + size_t size = 2; + const char** values = new const char*[size]; + values[0] = "Value 1"; + values[1] = "Value 2"; + libcmis_PropertyPtr property = libcmis_property_create( propertyType, values, size ); + delete[] values; + libcmis_vector_property_append( properties, property ); + + // Create the new folder (method to test) + libcmis_FolderPtr created = libcmis_folder_createFolder( tested, properties, error ); + + // Check + CPPUNIT_ASSERT( NULL == created ); + + const char* actualMessage = libcmis_error_getMessage( error ); + CPPUNIT_ASSERT( !string( actualMessage ).empty( ) ); + + // Free everything + libcmis_folder_free( created ); + libcmis_property_free( property ); + libcmis_property_type_free( propertyType ); + libcmis_object_type_free( objectType ); + libcmis_vector_property_free( properties ); + libcmis_error_free( error ); + libcmis_folder_free( tested ); +} + +void FolderTest::createDocumentTest( ) +{ + libcmis_FolderPtr tested = getTested( true, false ); + libcmis_ErrorPtr error = libcmis_error_create( ); + + // Prepare the content to set + FILE* tmp = tmpfile( ); + string expectedStream( "New Content Stream" ); + fwrite( expectedStream.c_str( ), 1, expectedStream.size( ), tmp ); + rewind( tmp ); + + // Create the properties for the new version + libcmis_vector_property_Ptr properties = libcmis_vector_property_create( ); + libcmis_ObjectTypePtr objectType = libcmis_object_getTypeDescription( tested ); + const char* id = "Property1"; + libcmis_PropertyTypePtr propertyType = libcmis_object_type_getPropertyType( objectType, id ); + size_t size = 2; + const char** values = new const char*[size]; + values[0] = "Value 1"; + values[1] = "Value 2"; + libcmis_PropertyPtr property = libcmis_property_create( propertyType, values, size ); + delete[] values; + libcmis_vector_property_append( properties, property ); + + // get the content into a temporary file (tested method) + const char* contentType = "content/type"; + const char* filename = "name.txt"; + libcmis_DocumentPtr actual = libcmis_folder_createDocument( tested, properties, + ( libcmis_readFn )fread, tmp, contentType, filename, error ); + fclose( tmp ); + + // Check + string actualStream = getDocumentImplementation( actual )->getContentString( ); + CPPUNIT_ASSERT( NULL == libcmis_error_getMessage( error ) ); + CPPUNIT_ASSERT_EQUAL( expectedStream, actualStream ); + + libcmis_PropertyPtr checkedProperty = libcmis_object_getProperty( actual, "Property1" ); + libcmis_vector_string_Ptr newValues = libcmis_property_getStrings( checkedProperty ); + CPPUNIT_ASSERT_EQUAL( size_t( 2 ), libcmis_vector_string_size( newValues ) ); + + // Free it all + libcmis_vector_string_free( newValues ); + libcmis_property_free( checkedProperty ); + libcmis_document_free( actual ); + libcmis_property_free( property ); + libcmis_property_type_free( propertyType ); + libcmis_object_type_free( objectType ); + libcmis_vector_property_free( properties ); + libcmis_error_free( error ); + libcmis_folder_free( tested ); +} + +void FolderTest::createDocumentErrorTest( ) +{ + libcmis_FolderPtr tested = getTested( true, true ); + libcmis_ErrorPtr error = libcmis_error_create( ); + + // Prepare the content to set + FILE* tmp = tmpfile( ); + string newStream( "New Content Stream" ); + fwrite( newStream.c_str( ), 1, newStream.size( ), tmp ); + rewind( tmp ); + + // Create the properties for the new version + libcmis_vector_property_Ptr properties = libcmis_vector_property_create( ); + libcmis_ObjectTypePtr objectType = libcmis_object_getTypeDescription( tested ); + const char* id = "Property1"; + libcmis_PropertyTypePtr propertyType = libcmis_object_type_getPropertyType( objectType, id ); + size_t size = 2; + const char** values = new const char*[size]; + values[0] = "Value 1"; + values[1] = "Value 2"; + libcmis_PropertyPtr property = libcmis_property_create( propertyType, values, size ); + delete[] values; + libcmis_vector_property_append( properties, property ); + + // get the content into a temporary file (tested method) + const char* contentType = "content/type"; + const char* filename = "name.txt"; + libcmis_DocumentPtr actual = libcmis_folder_createDocument( tested, properties, + ( libcmis_readFn )fread, tmp, contentType, filename, error ); + fclose( tmp ); + + // Check + CPPUNIT_ASSERT( !string( libcmis_error_getMessage( error ) ).empty( ) ); + CPPUNIT_ASSERT( NULL == actual ); + + // Free it all + libcmis_property_free( property ); + libcmis_property_type_free( propertyType ); + libcmis_object_type_free( objectType ); + libcmis_vector_property_free( properties ); + libcmis_error_free( error ); + libcmis_folder_free( tested ); +} + +void FolderTest::removeTreeTest( ) +{ + libcmis_FolderPtr tested = getTested( false, false ); + libcmis_ErrorPtr error = libcmis_error_create( ); + CPPUNIT_ASSERT_MESSAGE( "Timestamp not set to 0 initially", 0 == libcmis_object_getRefreshTimestamp( tested ) ); + + // Remove the tree (method to test) + libcmis_vector_string_Ptr failed = libcmis_folder_removeTree( tested, true, libcmis_Delete, true, error ); + + // Check + CPPUNIT_ASSERT_MESSAGE( "Timestamp not updated", 0 != libcmis_object_getRefreshTimestamp( tested ) ); + CPPUNIT_ASSERT_EQUAL( size_t( 1 ), libcmis_vector_string_size( failed ) ); + CPPUNIT_ASSERT_EQUAL( string( "failed 1" ), string( libcmis_vector_string_get( failed, 0 ) ) ); + + // Free everything + libcmis_vector_string_free( failed ); + libcmis_error_free( error ); + libcmis_folder_free( tested ); +} + +void FolderTest::removeTreeErrorTest( ) +{ + libcmis_FolderPtr tested = getTested( false, true ); + libcmis_ErrorPtr error = libcmis_error_create( ); + + // Remove the tree (method to test) + libcmis_vector_string_Ptr failed = libcmis_folder_removeTree( + tested, true, libcmis_Delete, true, error ); + + // Check + const char* actualMessage = libcmis_error_getMessage( error ); + CPPUNIT_ASSERT( !string( actualMessage ).empty( ) ); + + // Free everything + libcmis_vector_string_free( failed ); + libcmis_error_free( error ); + libcmis_folder_free( tested ); +} diff --git a/qa/libcmis-c/test-object-type.cxx b/qa/libcmis-c/test-object-type.cxx new file mode 100644 index 0000000..99a0768 --- /dev/null +++ b/qa/libcmis-c/test-object-type.cxx @@ -0,0 +1,377 @@ + +/* libcmis + * Version: MPL 1.1 / GPLv2+ / LGPLv2+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License or as specified alternatively below. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * 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. + * + * Major Contributor(s): + * Copyright (C) 2011 SUSE <cbosdonnat@suse.com> + * + * + * All Rights Reserved. + * + * For minor contributions see the git repository. + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPLv2+"), or + * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"), + * in which case the provisions of the GPLv2+ or the LGPLv2+ are applicable + * instead of those above. + */ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/TestFixture.h> +#include <cppunit/TestAssert.h> + +#include <libcmis-c/error.h> +#include <libcmis-c/object-type.h> +#include <libcmis-c/property-type.h> + +#include "internals.hxx" +#include "test-dummies.hxx" + +using namespace std; + +class ObjectTypeTest : public CppUnit::TestFixture +{ + private: + libcmis_ObjectTypePtr getTested( bool rootType, bool triggersFaults ); + + public: + void getIdTest( ); + void getLocalNameTest( ); + void getLocalNamespaceTest( ); + void getQueryNameTest( ); + void getDisplayNameTest( ); + void getDescriptionTest( ); + void getParentTypeTest( ); + void getParentTypeRootTest( ); + void getParentTypeErrorTest( ); + void getBaseTypeTest( ); + void getBaseTypeErrorTest( ); + void getChildrenTest( ); + void getChildrenErrorTest( ); + void isCreatableTest( ); + void isFileableTest( ); + void isQueryableTest( ); + void isFulltextIndexedTest( ); + void isIncludedInSupertypeQueryTest( ); + void isControllablePolicyTest( ); + void isControllableACLTest( ); + void isVersionableTest( ); + void getContentStreamAllowedTest( ); + void getPropertiesTypesTest( ); + void getPropertyTypeTest( ); + void toStringTest( ); + + // TODO Add more tests + + CPPUNIT_TEST_SUITE( ObjectTypeTest ); + CPPUNIT_TEST( getIdTest ); + CPPUNIT_TEST( getLocalNameTest ); + CPPUNIT_TEST( getLocalNamespaceTest ); + CPPUNIT_TEST( getQueryNameTest ); + CPPUNIT_TEST( getDisplayNameTest ); + CPPUNIT_TEST( getDescriptionTest ); + CPPUNIT_TEST( getParentTypeTest ); + CPPUNIT_TEST( getParentTypeRootTest ); + CPPUNIT_TEST( getParentTypeErrorTest ); + CPPUNIT_TEST( getBaseTypeTest ); + CPPUNIT_TEST( getBaseTypeErrorTest ); + CPPUNIT_TEST( getChildrenTest ); + CPPUNIT_TEST( getChildrenErrorTest ); + CPPUNIT_TEST( isCreatableTest ); + CPPUNIT_TEST( isFileableTest ); + CPPUNIT_TEST( isQueryableTest ); + CPPUNIT_TEST( isFulltextIndexedTest ); + CPPUNIT_TEST( isIncludedInSupertypeQueryTest ); + CPPUNIT_TEST( isControllablePolicyTest ); + CPPUNIT_TEST( isControllableACLTest ); + CPPUNIT_TEST( isVersionableTest ); + CPPUNIT_TEST( getContentStreamAllowedTest ); + CPPUNIT_TEST( getPropertiesTypesTest ); + CPPUNIT_TEST( getPropertyTypeTest ); + CPPUNIT_TEST( toStringTest ); + CPPUNIT_TEST_SUITE_END( ); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION( ObjectTypeTest ); + +libcmis_ObjectTypePtr ObjectTypeTest::getTested( bool rootType, bool triggersFaults ) +{ + libcmis_ObjectTypePtr result = new libcmis_object_type( ); + libcmis::ObjectTypePtr handle( new dummies::ObjectType( rootType, triggersFaults ) ); + result->handle = handle; + + return result; +} + +void ObjectTypeTest::getIdTest( ) +{ + libcmis_ObjectTypePtr tested = getTested( false, false ); + char* id = libcmis_object_type_getId( tested ); + CPPUNIT_ASSERT_EQUAL( + string( "ObjectType::Id" ), + string( id ) ); + free( id ); + libcmis_object_type_free( tested ); +} + +void ObjectTypeTest::getLocalNameTest( ) +{ + libcmis_ObjectTypePtr tested = getTested( false, false ); + char* actual = libcmis_object_type_getLocalName( tested ); + CPPUNIT_ASSERT_EQUAL( + string( "ObjectType::LocalName" ), + string( actual ) ); + free( actual ); + libcmis_object_type_free( tested ); +} + +void ObjectTypeTest::getLocalNamespaceTest( ) +{ + libcmis_ObjectTypePtr tested = getTested( false, false ); + char* actual = libcmis_object_type_getLocalNamespace( tested ); + CPPUNIT_ASSERT_EQUAL( + string( "ObjectType::LocalNamespace" ), + string( actual ) ); + free( actual ); + libcmis_object_type_free( tested ); +} + +void ObjectTypeTest::getQueryNameTest( ) +{ + libcmis_ObjectTypePtr tested = getTested( false, false ); + char* actual = libcmis_object_type_getQueryName( tested ); + CPPUNIT_ASSERT_EQUAL( + string( "ObjectType::QueryName" ), + string( actual ) ); + free( actual ); + libcmis_object_type_free( tested ); +} + +void ObjectTypeTest::getDisplayNameTest( ) +{ + libcmis_ObjectTypePtr tested = getTested( false, false ); + char* actual = libcmis_object_type_getDisplayName( tested ); + CPPUNIT_ASSERT_EQUAL( + string( "ObjectType::DisplayName" ), + string( actual ) ); + free( actual ); + libcmis_object_type_free( tested ); +} + +void ObjectTypeTest::getDescriptionTest( ) +{ + libcmis_ObjectTypePtr tested = getTested( false, false ); + char* actual = libcmis_object_type_getDescription( tested ); + CPPUNIT_ASSERT_EQUAL( + string( "ObjectType::Description" ), + string( actual ) ); + free( actual ); + libcmis_object_type_free( tested ); +} + +void ObjectTypeTest::getParentTypeTest( ) +{ + libcmis_ObjectTypePtr tested = getTested( false, false ); + libcmis_ErrorPtr error = libcmis_error_create( ); + libcmis_ObjectTypePtr parent = libcmis_object_type_getParentType( tested, error ); + + CPPUNIT_ASSERT( NULL == libcmis_error_getMessage( error ) ); + char* id = libcmis_object_type_getId( parent ); + CPPUNIT_ASSERT_EQUAL( string( "ParentType::Id" ), string( id ) ); + free( id ); + + libcmis_error_free( error ); + libcmis_object_type_free( parent ); + libcmis_object_type_free( tested ); +} + +void ObjectTypeTest::getParentTypeRootTest( ) +{ + libcmis_ObjectTypePtr tested = getTested( true, false ); + libcmis_ErrorPtr error = libcmis_error_create( ); + libcmis_ObjectTypePtr parent = libcmis_object_type_getParentType( tested, error ); + + CPPUNIT_ASSERT( NULL == libcmis_error_getMessage( error ) ); + CPPUNIT_ASSERT( NULL == parent ); + + libcmis_error_free( error ); + libcmis_object_type_free( tested ); +} + +void ObjectTypeTest::getParentTypeErrorTest( ) +{ + libcmis_ObjectTypePtr tested = getTested( false, true ); + libcmis_ErrorPtr error = libcmis_error_create( ); + libcmis_ObjectTypePtr parent = libcmis_object_type_getParentType( tested, error ); + + CPPUNIT_ASSERT( NULL != libcmis_error_getMessage( error ) ); + CPPUNIT_ASSERT( NULL == parent ); + + libcmis_error_free( error ); + libcmis_object_type_free( tested ); +} + +void ObjectTypeTest::getBaseTypeTest( ) +{ + libcmis_ObjectTypePtr tested = getTested( false, false ); + libcmis_ErrorPtr error = libcmis_error_create( ); + libcmis_ObjectTypePtr base = libcmis_object_type_getBaseType( tested, error ); + + CPPUNIT_ASSERT( NULL == libcmis_error_getMessage( error ) ); + char* id = libcmis_object_type_getId( base ); + CPPUNIT_ASSERT_EQUAL( string( "RootType::Id" ), string( id ) ); + free( id ); + + libcmis_error_free( error ); + libcmis_object_type_free( base ); + libcmis_object_type_free( tested ); +} + +void ObjectTypeTest::getBaseTypeErrorTest( ) +{ + libcmis_ObjectTypePtr tested = getTested( false, true ); + libcmis_ErrorPtr error = libcmis_error_create( ); + libcmis_ObjectTypePtr base = libcmis_object_type_getBaseType( tested, error ); + + CPPUNIT_ASSERT( NULL != libcmis_error_getMessage( error ) ); + CPPUNIT_ASSERT( NULL == base ); + + libcmis_error_free( error ); + libcmis_object_type_free( tested ); +} + +void ObjectTypeTest::getChildrenTest( ) +{ + libcmis_ObjectTypePtr tested = getTested( false, false ); + libcmis_ErrorPtr error = libcmis_error_create( ); + libcmis_vector_object_type_Ptr children = libcmis_object_type_getChildren( tested, error ); + + CPPUNIT_ASSERT( NULL == libcmis_error_getMessage( error ) ); + size_t size = libcmis_vector_object_type_size( children ); + CPPUNIT_ASSERT_EQUAL( size_t( 2 ), size ); + + libcmis_error_free( error ); + libcmis_vector_object_type_free( children ); + libcmis_object_type_free( tested ); +} + +void ObjectTypeTest::getChildrenErrorTest( ) +{ + libcmis_ObjectTypePtr tested = getTested( false, true ); + libcmis_ErrorPtr error = libcmis_error_create( ); + libcmis_vector_object_type_Ptr children = libcmis_object_type_getChildren( tested, error ); + + CPPUNIT_ASSERT( NULL != libcmis_error_getMessage( error ) ); + CPPUNIT_ASSERT( NULL == children ); + + libcmis_error_free( error ); + libcmis_object_type_free( tested ); +} + +void ObjectTypeTest::isCreatableTest( ) +{ + libcmis_ObjectTypePtr tested = getTested( false, false ); + CPPUNIT_ASSERT( libcmis_object_type_isCreatable( tested ) ); + libcmis_object_type_free( tested ); +} + +void ObjectTypeTest::isFileableTest( ) +{ + libcmis_ObjectTypePtr tested = getTested( false, false ); + CPPUNIT_ASSERT( libcmis_object_type_isFileable( tested ) ); + libcmis_object_type_free( tested ); +} + +void ObjectTypeTest::isQueryableTest( ) +{ + libcmis_ObjectTypePtr tested = getTested( false, false ); + CPPUNIT_ASSERT( libcmis_object_type_isQueryable( tested ) ); + libcmis_object_type_free( tested ); +} + +void ObjectTypeTest::isFulltextIndexedTest( ) +{ + libcmis_ObjectTypePtr tested = getTested( false, false ); + CPPUNIT_ASSERT( libcmis_object_type_isFulltextIndexed( tested ) ); + libcmis_object_type_free( tested ); +} + +void ObjectTypeTest::isIncludedInSupertypeQueryTest( ) +{ + libcmis_ObjectTypePtr tested = getTested( false, false ); + CPPUNIT_ASSERT( libcmis_object_type_isIncludedInSupertypeQuery( tested ) ); + libcmis_object_type_free( tested ); +} + +void ObjectTypeTest::isControllablePolicyTest( ) +{ + libcmis_ObjectTypePtr tested = getTested( false, false ); + CPPUNIT_ASSERT( libcmis_object_type_isControllablePolicy( tested ) ); + libcmis_object_type_free( tested ); +} + +void ObjectTypeTest::isControllableACLTest( ) +{ + libcmis_ObjectTypePtr tested = getTested( false, false ); + CPPUNIT_ASSERT( libcmis_object_type_isControllableACL( tested ) ); + libcmis_object_type_free( tested ); +} + +void ObjectTypeTest::isVersionableTest( ) +{ + libcmis_ObjectTypePtr tested = getTested( false, false ); + CPPUNIT_ASSERT( libcmis_object_type_isVersionable( tested ) ); + libcmis_object_type_free( tested ); +} + +void ObjectTypeTest::getContentStreamAllowedTest( ) +{ + libcmis_ObjectTypePtr tested = getTested( false, false ); + CPPUNIT_ASSERT_EQUAL( + libcmis_Allowed, + libcmis_object_type_getContentStreamAllowed( tested ) ); + libcmis_object_type_free( tested ); +} + +void ObjectTypeTest::getPropertiesTypesTest( ) +{ + libcmis_ObjectTypePtr tested = getTested( false, false ); + libcmis_vector_property_type_Ptr propertiesTypes = libcmis_object_type_getPropertiesTypes( tested ); + CPPUNIT_ASSERT_EQUAL( size_t( 3 ), libcmis_vector_property_type_size( propertiesTypes ) ); + libcmis_vector_property_type_free( propertiesTypes ); + libcmis_object_type_free( tested ); +} + +void ObjectTypeTest::getPropertyTypeTest( ) +{ + libcmis_ObjectTypePtr tested = getTested( false, false ); + string id( "Property2" ); + libcmis_PropertyTypePtr propertyType = libcmis_object_type_getPropertyType( tested, id.c_str( ) ); + char* propertyId = libcmis_property_type_getId( propertyType ); + CPPUNIT_ASSERT_EQUAL( id, string( propertyId ) ); + free( propertyId ); + libcmis_property_type_free( propertyType ); + libcmis_object_type_free( tested ); +} + +void ObjectTypeTest::toStringTest( ) +{ + libcmis_ObjectTypePtr tested = getTested( false, false ); + char* actual = libcmis_object_type_toString( tested ); + CPPUNIT_ASSERT_EQUAL( + string( "ObjectType::toString" ), + string( actual ) ); + free( actual ); + libcmis_object_type_free( tested ); +} diff --git a/qa/libcmis-c/test-object.cxx b/qa/libcmis-c/test-object.cxx new file mode 100644 index 0000000..1b7324b --- /dev/null +++ b/qa/libcmis-c/test-object.cxx @@ -0,0 +1,425 @@ +/* libcmis + * Version: MPL 1.1 / GPLv2+ / LGPLv2+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License or as specified alternatively below. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * 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. + * + * Major Contributor(s): + * Copyright (C) 2011 SUSE <cbosdonnat@suse.com> + * + * + * All Rights Reserved. + * + * For minor contributions see the git repository. + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPLv2+"), or + * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"), + * in which case the provisions of the GPLv2+ or the LGPLv2+ are applicable + * instead of those above. + */ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/TestFixture.h> +#include <cppunit/TestAssert.h> + +#include <libcmis-c/allowable-actions.h> +#include <libcmis-c/error.h> +#include <libcmis-c/folder.h> +#include <libcmis-c/object.h> +#include <libcmis-c/object-type.h> +#include <libcmis-c/property.h> +#include <libcmis-c/property-type.h> +#include <libcmis-c/vectors.h> + +#include "internals.hxx" +#include "test-dummies.hxx" + +using namespace std; + +class ObjectTest : public CppUnit::TestFixture +{ + private: + libcmis_ObjectPtr getTested( bool triggersFaults ); + libcmis_FolderPtr getTestFolder( ); + + public: + void getIdTest( ); + void getNameTest( ); + void getPathsTest( ); + void getBaseTypeTest( ); + void getTypeTest( ); + void getCreatedByTest( ); + void getCreationDateTest( ); + void getLastModifiedByTest( ); + void getLastModificationDateTest( ); + void getChangeTokenTest( ); + void isImmutableTest( ); + void getPropertiesTest( ); + void getPropertyTest( ); + void getPropertyMissingTest( ); + void updatePropertiesTest( ); + void updatePropertiesErrorTest( ); + void getTypeDescriptionTest( ); + void getAllowableActionsTest( ); + void refreshTest( ); + void refreshErrorTest( ); + void removeTest( ); + void removeErrorTest( ); + void moveTest( ); + void moveErrorTest( ); + void toStringTest( ); + + CPPUNIT_TEST_SUITE( ObjectTest ); + CPPUNIT_TEST( getIdTest ); + CPPUNIT_TEST( getNameTest ); + CPPUNIT_TEST( getPathsTest ); + CPPUNIT_TEST( getBaseTypeTest ); + CPPUNIT_TEST( getTypeTest ); + CPPUNIT_TEST( getCreatedByTest ); + CPPUNIT_TEST( getCreationDateTest ); + CPPUNIT_TEST( getLastModifiedByTest ); + CPPUNIT_TEST( getLastModificationDateTest ); + CPPUNIT_TEST( getChangeTokenTest ); + CPPUNIT_TEST( isImmutableTest ); + CPPUNIT_TEST( getPropertiesTest ); + CPPUNIT_TEST( getPropertyTest ); + CPPUNIT_TEST( getPropertyMissingTest ); + CPPUNIT_TEST( updatePropertiesTest ); + CPPUNIT_TEST( updatePropertiesErrorTest ); + CPPUNIT_TEST( getTypeDescriptionTest ); + CPPUNIT_TEST( getAllowableActionsTest ); + CPPUNIT_TEST( refreshTest ); + CPPUNIT_TEST( refreshErrorTest ); + CPPUNIT_TEST( removeTest ); + CPPUNIT_TEST( removeErrorTest ); + CPPUNIT_TEST( moveTest ); + CPPUNIT_TEST( moveErrorTest ); + CPPUNIT_TEST( toStringTest ); + CPPUNIT_TEST_SUITE_END( ); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION( ObjectTest ); + +libcmis_ObjectPtr ObjectTest::getTested( bool triggersFaults ) +{ + libcmis_ObjectPtr result = new libcmis_object( ); + libcmis::ObjectPtr handle( new dummies::Object( triggersFaults ) ); + result->handle = handle; + + return result; +} + +libcmis_FolderPtr ObjectTest::getTestFolder( ) +{ + libcmis_FolderPtr result = new libcmis_folder( ); + libcmis::FolderPtr handle( new dummies::Folder( false, false ) ); + result->handle = handle; + + return result; +} + +void ObjectTest::getIdTest( ) +{ + libcmis_ObjectPtr tested = getTested( false ); + char* actual = libcmis_object_getId( tested ); + CPPUNIT_ASSERT_EQUAL( string( "Object::Id" ), string( actual ) ); + free( actual ); + libcmis_object_free( tested ); +} + +void ObjectTest::getNameTest( ) +{ + libcmis_ObjectPtr tested = getTested( false ); + char* actual = libcmis_object_getName( tested ); + CPPUNIT_ASSERT_EQUAL( string( "Object::Name" ), string( actual ) ); + free( actual ); + libcmis_object_free( tested ); +} + +void ObjectTest::getPathsTest( ) +{ + libcmis_ObjectPtr tested = getTested( false ); + libcmis_vector_string_Ptr actual = libcmis_object_getPaths( tested ); + CPPUNIT_ASSERT_EQUAL( size_t( 2 ), libcmis_vector_string_size( actual ) ); + CPPUNIT_ASSERT_EQUAL( + string( "/Path1/" ), + string( libcmis_vector_string_get( actual, 0 ) ) ); + libcmis_vector_string_free( actual ); + libcmis_object_free( tested ); +} + +void ObjectTest::getBaseTypeTest( ) +{ + libcmis_ObjectPtr tested = getTested( false ); + char* actual = libcmis_object_getBaseType( tested ); + CPPUNIT_ASSERT_EQUAL( string( "Object::BaseType" ), string( actual ) ); + free( actual ); + libcmis_object_free( tested ); +} + +void ObjectTest::getTypeTest( ) +{ + libcmis_ObjectPtr tested = getTested( false ); + char* actual = libcmis_object_getType( tested ); + CPPUNIT_ASSERT_EQUAL( string( "Object::Type" ), string( actual ) ); + free( actual ); + libcmis_object_free( tested ); +} + +void ObjectTest::getCreatedByTest( ) +{ + libcmis_ObjectPtr tested = getTested( false ); + char* actual = libcmis_object_getCreatedBy( tested ); + CPPUNIT_ASSERT_EQUAL( string( "Object::CreatedBy" ), string( actual ) ); + free( actual ); + libcmis_object_free( tested ); +} + +void ObjectTest::getCreationDateTest( ) +{ + libcmis_ObjectPtr tested = getTested( false ); + time_t actual = libcmis_object_getCreationDate( tested ); + CPPUNIT_ASSERT( 0 != actual ); + libcmis_object_free( tested ); +} + +void ObjectTest::getLastModifiedByTest( ) +{ + libcmis_ObjectPtr tested = getTested( false ); + char* actual = libcmis_object_getLastModifiedBy( tested ); + CPPUNIT_ASSERT_EQUAL( string( "Object::LastModifiedBy" ), string( actual ) ); + free( actual ); + libcmis_object_free( tested ); +} + +void ObjectTest::getLastModificationDateTest( ) +{ + libcmis_ObjectPtr tested = getTested( false ); + time_t actual = libcmis_object_getLastModificationDate( tested ); + CPPUNIT_ASSERT( 0 != actual ); + libcmis_object_free( tested ); +} + +void ObjectTest::getChangeTokenTest( ) +{ + libcmis_ObjectPtr tested = getTested( false ); + char* actual = libcmis_object_getChangeToken( tested ); + CPPUNIT_ASSERT_EQUAL( string( "Object::ChangeToken" ), string( actual ) ); + free( actual ); + libcmis_object_free( tested ); +} + +void ObjectTest::isImmutableTest( ) +{ + libcmis_ObjectPtr tested = getTested( false ); + CPPUNIT_ASSERT( libcmis_object_isImmutable( tested ) ); + libcmis_object_free( tested ); +} + +void ObjectTest::getPropertiesTest( ) +{ + libcmis_ObjectPtr tested = getTested( false ); + libcmis_vector_property_Ptr actual = libcmis_object_getProperties( tested ); + CPPUNIT_ASSERT_EQUAL( size_t( 1 ), libcmis_vector_property_size( actual ) ); + libcmis_vector_property_free( actual ); + libcmis_object_free( tested ); +} + +void ObjectTest::getPropertyTest( ) +{ + libcmis_ObjectPtr tested = getTested( false ); + const char* id = "Property1"; + libcmis_PropertyPtr actual = libcmis_object_getProperty( tested, id ); + CPPUNIT_ASSERT( NULL != actual ); + libcmis_property_free( actual ); + libcmis_object_free( tested ); +} + +void ObjectTest::getPropertyMissingTest( ) +{ + libcmis_ObjectPtr tested = getTested( false ); + const char* id = "MissingProperty"; + libcmis_PropertyPtr actual = libcmis_object_getProperty( tested, id ); + CPPUNIT_ASSERT( NULL == actual ); + libcmis_property_free( actual ); + libcmis_object_free( tested ); +} + +void ObjectTest::updatePropertiesTest( ) +{ + libcmis_ObjectPtr tested = getTested( false ); + CPPUNIT_ASSERT_MESSAGE( "Timestamp not set to 0 initially", 0 == libcmis_object_getRefreshTimestamp( tested ) ); + libcmis_ErrorPtr error = libcmis_error_create( ); + + // Create the changed properties map + libcmis_vector_property_Ptr newProperties = libcmis_vector_property_create( ); + libcmis_ObjectTypePtr objectType = libcmis_object_getTypeDescription( tested ); + libcmis_PropertyTypePtr propertyType = libcmis_object_type_getPropertyType( objectType, "cmis:Property2" ); + size_t size = 2; + const char** values = new const char*[size]; + values[0] = "Value 1"; + values[1] = "Value 2"; + libcmis_PropertyPtr newProperty = libcmis_property_create( propertyType, values, size ); + delete[ ] values; + libcmis_vector_property_append( newProperties, newProperty ); + + // Update the properties (method under test) + libcmis_ObjectPtr updated = libcmis_object_updateProperties( tested, newProperties, error ); + + // Checks + CPPUNIT_ASSERT_MESSAGE( "Timestamp not updated", 0 != libcmis_object_getRefreshTimestamp( tested ) ); + CPPUNIT_ASSERT( updated != NULL ); + + // Free it all + libcmis_object_free( updated ); + libcmis_property_free( newProperty ); + libcmis_property_type_free( propertyType ); + libcmis_object_type_free( objectType ); + libcmis_vector_property_free( newProperties ); + libcmis_error_free( error ); + libcmis_object_free( tested ); +} + +void ObjectTest::updatePropertiesErrorTest( ) +{ + libcmis_ObjectPtr tested = getTested( true ); + CPPUNIT_ASSERT_MESSAGE( "Timestamp not set to 0 initially", 0 == libcmis_object_getRefreshTimestamp( tested ) ); + libcmis_ErrorPtr error = libcmis_error_create( ); + + // Create the changed properties map + libcmis_vector_property_Ptr newProperties = libcmis_vector_property_create( ); + libcmis_ObjectTypePtr objectType = libcmis_object_getTypeDescription( tested ); + libcmis_PropertyTypePtr propertyType = libcmis_object_type_getPropertyType( objectType, "cmis:Property2" ); + size_t size = 2; + const char** values = new const char*[size]; + values[0] = "Value 1"; + values[1] = "Value 2"; + libcmis_PropertyPtr newProperty = libcmis_property_create( propertyType, values, size ); + delete[ ] values; + libcmis_vector_property_append( newProperties, newProperty ); + + // Update the properties (method under test) + libcmis_ObjectPtr updated = libcmis_object_updateProperties( tested, newProperties, error ); + + // Checks + CPPUNIT_ASSERT( updated == NULL ); + const char* actualMessage = libcmis_error_getMessage( error ); + CPPUNIT_ASSERT( !string( actualMessage ).empty( ) ); + + // Free it all + libcmis_object_free( updated ); + libcmis_property_free( newProperty ); + libcmis_property_type_free( propertyType ); + libcmis_object_type_free( objectType ); + libcmis_vector_property_free( newProperties ); + libcmis_error_free( error ); + libcmis_object_free( tested ); +} + +void ObjectTest::getTypeDescriptionTest( ) +{ + libcmis_ObjectPtr tested = getTested( false ); + libcmis_ObjectTypePtr actual = libcmis_object_getTypeDescription( tested ); + char* actualId = libcmis_object_type_getId( actual ); + CPPUNIT_ASSERT( !string( actualId ).empty( ) ); + free( actualId ); + libcmis_object_type_free( actual ); + libcmis_object_free( tested ); +} + +void ObjectTest::getAllowableActionsTest( ) +{ + libcmis_ObjectPtr tested = getTested( false ); + libcmis_AllowableActionsPtr actual = libcmis_object_getAllowableActions( tested ); + CPPUNIT_ASSERT( libcmis_allowable_actions_isDefined( actual, libcmis_GetFolderParent ) ); + libcmis_allowable_actions_free( actual ); + libcmis_object_free( tested ); +} + +void ObjectTest::refreshTest( ) +{ + libcmis_ObjectPtr tested = getTested( false ); + CPPUNIT_ASSERT_MESSAGE( "Timestamp not set to 0 initially", 0 == libcmis_object_getRefreshTimestamp( tested ) ); + libcmis_ErrorPtr error = libcmis_error_create( ); + libcmis_object_refresh( tested, error ); + CPPUNIT_ASSERT_MESSAGE( "Timestamp not updated", 0 != libcmis_object_getRefreshTimestamp( tested ) ); + libcmis_error_free( error ); + libcmis_object_free( tested ); +} + +void ObjectTest::refreshErrorTest( ) +{ + libcmis_ObjectPtr tested = getTested( true ); + CPPUNIT_ASSERT_MESSAGE( "Timestamp not set to 0 initially", 0 == libcmis_object_getRefreshTimestamp( tested ) ); + libcmis_ErrorPtr error = libcmis_error_create( ); + libcmis_object_refresh( tested, error ); + const char* actualMessage = libcmis_error_getMessage( error ); + CPPUNIT_ASSERT( !string( actualMessage ).empty( ) ); + libcmis_error_free( error ); + libcmis_object_free( tested ); +} + +void ObjectTest::removeTest( ) +{ + libcmis_ObjectPtr tested = getTested( false ); + CPPUNIT_ASSERT_MESSAGE( "Timestamp not set to 0 initially", 0 == libcmis_object_getRefreshTimestamp( tested ) ); + libcmis_ErrorPtr error = libcmis_error_create( ); + libcmis_object_remove( tested, true, error ); + CPPUNIT_ASSERT_MESSAGE( "Timestamp not updated", 0 != libcmis_object_getRefreshTimestamp( tested ) ); + libcmis_error_free( error ); + libcmis_object_free( tested ); +} + +void ObjectTest::removeErrorTest( ) +{ + libcmis_ObjectPtr tested = getTested( true ); + CPPUNIT_ASSERT_MESSAGE( "Timestamp not set to 0 initially", 0 == libcmis_object_getRefreshTimestamp( tested ) ); + libcmis_ErrorPtr error = libcmis_error_create( ); + libcmis_object_remove( tested, true, error ); + const char* actualMessage = libcmis_error_getMessage( error ); + CPPUNIT_ASSERT( !string( actualMessage ).empty( ) ); + libcmis_error_free( error ); + libcmis_object_free( tested ); +} + +void ObjectTest::moveTest( ) +{ + libcmis_ObjectPtr tested = getTested( false ); + CPPUNIT_ASSERT_MESSAGE( "Timestamp not set to 0 initially", 0 == libcmis_object_getRefreshTimestamp( tested ) ); + libcmis_ErrorPtr error = libcmis_error_create( ); + + // Move the object from source to dest (tested method) + libcmis_FolderPtr source = getTestFolder( ); + libcmis_FolderPtr dest = getTestFolder( ); + libcmis_object_move( tested, source, dest, error ); + + // Check + CPPUNIT_ASSERT_MESSAGE( "Timestamp not updated", 0 != libcmis_object_getRefreshTimestamp( tested ) ); + + // Free it all + libcmis_folder_free( dest ); + libcmis_folder_free( source ); + libcmis_error_free( error ); + libcmis_object_free( tested ); +} + +void ObjectTest::moveErrorTest( ) +{ +} + +void ObjectTest::toStringTest( ) +{ + libcmis_ObjectPtr tested = getTested( false ); + char* actual = libcmis_object_toString( tested ); + CPPUNIT_ASSERT_EQUAL( string( "Object::toString" ), string( actual ) ); + free( actual ); + libcmis_object_free( tested ); +} diff --git a/qa/libcmis-c/test-property-type.cxx b/qa/libcmis-c/test-property-type.cxx new file mode 100644 index 0000000..c8832f6 --- /dev/null +++ b/qa/libcmis-c/test-property-type.cxx @@ -0,0 +1,251 @@ +/* libcmis + * Version: MPL 1.1 / GPLv2+ / LGPLv2+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License or as specified alternatively below. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * 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. + * + * Major Contributor(s): + * Copyright (C) 2011 SUSE <cbosdonnat@suse.com> + * + * + * All Rights Reserved. + * + * For minor contributions see the git repository. + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPLv2+"), or + * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"), + * in which case the provisions of the GPLv2+ or the LGPLv2+ are applicable + * instead of those above. + */ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/TestFixture.h> +#include <cppunit/TestAssert.h> + +#include <libcmis-c/property-type.h> + +#include "internals.hxx" +#include "test-dummies.hxx" + +using namespace std; + +class PropertyTypeTest : public CppUnit::TestFixture +{ + private: + libcmis_PropertyTypePtr getTested( string id, string xmlType ); + + public: + void getIdTest( ); + void getLocalNameTest( ); + void getLocalNamespaceTest( ); + void getDisplayNameTest( ); + void getQueryNameTest( ); + void getTypeTest( ); + void isMultiValuedTest( ); + void isUpdatableTest( ); + void isInheritedTest( ); + void isRequiredTest( ); + void isQueryableTest( ); + void isOrderableTest( ); + void isOpenChoiceTest( ); + + CPPUNIT_TEST_SUITE( PropertyTypeTest ); + CPPUNIT_TEST( getIdTest ); + CPPUNIT_TEST( getLocalNameTest ); + CPPUNIT_TEST( getLocalNamespaceTest ); + CPPUNIT_TEST( getDisplayNameTest ); + CPPUNIT_TEST( getQueryNameTest ); + CPPUNIT_TEST( getTypeTest ); + CPPUNIT_TEST( isMultiValuedTest ); + CPPUNIT_TEST( isUpdatableTest ); + CPPUNIT_TEST( isInheritedTest ); + CPPUNIT_TEST( isRequiredTest ); + CPPUNIT_TEST( isQueryableTest ); + CPPUNIT_TEST( isOrderableTest ); + CPPUNIT_TEST( isOpenChoiceTest ); + CPPUNIT_TEST_SUITE_END( ); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION( PropertyTypeTest ); + +libcmis_PropertyTypePtr PropertyTypeTest::getTested( string id, string xmlType ) +{ + libcmis_PropertyTypePtr result = new libcmis_property_type( ); + libcmis::PropertyTypePtr handle( new dummies::PropertyType( id, xmlType ) ); + result->handle = handle; + + return result; +} + +void PropertyTypeTest::getIdTest( ) +{ + string id( "Id" ); + libcmis_PropertyTypePtr tested = getTested( id, "string" ); + char* actual = libcmis_property_type_getId( tested ); + CPPUNIT_ASSERT_EQUAL( id, string( actual ) ); + + free( actual ); + libcmis_property_type_free( tested ); +} + +void PropertyTypeTest::getLocalNameTest( ) +{ + libcmis_PropertyTypePtr tested = getTested( "id", "string" ); + char* actual = libcmis_property_type_getLocalName( tested ); + CPPUNIT_ASSERT_EQUAL( string( "PropertyType::LocalName" ), string( actual ) ); + + free( actual ); + libcmis_property_type_free( tested ); +} + +void PropertyTypeTest::getLocalNamespaceTest( ) +{ + libcmis_PropertyTypePtr tested = getTested( "id", "string" ); + char* actual = libcmis_property_type_getLocalNamespace( tested ); + CPPUNIT_ASSERT_EQUAL( string( "PropertyType::LocalNamespace" ), string( actual ) ); + + free( actual ); + libcmis_property_type_free( tested ); +} + +void PropertyTypeTest::getDisplayNameTest( ) +{ + libcmis_PropertyTypePtr tested = getTested( "id", "string" ); + char* actual = libcmis_property_type_getDisplayName( tested ); + CPPUNIT_ASSERT_EQUAL( string( "PropertyType::DisplayName" ), string( actual ) ); + + free( actual ); + libcmis_property_type_free( tested ); +} + +void PropertyTypeTest::getQueryNameTest( ) +{ + libcmis_PropertyTypePtr tested = getTested( "id", "string" ); + char* actual = libcmis_property_type_getQueryName( tested ); + CPPUNIT_ASSERT_EQUAL( string( "PropertyType::QueryName" ), string( actual ) ); + + free( actual ); + libcmis_property_type_free( tested ); +} + +void PropertyTypeTest::getTypeTest( ) +{ + // String + { + libcmis_PropertyTypePtr tested = getTested( "id", "string" ); + libcmis_property_type_Type actualType = libcmis_property_type_getType( tested ); + CPPUNIT_ASSERT_EQUAL( libcmis_String, actualType ); + char* actualXml = libcmis_property_type_getXmlType( tested ); + CPPUNIT_ASSERT_EQUAL( string( "String" ), string( actualXml ) ); + + free( actualXml ); + libcmis_property_type_free( tested ); + } + + // DateTime + { + libcmis_PropertyTypePtr tested = getTested( "id", "datetime" ); + libcmis_property_type_Type actualType = libcmis_property_type_getType( tested ); + CPPUNIT_ASSERT_EQUAL( libcmis_DateTime, actualType ); + char* actualXml = libcmis_property_type_getXmlType( tested ); + CPPUNIT_ASSERT_EQUAL( string( "DateTime" ), string( actualXml ) ); + + free( actualXml ); + libcmis_property_type_free( tested ); + } + + // Integer + { + libcmis_PropertyTypePtr tested = getTested( "id", "integer" ); + libcmis_property_type_Type actualType = libcmis_property_type_getType( tested ); + CPPUNIT_ASSERT_EQUAL( libcmis_Integer, actualType ); + char* actualXml = libcmis_property_type_getXmlType( tested ); + CPPUNIT_ASSERT_EQUAL( string( "Integer" ), string( actualXml ) ); + + free( actualXml ); + libcmis_property_type_free( tested ); + } + + // Html + { + libcmis_PropertyTypePtr tested = getTested( "id", "html" ); + libcmis_property_type_Type actualType = libcmis_property_type_getType( tested ); + CPPUNIT_ASSERT_EQUAL( libcmis_String, actualType ); + char* actualXml = libcmis_property_type_getXmlType( tested ); + CPPUNIT_ASSERT_EQUAL( string( "Html" ), string( actualXml ) ); + + free( actualXml ); + libcmis_property_type_free( tested ); + } +} + +void PropertyTypeTest::isMultiValuedTest( ) +{ + libcmis_PropertyTypePtr tested = getTested( "id", "string" ); + bool actual = libcmis_property_type_isMultiValued( tested ); + CPPUNIT_ASSERT_EQUAL( true , actual ); + + libcmis_property_type_free( tested ); +} + +void PropertyTypeTest::isUpdatableTest( ) +{ + libcmis_PropertyTypePtr tested = getTested( "id", "string" ); + bool actual = libcmis_property_type_isUpdatable( tested ); + CPPUNIT_ASSERT_EQUAL( true , actual ); + + libcmis_property_type_free( tested ); +} + +void PropertyTypeTest::isInheritedTest( ) +{ + libcmis_PropertyTypePtr tested = getTested( "id", "string" ); + bool actual = libcmis_property_type_isInherited( tested ); + CPPUNIT_ASSERT_EQUAL( true , actual ); + + libcmis_property_type_free( tested ); +} + +void PropertyTypeTest::isRequiredTest( ) +{ + libcmis_PropertyTypePtr tested = getTested( "id", "string" ); + bool actual = libcmis_property_type_isRequired( tested ); + CPPUNIT_ASSERT_EQUAL( true , actual ); + + libcmis_property_type_free( tested ); +} + +void PropertyTypeTest::isQueryableTest( ) +{ + libcmis_PropertyTypePtr tested = getTested( "id", "string" ); + bool actual = libcmis_property_type_isQueryable( tested ); + CPPUNIT_ASSERT_EQUAL( true , actual ); + + libcmis_property_type_free( tested ); +} + +void PropertyTypeTest::isOrderableTest( ) +{ + libcmis_PropertyTypePtr tested = getTested( "id", "string" ); + bool actual = libcmis_property_type_isOrderable( tested ); + CPPUNIT_ASSERT_EQUAL( true , actual ); + + libcmis_property_type_free( tested ); +} + +void PropertyTypeTest::isOpenChoiceTest( ) +{ + libcmis_PropertyTypePtr tested = getTested( "id", "string" ); + bool actual = libcmis_property_type_isOpenChoice( tested ); + CPPUNIT_ASSERT_EQUAL( true , actual ); + + libcmis_property_type_free( tested ); +} diff --git a/qa/libcmis-c/test-property.cxx b/qa/libcmis-c/test-property.cxx new file mode 100644 index 0000000..99c9b2c --- /dev/null +++ b/qa/libcmis-c/test-property.cxx @@ -0,0 +1,242 @@ +/* libcmis + * Version: MPL 1.1 / GPLv2+ / LGPLv2+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License or as specified alternatively below. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * 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. + * + * Major Contributor(s): + * Copyright (C) 2011 SUSE <cbosdonnat@suse.com> + * + * + * All Rights Reserved. + * + * For minor contributions see the git repository. + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPLv2+"), or + * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"), + * in which case the provisions of the GPLv2+ or the LGPLv2+ are applicable + * instead of those above. + */ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/TestFixture.h> +#include <cppunit/TestAssert.h> + +#include <libcmis-c/property.h> +#include <libcmis-c/property-type.h> +#include <libcmis-c/vectors.h> + +#include "internals.hxx" +#include "test-dummies.hxx" + +using namespace std; + +class PropertyTest : public CppUnit::TestFixture +{ + private: + libcmis_PropertyTypePtr getTestType( string xmlType ); + + public: + void getDateTimesTest( ); + void getBoolsTest( ); + void getStringsTest( ); + void getLongsTest( ); + void getDoublesTest( ); + void setValuesTest( ); + + CPPUNIT_TEST_SUITE( PropertyTest ); + CPPUNIT_TEST( getDateTimesTest ); + CPPUNIT_TEST( getBoolsTest ); + CPPUNIT_TEST( getStringsTest ); + CPPUNIT_TEST( getLongsTest ); + CPPUNIT_TEST( getDoublesTest ); + CPPUNIT_TEST( setValuesTest ); + CPPUNIT_TEST_SUITE_END( ); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION( PropertyTest ); + +libcmis_PropertyTypePtr PropertyTest::getTestType( string xmlType ) +{ + libcmis_PropertyTypePtr result = new libcmis_property_type( ); + libcmis::PropertyTypePtr handle( new dummies::PropertyType( "Id", xmlType ) ); + result->handle = handle; + + return result; +} + +void PropertyTest::getDateTimesTest( ) +{ + libcmis_PropertyTypePtr type = getTestType( "datetime" ); + size_t size = 2; + const char** values = new const char*[size]; + values[0] = "2012-01-19T09:06:57.388Z"; + values[1] = "2012-02-19T09:06:57.388Z"; + libcmis_PropertyPtr tested = libcmis_property_create( type, values, size ); + + libcmis_vector_time_Ptr times = libcmis_property_getDateTimes( tested ); + CPPUNIT_ASSERT_EQUAL( size, libcmis_vector_time_size( times ) ); + libcmis_vector_time_free( times ); + + libcmis_vector_string_Ptr strings = libcmis_property_getStrings( tested ); + CPPUNIT_ASSERT_EQUAL( size, libcmis_vector_string_size( strings ) ); + CPPUNIT_ASSERT_EQUAL( string( values[1] ), string( libcmis_vector_string_get( strings, 1 ) ) ); + libcmis_vector_string_free( strings ); + delete[] values; + + libcmis_vector_bool_Ptr bools = libcmis_property_getBools( tested ); + CPPUNIT_ASSERT_EQUAL( size_t( 0 ), libcmis_vector_bool_size( bools ) ); + libcmis_vector_bool_free( bools ); + + libcmis_property_free( tested ); + libcmis_property_type_free( type ); +} + +void PropertyTest::getBoolsTest( ) +{ + libcmis_PropertyTypePtr type = getTestType( "boolean" ); + size_t size = 2; + const char** values = new const char*[size]; + values[0] = "true"; + values[1] = "false"; + libcmis_PropertyPtr tested = libcmis_property_create( type, values, size ); + + libcmis_vector_bool_Ptr bools = libcmis_property_getBools( tested ); + CPPUNIT_ASSERT_EQUAL( size, libcmis_vector_bool_size( bools ) ); + CPPUNIT_ASSERT_EQUAL( true, libcmis_vector_bool_get( bools, 0 ) ); + CPPUNIT_ASSERT_EQUAL( false, libcmis_vector_bool_get( bools, 1 ) ); + libcmis_vector_bool_free( bools ); + + libcmis_vector_string_Ptr strings = libcmis_property_getStrings( tested ); + CPPUNIT_ASSERT_EQUAL( size, libcmis_vector_string_size( strings ) ); + CPPUNIT_ASSERT_EQUAL( string( values[1] ), string( libcmis_vector_string_get( strings, 1 ) ) ); + libcmis_vector_string_free( strings ); + delete[] values; + + libcmis_vector_long_Ptr longs = libcmis_property_getLongs( tested ); + CPPUNIT_ASSERT_EQUAL( size_t( 0 ), libcmis_vector_long_size( longs ) ); + libcmis_vector_long_free( longs ); + + libcmis_property_free( tested ); + libcmis_property_type_free( type ); +} + + +void PropertyTest::getStringsTest( ) +{ + libcmis_PropertyTypePtr type = getTestType( "string" ); + size_t size = 2; + const char** values = new const char*[size]; + values[0] = "string 1"; + values[1] = "string 2"; + libcmis_PropertyPtr tested = libcmis_property_create( type, values, size ); + + libcmis_vector_string_Ptr strings = libcmis_property_getStrings( tested ); + CPPUNIT_ASSERT_EQUAL( size, libcmis_vector_string_size( strings ) ); + CPPUNIT_ASSERT_EQUAL( string( values[0] ), string( libcmis_vector_string_get( strings, 0 ) ) ); + CPPUNIT_ASSERT_EQUAL( string( values[1] ), string( libcmis_vector_string_get( strings, 1 ) ) ); + libcmis_vector_string_free( strings ); + delete[] values; + + libcmis_vector_double_Ptr doubles = libcmis_property_getDoubles( tested ); + CPPUNIT_ASSERT_EQUAL( size_t( 0 ), libcmis_vector_double_size( doubles ) ); + libcmis_vector_double_free( doubles ); + + libcmis_property_free( tested ); + libcmis_property_type_free( type ); +} + + +void PropertyTest::getLongsTest( ) +{ + libcmis_PropertyTypePtr type = getTestType( "integer" ); + size_t size = 2; + const char** values = new const char*[size]; + values[0] = "123456"; + values[1] = "789"; + libcmis_PropertyPtr tested = libcmis_property_create( type, values, size ); + + libcmis_vector_long_Ptr longs = libcmis_property_getLongs( tested ); + CPPUNIT_ASSERT_EQUAL( size, libcmis_vector_long_size( longs ) ); + CPPUNIT_ASSERT_EQUAL( long( 123456 ), libcmis_vector_long_get( longs, 0 ) ); + CPPUNIT_ASSERT_EQUAL( long( 789 ), libcmis_vector_long_get( longs, 1 ) ); + libcmis_vector_long_free( longs ); + + libcmis_vector_string_Ptr strings = libcmis_property_getStrings( tested ); + CPPUNIT_ASSERT_EQUAL( size, libcmis_vector_string_size( strings ) ); + CPPUNIT_ASSERT_EQUAL( string( values[1] ), string( libcmis_vector_string_get( strings, 1 ) ) ); + libcmis_vector_string_free( strings ); + delete[] values; + + libcmis_vector_time_Ptr times = libcmis_property_getDateTimes( tested ); + CPPUNIT_ASSERT_EQUAL( size_t( 0 ), libcmis_vector_time_size( times ) ); + libcmis_vector_time_free( times ); + + libcmis_property_free( tested ); + libcmis_property_type_free( type ); +} + + +void PropertyTest::getDoublesTest( ) +{ + libcmis_PropertyTypePtr type = getTestType( "decimal" ); + size_t size = 2; + const char** values = new const char*[size]; + values[0] = "123.456"; + values[1] = "7.89"; + libcmis_PropertyPtr tested = libcmis_property_create( type, values, size ); + + libcmis_vector_double_Ptr doubles = libcmis_property_getDoubles( tested ); + CPPUNIT_ASSERT_EQUAL( size, libcmis_vector_double_size( doubles ) ); + CPPUNIT_ASSERT_EQUAL( 123.456, libcmis_vector_double_get( doubles, 0 ) ); + CPPUNIT_ASSERT_EQUAL( 7.89, libcmis_vector_double_get( doubles, 1 ) ); + libcmis_vector_double_free( doubles ); + + libcmis_vector_string_Ptr strings = libcmis_property_getStrings( tested ); + CPPUNIT_ASSERT_EQUAL( size, libcmis_vector_string_size( strings ) ); + CPPUNIT_ASSERT_EQUAL( string( values[1] ), string( libcmis_vector_string_get( strings, 1 ) ) ); + libcmis_vector_string_free( strings ); + delete[] values; + + libcmis_vector_long_Ptr longs = libcmis_property_getLongs( tested ); + CPPUNIT_ASSERT_EQUAL( size_t( 0 ), libcmis_vector_long_size( longs ) ); + libcmis_vector_long_free( longs ); + + libcmis_property_free( tested ); + libcmis_property_type_free( type ); +} + + +void PropertyTest::setValuesTest( ) +{ + libcmis_PropertyTypePtr type = getTestType( "string" ); + size_t size = 1; + const char** values = new const char*[size]; + values[0] = "string 1"; + libcmis_PropertyPtr tested = libcmis_property_create( type, values, size ); + delete[] values; + + size_t newSize = 2; + const char** newValues = new const char*[newSize]; + newValues[0] = "new string 1"; + newValues[1] = "new string 2"; + libcmis_property_setValues( tested, newValues, newSize ); + + libcmis_vector_string_Ptr newStrings = libcmis_property_getStrings( tested ); + CPPUNIT_ASSERT_EQUAL( newSize, libcmis_vector_string_size( newStrings ) ); + CPPUNIT_ASSERT_EQUAL( string( newValues[0] ), string( libcmis_vector_string_get( newStrings, 0 ) ) ); + CPPUNIT_ASSERT_EQUAL( string( newValues[1] ), string( libcmis_vector_string_get( newStrings, 1 ) ) ); + libcmis_vector_string_free( newStrings ); + delete[] newValues; + + libcmis_property_free( tested ); + libcmis_property_type_free( type ); +} diff --git a/qa/libcmis-c/test-repository.cxx b/qa/libcmis-c/test-repository.cxx new file mode 100644 index 0000000..63e7363 --- /dev/null +++ b/qa/libcmis-c/test-repository.cxx @@ -0,0 +1,205 @@ +/* libcmis + * Version: MPL 1.1 / GPLv2+ / LGPLv2+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License or as specified alternatively below. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * 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. + * + * Major Contributor(s): + * Copyright (C) 2011 SUSE <cbosdonnat@suse.com> + * + * + * All Rights Reserved. + * + * For minor contributions see the git repository. + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPLv2+"), or + * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"), + * in which case the provisions of the GPLv2+ or the LGPLv2+ are applicable + * instead of those above. + */ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/TestFixture.h> +#include <cppunit/TestAssert.h> + +#include <libcmis-c/repository.h> + +#include "internals.hxx" +#include "test-dummies.hxx" + +using namespace std; + +class RepositoryTest : public CppUnit::TestFixture +{ + private: + libcmis_RepositoryPtr getTested( ); + + public: + void getIdTest( ); + void getNameTest( ); + void getDescriptionTest( ); + void getVendorNameTest( ); + void getProductNameTest( ); + void getProductVersionTest( ); + void getRootIdTest( ); + void getCmisVersionSupportedTest( ); + void getThinClientUriTest( ); + void getPrincipalAnonymousTest( ); + void getPrincipalAnyoneTest( ); + + CPPUNIT_TEST_SUITE( RepositoryTest ); + CPPUNIT_TEST( getIdTest ); + CPPUNIT_TEST( getNameTest ); + CPPUNIT_TEST( getDescriptionTest ); + CPPUNIT_TEST( getVendorNameTest ); + CPPUNIT_TEST( getProductNameTest ); + CPPUNIT_TEST( getProductVersionTest ); + CPPUNIT_TEST( getRootIdTest ); + CPPUNIT_TEST( getCmisVersionSupportedTest ); + CPPUNIT_TEST( getThinClientUriTest ); + CPPUNIT_TEST( getPrincipalAnonymousTest ); + CPPUNIT_TEST( getPrincipalAnyoneTest ); + CPPUNIT_TEST_SUITE_END( ); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION( RepositoryTest ); + +libcmis_RepositoryPtr RepositoryTest::getTested( ) +{ + libcmis_RepositoryPtr result = new libcmis_repository( ); + + libcmis::RepositoryPtr handle( new dummies::Repository( ) ); + result->handle = handle; + + return result; +} + +void RepositoryTest::getIdTest( ) +{ + libcmis_RepositoryPtr tested = getTested( ); + char* actual = libcmis_repository_getId( tested ); + string expected( "Repository::Id" ); + CPPUNIT_ASSERT_EQUAL( expected, string( actual ) ); + + free( actual ); + libcmis_repository_free( tested ); +} + +void RepositoryTest::getNameTest( ) +{ + libcmis_RepositoryPtr tested = getTested( ); + char* actual = libcmis_repository_getName( tested ); + string expected( "Repository::Name" ); + CPPUNIT_ASSERT_EQUAL( expected, string( actual ) ); + + free( actual ); + libcmis_repository_free( tested ); +} + +void RepositoryTest::getDescriptionTest( ) +{ + libcmis_RepositoryPtr tested = getTested( ); + char* actual = libcmis_repository_getDescription( tested ); + string expected( "Repository::Description" ); + CPPUNIT_ASSERT_EQUAL( expected, string( actual ) ); + + free( actual ); + libcmis_repository_free( tested ); +} + +void RepositoryTest::getVendorNameTest( ) +{ + libcmis_RepositoryPtr tested = getTested( ); + char* actual = libcmis_repository_getVendorName( tested ); + string expected( "Repository::VendorName" ); + CPPUNIT_ASSERT_EQUAL( expected, string( actual ) ); + + free( actual ); + libcmis_repository_free( tested ); +} + +void RepositoryTest::getProductNameTest( ) +{ + libcmis_RepositoryPtr tested = getTested( ); + char* actual = libcmis_repository_getProductName( tested ); + string expected( "Repository::ProductName" ); + CPPUNIT_ASSERT_EQUAL( expected, string( actual ) ); + + free( actual ); + libcmis_repository_free( tested ); +} + +void RepositoryTest::getProductVersionTest( ) +{ + libcmis_RepositoryPtr tested = getTested( ); + char* actual = libcmis_repository_getProductVersion( tested ); + string expected( "Repository::ProductVersion" ); + CPPUNIT_ASSERT_EQUAL( expected, string( actual ) ); + + free( actual ); + libcmis_repository_free( tested ); +} + +void RepositoryTest::getRootIdTest( ) +{ + libcmis_RepositoryPtr tested = getTested( ); + char* actual = libcmis_repository_getRootId( tested ); + string expected( "Repository::RootId" ); + CPPUNIT_ASSERT_EQUAL( expected, string( actual ) ); + + free( actual ); + libcmis_repository_free( tested ); +} + +void RepositoryTest::getCmisVersionSupportedTest( ) +{ + libcmis_RepositoryPtr tested = getTested( ); + char* actual = libcmis_repository_getCmisVersionSupported( tested ); + string expected( "Repository::CmisVersionSupported" ); + CPPUNIT_ASSERT_EQUAL( expected, string( actual ) ); + + free( actual ); + libcmis_repository_free( tested ); +} + +void RepositoryTest::getThinClientUriTest( ) +{ + libcmis_RepositoryPtr tested = getTested( ); + char* actual = libcmis_repository_getThinClientUri( tested ); + string expected( "Repository::ThinClientUri" ); + CPPUNIT_ASSERT_EQUAL( expected, string( actual ) ); + + free( actual ); + libcmis_repository_free( tested ); +} + +void RepositoryTest::getPrincipalAnonymousTest( ) +{ + libcmis_RepositoryPtr tested = getTested( ); + char* actual = libcmis_repository_getPrincipalAnonymous( tested ); + string expected( "Repository::PrincipalAnonymous" ); + CPPUNIT_ASSERT_EQUAL( expected, string( actual ) ); + + free( actual ); + libcmis_repository_free( tested ); +} + +void RepositoryTest::getPrincipalAnyoneTest( ) +{ + libcmis_RepositoryPtr tested = getTested( ); + char* actual = libcmis_repository_getPrincipalAnyone( tested ); + string expected( "Repository::PrincipalAnyone" ); + CPPUNIT_ASSERT_EQUAL( expected, string( actual ) ); + + free( actual ); + libcmis_repository_free( tested ); +} + diff --git a/qa/libcmis-c/test-session.cxx b/qa/libcmis-c/test-session.cxx new file mode 100644 index 0000000..b236bc5 --- /dev/null +++ b/qa/libcmis-c/test-session.cxx @@ -0,0 +1,88 @@ +/* libcmis + * Version: MPL 1.1 / GPLv2+ / LGPLv2+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License or as specified alternatively below. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * 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. + * + * Major Contributor(s): + * Copyright (C) 2011 SUSE <cbosdonnat@suse.com> + * + * + * All Rights Reserved. + * + * For minor contributions see the git repository. + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPLv2+"), or + * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"), + * in which case the provisions of the GPLv2+ or the LGPLv2+ are applicable + * instead of those above. + */ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/TestFixture.h> +#include <cppunit/TestAssert.h> + +#include <libcmis-c/libcmis-c.h> + +#include "internals.hxx" +#include "test-dummies.hxx" + +using namespace std; + +class SessionTest : public CppUnit::TestFixture +{ + private: + libcmis_SessionPtr getTested( ); + + public: + void getRepositoriesTest( ); + void getBaseTypesTest( ); + + CPPUNIT_TEST_SUITE( SessionTest ); + CPPUNIT_TEST( getRepositoriesTest ); + CPPUNIT_TEST( getBaseTypesTest ); + CPPUNIT_TEST_SUITE_END( ); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION( SessionTest ); + +libcmis_SessionPtr SessionTest::getTested( ) +{ + libcmis_SessionPtr result = new libcmis_session(); + libcmis::Session* handle = new dummies::Session( ); + result->handle = handle; + return result; +} + +void SessionTest::getRepositoriesTest( ) +{ + libcmis_SessionPtr session = getTested( ); + libcmis_vector_Repository_Ptr repos = libcmis_session_getRepositories( session ); + size_t actualSize = libcmis_vector_repository_size( repos ); + CPPUNIT_ASSERT_EQUAL( size_t( 2 ), actualSize ); + libcmis_vector_repository_free( repos ); + libcmis_session_free( session ); +} + +void SessionTest::getBaseTypesTest( ) +{ + libcmis_SessionPtr session = getTested( ); + libcmis_ErrorPtr error = libcmis_error_create( ); + + libcmis_vector_object_type_Ptr types = libcmis_session_getBaseTypes( session, error ); + + size_t size = libcmis_vector_object_type_size( types ); + CPPUNIT_ASSERT_EQUAL( size_t( 1 ), size ); + + libcmis_error_free( error ); + libcmis_vector_object_type_free( types ); + libcmis_session_free( session ); +} |