|
1 // Copyright (c) 2002-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 // Contain the implementation of the class for this null agent test |
|
15 // |
|
16 // |
|
17 |
|
18 #include "NullAgentTestSteps.h" |
|
19 #include "dummynifvar.h" |
|
20 #include "in_sock.h" |
|
21 |
|
22 CTestStepNullAgtLoopbackTest::CTestStepNullAgtLoopbackTest(TPtrC aName) |
|
23 { |
|
24 iTestStepName=aName; |
|
25 } |
|
26 |
|
27 enum TVerdict CTestStepNullAgtLoopbackTest::doTestStepL(void) |
|
28 { |
|
29 __UHEAP_MARK; |
|
30 |
|
31 TInt r; // the result of various operations |
|
32 TRequestStatus status; // status of asynchronous ops |
|
33 |
|
34 RSocketServ server; // connection paraphanelia |
|
35 RConnection connection; |
|
36 RSocket socket; |
|
37 |
|
38 TInetAddr dest; |
|
39 dest.SetAddress(KDummyNifLocalAddressBase + 4); |
|
40 dest.SetPort(KPortNo); |
|
41 |
|
42 TBuf8<KBufferLength> buffer; |
|
43 |
|
44 // connect to the socket server |
|
45 r = server.Connect(); |
|
46 TESTEL(r == KErrNone, r); |
|
47 CleanupClosePushL(server); |
|
48 |
|
49 // this is why we needed a socket server... |
|
50 r = connection.Open(server, KAfInet); |
|
51 TESTEL(r == KErrNone, r); |
|
52 CleanupClosePushL(connection); |
|
53 |
|
54 // start the connection up (outgoing) |
|
55 connection.Start(status); |
|
56 User::WaitForRequest(status); |
|
57 TESTEL(status.Int() == KErrNone, status.Int()); |
|
58 |
|
59 // open a udp socket |
|
60 r = socket.Open(server, KAfInet, KSockDatagram, KProtocolInetUdp); |
|
61 TESTEL(r == KErrNone, r); |
|
62 CleanupClosePushL(socket); |
|
63 TESTL(socket.SetOpt(KSoReuseAddr, KSolInetIp, 1)==KErrNone); |
|
64 // set the source port number - otherwise will panic cos it's zero |
|
65 r = socket.SetLocalPort(KPortNo); |
|
66 TESTEL(r == KErrNone, r); |
|
67 |
|
68 // build some data to send on the socket |
|
69 // this is an ICMP ping request apparently |
|
70 buffer.SetMax(); |
|
71 buffer.FillZ(); |
|
72 buffer[0] = (TUint8) 0x8; // ICMP type = 8 |
|
73 buffer[1] = (TUint8) 0x0; // ICMP code = 0 |
|
74 buffer[2] = (TUint8) 0xF7; // ICMP checksum high byte |
|
75 buffer[3] = (TUint8) 0xFF; // ICMP checksum low byte |
|
76 // NB the rest of the buffer is zero |
|
77 // hence the checksum (0xFFFF - 0x800) since 0x8 |
|
78 // is the only non-zero element of the buffer |
|
79 |
|
80 // send the data out over the socket |
|
81 socket.SendTo(buffer, dest, 0, status); |
|
82 User::WaitForRequest(status); |
|
83 TESTEL(status.Int() == KErrNone, status.Int()); |
|
84 |
|
85 buffer.Zero(); |
|
86 // I expect to get the data looped back from the dummy NIF |
|
87 socket.RecvFrom(buffer, dest, 0, status); |
|
88 User::WaitForRequest(status); |
|
89 TESTEL(status.Int() == KErrNone, status.Int()); |
|
90 |
|
91 // check that what we sent is what we got back |
|
92 if (status.Int() == KErrNone) |
|
93 { |
|
94 // if the receive times out and we access buffer we get a panic |
|
95 TEST(buffer[0] == 0x08); |
|
96 TEST(buffer[1] == 0x00); |
|
97 TEST(buffer[2] == 0xF7); |
|
98 TEST(buffer[3] == 0xFF); |
|
99 } |
|
100 |
|
101 // close the socket |
|
102 socket.Shutdown(RSocket::ENormal, status); |
|
103 User::WaitForRequest(status); |
|
104 TESTEL(status.Int() == KErrNone, status.Int()); |
|
105 CleanupStack::Pop(); |
|
106 |
|
107 // force the destruction of the connection |
|
108 r = connection.Stop(); |
|
109 TESTEL(r == KErrNone, r); |
|
110 CleanupStack::Pop(); |
|
111 |
|
112 // close the socket server |
|
113 server.Close(); |
|
114 CleanupStack::Pop(); |
|
115 |
|
116 __UHEAP_MARKEND; |
|
117 |
|
118 return iTestStepResult; |
|
119 } |