1 // SSTests.cpp: implementation of the SSTests class.
3 //////////////////////////////////////////////////////////////////////
7 #include <SSPhysLib/SSVersionObject.h>
8 #include <SSPhysLib/SSItemInfoObject.h>
9 #include <SSPhysLib/SSNameObject.h>
11 //#include <boost/filesystem/path.hpp>
12 //namespace fs = boost::filesystem;
14 //////////////////////////////////////////////////////////////////////
15 // Construction/Destruction
16 //////////////////////////////////////////////////////////////////////
18 void TestComments (SSRecordFile
& file
)
21 int nCommentRecords
= 0;
23 for (pRecord
= file
.GetFirstRecord (); pRecord
; )
25 if (pRecord
->GetType () == eCommentRecord
)
29 else if (pRecord
->GetType () == eHistoryRecord
)
31 // std::auto_ptr <SSVersionObject> pVersion (SSVersionObject::MakeVersion(pRecord));
32 // SSLabeledAction* pAction = dynamic_cast <SSLabeledAction*> (pVersion.get());
33 std::auto_ptr
<SSVersionObject
> pVersion (new SSVersionObject (file
.GetFileImp(), pRecord
));
34 SSLabeledAction
* pAction
= dynamic_cast <SSLabeledAction
*> (pVersion
.get());
36 // es gibt bishet anscheinend immer nur einen Comment oder einen LabelComment,
37 // bzw. Comment und LabelComment sind identisch
38 if (!pVersion
->GetComment ().empty() || (pAction
&& pAction
->GetLabelComment ().empty()))
43 pRecord
= file
.GetNextRecord (pRecord
);
46 assert (nComments
== nCommentRecords
);
49 void CheckOffsetsToComment (SSFile
& file
)
53 for (pRecord
= file
.GetFirstRecord (); pRecord
; )
55 if (pRecord
->GetType () == eHistoryRecord
)
57 std::auto_ptr
<SSVersionObject
> pVersion (SSVersionObject::MakeVersion(pRecord
));
58 const VERSION_RECORD
* pV
= reinterpret_cast<const VERSION_RECORD
*> (pVersion
->GetDataPtr ());
60 // std::cout << std::hex << pV->offsetToLabelComment <<std::endl;
61 // offsetToLabelComment zeigt immer auf einen MC record
62 if (pV
->offsetToLabelComment
)
64 SSRecordPtr pNext
= file
.GetRecord (pV
->offsetToLabelComment
);
65 // assert (pNext->GetType () == eCommentRecord);
68 // im Labeled Fall zeigt offsetToNextRecordOrComment immer auf einen MC record
69 if (pVersion
->GetActionId () == Labeled
&& pV
->offsetToNextRecordOrComment
)
71 SSRecordPtr pNext
= file
.GetRecord (pV
->offsetToNextRecordOrComment
);
72 // assert (pNext->GetType () == eCommentRecord);
75 // offsetToNextRecordOrComment zeigt immer auf den nächsten in der List
76 if (pV
->offsetToNextRecordOrComment
)
78 // assert (pV->offsetToNextRecordOrComment == pRecord->GetNextOffset ());
82 pRecord
= file
.GetNextRecord (pRecord
);
87 void CheckLabelValid (SSFile
& file
)
91 for (pRecord
= file
.GetFirstRecord (); pRecord
; )
93 if (pRecord
->GetType () == eHistoryRecord
)
95 std::auto_ptr
<SSVersionObject
> pVersion (SSVersionObject::MakeVersion(pRecord
));
96 const VERSION_RECORD
* pV
= reinterpret_cast<const VERSION_RECORD
*> (pVersion
->GetDataPtr ());
97 SSLabeledAction
* pAction
= dynamic_cast <SSLabeledAction
*> (pVersion
.get());
101 if (pV
->offsetToLabelComment
)
103 SSRecordPtr pComment1
= file
.GetRecord (pV
->offsetToLabelComment
);
104 assert (pV
->lengthLabelComment
== pComment1
->GetLen ());
106 // BUG: Nach dem Löschen eines Labels wird eigentlich das erste char des Label auf 0 gesetzt und der
107 // Label comment gelöscht. (neuer MC eintrag mit Länge 1) der Comment wird nicht angefaßt. Anscheinend
108 // kann es aber passieren, daß die Länge des Comment auf 0 gesetzt wird, obwohl der Eintrag auf einen
109 // leeren 1 Byte langen Comment verweist.
110 // Ich bin mir noch nicht sicher, ob das ein Bug oder ein Feature ist
111 if (pV
->lengthComment
!= 0 &&
112 pV
->offsetToNextRecordOrComment
&& pV
->offsetToNextRecordOrComment
!= pV
->offsetToLabelComment
)
114 SSRecordPtr pComment2
= file
.GetRecord (pV
->offsetToNextRecordOrComment
);
115 assert (pV
->lengthComment
== pComment2
->GetLen ());
120 pRecord
= file
.GetNextRecord (pRecord
);
125 void CheckFileSize (SSHistoryFile
& file
)
127 std::auto_ptr
<SSItemInfoObject
> pItem (file
.GetItemInfo());
128 assert (pItem
.get () && "no item found in this file");
131 void IntegrityCheck (SSHistoryFile
& file
)
133 // 1.) run the linear list of records, one record is succeeded by another record
135 SSRecordPtr pRecord
= file
.GetFirstRecord ();
138 pRecord
= file
.GetNextRecord (pRecord
);
141 catch (SSException
& ex
)
143 std::cout
<< "Warning while testing linear: " << ex
.what () << std::endl
;
146 // 2.) run the linked list of records
148 std::auto_ptr
<SSItemInfoObject
> pItem (file
.GetItemInfo());
151 for (int i
= pItem
->GetNumberOfActions (); i
> 0; i
--)
153 std::auto_ptr
<SSVersionObject
> pVersion (pItem
->GetVersion (i
));
154 std::string pComment
= pVersion
->GetComment();
158 catch (SSException
& ex
) {
159 std::cout
<< "Warning while testing linked history list: " << ex
.what () << std::endl
;
162 // 3.) run the parent project linked list
164 // SSItemInfo* pItem = file.GetItem ();
167 // for (int i = pItem->GetNumberOfParents (); i> 0; i--)
169 // SSVersionObject* pVersion = pItem->GetParent (i);
173 // catch (SSException& ex) {
174 // std::cout << "Warning while testing linked parent project list: " << ex.what () << std::endl;
179 void DumpNamesCache (SSNamesCacheFile
& namesCache
)
182 for (pRecord
= namesCache
.GetFirstRecord (); pRecord
; )
184 if (pRecord
->GetType () == eNameCacheEntry
)
186 SSNameObject
name (namesCache
.GetFileImp(), pRecord
);
187 name
.Dump (std::cout
);
189 pRecord
= namesCache
.GetNextRecord (pRecord
);
194 //void TestSrcSafeIni (const COptions& options)
196 // fs::path basePath = fs::path(options.GetSrcSafeIniPath (), fs::native);
198 // std::string database = options.GetDatabase ();
199 // if (!database.empty())
201 // database = " (" + database + ")";
204 // if (!basePath.empty ())
206 // fs::path srcSafeIni = basePath / "srcsafe.ini";
207 // fs::path dataPath = basePath / CIniFile::GetValue("Data_Path" + database, "", srcSafeIni.string());
208 // fs::path usersPath = basePath / CIniFile::GetValue("Users_Path"+ database, "", srcSafeIni.string());
209 // fs::path usersText = basePath / CIniFile::GetValue("Users_Text"+ database, "", srcSafeIni.string());
210 // fs::path tempPath = basePath / CIniFile::GetValue("Temp_Path" + database, "", srcSafeIni.string());