baseport/syborg/webcamera/webcamera_app.cpp
author Shimizu Satoshi <s_shimizu@isb.co.jp>
Mon, 18 Oct 2010 19:39:25 +0900
changeset 124 606eafc6d6a8
parent 52 0dfaca43d90e
permissions -rw-r--r--
Obtain an image of Webcamera from QEMU and add the Bitmap change display function.

/*
* Copyright (c) 2010 ISB.
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of the License "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* ISB - initial contribution.
*
* Contributors:
*
* Description: USB driver for test
*
*/
#include <e32test.h>
#include <webcamera_driver.h>

#include <e32debug.h>
#define DP(format...) RDebug::Printf(format)

LOCAL_D RTest test(_L("WebcameraDevice_TEST"));

//Dummy environment for Wins
_LIT(KWebcameraPddFileName, "webcamera.pdd");
_LIT(KWebcameraLddFileName, "ewebcamera.ldd");

GLDEF_C TInt E32Main()
	{
	test.Title();
	TInt r;

	test.Start(_L("Load Physical Device"));
	r = User::LoadPhysicalDevice(KWebcameraPddFileName);
	test(r == KErrNone || r == KErrAlreadyExists);

	test.Next(_L("Load Logical Device"));
	r = User::LoadLogicalDevice(KWebcameraLddFileName);
	test(r == KErrNone || r == KErrAlreadyExists);
	__KHEAP_MARK;

	test.Next(_L("Open Logical Channel"));
	RWebcameraDevice ldd;
	r = ldd.Open();
	test(r == KErrNone);

	test.Next(_L("Check sharedChunk"));
	RChunk Chunk;
	RWebcameraDevice::TChunkInfo ChunkInfo;
	r = ldd.OpenSharedChunks(Chunk,ChunkInfo);
	DP("ChunkHandle = %d",ChunkInfo.iChunkHandle);
	DP("Chunk.Handle() = %d",Chunk.Handle());
	DP("r = %d",r);
	test(r == KErrNone);

	if (Chunk.IsReadable())
		{
		DP("mapped into its process address space");
		}
	test.Next(_L("Check access by wrong client"));
	RWebcameraDevice ldd2=ldd;
	r = ldd2.Duplicate(RThread(),EOwnerProcess);
	test(r == KErrAccessDenied);

	test.Next(_L("Check handle duplication"));
	ldd2=ldd;
	r = ldd2.Duplicate(RThread(),EOwnerThread);
	test(r == KErrNone);
	ldd2.Close();

	test.Next(_L("ReceiveData"));
	TRequestStatus status;
	TInt size = 0;
	ldd.StartViewFinder(status,size);
	DP("size = %d",size);

	test.Next(_L("ReceiveDataCancel"));
	ldd.StopViewFinder();
	User::WaitForRequest(status);
	r = status.Int();
	test(r == KErrNone);
	size = 0;
	ldd.StartViewFinder(status,size);
	User::WaitForRequest(status);
	r = status.Int();
	test(r == KErrNone);

	test.Next(_L("CaptureData"));
	TInt size1 = 0;
	ldd.Capture(status,size1);
	User::WaitForRequest(status);
	r = status.Int();
	test(r == KErrNone);

	test.Next(_L("Close Logical Channel"));
	ldd.Close();

//	__KHEAP_MARKEND;

	test.Next(_L("Unload Logical Device"));
	r = User::FreeLogicalDevice(RWebcameraDevice::Name());
	test(r == KErrNone);

	test.Next(_L("Unload Physical Device"));
	TName pddName(RWebcameraDevice::Name());
	_LIT(KVariantExtension,".pdd");
	pddName.Append(KVariantExtension);
	r = User::FreePhysicalDevice(pddName);
	test(r == KErrNone);

	test.End();

	return(0);
	}