commsfwutils/commsbufs/reference/loopback_driver/test.cpp
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 /*
       
     2 * Copyright (c) 2003-2005 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 "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 <e32test.h>
       
    20 #include <e32def_private.h>
       
    21 
       
    22 #ifdef SYMBIAN_OLD_EXPORT_LOCATION
       
    23 #include <comms-infras/legacy_loopback_driver.h>
       
    24 #else
       
    25 //this header is not exported, needs to be a user include
       
    26 #include "legacy_loopback_driver.h"
       
    27 #endif
       
    28 
       
    29 
       
    30 LOCAL_D RTest test(_L("LEGACY_LOOPBACK_DRIVER_TEST"));
       
    31 
       
    32 _LIT8(KTestSendData,"abcdefghijklmnopqrstuvwxyz");
       
    33 
       
    34 GLDEF_C TInt E32Main()
       
    35     {
       
    36 	test.Title();
       
    37 
       
    38 	TInt r;
       
    39 
       
    40 	test.Start(_L("Load Physical Device"));
       
    41 	r=User::LoadPhysicalDevice(KLegacyLoopbackPddFileName);
       
    42 	test(r==KErrNone || r==KErrAlreadyExists);
       
    43 
       
    44 	test.Next(_L("Load Logical Device"));
       
    45 	r=User::LoadLogicalDevice(KLegacyLoopbackLddFileName);
       
    46 	test(r==KErrNone || r==KErrAlreadyExists);
       
    47 
       
    48 	__KHEAP_MARK;
       
    49 
       
    50 	test.Next(_L("Open Device"));
       
    51 	RDevice device;
       
    52 	r=device.Open(RLegacyLoopbackDriver::Name());
       
    53 	test(r==KErrNone);
       
    54 
       
    55 	test.Next(_L("Get Device Capabilities"));
       
    56 	RLegacyLoopbackDriver::TCaps caps;
       
    57 	TPckg<RLegacyLoopbackDriver::TCaps>capsPckg(caps);
       
    58 	capsPckg.FillZ(); // Zero 'caps' so we can tell if GetCaps has really filled it
       
    59 	device.GetCaps(capsPckg);
       
    60 	TVersion expectedVer(RLegacyLoopbackDriver::VersionRequired());
       
    61 	test(caps.iVersion.iMajor==expectedVer.iMajor);
       
    62 	test(caps.iVersion.iMinor==expectedVer.iMinor);
       
    63 	test(caps.iVersion.iBuild==expectedVer.iBuild);
       
    64 
       
    65 	test.Next(_L("Close Device"));
       
    66 	device.Close();
       
    67 
       
    68 	test.Next(_L("Open Logical Channel"));
       
    69 	RLegacyLoopbackDriver ldd;
       
    70 	r=ldd.Open();
       
    71 	test(r==KErrNone);
       
    72 
       
    73 	test.Next(_L("GetConfig"));
       
    74 	RLegacyLoopbackDriver::TConfigBuf configBuf;
       
    75 	configBuf.FillZ();   // Zero 'config' so we can tell if GetConfig has really filled it
       
    76 	r=ldd.GetConfig(configBuf);
       
    77 	test(r==KErrNone);
       
    78 
       
    79 	RLegacyLoopbackDriver::TConfig& config=configBuf();
       
    80 	test(config.iPddBufferSize!=0);
       
    81 	test(config.iMaxSendDataSize!=0);
       
    82 	test(config.iMaxReceiveDataSize!=0);
       
    83 
       
    84 	test.Next(_L("SetConfig"));
       
    85 	TInt speed = configBuf().iSpeed+1;
       
    86 	configBuf().iSpeed = speed;
       
    87 	r=ldd.SetConfig(configBuf); // Use SetConfig to change speed
       
    88 	test(r==KErrNone);
       
    89 
       
    90 	configBuf.FillZ();
       
    91 	r=ldd.GetConfig(configBuf);
       
    92 	test(r==KErrNone);
       
    93 	test(configBuf().iSpeed==speed);
       
    94 	TRequestStatus status;
       
    95 /*
       
    96 	test.Next(_L("Check access by wrong client"));
       
    97 	RLegacyLoopbackDriver ldd2=ldd;
       
    98 	r=ldd2.Duplicate(RThread(),EOwnerProcess);
       
    99 	test(r==KErrAccessDenied);
       
   100 
       
   101 	test.Next(_L("Check handle duplication"));
       
   102 	ldd2=ldd;
       
   103 	r=ldd2.Duplicate(RThread(),EOwnerThread);
       
   104 	test(r==KErrNone);
       
   105 	ldd2.Close();
       
   106 
       
   107 	test.Next(_L("SendData"));
       
   108 	ldd.SendData(status,KTestSendData);
       
   109 
       
   110 	test.Next(_L("SendDataCancel"));
       
   111 	ldd.SendDataCancel();
       
   112 	User::WaitForRequest(status);
       
   113 	r=status.Int();
       
   114 	test(r==KErrCancel);
       
   115 */
       
   116 	test.Next(_L("SendData"));
       
   117 	ldd.SendData(status,KTestSendData);
       
   118 	User::WaitForRequest(status);
       
   119 	r=status.Int();
       
   120 	test(r==KErrNone);
       
   121 
       
   122 	test.Next(_L("ReceiveData"));
       
   123 	TBuf8<256> buffer;
       
   124 	ldd.ReceiveData(status,buffer);
       
   125 	User::WaitForRequest(status);
       
   126 	r=status.Int();
       
   127 	test(r==KErrNone);
       
   128 	
       
   129 	test(buffer.Size()==KTestSendData().Size());
       
   130 	test(buffer==KTestSendData);
       
   131 
       
   132 
       
   133 /*	
       
   134 	test.Next(_L("ReceiveDataCancel"));
       
   135 	ldd.ReceiveDataCancel();
       
   136 	User::WaitForRequest(status);
       
   137 	r=status.Int();
       
   138 	test(r==KErrCancel);
       
   139 
       
   140 	test.Next(_L("ReceiveData"));
       
   141 	buffer.FillZ(buffer.MaxLength());
       
   142 	buffer.Zero();
       
   143 	ldd.ReceiveData(status,buffer);
       
   144 	User::WaitForRequest(status);
       
   145 	r=status.Int();
       
   146 	test(r==KErrNone);
       
   147 
       
   148 	TInt expectedSize = config.iPddBufferSize;
       
   149 	if(expectedSize>(&KTestSendData)->Size())
       
   150 		expectedSize = (&KTestSendData)->Size();
       
   151 	test(buffer.Size()==expectedSize);
       
   152 	test(buffer==(&KTestSendData)->Right(expectedSize));
       
   153 */
       
   154 	test.Next(_L("Close Logical Channel"));
       
   155 	ldd.Close();
       
   156 
       
   157 	__KHEAP_MARKEND;
       
   158 
       
   159 	test.Next(_L("Unload Logical Device"));
       
   160 	r=User::FreeLogicalDevice(RLegacyLoopbackDriver::Name());
       
   161 	test(r==KErrNone);
       
   162 
       
   163 	test.Next(_L("Unload Physical Device"));
       
   164 	TName pddName(RLegacyLoopbackDriver::Name());
       
   165 	_LIT(KVariantExtension,".template");
       
   166 	pddName.Append(KVariantExtension);
       
   167 	r=User::FreePhysicalDevice(pddName);
       
   168 	test(r==KErrNone);
       
   169 
       
   170 	test.End();
       
   171 
       
   172 	return(0);
       
   173     }
       
   174 
       
   175