public void ValidateStructs() { List <string> files = GetFileList(); bool success = true; foreach (string file in files) { LogHelper.Log("File {0} :", file); string curPath = ExtractFilePath(file, string.Empty, false); List <string> content = ValidationHelper.ReadAllLines(curPath); Structs curStructs = ValidationHelper.ParseStructs(content); List <string> versions = GetVersionList(); foreach (string version in versions) { LogHelper.Log("Version {0} :", version); string prePath = ExtractFilePath(file, version, true); List <string> preContent = ValidationHelper.ReadAllLines(prePath); Structs preStructs = ValidationHelper.ParseStructs(preContent); LogHelper.Log("**************************************************************************"); LogHelper.Log("Comparing structs:"); List <string> differences = preStructs.Compare(curStructs); success &= (differences == null || differences.Count == 0); LogHelper.Log("{0} structs are different.", (differences == null) ? 0 : differences.Count); LogHelper.Log("**************************************************************************"); } } Assert.IsTrue(success, "Comparison completed. No structs is changed."); }
public List <string> Compare(Structs target) { if (this.Count == 0 || target == null || target.Count == 0) { return(null); } List <string> differences = new List <string>(); // Search structs which defined in previous release from current build // If it is found, compare the struct // If the content of same struct are differrent // Compare and output the different members foreach (KeyValuePair <string, StructObject> pair in this.infos) { if (ValidationIgnoreList .ValidationIgnoreListStructs .ContainsKey(pair.Key)) { // Ignore a set of STRUCTS from this validation. continue; } string name = pair.Key; if (target.infos.ContainsKey(name)) { StructObject cur = target[name]; StructObject pre = pair.Value; if (!pre.Equals(cur)) { Members curMethods = ValidationHelper.ParseMemberInformation(cur.Body); Members preMethods = ValidationHelper.ParseMemberInformation(pre.Body); string difference = preMethods.Compare(curMethods); LogHelper.Log("Differences of {0}:", name); LogHelper.Log(difference); differences.Add(difference); } } } return(differences); }
/// <summary> /// Read all content of .h and parse struct name and body /// </summary> /// <param name="lines">Content of .h file</param> /// <returns>StructObject collection</returns> public static Structs ParseStructs(List <string> lines) { LogHelper.Log("Start getting structs:"); Structs structs = new Structs(); const string match = "typedef struct"; const string sFlag = "{"; const string notMatch = "Vtbl"; const string endFlag = "}"; const char space = ' '; int i = 0; while (i < lines.Count) { string line = lines[i++]; if (!line.StartsWith(match) || line.Contains(notMatch) || !lines[i].Contains(sFlag)) { continue; } StructObject so = new StructObject(); so.Name = line.Split(space)[2]; StringBuilder sb = new StringBuilder(); while (++i < lines.Count && !lines[i].Contains(endFlag)) { sb.AppendLine(lines[i]); } so.Body = sb.ToString(); structs.Add(so.Name, so); } LogHelper.Log("Completed getting structs: {0} structs.", structs.Count); return(structs); }