Fixed typo. Was not getting any text after pRecord->GetRecordType() (which was proba...
[vss2svn.git] / ssphys / SSPhys / SSTests.cpp
blob1b416e5384b44dc894d53e3bce8ec63a82d52995
1 // SSTests.cpp: implementation of the SSTests class.
2 //
3 //////////////////////////////////////////////////////////////////////
5 #include "StdAfx.h"
6 #include "SSTests.h"
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)
20 SSRecordPtr pRecord;
21 int nCommentRecords = 0;
22 int nComments = 0;
23 for (pRecord = file.GetFirstRecord (); pRecord; )
25 if (pRecord->GetType () == eCommentRecord)
27 nCommentRecords++;
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()))
40 nComments++;
43 pRecord = file.GetNextRecord (pRecord);
46 assert (nComments == nCommentRecords);
49 void CheckOffsetsToComment (SSFile& file)
51 #if 0
52 SSRecordPtr pRecord;
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);
84 #endif
87 void CheckLabelValid (SSFile& file)
89 #if 0
90 SSRecordPtr pRecord;
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());
99 if (pAction)
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);
122 #endif
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
134 try {
135 SSRecordPtr pRecord = file.GetFirstRecord ();
136 while (pRecord)
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
147 try {
148 std::auto_ptr<SSItemInfoObject> pItem (file.GetItemInfo());
149 if (pItem.get ())
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
163 // try {
164 // SSItemInfo* pItem = file.GetItem ();
165 // if (pItem)
166 // {
167 // for (int i = pItem->GetNumberOfParents (); i> 0; i--)
168 // {
169 // SSVersionObject* pVersion = pItem->GetParent (i);
170 // }
171 // }
172 // }
173 // catch (SSException& ex) {
174 // std::cout << "Warning while testing linked parent project list: " << ex.what () << std::endl;
175 // }
179 void DumpNamesCache (SSNamesCacheFile& namesCache)
181 SSRecordPtr pRecord;
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())
200 // {
201 // database = " (" + database + ")";
202 // }
204 // if (!basePath.empty ())
205 // {
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());
211 // }