datacommsserver/esockserver/test/TS_MultiHoming/TS_CopyComDbFile.cpp
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     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 // This contains TS_MultiHoming RConnection Start primitive.
       
    15 // RConnection starts opens and starts a connection, and 
       
    16 // stores this connection in C
       
    17 // 
       
    18 //
       
    19 
       
    20 /**
       
    21  @file
       
    22 */
       
    23  
       
    24 
       
    25 #include "TS_CopyComDbFile.h"
       
    26 
       
    27 /* 
       
    28  * Test 1.1
       
    29  * Open a default / named connection
       
    30  */
       
    31 CTS_CopyComDbFile::CTS_CopyComDbFile()
       
    32 	{
       
    33 	iTestStepName = KCopyComDbFile;
       
    34 	}
       
    35 
       
    36 CTS_CopyComDbFile::~CTS_CopyComDbFile()
       
    37 	{	
       
    38 	}
       
    39 
       
    40 enum TVerdict CTS_CopyComDbFile::doTestStepPreambleL()
       
    41 /**
       
    42  * Implements OOM testing in each test
       
    43  */
       
    44 	{
       
    45 	if (!(GetBoolFromConfig(KCopyComDbFile,KOomTest,iIsOOMTest)))
       
    46 		{
       
    47 		iIsOOMTest=EFalse;
       
    48 		}
       
    49 	return EPass;
       
    50 	}
       
    51 
       
    52 
       
    53 enum TVerdict CTS_CopyComDbFile::doTestStepL()
       
    54 /**
       
    55  * Reads the configuration file to find out which
       
    56  * connection(s) need to be closed.
       
    57  * Started connections are stored in the array.
       
    58  */
       
    59 	{
       
    60 	TInt numRenames=0;
       
    61 	TPtrC connPtr(KNameDefault);
       
    62 	TInt err = KErrNone;
       
    63 
       
    64 	
       
    65 	err = GetStringFromConfig(KCopyComDbFile, KSourceFileName, connPtr);
       
    66 	
       
    67 	if(err != 1)		// We have no config available, so 1 default connection
       
    68 		{	
       
    69 		return EFail;
       
    70 		}
       
    71 
       
    72 
       
    73 
       
    74 	// create a File Server and File Manager
       
    75 	RFs theFs;
       
    76 	theFs.Connect();
       
    77 	CFileMan * Fileman= CFileMan::NewL(theFs);
       
    78 
       
    79 	_LIT(KCommDb,"c:\\private\\100012a5\\dbs[10004e1d]cdbv3.dat");
       
    80 
       
    81 	TBuf<100> newComDbname(KCommDb);
       
    82 
       
    83 	// use filemanager to delete Commmdb
       
    84 //	Fileman->Delete( KCommDb );
       
    85 
       
    86 //	LogExtra(((TText8*)(__FILE__)), (__LINE__), ESevrErr,
       
    87 //		_L("Copying %S to new cdbv3.dat"), connPtr);
       
    88 	newComDbname.AppendNum(numRenames++);
       
    89 	Fileman->Rename( KCommDb, newComDbname);
       
    90 	RFile comDb, sourceFile;
       
    91 
       
    92 	// Open the file for reading
       
    93 
       
    94 	err = sourceFile.Open(theFs, connPtr, EFileRead|EFileShareAny);
       
    95 	err = comDb.Create(theFs, KCommDb, EFileWrite | EFileShareAny);
       
    96 
       
    97 
       
    98 	TInt fileSize;
       
    99 	err = sourceFile.Size(fileSize);
       
   100 	HBufC8 *buffer = HBufC8::New(fileSize);
       
   101 	TPtr8 ptr = buffer->Des();
       
   102 
       
   103 	err = sourceFile.Read(ptr);
       
   104 
       
   105 	err = comDb.Write(ptr); 
       
   106 
       
   107 	sourceFile.Close();
       
   108 	comDb.Close();
       
   109 	theFs.Close();
       
   110 
       
   111 	delete buffer;
       
   112 
       
   113 		
       
   114 	return iTestStepResult;
       
   115 	}
       
   116 
       
   117