datacommsserver/esockserver/commsdataobjects/test/src/testapp.cpp
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <e32base.h>
       
    17 #include <c32comm.h>
       
    18 #include <c32root.h>
       
    19 #include <es_sock.h>
       
    20 #include <comms-infras/es_commsdataobject.h>
       
    21 #include <connpref.h>
       
    22 #include <CommDbConnPref.h>
       
    23 #include <metadatabase.h>
       
    24 #include <commsdattypeinfov1_1.h>
       
    25 #include <comms-infras/connectionqueryset.h>
       
    26 #include <comms-infras/ss_commsdataobject.h>
       
    27 #include <ecom/ecom.h>
       
    28 
       
    29 #include "queryconnsettingstiermgrimpl.h"
       
    30 #include "noddyqueryconnsettingsimpl.h"
       
    31 
       
    32 using namespace ESock;
       
    33 
       
    34 	
       
    35 void Test0cL()
       
    36 	{
       
    37 	// ---------------------------------------------------------------------
       
    38 	// Creating the query
       
    39 	// ---------------------------------------------------------------------
       
    40 	XConnectionQuerySet* querySet = XConnectionQuerySet::NewL();
       
    41 	CleanupDeletePushL(querySet);
       
    42 
       
    43 	XConnectionQueryBase* query;
       
    44 	query = XText8Query::NewL(CommsDat::KCDTIdPortName, *querySet);
       
    45 	query = XText16Query::NewL(CommsDat::KCDTIdNifName, *querySet);
       
    46 	query = XText16Query::NewL(CommsDat::KCDTIdTsyName, *querySet);
       
    47 	query = XBoolQuery::NewL(CommsDat::KCDTIdIpAddrFromServer, *querySet);
       
    48 	query = XUintQuery::NewL(CommsDat::KCDTIdLastSessionClosedTimeout, *querySet);
       
    49 	query = XBoolQuery::NewL(CommsDat::KCDTIdIfPromptForAuth, *querySet);
       
    50 
       
    51 	CleanupStack::PopAndDestroy(querySet);
       
    52 	}
       
    53 	
       
    54 	
       
    55 void Test1L()
       
    56 	{
       
    57 	// ---------------------------------------------------------------------
       
    58 	// Creating the query
       
    59 	// ---------------------------------------------------------------------
       
    60 	
       
    61 	XConnectionQuerySet* querySet = XConnectionQuerySet::NewL();
       
    62 	CleanupDeletePushL(querySet);
       
    63 
       
    64 	XConnectionQueryBase* query;
       
    65 	query = XText8Query::NewL(CommsDat::KCDTIdPortName, *querySet);
       
    66 	query = XText16Query::NewL(CommsDat::KCDTIdNifName, *querySet);
       
    67 	query = XText16Query::NewL(CommsDat::KCDTIdTsyName, *querySet);
       
    68 	query = XBoolQuery::NewL(CommsDat::KCDTIdIpAddrFromServer, *querySet);
       
    69 	query = XUintQuery::NewL(CommsDat::KCDTIdLastSessionClosedTimeout, *querySet);
       
    70 	query = XBoolQuery::NewL(CommsDat::KCDTIdIfPromptForAuth, *querySet);
       
    71 
       
    72 
       
    73 	// ---------------------------------------------------------------------
       
    74 	// Serialisation/Deserialisation Test
       
    75 	// ---------------------------------------------------------------------
       
    76 	CConnectionQuerySet* cdo = CConnectionQuerySet::NewL(querySet);
       
    77 	CleanupStack::Pop(querySet);
       
    78 	CleanupStack::PushL(cdo);
       
    79 	
       
    80 	TInt length = cdo->Length();
       
    81 	HBufC8* buffer = HBufC8::NewLC(length);
       
    82 	if (!buffer) 
       
    83 		{
       
    84 		User::Leave(KErrNoMemory);
       
    85 		}
       
    86 
       
    87 
       
    88 	TPtr8 storePtr(buffer->Des());
       
    89 	TInt ret = cdo->Store(storePtr);
       
    90 	User::LeaveIfError(ret);
       
    91 	
       
    92 
       
    93 	// Load using Load()
       
    94 	TPtrC8 loadPtr = buffer->Des();
       
    95 	CConnectionQuerySet* outputContainer = CConnectionQuerySet::LoadL(loadPtr);
       
    96 	
       
    97 	delete outputContainer;
       
    98 
       
    99 	CleanupStack::PopAndDestroy(buffer);
       
   100 	CleanupStack::PopAndDestroy(cdo);
       
   101 	}
       
   102 
       
   103 
       
   104 
       
   105 void Test3L()
       
   106 	{
       
   107 	// ---------------------------------------------------------------------
       
   108 	// Creating the query
       
   109 	// ---------------------------------------------------------------------
       
   110 	
       
   111 	CNoddyQueryConnSettingsImpl* impl = new (ELeave)CNoddyQueryConnSettingsImpl();
       
   112 	CleanupStack::PushL(impl);
       
   113 	
       
   114 	XConnectionQuerySet* querySet = XConnectionQuerySet::NewL();
       
   115 	CleanupDeletePushL(querySet);
       
   116 
       
   117 	XConnectionQueryBase* query;
       
   118 	query = XText8Query::NewL(CommsDat::KCDTIdPortName, *querySet);
       
   119 	query = XText16Query::NewL(CommsDat::KCDTIdNifName, *querySet);
       
   120 	query = XBoolQuery::NewL(CommsDat::KCDTIdIpAddrFromServer, *querySet);
       
   121 	query = XUintQuery::NewL(CommsDat::KCDTIdLastSessionClosedTimeout, *querySet);
       
   122 	query = XIntQuery::NewL(CommsDat::KCDTIdIfPromptForAuth, *querySet);
       
   123 
       
   124 
       
   125 	querySet->DispatchL(static_cast<MQueryConnSettingsApiExt*>(impl), NULL);
       
   126 
       
   127 	
       
   128 	// ---------------------------------------------------------------------
       
   129 	// Testing the iterators
       
   130 	// ---------------------------------------------------------------------
       
   131 	TConnectionQueryIter iter1(querySet->GetQueryIter(XConnectionQueryBase::ENotAnswered));
       
   132 	TInt count = 0;
       
   133 	query = NULL;
       
   134 	query = iter1++;
       
   135 	while (query) 
       
   136 		{
       
   137 		count++;
       
   138 		query = iter1++;;
       
   139 		}
       
   140 	ASSERT(count == 1);
       
   141 
       
   142 
       
   143 	TConnectionQueryIter iter2(querySet->GetQueryIter(XConnectionQueryBase::EAnswered));
       
   144 	count = 0;
       
   145 	query = NULL;
       
   146 	query = iter2++;
       
   147 	while (query) 
       
   148 		{
       
   149 		count++;
       
   150 		query = iter2++;
       
   151 		}
       
   152 	ASSERT(count == 4);
       
   153 
       
   154 	
       
   155 	CleanupStack::PopAndDestroy(querySet);
       
   156 	CleanupStack::PopAndDestroy(impl);
       
   157 	}
       
   158 
       
   159 	
       
   160 	
       
   161 
       
   162 void Test4L()
       
   163 	{
       
   164 	// ---------------------------------------------------------------------
       
   165 	// Creating the query
       
   166 	// ---------------------------------------------------------------------
       
   167 	
       
   168 	CQueryConnSettingsTierMgrImpl* impl = CQueryConnSettingsTierMgrImpl::NewL(1);
       
   169 	CleanupStack::PushL(impl);
       
   170 	
       
   171 	XConnectionQuerySet* querySet = XConnectionQuerySet::NewL();
       
   172 	CleanupDeletePushL(querySet);
       
   173 
       
   174 	XConnectionQueryBase* query;
       
   175 	query = XUintQuery::NewL(CommsDat::KCDTIdIAPRecord | CommsDat::KCDTIdRecordTag, *querySet);
       
   176 	query = XText16Query::NewL(CommsDat::KCDTIdIAPRecord | CommsDat::KCDTIdRecordName, *querySet);
       
   177 	query = XUintQuery::NewL(CommsDat::KCDTIdIAPLocation, *querySet);
       
   178 
       
   179 	query = XText8Query::NewL(CommsDat::KCDTIdPortName, *querySet);
       
   180 	query = XText16Query::NewL(CommsDat::KCDTIdNifName, *querySet);
       
   181 	query = XBoolQuery::NewL(CommsDat::KCDTIdIpAddrFromServer, *querySet);
       
   182 	query = XUintQuery::NewL(CommsDat::KCDTIdLastSessionClosedTimeout, *querySet);
       
   183 	query = XIntQuery::NewL(CommsDat::KCDTIdIfPromptForAuth, *querySet);
       
   184 
       
   185 
       
   186 	querySet->DispatchL(static_cast<MQueryConnSettingsApiExt*>(impl), NULL);
       
   187 
       
   188 	TBuf8<200> des8;
       
   189 	TBuf16<200> des16;
       
   190 	TBool b;
       
   191 	TInt i(0x0F0F0F0F);
       
   192 	TUint32 ui(0xF0F0F0F0);
       
   193 
       
   194 	TInt count = 0;
       
   195 	// Option 1 - Iterate through the query results
       
   196 	TConnectionQueryIter iter (querySet->GetQueryIter(XConnectionQueryBase::EAnswered));
       
   197 	const XConnectionQueryBase* qBase = iter++;
       
   198 	while (qBase) 
       
   199 		{
       
   200 		count++;
       
   201 		// Do something with query/data
       
   202 		switch (qBase->Type()) 
       
   203 			{
       
   204 			case XConnectionQueryBase::EInt:
       
   205 				{
       
   206 				const XIntQuery* qInt = static_cast<const XIntQuery*>(qBase);
       
   207 				i = qInt->Data();
       
   208 				}
       
   209 				break;
       
   210 
       
   211 			case XConnectionQueryBase::EUint:
       
   212 				{
       
   213 				const XUintQuery* qUInt = static_cast<const XUintQuery*>(qBase);
       
   214 				ui = qUInt->Data();
       
   215 				}
       
   216 				break;
       
   217 
       
   218 			case XConnectionQueryBase::EBool:
       
   219 				{
       
   220 				const XBoolQuery* qBool = static_cast<const XBoolQuery*>(qBase);
       
   221 				b = qBool->Data();
       
   222 				}
       
   223 				break;
       
   224 
       
   225 			case XConnectionQueryBase::EText8:
       
   226 				{
       
   227 				const XText8Query* qText8 = static_cast<const XText8Query*>(qBase);
       
   228 				des8 = qText8->Data();
       
   229 				}
       
   230 				break;
       
   231 
       
   232 			case XConnectionQueryBase::EText16:
       
   233 				{
       
   234 				const XText16Query* qText16 = static_cast<const XText16Query*>(qBase);
       
   235 				des16 = qText16->Data();
       
   236 				}
       
   237 				break;
       
   238 			}
       
   239 			
       
   240 		qBase = iter++;
       
   241 		}
       
   242 	
       
   243 	CleanupStack::PopAndDestroy(querySet);
       
   244 	CleanupStack::PopAndDestroy(impl);
       
   245 	}
       
   246 
       
   247 
       
   248 /*
       
   249 void Test4L()
       
   250 	{
       
   251 	// ---------------------------------------------------------------------
       
   252 	// Creating the query
       
   253 	// ---------------------------------------------------------------------
       
   254 	
       
   255 	XConnectionQuerySet* querySet = XConnectionQuerySet::NewL();
       
   256 	CleanupDeletePushL(querySet);
       
   257 
       
   258 	XConnectionQueryBase* query;
       
   259 	query = XText8Query::NewL(CommsDat::KCDTIdPortName, *querySet);
       
   260 	query = XText16Query::NewL(CommsDat::KCDTIdNifName, *querySet);
       
   261 	query = XText16Query::NewL(CommsDat::KCDTIdTsyName, *querySet);
       
   262 	query = XBoolQuery::NewL(CommsDat::KCDTIdIpAddrFromServer, *querySet);
       
   263 	query = XUintQuery::NewL(CommsDat::KCDTIdLastSessionClosedTimeout, *querySet);
       
   264 	query = XBoolQuery::NewL(CommsDat::KCDTIdIfPromptForAuth, *querySet);
       
   265 
       
   266 
       
   267 	// ---------------------------------------------------------------------
       
   268 	// Testing Find Query/Setting Data/Answered
       
   269 	// ---------------------------------------------------------------------
       
   270 	XText8Query* text8Query;
       
   271 	text8Query = static_cast<XText8Query*>(querySet->FindQuery(CommsDat::KCDTIdPortName));
       
   272 //	text8Query->SetData(_L8("oddlength"));
       
   273 //	text8Query->SetQueryAnswered();
       
   274 
       
   275 	XText16Query* textQuery;
       
   276 	textQuery = static_cast<XText16Query*>(querySet->FindQuery(CommsDat::KCDTIdNifName));
       
   277 //	textQuery->SetData(_L("Testing.nif"));
       
   278 //	textQuery->SetQueryAnswered();
       
   279 
       
   280 	// ---------------------------------------------------------------------
       
   281 	// Serialisation/Deserialisation Test 2 (with some populated data)
       
   282 	// ---------------------------------------------------------------------
       
   283 	TInt length = queryContainer->Length();
       
   284 	HBufC8* buffer = HBufC8::NewLC(length);
       
   285 	if (!buffer) 
       
   286 		{
       
   287 		User::Leave(KErrNoMemory);
       
   288 		}
       
   289 
       
   290 	TInt ret;
       
   291 	TPtr8 storePtr(buffer->Des());
       
   292 	ret = queryContainer->Store(storePtr);
       
   293 	User::LeaveIfError(ret);
       
   294 	
       
   295 	CParameterSetContainer* outputContainer = CParameterSetContainer::NewL();
       
   296 	TPtrC8 loadPtr(buffer->Des());
       
   297 	outputContainer->Load(loadPtr);
       
   298 	delete outputContainer;
       
   299 	
       
   300 	CleanupStack::PopAndDestroy(buffer);
       
   301 	CleanupStack::PopAndDestroy(queryContainer);
       
   302 	}
       
   303 */	
       
   304 	
       
   305 void Test5L()
       
   306 	{
       
   307 	// ---------------------------------------------------------------------
       
   308 	// Creating the query
       
   309 	// ---------------------------------------------------------------------
       
   310 	
       
   311 	XConnectionQuerySet* querySet = XConnectionQuerySet::NewL();
       
   312 	CleanupDeletePushL(querySet);
       
   313 
       
   314 	XConnectionQueryBase* query;
       
   315 	query = XText8Query::NewL(CommsDat::KCDTIdPortName, *querySet);
       
   316 	query = XText16Query::NewL(CommsDat::KCDTIdNifName, *querySet);
       
   317 	query = XText16Query::NewL(CommsDat::KCDTIdTsyName, *querySet);
       
   318 	query = XText16Query::NewL(CommsDat::KCDTIdPortName, *querySet);
       
   319 	query = XBoolQuery::NewL(CommsDat::KCDTIdIpAddrFromServer, *querySet);
       
   320 	query = XUintQuery::NewL(CommsDat::KCDTIdLastSessionClosedTimeout, *querySet);
       
   321 	query = XBoolQuery::NewL(CommsDat::KCDTIdIfPromptForAuth, *querySet);
       
   322 
       
   323 	// ---------------------------------------------------------------------
       
   324 	// RConnection API additional method test
       
   325 	// ---------------------------------------------------------------------
       
   326     TInt err;
       
   327     RSocketServ ss;
       
   328 	err = ss.Connect();
       
   329 	
       
   330 	RConnection con;
       
   331 	err = con.Open(ss);
       
   332 
       
   333 	CConnectionQuerySet* cdo = CConnectionQuerySet::NewL(querySet);
       
   334 	CleanupStack::Pop(querySet);
       
   335 	CleanupStack::PushL(cdo);
       
   336 
       
   337 	// This should fail with KErrNotReady since the connection hasn't been started
       
   338 	err = con.GetParameters(*cdo);
       
   339 	ASSERT(err == KErrNotReady);
       
   340 
       
   341 	// This should succeed
       
   342 	err = con.Start();
       
   343 	err = con.GetParameters(*cdo);
       
   344 	
       
   345 	TBuf8<200> des8;
       
   346 	TBuf16<200> des16;
       
   347 	TBool b;
       
   348 	TInt i(0x0F0F0F0F);
       
   349 	TUint32 ui(0xF0F0F0F0);
       
   350 	
       
   351 	
       
   352 	TInt count = 0;
       
   353 	if (err == KErrNone)
       
   354 		{
       
   355 		XConnectionQuerySet& outputQuerySet = cdo->DataObject();
       
   356 	
       
   357 		// Option 1 - Iterate through the query results
       
   358 		TConnectionQueryIter iter (outputQuerySet.GetQueryIter(XConnectionQueryBase::EAnswered));
       
   359 		const XConnectionQueryBase* qBase = iter++;
       
   360 		while (qBase) 
       
   361 			{
       
   362 			count++;
       
   363 			// Do something with query/data
       
   364 			switch (qBase->Type()) 
       
   365 				{
       
   366 				case XConnectionQueryBase::EInt:
       
   367 					{
       
   368 					const XIntQuery* qInt = static_cast<const XIntQuery*>(qBase);
       
   369 					i = qInt->Data();
       
   370 					}
       
   371 					break;
       
   372 
       
   373 				case XConnectionQueryBase::EUint:
       
   374 					{
       
   375 					const XUintQuery* qUInt = static_cast<const XUintQuery*>(qBase);
       
   376 					ui = qUInt->Data();
       
   377 					}
       
   378 					break;
       
   379 
       
   380 				case XConnectionQueryBase::EBool:
       
   381 					{
       
   382 					const XBoolQuery* qBool = static_cast<const XBoolQuery*>(qBase);
       
   383 					b = qBool->Data();
       
   384 					}
       
   385 					break;
       
   386 
       
   387 				case XConnectionQueryBase::EText8:
       
   388 					{
       
   389 					const XText8Query* qText8 = static_cast<const XText8Query*>(qBase);
       
   390 					des8 = qText8->Data();
       
   391 					}
       
   392 					break;
       
   393 
       
   394 				case XConnectionQueryBase::EText16:
       
   395 					{
       
   396 					const XText16Query* qText16 = static_cast<const XText16Query*>(qBase);
       
   397 					des16 = qText16->Data();
       
   398 					}
       
   399 					break;
       
   400 				}
       
   401 				
       
   402 			qBase = iter++;
       
   403 			}
       
   404 	
       
   405 		// Option 2 - Get a query response directly
       
   406 		const XConnectionQueryBase* directQuery;
       
   407 		directQuery = outputQuerySet.FindQuery(CommsDat::KCDTIdIfNetworks); // wont be found
       
   408 		directQuery = outputQuerySet.FindQuery(CommsDat::KCDTIdTsyName);
       
   409 		}
       
   410 	
       
   411 	con.Stop();
       
   412     con.Close();
       
   413     ss.Close();
       
   414 
       
   415 	CleanupStack::PopAndDestroy(cdo);
       
   416 	querySet = NULL;
       
   417 	}
       
   418 	
       
   419 // Secure variants much simpler
       
   420 // For EKA2, just an E32Main and a MainL()
       
   421 LOCAL_C void MainL()
       
   422 /**
       
   423  * Secure variant
       
   424  * Much simpler, uses the new Rendezvous() call to sync with the client
       
   425  */
       
   426 	{
       
   427     _LIT(KLddName, "ECOMM");
       
   428     _LIT(KPddName, "ECDRV");
       
   429 
       
   430     // Load device drivers
       
   431     User::LoadPhysicalDevice(KPddName);
       
   432     User::LoadLogicalDevice(KLddName);
       
   433     
       
   434 	// self contained query set / container tests
       
   435 
       
   436 	TInt err = KErrNone;
       
   437 //	TRAP(err, Test0cL());
       
   438 	
       
   439 //	TRAP(err, Test1L());
       
   440 	TRAP(err, Test3L());
       
   441 	TRAP(err, Test4L());
       
   442 	
       
   443 	// using rconnection - full end-to-end
       
   444 	TRAP(err, Test5L());
       
   445 	
       
   446 	REComSession::FinalClose();
       
   447    	}
       
   448 
       
   449 
       
   450 
       
   451 GLDEF_C TInt E32Main()
       
   452 /**
       
   453  * @return - Standard Epoc error code on process exit
       
   454  * Secure variant only
       
   455  * Process entry point. Called by client using RProcess API
       
   456  */
       
   457 	{
       
   458 	__UHEAP_MARK;
       
   459 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
   460 	if(cleanup == NULL)
       
   461 		{
       
   462 		return KErrNoMemory;
       
   463 		}
       
   464 	TRAPD(err,MainL());
       
   465 	delete cleanup;
       
   466 	__UHEAP_MARKEND;
       
   467 	return err;
       
   468     }
       
   469