First public contribution.
2 * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
19 #include <test/testexecutelog.h>
20 #include <caf/content.h>
22 #include <caf/attribute.h>
23 #include "cafserver.h"
25 #include "Consumerstep.h"
26 #include "attributeset.h"
27 #include "stringattributeset.h"
28 #include <caf/virtualpath.h>
32 using namespace ContentAccess;
34 const TInt KCafTestMaxDataTypeLength = 255;
35 const TInt KCafTestSecToMS = 1000;
37 _LIT(KCDataThreadSemaphore, "CData_Thread_Test");
40 * Step1 compares an agent 'size' call with that obtained by RFile
44 CCAFSizeStep::~CCAFSizeStep()
48 CCAFSizeStep::CCAFSizeStep(CCAFServer& aParent)
51 SetTestStepName(KCAFSizeStep);
54 TVerdict CCAFSizeStep::doTestStepL()
58 SetTestStepResult(EInconclusive);
60 INFO_PRINTF1(_L("Basic Open Content Test"));
64 GetStringFromConfig(ConfigSection(),_L("URI1"),uri1);
65 GetStringFromConfig(ConfigSection(),_L("URI2"),uri2);
67 INFO_PRINTF2(_L("Creating CContent object with uri: %S"), &uri1);
68 CContent* content = CContent::NewLC(uri1);
69 INFO_PRINTF1(_L("Creating CData object from content"));
71 CData* data = content->OpenContentL(EPeek);
72 CleanupStack::PushL(data);
75 data->DataSizeL(size);
76 INFO_PRINTF2(_L("Size of content from caf CContent::OpenContentL(): %d"),size);
77 CleanupStack::PopAndDestroy(data);
78 CleanupStack::PopAndDestroy(content);
80 INFO_PRINTF2(_L("Creating CData object with uri: %S"), &uri1);
84 if (!GetBoolFromConfig(ConfigSection(),_L("WITHOUTINTENT"),withoutIntent))
86 INFO_PRINTF1(_L("With Intent"));
87 data = CData::NewL(TVirtualPathPtr(uri1), EPeek, EContentShareReadOnly);
91 INFO_PRINTF1(_L("Without Intent"));
92 data = CData::NewL(TVirtualPathPtr(uri1), EContentShareReadOnly);
93 data->SetProperty(EAgentPropertyAgentUI, 0);
94 User::LeaveIfError(data->EvaluateIntent(EPeek));
97 CleanupStack::PushL(data);
98 data->DataSizeL(size1);
99 INFO_PRINTF2(_L("Size of content from caf CData::NewL(): %d"),size1);
100 CleanupStack::PopAndDestroy(data);
102 INFO_PRINTF2(_L("Opening standard RFile interface with uri: %S"),&uri2);
104 User::LeaveIfError(file.Open(iParent.Fs(), uri2, EFileRead));
110 INFO_PRINTF2(_L("Size of content from f32: %d"),size2);
112 if(size == size2 && size == size1)
114 SetTestStepResult(EPass);
118 SetTestStepResult(EFail);
122 return TestStepResult();
125 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
127 * This is the 64bit version of CCAFSizeStep
130 CCAFSizeStep64::~CCAFSizeStep64()
134 CCAFSizeStep64::CCAFSizeStep64(CCAFServer& aParent)
137 SetTestStepName(KCAFSizeStep);
140 TVerdict CCAFSizeStep64::doTestStepL()
144 SetTestStepResult(EInconclusive);
146 INFO_PRINTF1(_L("Basic Open Content Test"));
150 GetStringFromConfig(ConfigSection(),_L("URI1"),uri1);
151 GetStringFromConfig(ConfigSection(),_L("URI2"),uri2);
153 INFO_PRINTF2(_L("Creating CContent object with uri: %S"), &uri1);
154 CContent* content = CContent::NewLC(uri1);
155 INFO_PRINTF1(_L("Creating CData object from content"));
157 CData* data = content->OpenContentL(EPeek);
158 CleanupStack::PushL(data);
161 data->DataSize64L(size);
162 INFO_PRINTF2(_L("Size of content from caf CContent::OpenContentL(): %Ld"),size);
163 CleanupStack::PopAndDestroy(data);
164 CleanupStack::PopAndDestroy(content);
166 INFO_PRINTF2(_L("Creating CData object with uri: %S"), &uri1);
170 if (!GetBoolFromConfig(ConfigSection(),_L("WITHOUTINTENT"),withoutIntent))
172 INFO_PRINTF1(_L("With Intent"));
173 data = CData::NewL(TVirtualPathPtr(uri1), EPeek, EContentShareReadOnly);
177 INFO_PRINTF1(_L("Without Intent"));
178 data = CData::NewL(TVirtualPathPtr(uri1), EContentShareReadOnly);
179 data->SetProperty(EAgentPropertyAgentUI, 0);
180 User::LeaveIfError(data->EvaluateIntent(EPeek));
183 CleanupStack::PushL(data);
184 data->DataSize64L(size1);
185 INFO_PRINTF2(_L("Size of content from caf CData::NewL(): %Ld"),size1);
186 CleanupStack::PopAndDestroy(data);
188 INFO_PRINTF2(_L("Opening standard RFile interface with uri: %S"),&uri2);
190 User::LeaveIfError(file.Open(iParent.Fs(), uri2, EFileRead));
196 INFO_PRINTF2(_L("Size of content from f32: %Ld"),size2);
198 if(size == size2 && size == size1)
200 SetTestStepResult(EPass);
204 SetTestStepResult(EFail);
208 return TestStepResult();
210 #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
213 * This step compares a seek and read using CAF with that using RFile
217 CCAFSeekReadStep::~CCAFSeekReadStep()
221 CCAFSeekReadStep::CCAFSeekReadStep(CCAFServer& aParent)
224 SetTestStepName(KCAFSeekReadStep);
227 void CCAFSeekReadStep::StandardCheckReturnValue(TInt aReturnValue)
229 if (aReturnValue != KErrNone)
231 INFO_PRINTF2(_L("ERROR Unexpected return value: %d"),aReturnValue);
232 SetTestStepResult(EFail);
235 TVerdict CCAFSeekReadStep::doTestStepL()
237 SetTestStepResult(EInconclusive);
241 TRequestStatus status;
244 INFO_PRINTF1(_L("Basic Open Content Test"));
248 GetStringFromConfig(ConfigSection(),_L("URI1"),uri1);
249 GetStringFromConfig(ConfigSection(),_L("URI2"),uri2);
251 INFO_PRINTF2(_L("Creating content object with uri: %S"), &uri1);
252 CContent* content = CContent::NewLC(uri1);
254 INFO_PRINTF1(_L("Creating data object from content"));
255 CData* data = content->OpenContentL(EPeek);
257 // don't need CContent any more
258 CleanupStack::PopAndDestroy(content);
259 CleanupStack::PushL(data);
261 // Now, open the same file using RFile
263 INFO_PRINTF2(_L("Opening standard RFile interface with uri: %S"),&uri2);
264 User::LeaveIfError(file.Open(iParent.Fs(), uri2, EFileRead | EFileShareReadersOnly));
265 CleanupClosePushL(file);
269 INFO_PRINTF2(_L("Size of content from f32: %d"),size);
271 // Seek and read from start using both CAF and RFile
273 data->Seek(ESeekStart, pos1);
275 file.Seek(ESeekStart, pos2);
278 INFO_PRINTF2(_L("Position from ESeekStart test using CData: %d"), pos1);
279 INFO_PRINTF2(_L("Position from ESeekStart test using RFile: %d"), pos2);
280 if (buf1 != buf2 || pos1 != pos2 || pos1 != size/4)
282 INFO_PRINTF1(_L("ERROR buffers or position do not match"));
283 SetTestStepResult(EFail);
286 // set the location within the file then retrieve the current location within the file
289 data->Seek(ESeekCurrent, pos1);
290 file.Seek(ESeekCurrent, pos2);
292 INFO_PRINTF2(_L("Current position using CData: %d"), pos1);
293 INFO_PRINTF2(_L("Current position using RFile: %d"), pos2);
295 if(pos1 != pos2 || pos1 != (size/4 + buf1.Length()))
297 INFO_PRINTF1(_L("ERROR buffers or position do not match"));
298 SetTestStepResult(EFail);
301 // Seek and read from current using both CAF and RFile
303 data->Seek(ESeekCurrent, pos1);
305 file.Seek(ESeekCurrent, pos2);
308 INFO_PRINTF2(_L("Position from ESeekCurrent test using CData: %d"), pos1);
309 INFO_PRINTF2(_L("Position from ESeekCurrent test using RFile: %d"), pos2);
310 if (buf1 != buf2 || pos1 != pos2 || pos1 != (size/2 + buf1.Length()))
312 INFO_PRINTF1(_L("ERROR buffers or position do not match"));
313 SetTestStepResult(EFail);
316 // Seek and read from end using both CAF and RFile
318 data->Seek(ESeekEnd, pos1);
320 file.Seek(ESeekEnd, pos2);
323 INFO_PRINTF2(_L("Position from ESeekEnd test using CData: %d"), pos1);
324 INFO_PRINTF2(_L("Position from ESeekEnd test using RFile: %d"), pos2);
325 if (buf1 != buf2 || pos1 != pos2 || pos1 != (size - size/4))
327 INFO_PRINTF1(_L("ERROR buffers or position do not match"));
328 SetTestStepResult(EFail);
331 // Test other overloaded forms of CData::Read
333 // Read only 1 byte using both CAF and RFile
335 data->Seek(ESeekStart, pos1);
337 file.Seek(ESeekStart, pos2);
340 INFO_PRINTF2(_L("Data Length from CData::Read(TDesC& ,TInt Length) : %d"), buf1.Length());
341 INFO_PRINTF2(_L("Data Length from RFile::Read(TDesC& , TInt Length): %d"), buf2.Length());
345 data->Seek(ESeekCurrent, pos1);
346 file.Seek(ESeekCurrent,pos2);
347 if (buf1 != buf2 || pos1 != pos2 || buf1.Length() != buf2.Length())
349 INFO_PRINTF1(_L("ERROR buffers or position do not match"));
350 SetTestStepResult(EFail);
353 // Read asynchronously using both CAF and RFile
354 INFO_PRINTF1(_L("Asynchronous read from CAF and RFile"));
356 data->Seek(ESeekStart, pos1);
358 file.Seek(ESeekStart, pos2);
359 status = KRequestPending;
360 data->Read(buf1,status);
361 User::WaitForRequest(status);
362 status = KRequestPending;
363 file.Read(buf2,status);
364 User::WaitForRequest(status);
365 INFO_PRINTF2(_L("Data length from CData::Read(TDesC& ,TRequestStatus& aStatus): %d"), buf1.Length());
366 INFO_PRINTF2(_L("Data length from RFile::Read(TDesC& , TRequestStatus& aStatus): %d"), buf2.Length());
370 data->Seek(ESeekCurrent, pos1);
371 file.Seek(ESeekCurrent,pos2);
372 if (buf1 != buf2 || pos1 != pos2 || buf1.Length() != buf2.Length())
374 INFO_PRINTF1(_L("ERROR buffers or position do not match"));
375 SetTestStepResult(EFail);
378 // Read only 1 byte asynchronously using both CAF and RFile
379 INFO_PRINTF1(_L("Asynchronous read of 1 byte from CAF and RFile"));
381 data->Seek(ESeekStart, pos1);
383 file.Seek(ESeekStart, pos2);
384 status = KRequestPending;
385 data->Read(buf1,1,status);
386 User::WaitForRequest(status);
387 status = KRequestPending;
388 file.Read(buf2,1, status);
389 User::WaitForRequest(status);
390 INFO_PRINTF2(_L("Data Length from CData::Read(TDesC& ,TInt Length, TRequestStatus aStatus) : %d"), buf1.Length());
391 INFO_PRINTF2(_L("Data Length from RFile::Read(TDesC& , TInt Length, TRequestStatus aStatus): %d"), buf2.Length());
395 data->Seek(ESeekCurrent, pos1);
396 file.Seek(ESeekCurrent,pos2);
397 if (buf1 != buf2 || pos1 != pos2 || buf1.Length() != buf2.Length())
399 INFO_PRINTF1(_L("ERROR buffers or position do not match"));
400 SetTestStepResult(EFail);
406 data->Seek(ESeekStart, pos1);
407 file.Seek(ESeekStart, pos2);
411 if(buf1.Length() != 0 || buf1.Length() != 0)
413 INFO_PRINTF1(_L("ERROR data read past EOF"));
414 SetTestStepResult(EFail);
418 // Read asynchronously supplying an offset using both CAF and RFile
420 INFO_PRINTF1(_L("Asynchronous read of 1 byte from CAF and RFile supplying an offset within the file"));
423 status = KRequestPending;
424 err = data->Read(pos1,buf1,1,status);
426 StandardCheckReturnValue(err);
428 User::WaitForRequest(status);
429 status = KRequestPending;
430 file.Read(pos2, buf2,1, status);
431 User::WaitForRequest(status);
432 INFO_PRINTF2(_L("Data Length from CData::Read(TInt aPos, TDesC& , TInt Length, TRequestStatus aStatus) : %d"), buf1.Length());
433 INFO_PRINTF2(_L("Data Length from RFile::Read(TInt aPos, TDesC& , TInt Length, TRequestStatus aStatus): %d"), buf2.Length());
437 data->Seek(ESeekCurrent, pos1);
438 file.Seek(ESeekCurrent,pos2);
439 if (buf1 !=buf2 || pos1 != pos2 || buf1.Length() != buf2.Length())
441 INFO_PRINTF1(_L("ERROR buffers or position do not match"));
442 SetTestStepResult(EFail);
445 // Check asynchronous cancellation
447 INFO_PRINTF1(_L("Asynchronous read cancellation using both CAF and RFile with an offset within the file"));
450 status = KRequestPending;
451 err = data->Read(pos1,buf1,1,status);
452 StandardCheckReturnValue(err);
453 data->ReadCancel(status);
454 User::WaitForRequest(status);
455 TRequestStatus status2(KRequestPending);
456 file.Read(pos2, buf2,1, status2);
458 User::WaitForRequest(status2);
459 INFO_PRINTF3(_L("Data Length from CData::Read(TInt aPos, TDesC& , TInt Length, TRequestStatus aStatus) : %d, status is %d"), buf1.Length(), status.Int());
460 INFO_PRINTF3(_L("Data Length from RFile::Read(TInt aPos, TDesC& , TInt Length, TRequestStatus aStatus): %d, status is %d"), buf2.Length(), status2.Int());
461 if (status.Int() != status2.Int() || buf1 !=buf2 || pos1 != pos2 || buf1.Length() != buf2.Length())
463 INFO_PRINTF1(_L("ERROR status, buffers or position do not match"));
464 SetTestStepResult(EFail);
470 status = KRequestPending;
471 data->Read(pos1,buf1,1,status);
472 StandardCheckReturnValue(err);
473 User::WaitForRequest(status);
474 status = KRequestPending;
475 file.Read(pos2,buf2,1,status);
476 User::WaitForRequest(status);
478 if(buf1.Length() != 0 || buf1.Length() != 0)
480 INFO_PRINTF1(_L("ERROR data read past EOF"));
481 SetTestStepResult(EFail);
484 // read over the length of the buffer
485 INFO_PRINTF1(_L("Asynchronous read of 5 bytes from CAF and RFile supplying an offset within the file"));
488 status = KRequestPending;
489 err = data->Read(pos1,buf1,5,status);
490 StandardCheckReturnValue(err);
491 User::WaitForRequest(status);
492 if(status.Int()!=KErrOverflow)
494 INFO_PRINTF2(_L("ERROR Unexpected status returned: %d"),status.Int());
495 SetTestStepResult(EFail);
497 status = KRequestPending;
498 file.Read(pos2, buf2,5, status);
499 User::WaitForRequest(status);
500 INFO_PRINTF2(_L("Data Length from CData::Read(TInt aPos, TDesC& , TInt Length, TRequestStatus aStatus) : %d"), buf1.Length());
501 INFO_PRINTF2(_L("Data Length from RFile::Read(TInt aPos, TDesC& , TInt Length, TRequestStatus aStatus): %d"), buf2.Length());
503 if (buf1 !=buf2 || buf1.Length() != buf2.Length())
505 INFO_PRINTF1(_L("ERROR buffers or position do not match"));
506 SetTestStepResult(EFail);
508 // read negative position this should return KErrArgument, dont supply -ve pos to RFile as will panic test
509 INFO_PRINTF1(_L("Asynchronous read from CAF supplying a negative offset within the file"));
511 status = KRequestPending;
512 err = data->Read(pos1,buf1,5,status);
513 if(err!=KErrArgument)
515 INFO_PRINTF2(_L("ERROR Unexpected return value: %d"),err);
516 SetTestStepResult(EFail);
519 // Read asynchronously supplying an offset of 0 and a length greater than size of file using both CAF and RFile
520 INFO_PRINTF1(_L("Asynchronous read of length greater than size of file from CAF and RFile supplying an offset of 0 within the file"));
525 status = KRequestPending;
526 err = data->Read(pos1,buf3,size+1,status);
527 StandardCheckReturnValue(err);
528 User::WaitForRequest(status);
529 status = KRequestPending;
530 file.Read(pos2, buf4,size+1, status);
531 User::WaitForRequest(status);
532 INFO_PRINTF2(_L("Data Length from CData::Read(TInt aPos, TDesC& , TInt Length, TRequestStatus aStatus) : %d"), buf3.Size());
533 INFO_PRINTF2(_L("Data Length from RFile::Read(TInt aPos, TDesC& , TInt Length, TRequestStatus aStatus): %d"), buf4.Size());
537 data->Seek(ESeekCurrent, pos1);
538 file.Seek(ESeekCurrent,pos2);
539 if (buf3 != buf4 || pos1 != pos2 || buf3.Length() != buf4.Length() || pos1 != size ||
540 pos2 != size || buf3.Size() != pos1 || buf4.Size() != pos2)
542 INFO_PRINTF1(_L("ERROR buffers or position do not match"));
543 SetTestStepResult(EFail);
546 // Read asynchronously supplying an offset of size/4 and a length greater than size of file using both CAF and RFile
547 INFO_PRINTF1(_L("Asynchronous read of length greater than size of file from CAF and RFile supplying an offset within the file"));
550 status = KRequestPending;
551 err = data->Read(pos1,buf3,size+1,status);
552 StandardCheckReturnValue(err);
553 User::WaitForRequest(status);
554 status = KRequestPending;
555 file.Read(pos2, buf4,size+1, status);
556 User::WaitForRequest(status);
557 INFO_PRINTF2(_L("Data Length from CData::Read(TInt aPos, TDesC& , TInt Length, TRequestStatus aStatus) : %d"), buf3.Size());
558 INFO_PRINTF2(_L("Data Length from RFile::Read(TInt aPos, TDesC& , TInt Length, TRequestStatus aStatus): %d"), buf4.Size());
562 data->Seek(ESeekCurrent, pos1);
563 file.Seek(ESeekCurrent,pos2);
564 if (buf3 != buf4 || pos1 != pos2 || buf3.Size() != buf4.Size() || pos1 != size || pos2 != size)
566 INFO_PRINTF1(_L("ERROR buffers or position do not match"));
567 SetTestStepResult(EFail);
570 CleanupStack::PopAndDestroy(2, data);
574 if (TestStepResult() != EFail)
576 SetTestStepResult(EPass);
579 return TestStepResult();
583 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
585 * This is the 64bit version of CCAFSeekReadStep.
588 CCAFSeekReadStep64::~CCAFSeekReadStep64()
592 CCAFSeekReadStep64::CCAFSeekReadStep64(CCAFServer& aParent)
595 SetTestStepName(KCAFSeekReadStep);
598 void CCAFSeekReadStep64::StandardCheckReturnValue(TInt aReturnValue)
600 if (aReturnValue != KErrNone)
602 INFO_PRINTF2(_L("ERROR Unexpected return value: %d"),aReturnValue);
603 SetTestStepResult(EFail);
606 TVerdict CCAFSeekReadStep64::doTestStepL()
608 SetTestStepResult(EInconclusive);
612 TRequestStatus status;
615 INFO_PRINTF1(_L("Basic Open Content Test"));
619 GetStringFromConfig(ConfigSection(),_L("URI1"),uri1);
620 GetStringFromConfig(ConfigSection(),_L("URI2"),uri2);
622 INFO_PRINTF2(_L("Creating content object with uri: %S"), &uri1);
623 CContent* content = CContent::NewLC(uri1);
625 INFO_PRINTF1(_L("Creating data object from content"));
626 CData* data = content->OpenContentL(EPeek);
628 // don't need CContent any more
629 CleanupStack::PopAndDestroy(content);
630 CleanupStack::PushL(data);
632 // Now, open the same file using RFile
634 INFO_PRINTF2(_L("Opening standard RFile interface with uri: %S"),&uri2);
635 User::LeaveIfError(file.Open(iParent.Fs(), uri2, EFileRead | EFileShareReadersOnly));
636 CleanupClosePushL(file);
640 INFO_PRINTF2(_L("Size of content from f32: %Ld"),size);
642 // Seek and read from start using both CAF and RFile
643 TInt64 pos1 = size/4;
644 data->Seek64(ESeekStart, pos1);
645 //pos2 needs to be modified to TInt64 when file server supports 64bit
646 TInt64 pos2 = size/4;
647 file.Seek(ESeekStart, pos2);
650 INFO_PRINTF2(_L("Position from ESeekStart test using CData: %Ld"), pos1);
651 INFO_PRINTF2(_L("Position from ESeekStart test using RFile: %Ld"), pos2);
652 if (buf1 != buf2 || pos1 != pos2 || pos1 != size/4)
654 INFO_PRINTF1(_L("ERROR buffers or position do not match"));
655 SetTestStepResult(EFail);
658 // set the location within the file then retrieve the current location within the file
661 data->Seek64(ESeekCurrent, pos1);
662 file.Seek(ESeekCurrent, pos2);
664 INFO_PRINTF2(_L("Current position using CData: %Ld"), pos1);
665 INFO_PRINTF2(_L("Current position using RFile: %Ld"), pos2);
667 if(pos1 != pos2 || pos1 != (size/4 + buf1.Length()))
669 INFO_PRINTF1(_L("ERROR buffers or position do not match"));
670 SetTestStepResult(EFail);
673 // Seek and read from current using both CAF and RFile
675 data->Seek64(ESeekCurrent, pos1);
677 file.Seek(ESeekCurrent, pos2);
680 INFO_PRINTF2(_L("Position from ESeekCurrent test using CData: %Ld"), pos1);
681 INFO_PRINTF2(_L("Position from ESeekCurrent test using RFile: %Ld"), pos2);
682 if (buf1 != buf2 || pos1 != pos2 || pos1 != (size/2 + buf1.Length()))
684 INFO_PRINTF1(_L("ERROR buffers or position do not match"));
685 SetTestStepResult(EFail);
688 // Seek and read from end using both CAF and RFile
690 data->Seek64(ESeekEnd, pos1);
692 file.Seek(ESeekEnd, pos2);
695 INFO_PRINTF2(_L("Position from ESeekEnd test using CData: %Ld"), pos1);
696 INFO_PRINTF2(_L("Position from ESeekEnd test using RFile: %Ld"), pos2);
697 if (buf1 != buf2 || pos1 != pos2 || pos1 != (size - size/4))
699 INFO_PRINTF1(_L("ERROR buffers or position do not match"));
700 SetTestStepResult(EFail);
703 // Test other overloaded forms of CData::Read
705 // Read only 1 byte using both CAF and RFile
707 data->Seek64(ESeekStart, pos1);
709 file.Seek(ESeekStart, pos2);
712 INFO_PRINTF2(_L("Data Length from CData::Read(TDesC& ,TInt Length) : %d"), buf1.Length());
713 INFO_PRINTF2(_L("Data Length from RFile::Read(TDesC& , TInt Length): %d"), buf2.Length());
717 data->Seek64(ESeekCurrent, pos1);
718 file.Seek(ESeekCurrent,pos2);
719 if (buf1 != buf2 || pos1 != pos2 || buf1.Length() != buf2.Length())
721 INFO_PRINTF1(_L("ERROR buffers or position do not match"));
722 SetTestStepResult(EFail);
725 // Read asynchronously using both CAF and RFile
726 INFO_PRINTF1(_L("Asynchronous read from CAF and RFile"));
728 data->Seek64(ESeekStart, pos1);
730 file.Seek(ESeekStart, pos2);
731 status = KRequestPending;
732 data->Read(buf1,status);
733 User::WaitForRequest(status);
734 status = KRequestPending;
735 file.Read(buf2,status);
736 User::WaitForRequest(status);
737 INFO_PRINTF2(_L("Data length from CData::Read(TDesC& ,TRequestStatus& aStatus): %d"), buf1.Length());
738 INFO_PRINTF2(_L("Data length from RFile::Read(TDesC& , TRequestStatus& aStatus): %d"), buf2.Length());
742 data->Seek64(ESeekCurrent, pos1);
743 file.Seek(ESeekCurrent,pos2);
744 if (buf1 != buf2 || pos1 != pos2 || buf1.Length() != buf2.Length())
746 INFO_PRINTF1(_L("ERROR buffers or position do not match"));
747 SetTestStepResult(EFail);
750 // Read only 1 byte asynchronously using both CAF and RFile
751 INFO_PRINTF1(_L("Asynchronous read of 1 byte from CAF and RFile"));
753 data->Seek64(ESeekStart, pos1);
755 file.Seek(ESeekStart, pos2);
756 status = KRequestPending;
757 data->Read(buf1,1,status);
758 User::WaitForRequest(status);
759 status = KRequestPending;
760 file.Read(buf2,1, status);
761 User::WaitForRequest(status);
762 INFO_PRINTF2(_L("Data Length from CData::Read(TDesC& ,TInt Length, TRequestStatus aStatus) : %d"), buf1.Length());
763 INFO_PRINTF2(_L("Data Length from RFile::Read(TDesC& , TInt Length, TRequestStatus aStatus): %d"), buf2.Length());
767 data->Seek64(ESeekCurrent, pos1);
768 file.Seek(ESeekCurrent,pos2);
769 if (buf1 != buf2 || pos1 != pos2 || buf1.Length() != buf2.Length())
771 INFO_PRINTF1(_L("ERROR buffers or position do not match"));
772 SetTestStepResult(EFail);
778 data->Seek64(ESeekStart, pos1);
779 file.Seek(ESeekStart, pos2);
783 if(buf1.Length() != 0 || buf1.Length() != 0)
785 INFO_PRINTF1(_L("ERROR data read past EOF"));
786 SetTestStepResult(EFail);
790 // Read asynchronously supplying an offset using both CAF and RFile
792 INFO_PRINTF1(_L("Asynchronous read of 1 byte from CAF and RFile supplying an offset within the file"));
795 status = KRequestPending;
796 err = data->Read(pos1,buf1,1,status);
798 StandardCheckReturnValue(err);
800 User::WaitForRequest(status);
801 status = KRequestPending;
802 file.Read(pos2, buf2,1, status);
803 User::WaitForRequest(status);
804 INFO_PRINTF2(_L("Data Length from CData::Read(TInt64 aPos, TDesC& , TInt Length, TRequestStatus aStatus) : %d"), buf1.Length());
805 INFO_PRINTF2(_L("Data Length from RFile::Read(TInt64 aPos, TDesC& , TInt Length, TRequestStatus aStatus): %d"), buf2.Length());
809 data->Seek64(ESeekCurrent, pos1);
810 file.Seek(ESeekCurrent,pos2);
811 if (buf1 !=buf2 || pos1 != pos2 || buf1.Length() != buf2.Length())
813 INFO_PRINTF1(_L("ERROR buffers or position do not match"));
814 SetTestStepResult(EFail);
817 // Check asynchronous cancellation
819 INFO_PRINTF1(_L("Asynchronous read cancellation using both CAF and RFile with an offset within the file"));
822 status = KRequestPending;
823 err = data->Read(pos1,buf1,1,status);
824 StandardCheckReturnValue(err);
825 data->ReadCancel(status);
826 User::WaitForRequest(status);
827 TRequestStatus status2(KRequestPending);
828 file.Read(pos2, buf2,1, status2);
830 User::WaitForRequest(status2);
831 INFO_PRINTF3(_L("Data Length from CData::Read(TInt64 aPos, TDesC& , TInt Length, TRequestStatus aStatus) : %d, status is %d"), buf1.Length(), status.Int());
832 INFO_PRINTF3(_L("Data Length from RFile::Read(TInt64 aPos, TDesC& , TInt Length, TRequestStatus aStatus): %d, status is %d"), buf2.Length(), status2.Int());
833 if (status.Int() != status2.Int() || buf1 !=buf2 || pos1 != pos2 || buf1.Length() != buf2.Length())
835 INFO_PRINTF1(_L("ERROR status, buffers or position do not match"));
836 SetTestStepResult(EFail);
842 status = KRequestPending;
843 data->Read(pos1,buf1,1,status);
844 StandardCheckReturnValue(err);
845 User::WaitForRequest(status);
846 status = KRequestPending;
847 file.Read(pos2,buf2,1,status);
848 User::WaitForRequest(status);
850 if(buf1.Length() != 0 || buf1.Length() != 0)
852 INFO_PRINTF1(_L("ERROR data read past EOF"));
853 SetTestStepResult(EFail);
856 // read over the length of the buffer
857 INFO_PRINTF1(_L("Asynchronous read of 5 bytes from CAF and RFile supplying an offset within the file"));
860 status = KRequestPending;
861 err = data->Read(pos1,buf1,5,status);
862 StandardCheckReturnValue(err);
863 User::WaitForRequest(status);
864 if(status.Int()!=KErrOverflow)
866 INFO_PRINTF2(_L("ERROR Unexpected status returned: %d"),status.Int());
867 SetTestStepResult(EFail);
869 status = KRequestPending;
870 file.Read(pos2, buf2,5, status);
871 User::WaitForRequest(status);
872 INFO_PRINTF2(_L("Data Length from CData::Read(TInt64 aPos, TDesC& , TInt Length, TRequestStatus aStatus) : %d"), buf1.Length());
873 INFO_PRINTF2(_L("Data Length from RFile::Read(TInt64 aPos, TDesC& , TInt Length, TRequestStatus aStatus): %d"), buf2.Length());
875 if (buf1 !=buf2 || buf1.Length() != buf2.Length())
877 INFO_PRINTF1(_L("ERROR buffers or position do not match"));
878 SetTestStepResult(EFail);
880 // read negative position this should return KErrArgument, dont supply -ve pos to RFile as will panic test
881 INFO_PRINTF1(_L("Asynchronous read from CAF supplying a negative offset within the file"));
883 status = KRequestPending;
884 err = data->Read(pos1,buf1,5,status);
885 if(err!=KErrArgument)
887 INFO_PRINTF2(_L("ERROR Unexpected return value: %d"),err);
888 SetTestStepResult(EFail);
891 // Read asynchronously supplying an offset of 0 and a length greater than size of file using both CAF and RFile
892 INFO_PRINTF1(_L("Asynchronous read of length greater than size of file from CAF and RFile supplying an offset of 0 within the file"));
897 status = KRequestPending;
898 err = data->Read(pos1,buf3,size+1,status);
899 StandardCheckReturnValue(err);
900 User::WaitForRequest(status);
901 status = KRequestPending;
902 file.Read(pos2, buf4,size+1, status);
903 User::WaitForRequest(status);
904 INFO_PRINTF2(_L("Data Length from CData::Read(TInt64 aPos, TDesC& , TInt Length, TRequestStatus aStatus) : %d"), buf3.Size());
905 INFO_PRINTF2(_L("Data Length from RFile::Read(TInt64 aPos, TDesC& , TInt Length, TRequestStatus aStatus): %d"), buf4.Size());
909 data->Seek64(ESeekCurrent, pos1);
910 file.Seek(ESeekCurrent,pos2);
911 if (buf3 != buf4 || pos1 != pos2 || buf3.Length() != buf4.Length() || pos1 != size ||
912 pos2 != size || buf3.Size() != pos1 || buf4.Size() != pos2)
914 INFO_PRINTF1(_L("ERROR buffers or position do not match"));
915 SetTestStepResult(EFail);
918 // Read asynchronously supplying an offset of size/4 and a length greater than size of file using both CAF and RFile
919 INFO_PRINTF1(_L("Asynchronous read of length greater than size of file from CAF and RFile supplying an offset within the file"));
922 status = KRequestPending;
923 err = data->Read(pos1,buf3,size+1,status);
924 StandardCheckReturnValue(err);
925 User::WaitForRequest(status);
926 status = KRequestPending;
927 file.Read(pos2, buf4,size+1, status);
928 User::WaitForRequest(status);
929 INFO_PRINTF2(_L("Data Length from CData::Read(TInt64 aPos, TDesC& , TInt Length, TRequestStatus aStatus) : %d"), buf3.Size());
930 INFO_PRINTF2(_L("Data Length from RFile::Read(TInt64 aPos, TDesC& , TInt Length, TRequestStatus aStatus): %d"), buf4.Size());
934 data->Seek64(ESeekCurrent, pos1);
935 file.Seek(ESeekCurrent,pos2);
936 if (buf3 != buf4 || pos1 != pos2 || buf3.Size() != buf4.Size() || pos1 != size || pos2 != size)
938 INFO_PRINTF1(_L("ERROR buffers or position do not match"));
939 SetTestStepResult(EFail);
942 CleanupStack::PopAndDestroy(2, data);
946 if (TestStepResult() != EFail)
948 SetTestStepResult(EPass);
951 return TestStepResult();
954 #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
956 * This step retrieves the attributes of a file using the CAF framework
960 CCAFAttributesStep::~CCAFAttributesStep()
964 CCAFAttributesStep::CCAFAttributesStep(CCAFServer& aParent) : iParent(aParent)
966 SetTestStepName(KCAFAttributesStep);
970 TVerdict CCAFAttributesStep::doTestStepL()
981 SetTestStepResult(EFail);
983 GetStringFromConfig(ConfigSection(),_L("filename"),fileName);
984 GetBoolFromConfig(ConfigSection(),_L("Protected"),Protected);
985 GetBoolFromConfig(ConfigSection(),_L("Forwardable"),Forwardable);
988 INFO_PRINTF2(_L("Check attributes of file: %S"), &fileName);
992 // Open a file and retrieve the attributes
993 content = CContent::NewLC(fileName);
994 attrs = content->NewAttributeL(ETrue);
995 CleanupStack::PushL(attrs);
997 // Assume all the attributes are what we expect them to be
998 SetTestStepResult(EPass);
1000 Value = attrs->ResponseSet().IsSet(EIsProtected);
1001 if(Value != Protected)
1003 SetTestStepResult(EFail);
1004 Protected ? INFO_PRINTF1(_L("File is Protected")) : INFO_PRINTF1(_L("File is not Protected"));
1007 Value = attrs->ResponseSet().IsSet(EIsForwardable);
1008 if(Value != Forwardable)
1010 SetTestStepResult(EFail);
1011 Forwardable ? INFO_PRINTF1(_L("File is Forwardable")) : INFO_PRINTF1(_L("File is not Forwardable"));
1014 CleanupStack::PopAndDestroy(2, content);
1017 return TestStepResult();
1022 * This step retrieves the string attributes of a file using the CAF framework
1026 CCAFStringAttributesStep::~CCAFStringAttributesStep()
1030 CCAFStringAttributesStep::CCAFStringAttributesStep(CCAFServer& aParent) : iParent(aParent)
1032 SetTestStepName(KCAFStringAttributesStep);
1036 TVerdict CCAFStringAttributesStep::doTestStepL()
1038 TInt expectedResult;
1040 TPtrC expectedValue;
1041 TBuf <256> value; //this will be used to test KErrOverFlow when transactionid is 257char long.
1042 TInt result = KErrNone;
1046 SetTestStepResult(EPass);
1048 GetIntFromConfig(ConfigSection(),_L("stringattribute"),attribute);
1049 GetStringFromConfig(ConfigSection(),_L("uri"),uri);
1050 GetStringFromConfig(ConfigSection(),_L("uniqueid"),uniqueId);
1051 GetStringFromConfig(ConfigSection(),_L("value"),expectedValue);
1052 GetIntFromConfig(ConfigSection(),_L("result"),expectedResult);
1055 CContent *content = CContent::NewLC(uri);
1056 CData *data = content->OpenContentL(EPeek, uniqueId);
1057 result = data->GetStringAttribute(attribute, value);
1059 if(result != expectedResult)
1061 SetTestStepResult(EFail);
1062 INFO_PRINTF3(_L("CData::GetStringAttribute() Expected result: %d, actual result: %d"), expectedResult, result);
1064 if(value != expectedValue)
1066 SetTestStepResult(EFail);
1067 INFO_PRINTF3(_L("CData::GetStringAttribute() Expected value: %S, actual result: %S"), &expectedValue, &value);
1070 CleanupStack::PopAndDestroy(content);
1073 return TestStepResult();
1081 * Step reads from a CData from multiple threads
1085 CCAFMultiThreadCDataStep::~CCAFMultiThreadCDataStep()
1089 CCAFMultiThreadCDataStep::CCAFMultiThreadCDataStep(CCAFServer& aParent)
1092 SetTestStepName(KCAFMultiThreadCDataStep);
1095 TVerdict CCAFMultiThreadCDataStep::doTestStepL()
1100 _LIT(KCDataThread,"CData_Thread");
1102 SetTestStepResult(EInconclusive);
1104 INFO_PRINTF1(_L("Multi Thread CData Test"));
1107 GetStringFromConfig(ConfigSection(),_L("URI"),uri);
1109 INFO_PRINTF1(_L("Creating data object from content"));
1110 CContent* content = CContent::NewLC(uri);
1111 CData* data = content->OpenContentL(EPeek);
1112 CleanupStack::PushL(data);
1116 // Create a mutex for communication between our thread and the new thread
1117 RSemaphore threadSemaphore;
1118 threadSemaphore.CreateGlobal(KCDataThreadSemaphore(), 1, EOwnerProcess);
1119 threadSemaphore.Wait();
1121 // fire up a new thread, stack size and heap size 8k, might need to be bigger in the future
1122 RThread readerThread;
1123 User::LeaveIfError(readerThread.Create(KCDataThread(),CCAFMultiThreadCDataStep::ReaderThreadEntry,8192, KMinHeapSize, 8192, (TAny *) data, EOwnerProcess));
1125 // request notification of thread completion
1126 TRequestStatus stat;
1127 readerThread.Logon(stat);
1128 readerThread.Resume();
1130 data->DataSizeL(size);
1132 data->Seek(ESeekStart,pos);
1135 threadSemaphore.Wait(); // wait for thread function to run and signal the semaphore
1136 threadSemaphore.Signal(); // finished with semaphore
1137 threadSemaphore.Close(); // so close
1139 User::WaitForRequest(stat); // wait for thread to finish
1140 TInt error=(readerThread.ExitType()==EExitPanic) ? KErrGeneral : stat.Int();
1141 User::LeaveIfError(error);
1142 readerThread.Close(); // close the thread
1144 CleanupStack::PopAndDestroy(data);
1145 CleanupStack::PopAndDestroy(content);
1149 SetTestStepResult(EPass);
1150 return TestStepResult();
1153 TInt CCAFMultiThreadCDataStep::ReaderThreadEntry(TAny *aPtr)
1156 CData *data = reinterpret_cast <CData *> (aPtr);
1158 // create a trap handler
1159 CTrapCleanup* cleanup = CTrapCleanup::New();
1161 RSemaphore threadSemaphore;
1162 threadSemaphore.OpenGlobal(KCDataThreadSemaphore() ,EOwnerProcess);
1165 threadSemaphore.Signal(); // allow original thread to continue
1166 threadSemaphore.Close();
1174 * Obtains the mime type from a CData
1178 CCAFMimeTypeCDataStep::~CCAFMimeTypeCDataStep()
1182 CCAFMimeTypeCDataStep::CCAFMimeTypeCDataStep(CCAFServer& aParent)
1185 SetTestStepName(KCAFMimeTypeCDataStep);
1188 TVerdict CCAFMimeTypeCDataStep::doTestStepL()
1193 SetTestStepResult(EFail);
1195 INFO_PRINTF1(_L("CData MimeType Test"));
1198 TPtrC expectedMimeType;
1199 TBool mimeTypeKnown=EFalse;
1201 // Load INI parameters
1202 GetStringFromConfig(ConfigSection(),_L("URI"),uri);
1203 GetStringFromConfig(ConfigSection(),_L("ContentMimeType"),expectedMimeType);
1204 GetBoolFromConfig(ConfigSection(),_L("Known"),mimeTypeKnown);
1207 HBufC8 *expected = ConvertDes16toHBufC8LC(expectedMimeType);
1209 // Create CContent and CData
1210 INFO_PRINTF1(_L("Creating data object from content"));
1211 CContent* content = CContent::NewLC(uri);
1212 CData* data = content->OpenContentL(EPeek);
1213 CleanupStack::PushL(data);
1215 // Get mime type from CData
1216 INFO_PRINTF1(_L("Checking mime type"));
1217 HBufC8 *buffer = HBufC8::NewLC(KCafTestMaxDataTypeLength);
1218 TPtr8 ptr = buffer->Des();
1219 TBool r = data->GetMimeTypeL(ptr);
1221 // check if result matches expected result
1222 if(r == mimeTypeKnown && *buffer == *expected)
1224 SetTestStepResult(EPass);
1227 CleanupStack::PopAndDestroy(4,expected);
1229 return TestStepResult();
1233 * This step tests file sharing modes
1237 CCAFShareModeStep::~CCAFShareModeStep()
1241 CCAFShareModeStep::CCAFShareModeStep(CCAFServer& aParent) : iParent(aParent)
1243 SetTestStepName(KCAFShareModeStep);
1247 TVerdict CCAFShareModeStep::doTestStepL()
1249 TVerdict verdict = EFail;
1250 TRAPD(err, verdict = doShareModeStepL());
1253 if(err != KErrInUse)
1259 User::Leave(KErrGeneral);
1265 TVerdict CCAFShareModeStep::doShareModeStepL()
1267 CAttribute *attr = NULL;
1273 SetTestStepResult(EPass);
1275 GetStringFromConfig(ConfigSection(),_L("FileName"),fileName);
1277 // This function works if I step through everything but fails
1278 // when run or step over the TRAP
1279 // User::Leave(KErrGeneral);
1284 INFO_PRINTF2(_L("Creating Content object for file: %S"), &fileName);
1285 CContent* content= CContent::NewL(fileName);
1289 CleanupClosePushL(fs);
1292 INFO_PRINTF1(_L("Testing EContentShareReadOnly"));
1293 User::LeaveIfError(file.Open(fs, fileName, EFileShareReadersOnly | EFileRead | EFileStream));
1294 CleanupClosePushL(file);
1295 data = content->OpenContentL(EPeek);
1298 data = content->OpenContentL(EPeek, EContentShareReadOnly);
1301 TRAP(err, data = content->OpenContentL(EPeek, EContentShareReadWrite));
1305 // We can open read-write because CAF never writes.
1309 SetTestStepResult(EFail);
1312 // However, exclusive mode should be impossible.
1314 TRAP(err, data = content->OpenContentL(EPeek, EContentShareExclusive));
1317 if(err != KErrInUse)
1319 SetTestStepResult(EFail);
1321 CleanupStack::PopAndDestroy(&file);
1325 INFO_PRINTF1(_L("Testing EContentShareReadWrite"));
1326 content = CContent::NewL(fileName, EContentShareReadWrite);
1327 User::LeaveIfError(file.Open(fs, fileName, EFileShareReadersOrWriters | EFileRead | EFileStream));
1328 CleanupClosePushL(file);
1329 data = content->OpenContentL(EPeek, EContentShareReadWrite);
1333 // We should be able to open read-only
1335 TRAP(err, data = content->OpenContentL(EPeek, EContentShareReadOnly));
1340 SetTestStepResult(EFail);
1343 // but not share exclusive
1345 TRAP(err, data = content->OpenContentL(EPeek, EContentShareExclusive));
1348 if(err != KErrInUse)
1350 SetTestStepResult(EFail);
1352 CleanupStack::PopAndDestroy(&file);
1355 // Reopen the file with write attributes, and make sure ReadOnly becomes impossible
1356 User::LeaveIfError(file.Open(fs, fileName, EFileShareReadersOrWriters | EFileRead | EFileWrite | EFileStream));
1357 CleanupClosePushL(file);
1359 TRAP(err, data = content->OpenContentL(EPeek, EContentShareReadOnly));
1362 if(err != KErrInUse)
1364 SetTestStepResult(EFail);
1367 CleanupStack::PopAndDestroy(&file);
1371 INFO_PRINTF1(_L("Testing EContentShareExclusive"));
1372 User::LeaveIfError(file.Open(fs, fileName, EFileShareExclusive | EFileRead | EFileStream));
1373 CleanupClosePushL(file);
1374 TRAP(err, data = CData::NewL(TVirtualPathPtr(fileName), EPeek, EContentShareReadOnly));
1377 if(err != KErrInUse)
1379 SetTestStepResult(EFail);
1381 TRAP(err, data = CData::NewL(TVirtualPathPtr(fileName), EPeek, EContentShareReadWrite));
1384 if(err != KErrInUse)
1386 SetTestStepResult(EFail);
1388 TRAP(err, data = CData::NewL(TVirtualPathPtr(fileName), EPeek, EContentShareExclusive));
1391 if(err != KErrInUse)
1393 SetTestStepResult(EFail);
1395 CleanupStack::PopAndDestroy(&file);
1397 INFO_PRINTF1(_L("Testing CContent::NewAttributeL"));
1398 content = CContent::NewL(fileName, EContentShareReadWrite);
1399 User::LeaveIfError(file.Open(fs, fileName, EFileShareAny | EFileRead | EFileStream));
1400 CleanupClosePushL(file);
1401 attr = content->NewAttributeL(ETrue,EContentShareReadWrite);
1404 TRAP(err, attr = content->NewAttributeL(ETrue));
1407 if(err != KErrInUse)
1409 SetTestStepResult(EFail);
1411 CleanupStack::PopAndDestroy(2, &fs); // fs, file
1415 return TestStepResult();
1418 CCAFHandleSizeStep::CCAFHandleSizeStep(CCAFServer& aParent)
1421 SetTestStepName(KCAFHandleSizeStep);
1424 CCAFHandleSizeStep::~CCAFHandleSizeStep()
1430 TVerdict CCAFHandleSizeStep::doTestStepL()
1434 SetTestStepResult(EInconclusive);
1436 INFO_PRINTF1(_L("Basic Open Content Test"));
1440 GetStringFromConfig(ConfigSection(),_L("URI1"),uri1);
1441 GetStringFromConfig(ConfigSection(),_L("URI2"),uri2);
1443 INFO_PRINTF2(_L("Creating content object with uri: %S"), &uri1);
1446 User::LeaveIfError(file1.Open(iParent.Fs(), uri1, EFileRead));
1447 CleanupClosePushL(file1);
1449 CContent* content = CContent::NewLC(file1);
1451 INFO_PRINTF1(_L("Creating data object from content"));
1453 CData* data = content->OpenContentL(EPeek);
1454 CleanupStack::PushL(data);
1457 data->DataSizeL(size);
1458 INFO_PRINTF2(_L("Size of content from caf: %d"),size);
1459 CleanupStack::PopAndDestroy(data);
1460 CleanupStack::PopAndDestroy(content);
1463 file1.Seek(ESeekStart, pos);
1465 INFO_PRINTF2(_L("Creating CData object with uri: %S"), &uri1);
1467 data = CData::NewL(file1, KDefaultContentObject(), EPeek);
1468 CleanupStack::PushL(data);
1469 data->DataSizeL(size1);
1470 INFO_PRINTF2(_L("Size of content from caf CData::NewL(): %d"),size1);
1471 CleanupStack::PopAndDestroy(data);
1472 CleanupStack::PopAndDestroy(&file1);
1474 INFO_PRINTF2(_L("Opening standard RFile interface with uri: %S"),&uri2);
1476 User::LeaveIfError(file2.Open(iParent.Fs(), uri2, EFileRead));
1482 INFO_PRINTF2(_L("Size of content from f32: %d"),size2);
1484 if(size == size2 && size1 == size2)
1486 SetTestStepResult(EPass);
1490 SetTestStepResult(EFail);
1494 return TestStepResult();
1498 CCAFHandleSeekReadStep::~CCAFHandleSeekReadStep()
1503 CCAFHandleSeekReadStep::CCAFHandleSeekReadStep(CCAFServer& aParent)
1506 SetTestStepName(KCAFHandleSeekReadStep);
1509 TVerdict CCAFHandleSeekReadStep::doTestStepL()
1511 SetTestStepResult(EInconclusive);
1515 TRequestStatus status;
1518 INFO_PRINTF1(_L("Basic Open Content Test"));
1522 GetStringFromConfig(ConfigSection(),_L("URI1"),uri1);
1523 GetStringFromConfig(ConfigSection(),_L("URI2"),uri2);
1525 INFO_PRINTF2(_L("Creating content object with uri: %S"), &uri1);
1527 User::LeaveIfError(file1.Open(iParent.Fs(), uri1, EFileRead | EFileShareReadersOnly));
1528 CleanupClosePushL(file1);
1529 CContent* content = CContent::NewLC(file1);
1531 INFO_PRINTF1(_L("Creating data object from content"));
1532 CData* data = content->OpenContentL(EPeek);
1533 CleanupStack::PushL(data);
1535 // Now, open the same file using RFile
1537 INFO_PRINTF2(_L("Opening standard RFile interface with uri: %S"),&uri2);
1538 //User::LeaveIfError(file2.Open(iParent.Fs(), uri2, EFileRead | EFileShareReadersOnly));
1539 TInt res = file2.Open(iParent.Fs(), uri2, EFileRead | EFileShareReadersOnly);
1540 CleanupClosePushL(file2);
1544 INFO_PRINTF2(_L("Size of content from f32: %d"),size);
1546 // Seek and read from start using both CAF and RFile
1548 data->Seek(ESeekStart, pos1);
1550 file2.Seek(ESeekStart, pos2);
1553 INFO_PRINTF2(_L("Position from ESeekStart test using CData: %d"), pos1);
1554 INFO_PRINTF2(_L("Position from ESeekStart test using RFile: %d"), pos2);
1555 if (buf1 != buf2 || pos1 != pos2 || pos1 != size/4)
1557 INFO_PRINTF1(_L("ERROR buffers or position do not match"));
1558 SetTestStepResult(EFail);
1561 // set the location within the file then retrieve the current location within the file
1564 data->Seek(ESeekCurrent, pos1);
1565 file2.Seek(ESeekCurrent, pos2);
1567 INFO_PRINTF2(_L("Current position using CData: %d"), pos1);
1568 INFO_PRINTF2(_L("Current position using RFile: %d"), pos2);
1570 if(pos1 != pos2 || pos1 != (size/4 + buf1.Length()))
1572 INFO_PRINTF1(_L("ERROR buffers or position do not match"));
1573 SetTestStepResult(EFail);
1576 // Seek and read from current using both CAF and RFile
1578 data->Seek(ESeekCurrent, pos1);
1580 file2.Seek(ESeekCurrent, pos2);
1583 INFO_PRINTF2(_L("Position from ESeekCurrent test using CData: %d"), pos1);
1584 INFO_PRINTF2(_L("Position from ESeekCurrent test using RFile: %d"), pos2);
1585 if (buf1 != buf2 || pos1 != pos2 || pos1 != (size/2 + buf1.Length()))
1587 INFO_PRINTF1(_L("ERROR buffers or position do not match"));
1588 SetTestStepResult(EFail);
1591 // Seek and read from end using both CAF and RFile
1593 data->Seek(ESeekEnd, pos1);
1595 file2.Seek(ESeekEnd, pos2);
1598 INFO_PRINTF2(_L("Position from ESeekEnd test using CData: %d"), pos1);
1599 INFO_PRINTF2(_L("Position from ESeekEnd test using RFile: %d"), pos2);
1600 if (buf1 != buf2 || pos1 != pos2 || pos1 != (size - size/4))
1602 INFO_PRINTF1(_L("ERROR buffers or position do not match"));
1603 SetTestStepResult(EFail);
1606 // Test other overloaded forms of CData::Read
1608 // Read only 1 byte using both CAF and RFile
1610 data->Seek(ESeekStart, pos1);
1612 file2.Seek(ESeekStart, pos2);
1615 INFO_PRINTF2(_L("Data Length from CData::Read(TDesC& ,TInt Length) : %d"), buf1.Length());
1616 INFO_PRINTF2(_L("Data Length from RFile::Read(TDesC& , TInt Length): %d"), buf2.Length());
1620 data->Seek(ESeekCurrent, pos1);
1621 file2.Seek(ESeekCurrent,pos2);
1622 if (buf1 != buf2 || pos1 != pos2 || buf1.Length() != buf2.Length())
1624 INFO_PRINTF1(_L("ERROR buffers or position do not match"));
1625 SetTestStepResult(EFail);
1628 // Read asynchronously using both CAF and RFile
1629 INFO_PRINTF1(_L("Asynchronous read from CAF and RFile"));
1631 data->Seek(ESeekStart, pos1);
1633 file2.Seek(ESeekStart, pos2);
1634 status = KRequestPending;
1635 data->Read(buf1,status);
1636 User::WaitForRequest(status);
1637 status = KRequestPending;
1638 file2.Read(buf2,status);
1639 User::WaitForRequest(status);
1640 INFO_PRINTF2(_L("Data length from CData::Read(TDesC& ,TRequestStatus& aStatus): %d"), buf1.Length());
1641 INFO_PRINTF2(_L("Data length from RFile::Read(TDesC& , TRequestStatus& aStatus): %d"), buf2.Length());
1645 data->Seek(ESeekCurrent, pos1);
1646 file2.Seek(ESeekCurrent,pos2);
1647 if (buf1 != buf2 || pos1 != pos2 || buf1.Length() != buf2.Length())
1649 INFO_PRINTF1(_L("ERROR buffers or position do not match"));
1650 SetTestStepResult(EFail);
1653 // Read only 1 byte asynchronously using both CAF and RFile
1654 INFO_PRINTF1(_L("Asynchronous read of 1 byte from CAF and RFile"));
1656 data->Seek(ESeekStart, pos1);
1658 file2.Seek(ESeekStart, pos2);
1659 status = KRequestPending;
1660 data->Read(buf1,1,status);
1661 User::WaitForRequest(status);
1662 status = KRequestPending;
1663 file2.Read(buf2,1, status);
1664 User::WaitForRequest(status);
1665 INFO_PRINTF2(_L("Data Length from CData::Read(TDesC& ,TInt Length, TRequestStatus aStatus) : %d"), buf1.Length());
1666 INFO_PRINTF2(_L("Data Length from RFile::Read(TDesC& , TInt Length, TRequestStatus aStatus): %d"), buf2.Length());
1670 data->Seek(ESeekCurrent, pos1);
1671 file2.Seek(ESeekCurrent,pos2);
1672 if (buf1 != buf2 || pos1 != pos2 || buf1.Length() != buf2.Length())
1674 INFO_PRINTF1(_L("ERROR buffers or position do not match"));
1675 SetTestStepResult(EFail);
1681 data->Seek(ESeekStart, pos1);
1682 file2.Seek(ESeekStart, pos2);
1686 if(buf1.Length() != 0 || buf1.Length() != 0)
1688 INFO_PRINTF1(_L("ERROR data read past EOF"));
1689 SetTestStepResult(EFail);
1692 CleanupStack::PopAndDestroy(4);
1696 if (TestStepResult() != EFail)
1698 SetTestStepResult(EPass);
1701 return TestStepResult();
1705 * Step reads from a CData from multiple threads using RFile handle
1709 CCAFHandleMultiThreadCDataStep::~CCAFHandleMultiThreadCDataStep()
1714 CCAFHandleMultiThreadCDataStep::CCAFHandleMultiThreadCDataStep(CCAFServer& aParent)
1718 SetTestStepName(KCAFHandleMultiThreadCDataStep);
1721 TVerdict CCAFHandleMultiThreadCDataStep::doTestStepL()
1726 _LIT(KCDataThread,"CData_Thread");
1728 SetTestStepResult(EInconclusive);
1730 INFO_PRINTF1(_L("Multi Thread CData Test using RFile Handle"));
1733 GetStringFromConfig(ConfigSection(),_L("URI"),uri);
1735 INFO_PRINTF1(_L("Creating data object from content"));
1737 User::LeaveIfError(file.Open(iParent.Fs(), uri, EFileRead));
1739 CleanupClosePushL(file);
1741 CContent* content = CContent::NewLC(file);
1742 CData* data = content->OpenContentL(EPeek);
1743 CleanupStack::PushL(data);
1747 // Create a mutex for communication between our thread and the new thread
1748 RSemaphore threadSemaphore;
1749 threadSemaphore.CreateGlobal(KCDataThreadSemaphore(), 1, EOwnerProcess);
1750 threadSemaphore.Wait();
1752 // fire up a new thread, stack size and heap size 8k, might need to be bigger in the future
1753 RThread readerThread;
1754 User::LeaveIfError(readerThread.Create(KCDataThread(),CCAFMultiThreadCDataStep::ReaderThreadEntry,8192, KMinHeapSize, 8192, (TAny *) data, EOwnerProcess));
1756 // request notification of thread completion
1757 TRequestStatus stat;
1758 readerThread.Logon(stat);
1759 readerThread.Resume();
1762 data->DataSizeL(size);
1764 data->Seek(ESeekStart,pos);
1767 threadSemaphore.Wait(); // wait for thread function to run and signal the semaphore
1768 threadSemaphore.Signal(); // finished with semaphore
1769 threadSemaphore.Close(); // so close
1771 User::WaitForRequest(stat); // wait for thread to finish
1772 TInt error=(readerThread.ExitType()==EExitPanic) ? KErrGeneral : stat.Int();
1773 User::LeaveIfError(error);
1774 readerThread.Close(); // close the thread
1776 CleanupStack::PopAndDestroy(data);
1777 CleanupStack::PopAndDestroy(content);
1778 CleanupStack::PopAndDestroy(&file); //file
1783 SetTestStepResult(EPass);
1784 return TestStepResult();
1787 TInt CCAFHandleMultiThreadCDataStep::ReaderThreadEntry(TAny *aPtr)
1790 CData *data = reinterpret_cast <CData *> (aPtr);
1792 // create a trap handler
1793 CTrapCleanup* cleanup = CTrapCleanup::New();
1795 RSemaphore threadSemaphore;
1796 threadSemaphore.OpenGlobal(KCDataThreadSemaphore() ,EOwnerProcess);
1799 threadSemaphore.Signal(); // allow original thread to continue
1800 threadSemaphore.Close();
1807 * Data attribute step
1811 CCAFDataAttributeStep::~CCAFDataAttributeStep()
1815 CCAFDataAttributeStep::CCAFDataAttributeStep(CCAFServer& aParent) : iParent(aParent)
1817 SetTestStepName(KCAFDataAttributeStep);
1820 TVerdict CCAFDataAttributeStep::doTestStepL()
1822 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
1823 TBool wmdrmFlag = EFalse;
1824 GetBoolFromConfig(ConfigSection(),_L("wmdrmEnabled"), wmdrmFlag);
1828 TVerdict verdict = doWmdrmTestStepL();
1831 #endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
1834 TInt value = KErrNone;
1835 TInt expectedValue = KErrNone;
1839 SetTestStepResult(EPass);
1841 GetIntFromConfig(ConfigSection(),_L("attribute"),attribute);
1842 GetStringFromConfig(ConfigSection(),_L("uri"),uri);
1843 GetStringFromConfig(ConfigSection(),_L("uniqueid"),uniqueId);
1844 GetIntFromConfig(ConfigSection(),_L("value"),expectedValue);
1847 CContent *content = CContent::NewLC(uri);
1848 CData *data = content->OpenContentL(EPeek, uniqueId);
1849 User::LeaveIfError(data->GetAttribute(attribute, value));
1851 if(expectedValue != value)
1853 SetTestStepResult(EFail);
1854 INFO_PRINTF3(_L("CData::GetAttribute() Expected value: %d, actual value: %d"), expectedValue, value);
1857 CleanupStack::PopAndDestroy(content);
1859 return TestStepResult();
1863 * Data attributeset step
1867 CCAFDataAttributeSetStep::~CCAFDataAttributeSetStep()
1871 CCAFDataAttributeSetStep::CCAFDataAttributeSetStep(CCAFServer& aParent) : iParent(aParent)
1873 SetTestStepName(KCAFDataAttributeSetStep);
1876 TVerdict CCAFDataAttributeSetStep::doTestStepL()
1878 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
1879 TBool wmdrmFlag = EFalse;
1880 GetBoolFromConfig(ConfigSection(),_L("wmdrmEnabled"), wmdrmFlag);
1884 TVerdict verdict = doWmdrmTestStepL();
1887 #endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
1889 TInt expectedValue1;
1890 TInt expectedValue2;
1895 TInt result = KErrNone;
1899 SetTestStepResult(EPass);
1901 GetStringFromConfig(ConfigSection(),_L("uri"),uri);
1902 GetStringFromConfig(ConfigSection(),_L("uniqueid"),uniqueId);
1903 GetIntFromConfig(ConfigSection(),_L("attribute1"),attribute1);
1904 GetIntFromConfig(ConfigSection(),_L("attribute2"),attribute2);
1905 GetIntFromConfig(ConfigSection(),_L("value1"),expectedValue1);
1906 GetIntFromConfig(ConfigSection(),_L("value2"),expectedValue2);
1909 CContent *content = CContent::NewLC(uri);
1910 RAttributeSet attributeSet;
1911 CleanupClosePushL(attributeSet);
1912 attributeSet.AddL(attribute1);
1913 attributeSet.AddL(attribute2);
1915 CData *data = content->OpenContentL(EPeek, uniqueId);
1916 result = data->GetAttributeSet(attributeSet);
1918 if(result != KErrNone)
1920 SetTestStepResult(EFail);
1921 INFO_PRINTF1(_L("CData::GetAttribute() failed"));
1923 User::LeaveIfError(attributeSet.GetValue(attribute1, value1));
1924 User::LeaveIfError(attributeSet.GetValue(attribute2, value2));
1925 if(value1 != expectedValue1 || value2 != expectedValue2 || attributeSet.Count() != 2)
1927 SetTestStepResult(EFail);
1928 INFO_PRINTF1(_L("CData::GetAttributeSet() values don't match expected values"));
1930 CleanupStack::PopAndDestroy(&attributeSet);
1931 CleanupStack::PopAndDestroy(content);
1934 return TestStepResult();
1939 * Data string attribute step
1943 CCAFDataStringAttributeStep::~CCAFDataStringAttributeStep()
1947 CCAFDataStringAttributeStep::CCAFDataStringAttributeStep(CCAFServer& aParent) : iParent(aParent)
1949 SetTestStepName(KCAFDataStringAttributeStep);
1952 TVerdict CCAFDataStringAttributeStep::doTestStepL()
1954 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
1955 TBool wmdrmFlag = EFalse;
1956 GetBoolFromConfig(ConfigSection(),_L("wmdrmEnabled"), wmdrmFlag);
1960 TVerdict verdict = doWmdrmTestStepL();
1963 #endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
1965 TInt expectedResult;
1967 TPtrC expectedValue;
1969 TInt result = KErrNone;
1973 SetTestStepResult(EPass);
1975 GetIntFromConfig(ConfigSection(),_L("attribute"),attribute);
1976 GetStringFromConfig(ConfigSection(),_L("uri"),uri);
1977 GetStringFromConfig(ConfigSection(),_L("uniqueid"),uniqueId);
1978 GetStringFromConfig(ConfigSection(),_L("value"),expectedValue);
1979 GetIntFromConfig(ConfigSection(),_L("result"),expectedResult);
1982 CContent *content = CContent::NewLC(uri);
1983 CData *data = content->OpenContentL(EPeek, uniqueId);
1984 result = data->GetStringAttribute(attribute, value);
1986 if(result != expectedResult)
1988 SetTestStepResult(EFail);
1989 INFO_PRINTF3(_L("CData::GetStringAttribute() Expected result: %d, actual result: %d"), expectedResult, result);
1991 if(value != expectedValue)
1993 SetTestStepResult(EFail);
1994 INFO_PRINTF3(_L("CData::GetStringAttribute() Expected value: %S, actual result: %S"), &expectedValue, &value);
1997 CleanupStack::PopAndDestroy(content);
2000 return TestStepResult();
2004 * Data StringAttributeSet step
2008 CCAFDataStringAttributeSetStep::~CCAFDataStringAttributeSetStep()
2012 CCAFDataStringAttributeSetStep::CCAFDataStringAttributeSetStep(CCAFServer& aParent) : iParent(aParent)
2014 SetTestStepName(KCAFDataStringAttributeSetStep);
2017 TVerdict CCAFDataStringAttributeSetStep::doTestStepL()
2019 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
2020 TBool wmdrmFlag = EFalse;
2021 GetBoolFromConfig(ConfigSection(),_L("wmdrmEnabled"), wmdrmFlag);
2025 TVerdict verdict = doWmdrmTestStepL();
2028 #endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
2030 TPtrC expectedValue1;
2031 TPtrC expectedValue2;
2036 TInt result = KErrNone;
2042 SetTestStepResult(EPass);
2044 GetStringFromConfig(ConfigSection(),_L("uri"),uri);
2045 GetStringFromConfig(ConfigSection(),_L("uniqueid"),uniqueId);
2046 GetIntFromConfig(ConfigSection(),_L("attribute1"),attribute1);
2047 GetIntFromConfig(ConfigSection(),_L("attribute2"),attribute2);
2048 GetStringFromConfig(ConfigSection(),_L("value1"),expectedValue1);
2049 GetStringFromConfig(ConfigSection(),_L("value2"),expectedValue2);
2050 GetIntFromConfig(ConfigSection(),_L("result1"),result1);
2051 GetIntFromConfig(ConfigSection(),_L("result2"),result2);
2054 CContent *content = CContent::NewLC(uri);
2055 RStringAttributeSet attributeSet;
2056 CleanupClosePushL(attributeSet);
2057 attributeSet.AddL(attribute1);
2058 attributeSet.AddL(attribute2);
2060 CData *data = content->OpenContentL(EPeek, uniqueId);
2061 result = data->GetStringAttributeSet(attributeSet);
2063 if(result != KErrNone)
2065 SetTestStepResult(EFail);
2066 INFO_PRINTF1(_L("CData::GetAttribute() failed"));
2068 if(result1 != attributeSet.GetValue(attribute1, value1))
2070 INFO_PRINTF1(_L("RStringAttributeSet::GetValue failed"));
2072 if(result2 != attributeSet.GetValue(attribute2, value2))
2074 INFO_PRINTF1(_L("RStringAttributeSet::GetValue failed"));
2076 if( value1 != expectedValue1 || value2 != expectedValue2 || attributeSet.Count() != 2)
2078 SetTestStepResult(EFail);
2079 INFO_PRINTF1(_L("CData::GetAttributeSet() values don't match expected values"));
2081 CleanupStack::PopAndDestroy(&attributeSet);
2082 CleanupStack::PopAndDestroy(content);
2086 return TestStepResult();
2090 CCAFExecuteIntentStep::~CCAFExecuteIntentStep()
2094 CCAFExecuteIntentStep::CCAFExecuteIntentStep(CCAFServer& aParent)
2097 SetTestStepName(KCAFSizeStep);
2100 TVerdict CCAFExecuteIntentStep::doTestStepL()
2104 SetTestStepResult(EInconclusive);
2106 INFO_PRINTF1(_L("Execute Intent Test"));
2110 TInt intent = EPeek;
2111 TInt expectedResult = KErrNone;
2113 GetStringFromConfig(ConfigSection(),_L("FileName"),fileName);
2114 GetStringFromConfig(ConfigSection(),_L("UniqueId"),uniqueId);
2115 GetIntFromConfig(ConfigSection(),_L("Intent"),intent);
2116 GetIntFromConfig(ConfigSection(),_L("ExpectedResult"),expectedResult);
2118 INFO_PRINTF3(_L("Creating CData object with filename: %S, UniqueId: %S"), &fileName, &uniqueId);
2122 TRAPD(err, data = CData::NewL(TVirtualPathPtr(fileName, uniqueId),static_cast<TIntent>(intent), EContentShareReadOnly));
2124 if(err != expectedResult)
2126 INFO_PRINTF2(_L("Unexpected result, EvaluateIntent() returned %d"), err);
2130 SetTestStepResult(EPass);
2133 err = data->ExecuteIntent(static_cast<TIntent>(intent));
2139 // read the entire content object
2140 while(err == KErrNone && length > 0)
2142 err = data->Read(buffer);
2143 length = buffer.Length();
2145 if(err != KErrEof && err != KErrNone)
2147 INFO_PRINTF2(_L("Unexpected error while reading content object: %d"), err);
2148 SetTestStepResult(EFail);
2153 INFO_PRINTF2(_L("Unexpected error, EvaluteIntent succeeded but ExecuteIntent failed with error: %d"), err);
2154 SetTestStepResult(EFail);
2162 return TestStepResult();
2166 * DRM File Open Performance Test Step
2170 CCAFDRMFileOpenPerformanceTest::~CCAFDRMFileOpenPerformanceTest()
2175 CCAFDRMFileOpenPerformanceTest::CCAFDRMFileOpenPerformanceTest(CCAFServer& aParent) : iParent(aParent)
2177 SetTestStepName(KCAFDRMFileOpenPerformanceStep);
2180 TVerdict CCAFDRMFileOpenPerformanceTest::doTestStepL()
2184 INFO_PRINTF1(_L("DRM File Open Performance Test"));
2186 TPtrC inputFileName;
2187 TInt maxValue = 0 ,iterCount = 0;
2189 GetStringFromConfig(ConfigSection(),_L("FileName"),inputFileName);
2190 GetIntFromConfig(ConfigSection(),_L("IterationCount"),iterCount);
2191 GetIntFromConfig(ConfigSection(),_L("MaxTimeLimitInMS"),maxValue);
2194 // iterated iterCount times to get the average time taken to open the file.
2195 for (TInt i = 0; i < iterCount; ++i)
2197 OpenAndReadFileContentL(inputFileName);
2201 HAL::Get(HAL::ENanoTickPeriod, tickPeriod);
2202 TInt nTickPeriodMS = tickPeriod / KCafTestSecToMS;
2204 TInt avgTimeForFileOpen = (iIterationSum * nTickPeriodMS) / iterCount;
2205 if((avgTimeForFileOpen > maxValue))
2207 INFO_PRINTF1(_L("Performance Test failed."));
2208 SetTestStepResult(EFail);
2211 INFO_PRINTF2(_L("Expected maximum time to open DRM file in millisecs is : %d"), maxValue);
2212 INFO_PRINTF2(_L("Obtained time in millisecs is: %d"), avgTimeForFileOpen);
2216 return TestStepResult();
2219 void CCAFDRMFileOpenPerformanceTest::OpenAndReadFileContentL(const TDesC& aFileName)
2221 TPtrC uniqueIdentifier;
2223 GetStringFromConfig(ConfigSection(),_L("UniqueId"),uniqueIdentifier);
2224 CContent *content = CContent::NewLC(aFileName);
2226 TUint32 tickCounterValBeforeFileOpen, tickCounterValAfterFileOpen;
2227 if(uniqueIdentifier.Length() > 0)
2229 tickCounterValBeforeFileOpen = User::NTickCount();
2230 data = content->OpenContentL(EPeek,uniqueIdentifier);
2231 tickCounterValAfterFileOpen = User::NTickCount();
2235 tickCounterValBeforeFileOpen = User::NTickCount();
2236 data = content->OpenContentL(EPeek);
2237 tickCounterValAfterFileOpen = User::NTickCount();
2240 // finished with Data object
2241 CleanupStack::PopAndDestroy(content);
2242 iIterationSum += tickCounterValAfterFileOpen - tickCounterValBeforeFileOpen;
2245 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
2247 CWmdrmCAFContentStep::~CWmdrmCAFContentStep()
2251 CWmdrmCAFContentStep::CWmdrmCAFContentStep()
2253 SetTestStepName(KWmdrmCAFContentStep);
2257 TVerdict CWmdrmCAFContentStep::doTestStepL()
2259 SetTestStepResult(EFail);
2262 GetBoolFromConfig(ConfigSection(),_L("attribValue1"), protectedVal);
2264 GetBoolFromConfig(ConfigSection(),_L("attribValue2"), forwardable);
2266 TBool headerDataPresent = ETrue;
2267 GetBoolFromConfig(ConfigSection(),_L("headerDataFlag"), headerDataPresent);
2269 INFO_PRINTF1(_L("Verify CContent APIs for WMDRM content"));
2273 CContent* content = NULL;
2275 // this condition verifies that CContent construction leaves with KErrMissingWmdrmHeaderData,
2276 // when no header data is provided.
2277 if(!headerDataPresent)
2279 content = CContent::NewL(KNullDesC8());
2283 // create a dummy header data.
2284 HBufC8* headerData = CreateWmdrmHeaderLC();
2286 // Open a file and retrieve the attributes.
2287 // If headerDataPresent is false, the code will never reach here.s
2288 content = CContent::NewL(*headerData);
2289 CleanupStack::PushL(content);
2290 CAttribute* attrs = content->NewAttributeL(ETrue);
2291 CleanupStack::PushL(attrs);
2293 TBool value1 = attrs->ResponseSet().IsSet(EIsProtected);
2294 TBool value2 = attrs->ResponseSet().IsSet(EIsForwardable);
2295 if(value1 == protectedVal && value2 == forwardable)
2297 SetTestStepResult(EPass);
2300 CleanupStack::PopAndDestroy(3, headerData);
2303 return TestStepResult();
2307 CWmdrmCAFDataStep::~CWmdrmCAFDataStep()
2311 CWmdrmCAFDataStep::CWmdrmCAFDataStep()
2313 SetTestStepName(KWmdrmCAFDataStep);
2316 TVerdict CWmdrmCAFDataStep::doTestStepL()
2318 SetTestStepResult(EFail);
2321 TInt expectedValue = KErrNone;
2323 GetIntFromConfig(ConfigSection(),_L("attribute"), attribute);
2324 GetIntFromConfig(ConfigSection(),_L("value"), expectedValue);
2328 HBufC8* headerData = CreateWmdrmHeaderLC();
2330 CContent *content = CContent::NewLC(*headerData);
2331 CData *data = content->OpenContentL(EPeek);
2332 TInt value = KErrNone;
2333 User::LeaveIfError(data->GetAttribute(attribute, value));
2336 if(expectedValue == value)
2338 SetTestStepResult(EPass);
2342 INFO_PRINTF3(_L("CData::GetAttribute() Expected value: %d, actual value: %d"), expectedValue, value);
2345 CleanupStack::PopAndDestroy(2, headerData);
2348 return TestStepResult();
2352 CWmdrmCAFReadStep::~CWmdrmCAFReadStep()
2356 CWmdrmCAFReadStep::CWmdrmCAFReadStep()
2358 SetTestStepName(KWmdrmCAFReadStep);
2362 TVerdict CWmdrmCAFReadStep::doTestStepL()
2364 SetTestStepResult(EFail);
2366 TBool synchronous = EFalse;
2367 GetBoolFromConfig(ConfigSection(),_L("synchronous"), synchronous);
2368 TBool intent = EFalse;
2369 GetBoolFromConfig(ConfigSection(),_L("intent"), intent);
2371 GetStringFromConfig(ConfigSection(),_L("inputPacket"), inputPacket);
2372 TPtrC expectedOutput;
2373 GetStringFromConfig(ConfigSection(),_L("outputPacket"), expectedOutput);
2377 HBufC8* headerData = NULL;
2379 if(GetStringFromConfig(ConfigSection(),_L("header"), header))
2381 headerData = ConvertDes16toHBufC8LC(header);
2385 headerData = CreateWmdrmHeaderLC();
2391 result = TestAsynchronousReadL(*headerData, intent, inputPacket, expectedOutput);
2395 result = TestSynchronousReadL(*headerData, intent, inputPacket, expectedOutput);
2398 if(result == KErrNone)
2400 SetTestStepResult(EPass);
2403 CleanupStack::PopAndDestroy(headerData);
2406 return TestStepResult();
2409 TInt CWmdrmCAFReadStep::TestSynchronousReadL(const TDesC8& aHeaderData, TBool aIntent, TDesC& aInputPacket, TDesC& aExpectedOutput)
2413 TInt returnVal = KErrGeneral;
2417 data = CData::NewL(aHeaderData, EPeek);
2421 data = CData::NewL(aHeaderData);
2424 CleanupStack::PushL(data);
2426 if(aInputPacket.Length() <= 0)
2428 // dummy output buffer.This loop essentially tests the error condition KErrInsufficientDataPacketLength.
2429 TBuf8<2> outputBuffer;
2430 User::LeaveIfError(data->Read(KNullDesC8(), outputBuffer));
2435 HBufC8* inputPacket = ConvertDes16toHBufC8LC(aInputPacket);
2436 HBufC8* outputPacket = HBufC8::NewLC(aInputPacket.Length());
2437 TPtr8 outputPacketPtr = outputPacket->Des();
2439 User::LeaveIfError(data->Read(*inputPacket, outputPacketPtr));
2440 HBufC8* expectedOutput = ConvertDes16toHBufC8LC(aExpectedOutput);
2441 if(expectedOutput->Compare(*outputPacket) == KErrNone)
2443 returnVal = KErrNone;
2446 CleanupStack::PopAndDestroy(3, inputPacket);
2449 CleanupStack::PopAndDestroy(data);
2455 TInt CWmdrmCAFReadStep::TestAsynchronousReadL(const TDesC8& aHeaderData, TBool aIntent, TDesC& aInputPacket, TDesC& aExpectedOutput)
2459 TInt returnVal = KErrGeneral;
2463 data = CData::NewL(aHeaderData, EPeek);
2467 data = CData::NewL(aHeaderData);
2470 CleanupStack::PushL(data);
2472 if(aInputPacket.Length() <= 0)
2474 TBuf8<2> outputBuffer;
2475 User::LeaveIfError(data->Read(KNullDesC8(), outputBuffer));
2480 HBufC8* inputPacket = ConvertDes16toHBufC8LC(aInputPacket);
2481 HBufC8* outputPacket = HBufC8::NewLC(aInputPacket.Length());
2482 TPtr8 outputPacketPtr = outputPacket->Des();
2484 TRequestStatus status;
2485 data->Read(*inputPacket, outputPacketPtr, status);
2486 User::WaitForRequest(status);
2488 if(status.Int() != KErrNone)
2490 CleanupStack::PopAndDestroy(3, data);
2491 return status.Int();
2494 HBufC8* expectedOutput = ConvertDes16toHBufC8LC(aExpectedOutput);
2495 if(expectedOutput->Compare(*outputPacket) == KErrNone)
2497 returnVal = KErrNone;
2500 CleanupStack::PopAndDestroy(3, inputPacket);
2503 CleanupStack::PopAndDestroy(data);
2509 TVerdict CCAFDataAttributeStep::doWmdrmTestStepL()
2511 SetTestStepResult(EFail);
2514 GetIntFromConfig(ConfigSection(),_L("attribute"), attribVal);
2517 GetIntFromConfig(ConfigSection(),_L("value"), expectedValue);
2521 HBufC8* headerData = NULL;
2523 if(GetStringFromConfig(ConfigSection(),_L("header"), header))
2525 headerData = ConvertDes16toHBufC8LC(header);
2529 headerData = CreateWmdrmHeaderLC();
2532 CContent *content = CContent::NewLC(*headerData);
2533 CData *data = content->OpenContentL(EPeek);
2535 User::LeaveIfError(data->GetAttribute(attribVal, value));
2538 if(expectedValue == value)
2540 SetTestStepResult(EPass);
2544 INFO_PRINTF3(_L("CData::GetAttribute() Expected value: %d, actual value: %d"), expectedValue, value);
2547 CleanupStack::PopAndDestroy(2, headerData);
2550 return TestStepResult();
2554 TVerdict CCAFDataAttributeSetStep::doWmdrmTestStepL()
2556 SetTestStepResult(EFail);
2559 GetIntFromConfig(ConfigSection(),_L("attribute1"),attribute1);
2562 GetIntFromConfig(ConfigSection(),_L("attribute2"),attribute2);
2564 TInt expectedValue1;
2565 GetIntFromConfig(ConfigSection(),_L("value1"),expectedValue1);
2567 TInt expectedValue2;
2568 GetIntFromConfig(ConfigSection(),_L("value2"),expectedValue2);
2573 HBufC8* headerData = NULL;
2575 if(GetStringFromConfig(ConfigSection(),_L("header"), header))
2577 headerData = ConvertDes16toHBufC8LC(header);
2581 headerData = CreateWmdrmHeaderLC();
2584 CContent *content = CContent::NewLC(*headerData);
2585 CData *data = content->OpenContentL(EPeek);
2587 RAttributeSet attributeSet;
2588 CleanupClosePushL(attributeSet);
2589 attributeSet.AddL(attribute1);
2590 attributeSet.AddL(attribute2);
2592 TInt result = data->GetAttributeSet(attributeSet);
2595 if(result == KErrNone)
2598 User::LeaveIfError(attributeSet.GetValue(attribute1, value1));
2601 User::LeaveIfError(attributeSet.GetValue(attribute2, value2));
2603 if(expectedValue1 == value1 && expectedValue2 == value2 && attributeSet.Count() == 2)
2605 SetTestStepResult(EPass);
2609 INFO_PRINTF1(_L("CData::GetAttributeSet() values don't match expected values"));
2615 INFO_PRINTF1(_L("CData::GetAttributeSet() failed"));
2618 CleanupStack::PopAndDestroy(3, headerData);
2622 return TestStepResult();
2626 TVerdict CCAFDataStringAttributeStep::doWmdrmTestStepL()
2628 SetTestStepResult(EFail);
2631 GetIntFromConfig(ConfigSection(),_L("attribute"),attribVal);
2633 TPtrC expectedValue;
2634 GetStringFromConfig(ConfigSection(),_L("value"),expectedValue);
2636 TInt expectedResult;
2637 GetIntFromConfig(ConfigSection(),_L("result"),expectedResult);
2641 HBufC8* headerData = NULL;
2643 if(GetStringFromConfig(ConfigSection(),_L("header"), header))
2645 headerData = ConvertDes16toHBufC8LC(header);
2649 headerData = CreateWmdrmHeaderLC();
2652 CContent *content = CContent::NewLC(*headerData);
2653 CData *data = content->OpenContentL(EPeek);
2656 TInt result = data->GetStringAttribute(attribVal, value);
2659 if(result == expectedResult && value == expectedValue)
2661 SetTestStepResult(EPass);
2665 INFO_PRINTF3(_L("CData::GetStringAttribute() Expected result: %d, actual result: %d"), expectedResult, result);
2666 INFO_PRINTF3(_L("CData::GetStringAttribute() Expected value: %S, actual value: %S"), &expectedValue, &value);
2669 CleanupStack::PopAndDestroy(2, headerData);
2673 return TestStepResult();
2677 TVerdict CCAFDataStringAttributeSetStep::doWmdrmTestStepL()
2679 SetTestStepResult(EFail);
2682 GetIntFromConfig(ConfigSection(),_L("attribute1"),attribute1);
2685 GetIntFromConfig(ConfigSection(),_L("attribute2"),attribute2);
2687 TPtrC expectedValue1;
2688 GetStringFromConfig(ConfigSection(),_L("value1"),expectedValue1);
2690 TPtrC expectedValue2;
2691 GetStringFromConfig(ConfigSection(),_L("value2"),expectedValue2);
2695 HBufC8* headerData = NULL;
2697 if(GetStringFromConfig(ConfigSection(),_L("header"), header))
2699 headerData = ConvertDes16toHBufC8LC(header);
2703 headerData = CreateWmdrmHeaderLC();
2706 CContent *content = CContent::NewLC(*headerData);
2707 CData *data = content->OpenContentL(EPeek);
2709 RStringAttributeSet attributeSet;
2710 CleanupClosePushL(attributeSet);
2711 attributeSet.AddL(attribute1);
2712 attributeSet.AddL(attribute2);
2714 TInt result = data->GetStringAttributeSet(attributeSet);
2719 if(result == KErrNone)
2721 TInt result3 = attributeSet.GetValue(attribute1, value1);
2722 TInt result4 = attributeSet.GetValue(attribute2, value2);
2724 if(value1 == expectedValue1 && value2 == expectedValue2 && attributeSet.Count() == 2
2725 && result3 == KErrNone && result4 == KErrNone)
2727 SetTestStepResult(EPass);
2731 INFO_PRINTF3(_L("RStringAttributeSet::GetValue() for attribute1.Expected value: %S, actual value: %S"), &expectedValue1, &value1);
2732 INFO_PRINTF3(_L("RStringAttributeSet::GetValue() for attribute2.Expected value: %S, actual value: %S"), &expectedValue2, &value2);
2733 INFO_PRINTF3(_L("RStringAttributeSet::GetValue() for attribute1. Expected result: %d, actual result: %d"), 0, result3);
2734 INFO_PRINTF3(_L("RStringAttributeSet::GetValue() for attribute2. Expected result: %d, actual result: %d"), 0, result4);
2739 INFO_PRINTF1(_L("CData::GetStringAttributeSet() failed"));
2742 CleanupStack::PopAndDestroy(3, headerData);
2746 return TestStepResult();
2749 #endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT