Exemplo n.º 1
0
        public static void ReadSourceCodeRequirements(string filePath, ref ReqPathMatrix codeReqLookup)
        {
            // Read the file as one string.
            System.IO.StreamReader fileAsStream = new System.IO.StreamReader(filePath);
            string fileAsString = fileAsStream.ReadToEnd();

            fileAsStream.Close();

            // Look for requirement references in the format something_SRS_something_123 or SRS_something_123
            // or _something_SRS_something_123 and _SRS_something_123
            string pattern = @"\b[A-Za-z_]*_?SRS_\w+_\d{2}_\d{3}";
            int    lineNum = 1; // Start counting lines from 1.
            int    pos     = 0; // First character index for a regular expression match is 0.

            foreach (Match m in Regex.Matches(fileAsString, pattern))
            {
                while (pos < fileAsString.Length && pos < m.Index)
                {
                    if (fileAsString[pos] == '\n')
                    {
                        lineNum++;
                    }
                    pos++;
                }
                codeReqLookup.Add(m.Value, new FilePathLineNum(filePath, lineNum));
            }
        }
Exemplo n.º 2
0
        private static void GenerateTraceabilityMatrix()
        {
            // Generate traceability matrix by checking if every requirement found in the source code
            // can be found in requirements documents.
            int    srsStartPos;
            string reqID;
            string reqPrefix;

            // Loop through each requirement reference (Codes_SRS_* or Tests_SRS_*) found in the code
            foreach (string codeReq in reqCodeLookup.Keys)
            {
                // Find the prefix of the requirement reference in the code
                srsStartPos = codeReq.IndexOf("SRS");
                reqPrefix   = codeReq.Substring(0, srsStartPos);
                // Find the requirement identifier (starting with "SRS_") in the key.
                reqID = codeReq.Substring(srsStartPos);
                // Check if the requirement reference prefix is correct and the requirement is found in requirement documents.
                if (reqPrefix.Equals("Codes_") &&
                    reqDocLookup.ContainsKey(reqID))
                {
                    // Update requirement-to-code matrix (req. ID and source code file paths).
                    reqCodeMatrix.Add(reqID, reqCodeLookup[codeReq]);
                }
                else if (reqPrefix.Equals("Tests_") &&
                         reqDocLookup.ContainsKey(reqID))
                {
                    // Update requirement-to-test matrix (req. ID and test code file paths).
                    reqTestMatrix.Add(reqID, reqCodeLookup[codeReq]);
                }
                else if (reqPrefix.Equals("Codes_") ||
                         reqPrefix.Equals("Tests_"))
                {
                    // Add requirement to the list of invalid requirements - requirement has no defition in .docm files.
                    invalidRequirements.Add(reqID, reqCodeLookup[codeReq], "Requirement definition not found");
                }
                else
                {
                    // Add requirement to the list of invalid requirements - requirement reference is missing "Codes_" or "Tests_" prefix.
                    invalidRequirements.Add(reqID, reqCodeLookup[codeReq], "Requirement prefix not valid");
                }
            }
        }