Update contrib.
1 // Copyright (c) 1998-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 the License "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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\misc\t_ymodem.cpp
22 RTest test(_L("YModem"));
24 #define TEST(c) ((void)((c)||(test.Printf(_L("Failed at line %d\n"),__LINE__),test.Getch(),test(0),0)))
26 const TInt KBufferSize=4096;
28 _LIT(KLddName,"ECOMM");
29 _LIT(KPddName,"EUART");
31 void LoadCommDrivers()
33 test.Printf(_L("Load LDD\n"));
34 TInt r=User::LoadLogicalDevice(KLddName);
35 TEST(r==KErrNone || r==KErrAlreadyExists);
41 TBuf<16> pddName=KPddName();
43 pddName.Append('0'+i);
44 TInt r=User::LoadPhysicalDevice(pddName);
45 if (r==KErrNone || r==KErrAlreadyExists)
48 test.Printf(_L("%S found\n"),&pddName);
54 GLDEF_C TInt E32Main()
56 RThread().SetPriority(EPriorityAbsoluteForeground);
57 test.SetLogged(EFalse);
61 User::CommandLine(cmd);
65 TUint8 c=(TUint8)cmd[0];
75 test.Next(_L("Connect to file server"));
80 test.Next(_L("Create YModem object"));
82 TRAP(r,pY=YModemU::NewL(port,ETrue));
83 test(r==KErrNone && pY!=NULL);
85 test.Next(_L("Create buffer"));
86 TUint8* buffer=(TUint8*)User::Alloc(KBufferSize);
89 test.Start(_L("Receive..."));
97 r=pY->StartDownload(mode, size, name);
100 test.Printf(_L("r=%d, size=%d, name %S\n"),r,size,&name);
103 test.Printf(_L("Opening file for write\n"));
105 r=file.Replace(fs,name,EFileWrite);
108 test.Printf(_L("RFile::Replace returns %d\n"),r);
115 r=pY->ReadPackets(pD,KBufferSize);
116 if (r==KErrNone || r==KErrEof)
119 if (size>0) // size was transmitted
121 if (blen>size-total_size)
122 blen=size-total_size;
125 TPtrC8 fptr(buffer,blen);
126 TInt s=file.Write(fptr);
129 test.Printf(_L("RFile::Write returns %d\n"),s);
136 test.Printf(_L("rx size=%d\n"),total_size);
142 test.Printf(_L("r=%d\n"),r);