|
1 /* |
|
2 * Copyright (c) 2005-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 "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 * Example CTestStep derived implementation |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 /** |
|
22 @file UDPStep.cpp |
|
23 */ |
|
24 #include "udpstep.h" |
|
25 #include "ipsuitedefs.h" |
|
26 |
|
27 CUDPStep::~CUDPStep() |
|
28 /** |
|
29 * Destructor |
|
30 */ |
|
31 { |
|
32 } |
|
33 |
|
34 CUDPStep::CUDPStep() |
|
35 /** |
|
36 * Constructor |
|
37 */ |
|
38 { |
|
39 // **MUST** call SetTestStepName in the constructor as the controlling |
|
40 // framework uses the test step name immediately following construction to set |
|
41 // up the step's unique logging ID. |
|
42 SetTestStepName(KDemoUDPStep); |
|
43 } |
|
44 |
|
45 TVerdict CUDPStep::doTestStepL() |
|
46 /** |
|
47 * @return - TVerdict code |
|
48 * Override of base class pure virtual |
|
49 * Our implementation only gets called if the base class doTestStepPreambleL() did |
|
50 * not leave. That being the case, the current test result value will be EPass. |
|
51 */ |
|
52 { |
|
53 |
|
54 RSocket socket; |
|
55 User::LeaveIfError(socket.Open(iServer, KAfInet, KSockDatagram, KProtocolInetUdp)); |
|
56 CleanupClosePushL(socket); |
|
57 |
|
58 // Get the IP Address into a 16 bit descriptor to print it |
|
59 TBuf<50> IPAddrBuf; |
|
60 iDestAddr.Output(IPAddrBuf); |
|
61 _LIT(KSendDataMessage,"Send Data to %S Port = %d Length = %d"); |
|
62 TPtr8 writeDataDes(iWriteData->Des()); |
|
63 INFO_PRINTF4(KSendDataMessage,&IPAddrBuf,iDestAddr.Port(),writeDataDes.Length()); |
|
64 |
|
65 TRequestStatus status; |
|
66 socket.SendTo(writeDataDes,iDestAddr, 0,status); |
|
67 User::WaitForRequest(status); |
|
68 User::LeaveIfError(status.Int()); |
|
69 |
|
70 _LIT(KSentDataMessage,"Data Sent"); |
|
71 INFO_PRINTF1(KSentDataMessage); |
|
72 |
|
73 // Use RecvFrom in this case |
|
74 // The status is not completed until the descriptor is full |
|
75 // or there is a socket error/timeout -22 |
|
76 TPtr8 readDataDes(iReadData->Des()); |
|
77 socket.RecvFrom(readDataDes,iDestAddr, 0, status); |
|
78 User::WaitForRequest(status); |
|
79 User::LeaveIfError(status.Int()); |
|
80 |
|
81 _LIT(KRecvDataMessage,"Data Received Length = %d"); |
|
82 INFO_PRINTF2(KRecvDataMessage,readDataDes.Length()); |
|
83 |
|
84 // The receive data should always match the sent |
|
85 // Try deliberately corrupting the send or receive descriptor and |
|
86 // the panic will be picked up in the script engine |
|
87 __ASSERT_ALWAYS(readDataDes == writeDataDes,User::Panic(KDemoIPSuitePanic,EUDPDataCorrupt)); |
|
88 |
|
89 socket.Close(); |
|
90 |
|
91 CleanupStack::Pop(1); // Server and Socket Handles |
|
92 |
|
93 return TestStepResult(); |
|
94 } |