baseport/syborg/webcamera/webcamera_app.cpp
changeset 124 606eafc6d6a8
parent 52 0dfaca43d90e
equal deleted inserted replaced
52:0dfaca43d90e 124:606eafc6d6a8
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description: USB driver for test
    14 * Description: USB driver for test
    15 *
    15 *
    16 */
    16 */
    17 
       
    18 #include <e32test.h>
    17 #include <e32test.h>
    19 #include <webcamera_driver.h>
    18 #include <webcamera_driver.h>
    20 
    19 
    21 #include <e32debug.h>
    20 #include <e32debug.h>
    22 #define DP(format...) RDebug::Printf(format)
    21 #define DP(format...) RDebug::Printf(format)
    23 
    22 
    24 LOCAL_D RTest test(_L("WebcameraDevice_TEST"));
    23 LOCAL_D RTest test(_L("WebcameraDevice_TEST"));
    25 
    24 
    26 //Wins用ダミーなので実機では正式なものを使用する
    25 //Dummy environment for Wins
    27 _LIT(KWebcameraPddFileName, "webcamera.pdd");
    26 _LIT(KWebcameraPddFileName, "webcamera.pdd");
    28 _LIT(KWebcameraLddFileName, "ewebcamera.ldd");
    27 _LIT(KWebcameraLddFileName, "ewebcamera.ldd");
    29 
    28 
    30 GLDEF_C TInt E32Main()
    29 GLDEF_C TInt E32Main()
    31  {
    30 	{
    32     test.Title();
    31 	test.Title();
    33     TInt r;
    32 	TInt r;
    34     
       
    35     test.Start(_L("Load Physical Device"));
       
    36     r=User::LoadPhysicalDevice(KWebcameraPddFileName);
       
    37     test(r==KErrNone || r==KErrAlreadyExists);
       
    38 
    33 
    39     test.Next(_L("Load Logical Device"));
    34 	test.Start(_L("Load Physical Device"));
    40     r=User::LoadLogicalDevice(KWebcameraLddFileName);
    35 	r = User::LoadPhysicalDevice(KWebcameraPddFileName);
    41     test(r==KErrNone || r==KErrAlreadyExists);
    36 	test(r == KErrNone || r == KErrAlreadyExists);
    42 //    __KHEAP_MARK;
       
    43 
    37 
    44 //    test.Next(_L("Open Device"));
    38 	test.Next(_L("Load Logical Device"));
    45 //    RDevice device;
    39 	r = User::LoadLogicalDevice(KWebcameraLddFileName);
    46 //    r=device.Open(RWebcameraDevice::Name());
    40 	test(r == KErrNone || r == KErrAlreadyExists);
    47 //    test(r==KErrNone);
    41 	__KHEAP_MARK;
    48 
    42 
    49     //test.Next(_L("Close Device"));
    43 	test.Next(_L("Open Logical Channel"));
    50     //device.Close();
    44 	RWebcameraDevice ldd;
       
    45 	r = ldd.Open();
       
    46 	test(r == KErrNone);
    51 
    47 
    52     test.Next(_L("Open Logical Channel"));
    48 	test.Next(_L("Check sharedChunk"));
    53     RWebcameraDevice ldd;
    49 	RChunk Chunk;
    54     r=ldd.Open();
    50 	RWebcameraDevice::TChunkInfo ChunkInfo;
    55     test(r==KErrNone);
    51 	r = ldd.OpenSharedChunks(Chunk,ChunkInfo);
       
    52 	DP("ChunkHandle = %d",ChunkInfo.iChunkHandle);
       
    53 	DP("Chunk.Handle() = %d",Chunk.Handle());
       
    54 	DP("r = %d",r);
       
    55 	test(r == KErrNone);
    56 
    56 
    57     test.Next(_L("Check access by wrong client"));
    57 	if (Chunk.IsReadable())
    58     RWebcameraDevice ldd2=ldd;
    58 		{
    59     r=ldd2.Duplicate(RThread(),EOwnerProcess);
    59 		DP("mapped into its process address space");
    60     test(r==KErrAccessDenied);
    60 		}
       
    61 	test.Next(_L("Check access by wrong client"));
       
    62 	RWebcameraDevice ldd2=ldd;
       
    63 	r = ldd2.Duplicate(RThread(),EOwnerProcess);
       
    64 	test(r == KErrAccessDenied);
    61 
    65 
    62     test.Next(_L("Check handle duplication"));
    66 	test.Next(_L("Check handle duplication"));
    63     ldd2=ldd;
    67 	ldd2=ldd;
    64     r=ldd2.Duplicate(RThread(),EOwnerThread);
    68 	r = ldd2.Duplicate(RThread(),EOwnerThread);
    65     test(r==KErrNone);
    69 	test(r == KErrNone);
    66     ldd2.Close();
    70 	ldd2.Close();
    67 
    71 
    68     test.Next(_L("ReceiveData"));
    72 	test.Next(_L("ReceiveData"));
    69     TRequestStatus status;
    73 	TRequestStatus status;
    70     HBufC8 * buffer = HBufC8::NewL(BUFSIZE);
    74 	TInt size = 0;
    71     TPtr8	itempPtr(buffer->Des());
    75 	ldd.StartViewFinder(status,size);
    72     itempPtr.SetLength(0);
    76 	DP("size = %d",size);
    73     ldd.StartViewFinder(status,itempPtr);
       
    74 
    77 
    75     test.Next(_L("ReceiveDataCancel"));
    78 	test.Next(_L("ReceiveDataCancel"));
    76     ldd.StopViewFinder();
    79 	ldd.StopViewFinder();
    77     User::WaitForRequest(status);
    80 	User::WaitForRequest(status);
    78     r=status.Int();
    81 	r = status.Int();
    79     test(r==KErrNone);
    82 	test(r == KErrNone);
    80 	
    83 	size = 0;
    81     itempPtr.SetLength(0);
    84 	ldd.StartViewFinder(status,size);
    82     ldd.StartViewFinder(status,itempPtr);
    85 	User::WaitForRequest(status);
    83     User::WaitForRequest(status);
    86 	r = status.Int();
    84     r=status.Int();
    87 	test(r == KErrNone);
    85 	test(r==KErrNone);
       
    86 	
       
    87     test.Next(_L("CaptureData"));
       
    88     HBufC8 * buffer1 = buffer;
       
    89     TPtr8	itempPtr1(buffer1->Des());
       
    90     itempPtr1.SetLength(0);
       
    91     ldd.Capture(status,itempPtr1);
       
    92     User::WaitForRequest(status);
       
    93     r=status.Int();
       
    94     test(r==KErrNone);
       
    95     
       
    96     test.Next(_L("Close Logical Channel"));
       
    97     ldd.Close();
       
    98 
    88 
    99 //    __KHEAP_MARKEND;
    89 	test.Next(_L("CaptureData"));
       
    90 	TInt size1 = 0;
       
    91 	ldd.Capture(status,size1);
       
    92 	User::WaitForRequest(status);
       
    93 	r = status.Int();
       
    94 	test(r == KErrNone);
   100 
    95 
   101     test.Next(_L("Unload Logical Device"));
    96 	test.Next(_L("Close Logical Channel"));
   102     r=User::FreeLogicalDevice(RWebcameraDevice::Name());
    97 	ldd.Close();
   103     test(r==KErrNone);
       
   104 
    98 
   105     test.Next(_L("Unload Physical Device"));
    99 //	__KHEAP_MARKEND;
   106     TName pddName(RWebcameraDevice::Name());
       
   107     _LIT(KVariantExtension,".pdd");
       
   108     pddName.Append(KVariantExtension);
       
   109     r=User::FreePhysicalDevice(pddName);
       
   110     test(r==KErrNone);
       
   111 	
       
   112     test.End();
       
   113 
   100 
   114     return(0);
   101 	test.Next(_L("Unload Logical Device"));
   115  }
   102 	r = User::FreeLogicalDevice(RWebcameraDevice::Name());
       
   103 	test(r == KErrNone);
       
   104 
       
   105 	test.Next(_L("Unload Physical Device"));
       
   106 	TName pddName(RWebcameraDevice::Name());
       
   107 	_LIT(KVariantExtension,".pdd");
       
   108 	pddName.Append(KVariantExtension);
       
   109 	r = User::FreePhysicalDevice(pddName);
       
   110 	test(r == KErrNone);
       
   111 
       
   112 	test.End();
       
   113 
       
   114 	return(0);
       
   115 	}