public static CoverageOptionsDescriptor ReadExternal(EmmaBinaryReader ebr)
 {
     //bool excludeEmptyClasses = br.ReadBoolean();
     //bool excludeSyntheticMethods = ebr.ReadBoolean();
     //bool excludeBridgeMethods = ebr.ReadBoolean();
     //bool doSUIDCompensation = ebr.ReadBoolean();
     return new CoverageOptionsDescriptor(ebr.ReadBoolean(), ebr.ReadBoolean(), ebr.ReadBoolean());
 }
        public static void CreateCttm(string emFilePath, string srcPath, string outputPath)
        {
            EmmaBinaryReader cebre = new EmmaBinaryReader(emFilePath);
            MetaDataDescriptor cedata = (MetaDataDescriptor)LoadEmmaFile(cebre);
            cebre.Close();
            Report.ReportDataModel current = new Report.ReportDataModel();
            Report.RootItem croot = current.CreateViewForDiff(cedata, srcPath);

            FileStream fs = new FileStream(outputPath, FileMode.OpenOrCreate);
            BinaryFormatter bf = new BinaryFormatter();
            bf.Serialize(fs, current);
            fs.Close();
            fs.Dispose();
        }
 public static int[] ReadIntArray(EmmaBinaryReader ebr)
 {
     int length = ebr.ReadInt32();
     if (length == NULL_ARRAY_LENGTH)
         return null;
     else
     {
         int[] result = new int[length];
         for (int i = length; --i >= 0; )
         {
             result[i] = ebr.ReadInt32();
         }
         return result;
     }
 }
 public static MetaDataDescriptor ReadExternal(EmmaBinaryReader ebr)
 {
     CoverageOptionsDescriptor options = CoverageOptionsDescriptor.ReadExternal(ebr);
     bool hasSrcFileInfo = ebr.ReadBoolean();
     bool hasLineNumberInfo = ebr.ReadBoolean();
     int size = ebr.ReadInt32();
     Dictionary<string, ClassDescriptor> classMap = new Dictionary<string, ClassDescriptor>();
     for (int i = 0; i < size; ++i)
     {
         string className = ebr.ReadUTF();
         ClassDescriptor cls = ClassDescriptor.ReadExternal(ebr);
         classMap.Add(className, cls);
     }
     return new MetaDataDescriptor(options, classMap, hasSrcFileInfo, hasLineNumberInfo);
 }
        public static bool[] readBooleanArray(EmmaBinaryReader ebr)
        {
            int length = ebr.ReadInt32();
            if (length == NULL_ARRAY_LENGTH)
                return null;
            else
            {
                bool[] result = new bool[length];

                // read array in reverse order:
                for (int i = length; --i >= 0; )
                {
                    result[i] = ebr.ReadBoolean();
                }

                return result;
            }
        }
        public static CoverageDataDescriptor ReadExternal(EmmaBinaryReader ebr)
        {
            int size = ebr.ReadInt32();
            Dictionary<string, DataHolder> coverageMap = new Dictionary<string, DataHolder>();

            for (int i = 0; i < size; ++i)
            {
                string classVMName = ebr.ReadUTF();
                long stamp = ebr.ReadLong();

                int length = ebr.ReadInt32();
                bool[][] coverage = new bool[length][];
                for (int c = 0; c < length; ++c)
                {
                    coverage[c] = DataFactory.readBooleanArray(ebr);
                }

                coverageMap.Add(classVMName, new DataHolder(coverage, stamp));
            }

            return new CoverageDataDescriptor(coverageMap);
        }
        public static ClassDescriptor ReadExternal(EmmaBinaryReader ebr)
        {
            string packageVMName = ebr.ReadUTF();
            string name = ebr.ReadUTF();

            long stamp = ebr.ReadLong();

            sbyte srcFileNameFlag = ebr.ReadSbyte();
            string srcFileName = srcFileNameFlag != 0 ? ebr.ReadUTF() : null;

            int length = ebr.ReadInt32();
            MethodDescriptor[] methods = new MethodDescriptor[length];
            for (int i = 0; i < length; ++i)
            {
                methods[i] = MethodDescriptor.ReadExternal(ebr);
            }
            return new ClassDescriptor(packageVMName,name,stamp,srcFileName,methods);
        }
        public static MethodDescriptor ReadExternal(EmmaBinaryReader ebr)
        {
            string name = ebr.ReadUTF();
            string descriptor = ebr.ReadUTF();

            int status = ebr.ReadInt32();

            int[] blockSizes = null;
            int[][] blockMap = null;
            int firstLine = 0;

            if ((status & DataConstants.METHOD_NO_BLOCK_DATA) == 0)
            {
                blockSizes = DataFactory.ReadIntArray(ebr);
                if ((status & DataConstants.METHOD_NO_LINE_DATA) == 0)
                {
                    int length = ebr.ReadInt32();
                    blockMap = new int[length][];
                    for (int i = 0; i < length; ++i)
                    {
                        blockMap[i] = DataFactory.ReadIntArray(ebr);
                    }
                    firstLine = ebr.ReadInt32();
                }
            }

            return new MethodDescriptor(name,descriptor,status,blockSizes,blockMap,firstLine);
        }
        private static ReportDataModel CreateModuleForCttr(string emFilePath, CttCaseCollection ecFilesPaths, string srcPath)
        {
            EmmaBinaryReader ebre = new EmmaBinaryReader(emFilePath);
            MetaDataDescriptor edata = (MetaDataDescriptor)LoadEmmaFile(ebre);
            ebre.Close();
            CaseCoverageDescriptor ccdata = new CaseCoverageDescriptor();

            foreach (CttCase cttCase in ecFilesPaths.CoverageFilePaths)
            {
                EmmaBinaryReader ebrc = new EmmaBinaryReader(cttCase.ResultPath);
                CoverageDataDescriptor cdata = (CoverageDataDescriptor)LoadEmmaFile(ebrc);
                ebrc.Close();

                ccdata.MergeCaseCoverageData(cdata, cttCase.CaseId);
            }

            ReportDataModel previous = new Report.ReportDataModel();
            RootItem root = previous.CreateViewForCaseCoverage(edata, ccdata, srcPath);
            return previous;
        }
        private static object LoadEmmaFile(EmmaBinaryReader ebr)
        {
            long length = ebr.Length;
            int m = ebr.ReadInt32();
            bool t = m == Magic;
            long a = ebr.ReadLong();
            bool t2 = a == DATA_FORMAT_VERSION;
            int major = 0, minor = 0, build = 0;
            bool gotAppVersion = false;

            major = ebr.ReadInt32();
            minor = ebr.ReadInt32();
            build = ebr.ReadInt32();

            gotAppVersion = true;
            ebr.Seek(FILE_HEADER_LENGTH, SeekOrigin.Begin);
            long position = FILE_HEADER_LENGTH;
            long entryLength;
            long entrystart = 0;

            object data = null;

            while (true)
            {
                if (position >= length)
                    break;
                entryLength = ebr.ReadLong();
                if ((entryLength <= 0) || (position + entryLength + ENTRY_HEADER_LENGTH > length))
                    break;
                else
                {
                    sbyte type = ebr.ReadSbyte();
                    if ((type < 0) || (type >= 2))
                        break;

                    switch (type)
                    {
                        case TYPE_METADATA: data = MetaDataDescriptor.ReadExternal(ebr);
                            break;

                        case TYPE_COVERAGEDATA: data = CoverageDataDescriptor.ReadExternal(ebr);
                            break;

                    } // end of switch

                    //MetaDataDescriptor data=MetaDataDescriptor.ReadExternal(ebr);
                    position += entryLength + ENTRY_HEADER_LENGTH;
                    ebr.Seek(position, SeekOrigin.Begin);
                }
            }
            return data;
        }