public bool RunTest(out IReplayInformations infos) { infos = null; AssertException exception = null; Action invariantsEncapsulated = delegate { try { invariantsMethod (); } catch (TargetInvocationException e) { Scheduler.Stop (); exception = e.InnerException as AssertException; } }; foreach (Action action in testMethods) Scheduler.EnqueueWork (new HeisenThread (action)); Scheduler.Run (initMethod, invariantsEncapsulated); Console.WriteLine ("Test concluded after {0} mixed-interleaving runs", Scheduler.NumberOfRun.ToString ()); if (exception != null) infos = new ReplayInfos (exception); return exception == null; }
public void Init() { #if UseReplayInfoFile // 加载info文件 string path = Application.streamingAssetsPath + "/Rep/data.ri"; if (!System.IO.File.Exists(path)) { ReplayInfos tmp = new ReplayInfos(); tmp.infos = new List <ReplayInfo>(); FileStream fs = new FileStream(path, FileMode.Create); BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(fs, tmp); fs.Close(); _replayInfoList = tmp.infos; } else { FileStream fs = new FileStream(path, FileMode.Open); BinaryFormatter bf = new BinaryFormatter(); ReplayInfos tmp = (ReplayInfos)bf.Deserialize(fs); fs.Close(); _replayInfoList = tmp.infos; } #else #if Debug _repFolderPath = Application.dataPath; #else _repFolderPath = Application.dataPath + "../Rep"; #endif // 挨个读取rep文件生成replay数据 _replayInfoList = new List <ReplayInfo>(); string repPath; FileStream fs; BinaryFormatter bf = new BinaryFormatter(); for (int i = 0; i < Consts.MaxReplayCount; i++) { repPath = _repFolderPath + "/replay" + i + ".rep"; if (System.IO.File.Exists(repPath)) { fs = new FileStream(repPath, FileMode.Open); ReplayData repData = (ReplayData)bf.Deserialize(fs); fs.Close(); // 添加repInfo _replayInfoList.Add(repData.info); } } #endif }
/// <summary> /// 将info写入RepInfo文件中 /// </summary> /// <param name="info"></param> private void WriteRepInfoFile(ReplayInfo info) { #if UseReplayInfoFile string path = Application.streamingAssetsPath + "/Rep/data.ri"; FileStream fs = new FileStream(path, FileMode.Open); BinaryFormatter bf = new BinaryFormatter(); ReplayInfos tmp = (ReplayInfos)bf.Deserialize(fs); fs.Close(); bool isExist = false; for (int i = 0; i < tmp.infos.Count; i++) { if (tmp.infos[i].replayIndex == info.replayIndex) { isExist = true; tmp.infos[i] = info; break; } } if (!isExist) { tmp.infos.Add(info); } fs = new FileStream(path, FileMode.Truncate); bf = new BinaryFormatter(); bf.Serialize(fs, tmp); fs.Close(); // 将更新后的info赋值 _replayInfoList = tmp.infos; #else bool isExist = false; for (int i = 0; i < _replayInfoList.Count; i++) { if (_replayInfoList[i].replayIndex == info.replayIndex) { isExist = true; _replayInfoList[i] = info; break; } } if (!isExist) { _replayInfoList.Add(info); } #endif }