os/security/contentmgmt/referencedrmagent/tsmoke/smoke.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     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".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 *
    16 */
    17 
    18 
    19 #include <ecom/ecom.h>
    20 #include <caf/content.h>
    21 #include <caf/data.h>
    22 
    23 #include "smoke.h"
    24 #include <ecom/implementationinformation.h>
    25 
    26 using namespace ContentAccess;
    27 
    28 CTestConsole* CTestConsole::NewL(CConsoleBase* aCon)
    29 {
    30   CTestConsole* self;
    31   self=new (ELeave) CTestConsole;
    32   self->iCon=aCon;
    33   self->iFile=NULL;
    34   return self;
    35 }
    36 
    37 CTestConsole::CTestConsole(void):CConsoleBase()
    38 {}
    39 
    40 CTestConsole::~CTestConsole(void)
    41 {
    42   delete iCon;
    43   if (iFile)
    44     {
    45       iFile->Close();
    46     }
    47 }
    48 
    49 void CTestConsole::Write(const TDesC16& aString)
    50 {
    51   iCon->Write(aString);
    52   if (iFile)
    53     {
    54       TUint8 space[200];
    55       TPtr8 ptr(space,200);
    56       ptr.Copy(aString);
    57       iFile->Write(ptr);
    58     }
    59 }
    60 
    61 void CTestConsole::SetLogFile(RFile* aFile)
    62 {
    63   iFile=aFile;
    64 }
    65 
    66 RTest test(_L("CAF Build Test"));
    67 
    68 void RunTest1(void)
    69 {
    70   test.Start(_L(" @SYMTestCaseID:SEC-CAF-SMOKE-0001 CAF Test "));		 
    71 
    72   CTestConsole* con=NULL;
    73   TRAPD(ret, con=CTestConsole::NewL(test.Console()));
    74   RFs fs;
    75   
    76   fs.Connect();
    77   RFile* file;
    78   file=new (ELeave) RFile;
    79   
    80   file->Replace(fs,_L("c:\\DRMLog.txt"),EFileShareAny|EFileWrite);
    81   con->SetLogFile(file);
    82   test.SetConsole(con);
    83   
    84   const TUid KInterfaceUID = {0x101FC2CE};
    85 
    86   RImplInfoPtrArray aImplInfoArray;
    87 
    88   // do here
    89   test.Printf(_L("\nCAF Test Starting\n"));
    90   test.Getch();
    91 
    92   test.Printf(_L("Ready to get implementations of %08X\n"),KInterfaceUID);
    93   //test.Getch();
    94 
    95   __UHEAP_MARK; // start heap debug
    96   
    97   REComSession::ListImplementationsL(KInterfaceUID , aImplInfoArray);
    98 
    99   TUint count = aImplInfoArray.Count();
   100   CImplementationInformation *infoptr = aImplInfoArray[0];
   101 
   102   TBufC<30> temp = infoptr->DisplayName();
   103   test.Printf(_L("Found %d agent implementation(s).\n"),count);
   104   test.Printf(_L("Name: %S\n"),&temp);
   105   test.Getch();
   106 
   107   // Need to delete implementation array
   108   aImplInfoArray.ResetAndDestroy();
   109 
   110   /*
   111   TUid key;
   112   TAgentCreationParams params;
   113   params.iURIPtr    = &temp;
   114   params.iIntentPtr = &temp;
   115 
   116   // Note that we have no idea about the real type of CAgent...
   117     CAgent *agent = 
   118 	reinterpret_cast<CAgent *>(REComSession::CreateImplementationL(KF32ImplementationUID, 
   119 																   key,
   120 																   (TAny*)&params));
   121   TUint major=0, minor=0;
   122   agent->Version(major, minor);
   123   test.Printf(_L("\nVersion (key %d) returned %d:%d\n"),key,major,minor);
   124   delete agent;
   125   REComSession::DestroyedImplementation(key);
   126   */
   127 
   128   _LIT(KDummyContent,"c:\\dummy.txt");
   129   test.Printf(_L("Hit enter to create content object (accessing %S)...\n"),&KDummyContent);
   130   test.Getch();
   131 
   132   CContent *myContent = 0; ret = 0;
   133 
   134   TRAP(ret, myContent = CContent::NewL(KDummyContent));
   135   if (ret)
   136 	  {
   137 	  test.Printf(_L("Content create failed (%d)..."),ret);
   138 	  test.Getch();
   139 	  }
   140   
   141   test.Printf(_L("Hit enter to create data object..."),ret);
   142   test.Getch();
   143 
   144   CData *myData = NULL;
   145 
   146   TRAP(ret, myData = myContent->OpenContentL(EPeek));
   147 
   148   if (ret)
   149 	  {
   150 	  test.Printf(_L("Data create failed (%d)..."),ret);
   151 	  test.Getch();
   152 	  }
   153 
   154   TInt mySize;
   155   myData->DataSizeL(mySize);
   156   test.Printf(_L("\nAgent reports data size as %d bytes\n"),mySize);
   157   test.Getch();
   158 
   159   test.Printf(_L("\nTest Ending\n"));
   160   test.Getch();
   161   __UHEAP_MARKEND; // end heap debug
   162   
   163   test.End();
   164   test.Close();
   165 }
   166 
   167 
   168 GLDEF_C TInt E32Main(void)
   169 {
   170   CTrapCleanup* cleanup;
   171   cleanup = CTrapCleanup::New();
   172   // CActiveScheduler* s = new CActiveScheduler;
   173   // s->Install(s);
   174   
   175   TRAP_IGNORE(RunTest1());
   176   
   177   
   178   delete cleanup;
   179   return(KErrNone);
   180 }