1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
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;
}
}
|