stif/StifTFwIf/src/UIStore.cpp
branchRCL_3
changeset 14 a9c038d69df8
parent 0 a03f92240627
child 18 3406c99bc375
equal deleted inserted replaced
13:da2cedce4920 14:a9c038d69df8
    44 _LIT( KUIStoreIf, "CUiStoreIf" );
    44 _LIT( KUIStoreIf, "CUiStoreIf" );
    45 //_LIT( KUIStoreDefaultDir, "C:\\TestFramework\\" );
    45 //_LIT( KUIStoreDefaultDir, "C:\\TestFramework\\" );
    46 
    46 
    47 _LIT( KUIStoreSetStart, "[TestSetStart]" );
    47 _LIT( KUIStoreSetStart, "[TestSetStart]" );
    48 _LIT( KUIStoreSetEnd, "[TestSetEnd]" );
    48 _LIT( KUIStoreSetEnd, "[TestSetEnd]" );
    49 _LIT( KUIStoreSetName, "TestSetName=" );
       
    50 _LIT( KUIStoreSetCaseStart, "[TestSetCaseStart]" );
    49 _LIT( KUIStoreSetCaseStart, "[TestSetCaseStart]" );
    51 _LIT( KUIStoreSetCaseEnd, "[TestSetCaseEnd]" );
    50 _LIT( KUIStoreSetCaseEnd, "[TestSetCaseEnd]" );
    52 _LIT( KUIStoreCaseModuleName, "ModuleName=" );
    51 _LIT( KUIStoreCaseModuleName, "ModuleName=" );
    53 _LIT( KUIStoreTestCaseTitle, "Title=" );
    52 _LIT( KUIStoreTestCaseTitle, "Title=" );
    54 _LIT( KUIStoreTestCaseFile, "TestCaseFile="); 
    53 _LIT( KUIStoreTestCaseFile, "TestCaseFile="); 
  1069             stset->NullOriginalTestSet();
  1068             stset->NullOriginalTestSet();
  1070             }
  1069             }
  1071         }
  1070         }
  1072     
  1071     
  1073     delete setInfo;
  1072     delete setInfo;
  1074 
  1073     TFileName setfile;
       
  1074     setfile.Append(KUIStoreDefaultDir);
       
  1075     setfile.Append(aSetName);
       
  1076     RFs fs;
       
  1077     TInt err=fs.Connect();
       
  1078     if(err!=KErrNone)
       
  1079     {
       
  1080     fs.Close();
       
  1081     return err;
       
  1082     }
       
  1083     err=fs.Delete(setfile);
       
  1084     if(err!=KErrNone)
       
  1085     {
       
  1086     fs.Close();
       
  1087     return err;    
       
  1088     }
       
  1089     
  1075     return KErrNone;
  1090     return KErrNone;
  1076     
  1091     
  1077     }
  1092     }
  1078 
  1093 
  1079 /*
  1094 /*
  1319 -------------------------------------------------------------------------------
  1334 -------------------------------------------------------------------------------
  1320 */
  1335 */
  1321 EXPORT_C TInt CUIStore::SaveTestSet2( TDes& aSetName )
  1336 EXPORT_C TInt CUIStore::SaveTestSet2( TDes& aSetName )
  1322     {
  1337     {
  1323     
  1338     
       
  1339     RRefArray<TDesC> testsets;
       
  1340     
       
  1341     GetTestSetsList(testsets);
       
  1342     TBool isexist(EFalse);
       
  1343     for(TInt i=0;i<testsets.Count();i++)
       
  1344     {
       
  1345        if(testsets[i]==aSetName)
       
  1346            {
       
  1347            isexist=ETrue;
       
  1348            break;
       
  1349            }
       
  1350     
       
  1351     }
       
  1352     testsets.Reset();
       
  1353     if(!isexist)
       
  1354     {
       
  1355         TTime current;
       
  1356         TDateTime date_rep;
       
  1357         current.HomeTime();
       
  1358         date_rep = current.DateTime();
       
  1359         TBuf<32> currSetName;
       
  1360         _LIT(f_ext,".set");
       
  1361         
       
  1362         //create "test set name" string
       
  1363         currSetName.AppendNum(date_rep.Year());
       
  1364         currSetName.Append('_');
       
  1365         currSetName.AppendNum(date_rep.Month()+1); // Incrimination necessary, because Day and Month fields of TDateTime class are 0 based
       
  1366         currSetName.Append('_');
       
  1367         currSetName.AppendNum(date_rep.Day()+1);
       
  1368         currSetName.Append('_');
       
  1369         currSetName.AppendNum(date_rep.Hour());
       
  1370         currSetName.Append('_');
       
  1371         currSetName.AppendNum(date_rep.Minute());
       
  1372         currSetName.Append('_');
       
  1373         currSetName.AppendNum(date_rep.Second());
       
  1374         currSetName.Append(f_ext);
       
  1375         
       
  1376         for(TInt i=0;i<iTestSets.Count();i++)
       
  1377         {
       
  1378             if(iTestSets[i]->Name()==aSetName)
       
  1379                 {
       
  1380                 iTestSets[i]->RenameTestSet(currSetName);
       
  1381                 
       
  1382                 }
       
  1383         
       
  1384         }
       
  1385         
       
  1386         
       
  1387         
       
  1388         aSetName.Zero();
       
  1389         aSetName.Copy(currSetName);
       
  1390        
       
  1391         
       
  1392     
       
  1393     }
  1324     TPtrC setName;
  1394     TPtrC setName;
  1325     TFileName tmp;
  1395     TFileName tmp;
  1326 
  1396 
  1327     TTime current;
  1397     
  1328     TDateTime date_rep;
       
  1329     current.HomeTime();
       
  1330     date_rep = current.DateTime();
       
  1331     TBuf<32> currSetName;
       
  1332     _LIT(f_ext,".set");
       
  1333     
       
  1334     //create "test set name" string
       
  1335      currSetName.AppendNum(date_rep.Year());
       
  1336      currSetName.Append('_');
       
  1337      currSetName.AppendNum(date_rep.Month()+1); // Incrimination necessary, because Day and Month fields of TDateTime class are 0 based
       
  1338      currSetName.Append('_');
       
  1339      currSetName.AppendNum(date_rep.Day()+1);
       
  1340      currSetName.Append('_');
       
  1341      currSetName.AppendNum(date_rep.Hour());
       
  1342      currSetName.Append('_');
       
  1343      currSetName.AppendNum(date_rep.Minute());
       
  1344      currSetName.Append(f_ext);
       
  1345 
  1398 
  1346     TInt ret = ParseTestSetName( aSetName, setName, tmp );
  1399     TInt ret = ParseTestSetName( aSetName, setName, tmp );
  1347     if( ret != KErrNone )
  1400     if( ret != KErrNone )
  1348         {
  1401         {
  1349         return ret;
  1402         return ret;
  1355         {
  1408         {
  1356         return ret;
  1409         return ret;
  1357         }
  1410         }
  1358      
  1411      
  1359     TRAPD( err,
  1412     TRAPD( err,
  1360         SaveTestSetL( *setInfo, currSetName );
  1413         SaveTestSetL( *setInfo, aSetName );
  1361         );
  1414         );
  1362     
  1415     
  1363     aSetName.Copy(currSetName);
  1416    
  1364     
  1417     
  1365     return err;
  1418     return err;
  1366     
  1419     
  1367     }  
  1420     }  
  1368 
  1421 
  1385 
  1438 
  1386 -------------------------------------------------------------------------------
  1439 -------------------------------------------------------------------------------
  1387 */
  1440 */
  1388 EXPORT_C TInt CUIStore::LoadTestSet( const TDesC& aSetName )
  1441 EXPORT_C TInt CUIStore::LoadTestSet( const TDesC& aSetName )
  1389     {
  1442     {
  1390     
       
  1391     TPtrC setName;
  1443     TPtrC setName;
  1392     TFileName tmp;
  1444     TFileName tmp;
  1393     TInt ret = ParseTestSetName( aSetName, setName, tmp );
  1445     TInt ret = ParseTestSetName( aSetName, setName, tmp );
  1394     if( ret != KErrNone )
  1446     if( ret != KErrNone )
  1395         {
  1447         {
  1396         return ret;
  1448         return ret;
  1397         }
  1449         }
  1398         
  1450     CTestSetInfo* setInfo= NULL;
  1399     TRAPD( err,
  1451     
       
  1452     FindSetByName( setName, setInfo );
       
  1453     if(setInfo != NULL)
       
  1454         {
       
  1455         return KErrNone;
       
  1456         }
       
  1457     
       
  1458     TRAPD( err, 
       
  1459         setInfo = CTestSetInfo::NewL( aSetName );
       
  1460         );
       
  1461     if( err != KErrNone )
       
  1462         {
       
  1463         return err;
       
  1464         }
       
  1465     if( iTestSets.Append( setInfo ) != KErrNone )
       
  1466         {
       
  1467         delete setInfo;
       
  1468         return KErrNoMemory;
       
  1469         }
       
  1470 
       
  1471     TRAP( err,
  1400         LoadTestSetL( setName, aSetName );
  1472         LoadTestSetL( setName, aSetName );
  1401         );
  1473         );
  1402     
  1474     
  1403      if( err != KErrNone && err != KErrAlreadyExists )
  1475      if( err != KErrNone && err != KErrAlreadyExists )
  1404         {
  1476         {
  1846 
  1918 
  1847     Status: Draft
  1919     Status: Draft
  1848 
  1920 
  1849 -------------------------------------------------------------------------------
  1921 -------------------------------------------------------------------------------
  1850 */
  1922 */
  1851 void CUIStore::LoadTestSetL( const TDesC& aSetName, const TDesC& aSetFileName )
  1923 void CUIStore::LoadTestSetL( const TDesC& aSetName, const TDesC& /*aSetFileName*/ )
  1852     {
  1924     {
  1853     
  1925     
  1854     TPtrC tmp;
  1926     TPtrC tmp;
  1855     TInt num;
  1927     TInt num;
  1856     TInt high;
  1928     TInt high;
  1857     TInt64 interval;
  1929     TInt64 interval;
  1858     
  1930     
  1859     CStifParser* parser = NULL;
  1931     CStifParser* parser = CStifParser::NewL( KUIStoreDefaultDir, aSetName );
  1860     
  1932 
  1861     TRAPD( err,
       
  1862         parser = CStifParser::NewL( _L(""), aSetFileName );
       
  1863         );
       
  1864     if( err != KErrNone )
       
  1865         {
       
  1866         parser = CStifParser::NewL( KUIStoreDefaultDir, aSetName );
       
  1867         }
       
  1868         
  1933         
  1869     CleanupStack::PushL( parser );
  1934     CleanupStack::PushL( parser );
  1870     
  1935     
  1871     CStifSectionParser* section = 
  1936     CStifSectionParser* section = 
  1872         parser->SectionL( KUIStoreSetStart, KUIStoreSetEnd );
  1937         parser->SectionL( KUIStoreSetStart, KUIStoreSetEnd );
  1873     CleanupStack::PushL( section );
  1938     CleanupStack::PushL( section );
  1874     
  1939     
  1875     CStifItemParser* item = section->GetItemLineL( KUIStoreSetName );
  1940     CStifItemParser* item;
  1876     CleanupStack::PushL( item );
  1941 
  1877     
       
  1878     User::LeaveIfError( item->GetString( KUIStoreSetName, tmp ) );
       
  1879     
       
  1880 	// get the standard method
       
  1881 	TCollationMethod method = *Mem::CollationMethodByIndex(0);
       
  1882 	// ignore case
       
  1883     method.iFlags |= TCollationMethod::EFoldCase;
       
  1884     
       
  1885 	TInt compare = aSetName.CompareC( tmp, 3, &method );
       
  1886 	if( compare != KErrNone )
       
  1887         {
       
  1888         User::LeaveIfError( KErrNotFound );
       
  1889         }
       
  1890         
       
  1891     CleanupStack::PopAndDestroy( item );
       
  1892         
       
  1893     // Get started test case (if possible)
  1942     // Get started test case (if possible)
  1894     TUint lastStartedCaseIndex = 0;
  1943     TUint lastStartedCaseIndex = 0;
  1895     item = section->GetItemLineL(KUIStoreLastStartedCaseIndex);
  1944     item = section->GetItemLineL(KUIStoreLastStartedCaseIndex);
  1896     if(item)
  1945     if(item)
  1897         {
  1946         {
  1906     else
  1955     else
  1907         {
  1956         {
  1908         __TRACE(KInit, (_L("Could not find [%S] from test set file."), &KUIStoreLastStartedCaseIndex));
  1957         __TRACE(KInit, (_L("Could not find [%S] from test set file."), &KUIStoreLastStartedCaseIndex));
  1909         }
  1958         }
  1910 
  1959 
  1911     User::LeaveIfError( CreateTestSet( aSetName ) );
       
  1912     
  1960     
  1913     CTestSetInfo* setInfo = NULL;
  1961     CTestSetInfo* setInfo = NULL;
  1914     User::LeaveIfError( FindSetByName( aSetName, setInfo ) );
  1962     User::LeaveIfError( FindSetByName( aSetName, setInfo ) );
  1915     
  1963     
  1916     // Update started case
  1964     // Update started case
  2045         buffer.Create(256);
  2093         buffer.Create(256);
  2046         CleanupClosePushL(buffer);
  2094         CleanupClosePushL(buffer);
  2047         
  2095         
  2048         // Saving
  2096         // Saving
  2049         buffer.Format(_L("%S"), &KUIStoreSetStart);
  2097         buffer.Format(_L("%S"), &KUIStoreSetStart);
  2050         WriteLineL(file, buffer);
       
  2051         buffer.Format(_L("%S %S"), &KUIStoreSetName,&aSetFileName);
       
  2052         WriteLineL(file, buffer);
  2098         WriteLineL(file, buffer);
  2053 
  2099 
  2054         // Saving test set causes reset of index
  2100         // Saving test set causes reset of index
  2055         aSetInfo.SetLastStartedCaseIndex(0);
  2101         aSetInfo.SetLastStartedCaseIndex(0);
  2056         buffer.Format(_L("%S "), &KUIStoreLastStartedCaseIndex);
  2102         buffer.Format(_L("%S "), &KUIStoreLastStartedCaseIndex);
  4735 TUint CTestSetInfo::GetLastStartedCaseIndex(void)
  4781 TUint CTestSetInfo::GetLastStartedCaseIndex(void)
  4736     {
  4782     {
  4737     return iLastStartedCaseIndex;
  4783     return iLastStartedCaseIndex;
  4738     }    
  4784     }    
  4739 
  4785 
       
  4786 /*
       
  4787 -------------------------------------------------------------------------------
       
  4788 
       
  4789     Class: CTestSetInfo
       
  4790 
       
  4791     Method: RenameTestSet
       
  4792 
       
  4793     Description:  rename test set
       
  4794         
       
  4795     Parameters: aTestSetName : new TestSetName
       
  4796 
       
  4797     Return Values: TInt: KErrNone if success.
       
  4798 
       
  4799     Errors/Exceptions: None
       
  4800 
       
  4801     Status: Approved
       
  4802 
       
  4803 -------------------------------------------------------------------------------
       
  4804 */
       
  4805 void CTestSetInfo::RenameTestSet(const TDesC& aTestSetName)
       
  4806     {
       
  4807     delete iName;
       
  4808     iName=NULL;
       
  4809     iName=aTestSetName.AllocL();
       
  4810     }
  4740 // ================= OTHER EXPORTED FUNCTIONS =================================
  4811 // ================= OTHER EXPORTED FUNCTIONS =================================
  4741 
  4812 
  4742 // End of File
  4813 // End of File