baseintegtests/baseintegrationtest/testsuites/sd/src/sdreadfiles2.cpp
branchanywhere
changeset 20 d63d727ee0a6
parent 19 f6d3d9676ee4
parent 16 6d8ad5bee44b
child 21 af091391d962
equal deleted inserted replaced
19:f6d3d9676ee4 20:d63d727ee0a6
     1 // Copyright (c) 2007-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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Check card contents after FileOperations2
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "sdreadfiles2.h"
       
    19 
       
    20 /*
       
    21 Class constructor
       
    22 
       
    23 @param None
       
    24 @return None
       
    25 */
       
    26 CBaseTestSDReadFiles2::CBaseTestSDReadFiles2()
       
    27 	{
       
    28 	SetTestStepName(KTestStepReadFiles2);
       
    29 	}
       
    30 
       
    31 /*
       
    32 Test step
       
    33 
       
    34 @param None
       
    35 @return EPass if successful or EFail if not
       
    36 @see TVerdict
       
    37 */
       
    38 TVerdict CBaseTestSDReadFiles2::doTestStepL()
       
    39 	{
       
    40 	if (TestStepResult() != EPass)
       
    41 		{
       
    42 		ERR_PRINTF1(_L("Test preamble did not complete succesfully - Test Step skipped"));
       
    43 		return TestStepResult();
       
    44 		}
       
    45 
       
    46 	TInt r;
       
    47 	TBuf<4> sessionPath;
       
    48 	sessionPath.Format(_L("%c:\\"), 'A' + iDrive);
       
    49 	r = iFs.SetSessionPath(sessionPath);
       
    50 	if (r != KErrNone)
       
    51 		{
       
    52 		ERR_PRINTF3(_L("Could not set session path to %c: (r = %d)"), 'A' + iDrive, r);
       
    53 		SetTestStepResult(EFail);
       
    54 		return TestStepResult();
       
    55 		}
       
    56 
       
    57 	// Check Volume Name
       
    58 	INFO_PRINTF1(_L("Check volume name"));
       
    59 	TVolumeInfo vi;
       
    60 	iFs.Volume(vi);
       
    61 	if (vi.iName != iVolumeName)
       
    62 		{
       
    63 		ERR_PRINTF3(_L("Expected '%S', got '%S'"), &iVolumeName, &vi.iName);
       
    64 		SetTestStepResult(EFail);
       
    65 		return TestStepResult();
       
    66 		}
       
    67 
       
    68 	// Check Entries
       
    69 	INFO_PRINTF1(_L("Check entries"));
       
    70 	if (CheckEntries() != KErrNone)
       
    71 		{
       
    72 		SetTestStepResult(EFail);
       
    73 		return TestStepResult();
       
    74 		}
       
    75 
       
    76 	return TestStepResult();
       
    77 	}
       
    78 
       
    79 /*
       
    80 Check disk contains expected entries
       
    81 
       
    82 @param None
       
    83 @return KErrNone if successful, otherwise any other system-wide error code
       
    84 */
       
    85 TInt CBaseTestSDReadFiles2::CheckEntries()
       
    86 	{
       
    87 	TInt r;
       
    88 	CDir* entryList;
       
    89 	TFileName sessionPath;
       
    90 	sessionPath.Format(_L("%c:\\"), 'A' + iDrive);
       
    91 	r = iFs.GetDir(sessionPath, KEntryAttMaskSupported, ESortByName | EDirsFirst, entryList);
       
    92 	if (r != KErrNone)
       
    93 		{
       
    94 		ERR_PRINTF2(_L("GetDir returned %d"), r);
       
    95 		return r;
       
    96 		}
       
    97 	
       
    98 	INFO_PRINTF1(_L("Check number of entries in root dir"));
       
    99 	TInt noentries = entryList->Count();
       
   100 	if (noentries != iRootEntries - iDeleteRootDirs)
       
   101 		{
       
   102 		ERR_PRINTF3(_L("Expected %d entries in root dir, got %d"), iRootEntries - iDeleteRootDirs, noentries);
       
   103 		return KErrUnknown;
       
   104 		}
       
   105 
       
   106 	INFO_PRINTF1(_L("Check directories are all here"));
       
   107 	TInt i;
       
   108 	for (i = iDeleteRootDirs; i < iRootEntries / 2; i++)
       
   109 		{
       
   110 		TFileName dirname;
       
   111 		dirname.Format(_L("%Sdir%03d"), &sessionPath, i);
       
   112 		RDir dir;
       
   113 		r = dir.Open(iFs, dirname, KEntryAttNormal);
       
   114 		if (r != KErrNone)
       
   115 			{
       
   116 			ERR_PRINTF3(_L("RDir::Open on %S returned %d"), &dirname, r);
       
   117 			return r;
       
   118 			}
       
   119 		dir.Close();
       
   120 		}
       
   121 
       
   122 	INFO_PRINTF1(_L("Check files are all here"));
       
   123 	for (i = iRootEntries / 2; i < iRootEntries; i++)
       
   124 		{
       
   125 		TFileName filename;
       
   126 		if (i - iRootEntries / 2 == 0)
       
   127 			{
       
   128 			filename.Format(_L("BACK"));
       
   129 			}
       
   130 		else if (i - iRootEntries / 2 == 1)
       
   131 			{
       
   132 			filename.Format(_L("Large File"));
       
   133 			}
       
   134 		else
       
   135 			{
       
   136 			filename.Format(_L("%Sfile%03d"), &sessionPath, i - iRootEntries / 2);
       
   137 			}
       
   138 		RFile file;
       
   139 		r = file.Open(iFs, filename, EFileRead);
       
   140 		if (r != KErrNone)
       
   141 			{
       
   142 			ERR_PRINTF3(_L("RFile::Open on %S returned %d"), &filename, r);
       
   143 			return r;
       
   144 			}
       
   145 		// Check size of expanded files
       
   146 		TInt size;
       
   147 		file.Size(size);
       
   148 		if (i - iRootEntries / 2 == 1)
       
   149 			{
       
   150 			if (size != iLargeFileSize * (1 << 20))
       
   151 				{
       
   152 				ERR_PRINTF4(_L("%S: expected size %d got %d"), &filename, iExpandRootFilesSize * (1 << 20), size);
       
   153 				return KErrUnknown;
       
   154 				}
       
   155 			}
       
   156 		else if ((i - iRootEntries / 2 > 1) && (i - iRootEntries / 2 - 2 < iExpandRootFilesNumber))
       
   157 			{
       
   158 			if (size != iExpandRootFilesSize * (1 << 20))
       
   159 				{
       
   160 				ERR_PRINTF4(_L("%S: expected size %d got %d"), &filename, iExpandRootFilesSize * (1 << 20), size);
       
   161 				return KErrUnknown;
       
   162 				}
       
   163 			}
       
   164 		file.Close();
       
   165 		}
       
   166 	delete entryList;
       
   167 
       
   168 	INFO_PRINTF1(_L("Now check the subdir entries"));
       
   169 	sessionPath.Format(_L("%c:\\dir%03d\\"), 'A' + iDrive, iRootEntries / 2 - 2);
       
   170 	r = iFs.GetDir(sessionPath, KEntryAttMaskSupported, ESortByName | EDirsFirst, entryList);
       
   171 	if (r != KErrNone)
       
   172 		{
       
   173 		ERR_PRINTF2(_L("GetDir returned %d"), r);
       
   174 		return r;
       
   175 		}
       
   176 	noentries = entryList->Count();
       
   177 	if (noentries != iSubDirEntries)
       
   178 		{
       
   179 		ERR_PRINTF4(_L("Expected %d entries in %S, got %d"), &sessionPath, iSubDirEntries, noentries);
       
   180 		return KErrUnknown;
       
   181 		}
       
   182 	for (i = 0; i < iSubDirEntries; i++)
       
   183 		{
       
   184 		TFileName filename;
       
   185 		filename.Format(_L("%Sfile%04d"), &sessionPath, i);
       
   186 		RFile file;
       
   187 		r = file.Open(iFs, filename, EFileRead);
       
   188 		if (r != KErrNone)
       
   189 			{
       
   190 			ERR_PRINTF3(_L("RFile::Open on %S returned %d"), &filename, r);
       
   191 			return r;
       
   192 			}
       
   193 		file.Close();
       
   194 		}
       
   195 	delete entryList;
       
   196 	return KErrNone;
       
   197 	}