static void OutputClassMethodMockDeclarations(CodeGen.Formatter output, CodeGen.Interface classData, Dictionary<string, CodeGen.QualifiableType> typeDictionary) { foreach (CodeGen.Interface.Method m in classData.Methods) { if (m.IsOverload) continue; output.WriteIndent(); output.Write("CALL_COUNTER_WITH_MOCK(" + m.Name + "Method, "); if (m.ReturnsHResult()) { output.Write("HRESULT"); } else { output.Write(typeDictionary[m.NativeReturnType].NativeName); } output.Write("("); for (int i=0; i<m.Parameters.Count; i++) { output.Write(GetParameterTypeNameIncludingIndirection(m.Parameters[i], typeDictionary)); if (m.Parameters[i].IsArray) { output.Write(", UINT32"); } if (i < m.Parameters.Count - 1) output.Write(", "); } output.Write("));"); output.WriteLine(); } output.WriteLine(); }
static void OutputClassMethodMockDeclarations(CodeGen.Formatter output, CodeGen.Interface classData, Dictionary <string, CodeGen.QualifiableType> typeDictionary) { foreach (CodeGen.Interface.Method m in classData.Methods) { if (m.IsOverload) { continue; } int projectedParameterCount = 0; for (int i = 0; i < m.Parameters.Count; i++) { projectedParameterCount++; if (m.Parameters[i].IsArray) { projectedParameterCount++; } } string constSuffix = m.IsConst ? "_CONST" : ""; output.WriteIndent(); output.Write($"MOCK_METHOD{projectedParameterCount}{constSuffix}({m.Name}, "); if (m.ReturnsHResult()) { output.Write("HRESULT"); } else { output.Write(typeDictionary[m.NativeReturnType].NativeName); } output.Write("("); for (int i = 0; i < m.Parameters.Count; i++) { output.Write(GetParameterTypeNameIncludingIndirection(m.Parameters[i], typeDictionary)); if (m.Parameters[i].IsArray) { output.Write(", UINT32"); } if (i < m.Parameters.Count - 1) { output.Write(", "); } } output.Write("));"); output.WriteLine(); } output.WriteLine(); }
static void OutputMock(string name, string inputDir, string outputDir) { CodeGen.Program.ProcessedInputFiles processedInputFiles = CodeGen.Program.ProcessInputFiles(inputDir); List<CodeGen.Interface> inheritanceHierarchy = new List<CodeGen.Interface>(); GetInheritanceHierarchy("D2D1::I" + name, processedInputFiles, inheritanceHierarchy); // Strip the revision number out of the mock name. string mockTypeName = "MockD2D" + name; if(mockTypeName.EndsWith("1") || mockTypeName.EndsWith("2") || mockTypeName.EndsWith("3")) { mockTypeName = mockTypeName.Remove(mockTypeName.Length - 1); } string outputFileName = mockTypeName + ".h"; string outputPath = Path.Combine(outputDir, outputFileName); using (CodeGen.Formatter output = new CodeGen.Formatter(outputPath)) { CodeGen.OutputDataTypes.OutputLeadingComment(output); output.WriteLine("#pragma once"); output.WriteLine(); output.WriteLine("namespace canvas"); output.WriteLine("{"); output.Indent(); output.WriteLine("class " + mockTypeName + " : public RuntimeClass<"); output.Indent(); output.WriteLine("RuntimeClassFlags<ClassicCom>,"); output.WriteIndent(); if (inheritanceHierarchy.Count > 1) { output.Write("ChainInterfaces<"); } for (int i = 0; i < inheritanceHierarchy.Count; i++) { output.Write(inheritanceHierarchy[i].NativeName); if (i < inheritanceHierarchy.Count - 1) output.Write(", "); } if (inheritanceHierarchy.Count > 1) { output.Write(">"); } output.Write(">"); output.WriteLine(); output.Unindent(); output.WriteLine("{"); output.WriteLine("public:"); output.Indent(); foreach (CodeGen.Interface classData in inheritanceHierarchy) { OutputClassMethodMockDeclarations(output, classData, processedInputFiles.TypeDictionary); } foreach (CodeGen.Interface classData in inheritanceHierarchy) { OutputClassMethodDefinitions(output, classData, processedInputFiles.TypeDictionary); } output.Unindent(); output.WriteLine("};"); output.Unindent(); output.WriteLine("}"); } }
static void OutputMock(string name, string inputDir, string outputDir) { CodeGen.Program.ProcessedInputFiles processedInputFiles = CodeGen.Program.ProcessInputFiles(inputDir); List <CodeGen.Interface> inheritanceHierarchy = new List <CodeGen.Interface>(); GetInheritanceHierarchy("D2D1::I" + name, processedInputFiles, inheritanceHierarchy); // Strip the revision number out of the mock name. string mockTypeName = "MockD2D" + name; if (mockTypeName.EndsWith("1") || mockTypeName.EndsWith("2") || mockTypeName.EndsWith("3")) { mockTypeName = mockTypeName.Remove(mockTypeName.Length - 1); } string outputFileName = mockTypeName + ".h"; string outputPath = Path.Combine(outputDir, outputFileName); using (CodeGen.Formatter output = new CodeGen.Formatter(outputPath)) { CodeGen.OutputDataTypes.OutputLeadingComment(output); output.WriteLine("#pragma once"); output.WriteLine(); output.WriteLine("namespace canvas"); output.WriteLine("{"); output.Indent(); output.WriteLine("class " + mockTypeName + " : public RuntimeClass<"); output.Indent(); output.WriteLine("RuntimeClassFlags<ClassicCom>,"); output.WriteIndent(); if (inheritanceHierarchy.Count > 1) { output.Write("ChainInterfaces<"); } for (int i = 0; i < inheritanceHierarchy.Count; i++) { output.Write(inheritanceHierarchy[i].NativeName); if (i < inheritanceHierarchy.Count - 1) { output.Write(", "); } } if (inheritanceHierarchy.Count > 1) { output.Write(">"); } output.Write(">"); output.WriteLine(); output.Unindent(); output.WriteLine("{"); output.WriteLine("public:"); output.Indent(); foreach (CodeGen.Interface classData in inheritanceHierarchy) { OutputClassMethodMockDeclarations(output, classData, processedInputFiles.TypeDictionary); } foreach (CodeGen.Interface classData in inheritanceHierarchy) { OutputClassMethodDefinitions(output, classData, processedInputFiles.TypeDictionary); } output.Unindent(); output.WriteLine("};"); output.Unindent(); output.WriteLine("}"); } }
static void OutputClassMethodDefinitions(CodeGen.Formatter output, CodeGen.Interface classData, Dictionary <string, CodeGen.QualifiableType> typeDictionary) { output.WriteLine("//"); output.WriteLine("// " + classData.NativeName); output.WriteLine("//"); output.WriteLine(); foreach (CodeGen.Interface.Method m in classData.Methods) { if (m.IsOverload) { continue; } output.WriteIndent(); if (m.ReturnsHResult()) { output.Write("STDMETHOD(" + m.Name + ")("); } else { output.Write("STDMETHOD_(" + typeDictionary[m.NativeReturnType].NativeName + ", " + m.Name + ")("); } output.Indent(); for (int i = 0; i < m.Parameters.Count; i++) { output.WriteLine(); string parameterString = GetParameterTypeNameIncludingIndirection(m.Parameters[i], typeDictionary) + " " + m.Parameters[i].Name; output.WriteIndent(); output.Write(parameterString); if (m.Parameters[i].IsArray) { output.Write(","); output.WriteLine(); output.WriteIndent(); output.Write("UINT32 " + m.Parameters[i].Name + "Count"); } if (i < m.Parameters.Count - 1) { output.Write(","); } } string constString = m.IsConst ? " const" : ""; output.Write(")" + constString + " override"); output.WriteLine(); output.Unindent(); output.WriteLine("{"); output.Indent(); output.WriteIndent(); if (m.NativeReturnType != "void") { output.Write("return "); } output.Write(m.Name + "Method.WasCalled("); for (int i = 0; i < m.Parameters.Count; i++) { output.Write(m.Parameters[i].Name); if (m.Parameters[i].IsArray) { output.Write(", " + m.Parameters[i].Name + "Count"); } if (i < m.Parameters.Count - 1) { output.Write(", "); } } output.Write(");"); output.WriteLine(); output.Unindent(); output.WriteLine("}"); output.WriteLine(); } }