Inheritance: ICCMNotify
Esempio n. 1
0
        public void SingleItemStored()
        {
            SortedListener l = new SortedListener(1, new List<string>(), 0);

            l.OnMetric(new ccMetric("a.cpp", "Foo::Bar", 3, 0), null);
            //l.OnMetric("Foo::Bar", 3, "a.cpp", 1, 1);

            Assert.AreEqual("Foo::Bar", l.Metrics[0].Unit);
            Assert.AreEqual(3, l.Metrics[0].CCM);
        }
Esempio n. 2
0
        public void CanContainMultipleMetricsWithSameCCM()
        {
            SortedListener l = new SortedListener(2, new List<string>(), 0);

            l.OnMetric(new ccMetric("a.cpp", "Foo::Bar", 3, 0), null);
            l.OnMetric(new ccMetric("b.cpp", "Foo::Bar2", 3, 0), null);

            Assert.AreEqual(2, l.Metrics.Count);

            Assert.AreEqual(3, l.Metrics[0].CCM);
            Assert.AreEqual(3, l.Metrics[1].CCM);
        }
Esempio n. 3
0
        public void TestCStyleFuncDecl()
        {
            string filename = "cstylefuncs.c"; // this is deployed through local.testsettings
              SortedListener listener = new SortedListener(10, new List<string>());
              using (StreamReader stream = new StreamReader(filename))
              {
            FileAnalyzer analyzer = new FileAnalyzer(stream, listener, null, true, filename);
            analyzer.Analyze();

            Assert.AreEqual(3, listener.Metrics.Count);

            Assert.IsNotNull(IntegrationTests.GetByName(listener.Metrics, "added"));
            Assert.IsNotNull(IntegrationTests.GetByName(listener.Metrics, "new_cfg_record"));
            Assert.IsNotNull(IntegrationTests.GetByName(listener.Metrics, "edit_cfg_record"));
              }
        }
Esempio n. 4
0
        public void MultiItemsAreSorted()
        {
            SortedListener l = new SortedListener(3, new List<string>(), 0);

            l.OnMetric(new ccMetric("a.cpp", "Foo::Bar3", 3, 0), null);
            l.OnMetric(new ccMetric("a.cpp", "Foo::Bar1", 1, 0), null);
            l.OnMetric(new ccMetric("a.cpp", "Foo::Bar7", 7, 0), null);

            Assert.AreEqual("Foo::Bar7", l.Metrics[0].Unit);
            Assert.AreEqual(7, l.Metrics[0].CCM);

            Assert.AreEqual("Foo::Bar3", l.Metrics[1].Unit);
            Assert.AreEqual(3, l.Metrics[1].CCM);

            Assert.AreEqual("Foo::Bar1", l.Metrics[2].Unit);
            Assert.AreEqual(1, l.Metrics[2].CCM);
        }
Esempio n. 5
0
        public void ExhaustedBufferHasCorrectItems()
        {
            SortedListener l = new SortedListener(3, new List<string>(), 0);

            l.OnMetric(new ccMetric("a.cpp", "Foo::Bar3", 3, 0), null);
            l.OnMetric(new ccMetric("a.cpp", "Foo::Bar1", 1, 0), null);
            l.OnMetric(new ccMetric("a.cpp", "Foo::Bar7", 7, 0), null);
            l.OnMetric(new ccMetric("a.cpp", "Foo::Bar9", 9, 0), null);

            Assert.AreEqual(l.Metrics.Count, 3);

            Assert.AreEqual("Foo::Bar9", l.Metrics[0].Unit);
            Assert.AreEqual(9, l.Metrics[0].CCM);

            Assert.AreEqual("Foo::Bar7", l.Metrics[1].Unit);
            Assert.AreEqual(7, l.Metrics[1].CCM);

            Assert.AreEqual("Foo::Bar3", l.Metrics[2].Unit);
            Assert.AreEqual(3, l.Metrics[2].CCM);
        }
Esempio n. 6
0
        private void RunFunctionAndUpdateUI(Function function)
        {
            try
              {
            lock (this.syncLock)
            {
              this.listener = new SortedListener(GetNumMetrics(), new List<string>(), 0);

              //
              // setup semaphore for multi processing
              //
              this.sempahore = new Semaphore(this.numWorkingThreads, this.numWorkingThreads);

              //
              // clear old items
              //
              this.listView.Items.Clear();
              this.listener.Clear();

              function();

              //
              // wait for completion of possible background workers
              for (int i = 0; i < this.numWorkingThreads; ++i)
            this.sempahore.WaitOne();

              UpdateUI(this.listener.Metrics);

              //
              // cleanup
              this.sempahore.Close();
              this.sempahore = null;
            }
              }
              catch (Exception)
              {
              }
        }
Esempio n. 7
0
 private void Init()
 {
     this.threadCount = Environment.ProcessorCount;
       this.threadSemaphore = new Semaphore(this.threadCount, this.threadCount);
       this.listener = new SortedListener(this.configFile.NumMetrics, this.configFile.ExcludeFunctions);
 }
Esempio n. 8
0
        public void TestIgnoresMetricBelowThreshold()
        {
            SortedListener l = new SortedListener(2, new List<string>(), 10);

            l.OnMetric(new ccMetric("a.cpp", "Foo::Bar", 3, null), null);
            l.OnMetric(new ccMetric("b.cpp", "Foo::Bar2", 10, null), null);

            Assert.AreEqual(1, l.Metrics.Count);
            Assert.AreEqual(10, l.Metrics[0].CCM);
        }
Esempio n. 9
0
        public void TestExcludes()
        {
            List<string> ignores = new List<string>();
            ignores.Add("Foo");
            ignores.Add("Bar");

            SortedListener l = new SortedListener(3, ignores, 0);

            l.OnMetric(new ccMetric("a.cpp", "Foo(int j)", 2, 0), null);
            l.OnMetric(new ccMetric("a.cpp", "Bar(double d, X& x)", 3, 0), null);

            Assert.AreEqual(0, l.Metrics.Count); // should all have been filtered away
        }
Esempio n. 10
0
        public void TestNoMetricsLeftAfterClear()
        {
            SortedListener l = new SortedListener(2, new List<string>(), 0);

            l.OnMetric(new ccMetric("a.cpp", "Foo::Bar", 3, 0), null);
            l.OnMetric(new ccMetric("b.cpp", "Foo::Bar2", 3, 0), null);

            Assert.AreEqual(2, l.Metrics.Count);

            l.Clear();

            Assert.AreEqual(0, l.Metrics.Count);
        }
Esempio n. 11
0
        public void TestMultipleItemsSameName()
        {
            SortedListener l = new SortedListener(10, new List<string>(), 0);

            l.OnMetric(new ccMetric("a.cpp", "Foo::Bar", 3, 0), null);
            l.OnMetric(new ccMetric("a.cpp", "Foo::Bar", 1, 0), null);
            l.OnMetric(new ccMetric("a.cpp", "Foo::Bar", 7, 0), null);

            Assert.AreEqual(l.Metrics.Count, 3);

            Assert.AreEqual("Foo::Bar", l.Metrics[0].Unit);
            Assert.AreEqual(7, l.Metrics[0].CCM);

            Assert.AreEqual("Foo::Bar", l.Metrics[1].Unit);
            Assert.AreEqual(3, l.Metrics[1].CCM);

            Assert.AreEqual("Foo::Bar", l.Metrics[2].Unit);
            Assert.AreEqual(1, l.Metrics[2].CCM);
        }
Esempio n. 12
0
        public void TestFileWithTabAfterEndif()
        {
            string filename = "FileWithTabAfterEndIf.c"; // this is deployed through local.testsettings
              SortedListener listener = new SortedListener(10, new List<string>());
              using (StreamReader stream = new StreamReader(filename))
              {
            FileAnalyzer analyzer = new FileAnalyzer(stream, listener, null, true, filename);
            analyzer.Analyze();

            Assert.AreEqual(1, listener.Metrics.Count);

            Assert.IsNotNull(IntegrationTests.GetByName(listener.Metrics, "Foo"));
              }
        }
Esempio n. 13
0
        public void TestTypescriptFileIsCorrectlyParsed()
        {
            string filename = "TypeScript.ts"; // this is deployed through local.testsettings
              SortedListener listener = new SortedListener(10, new List<string>());
              using (StreamReader stream = new StreamReader(filename))
              {
            FileAnalyzer analyzer = new FileAnalyzer(stream, listener, null, false, filename);
            analyzer.Analyze();

            Assert.AreEqual(3, listener.Metrics.Count);

            Assert.IsNotNull(IntegrationTests.GetByName(listener.Metrics, "Sayings::Greeter::greet()"));
            Assert.IsNotNull(IntegrationTests.GetByName(listener.Metrics, "Sayings::Greeter::constructor(message:string)"));
            Assert.IsNotNull(IntegrationTests.GetByName(listener.Metrics, "button.onclick()"));
              }
        }
Esempio n. 14
0
        public void TestJavascriptFileContainsAllFunctions()
        {
            string filename = "examples.js"; // this is deployed through local.testsettings
              SortedListener listener = new SortedListener(10, new List<string>());
              using (StreamReader stream = new StreamReader(filename))
              {
            FileAnalyzer analyzer = new FileAnalyzer(stream, listener, null, false, filename);
            analyzer.Analyze();

            Assert.AreEqual(10, listener.Metrics.Count);

            Assert.AreEqual(6, IntegrationTests.GetByName(listener.Metrics, "gcd(segmentA,segmentB)").CCM);
            Assert.AreEqual(2, IntegrationTests.GetByName(listener.Metrics, "function(monkey)").CCM);
            Assert.AreEqual(1, IntegrationTests.GetByName(listener.Metrics, "localFunction()").CCM);
            Assert.AreEqual(1, IntegrationTests.GetByName(listener.Metrics, "Some.Foo(args)").CCM);
            Assert.AreEqual(1, IntegrationTests.GetByName(listener.Metrics, "functionWithColon()").CCM);
            Assert.AreEqual(2, IntegrationTests.GetByName(listener.Metrics, "localFunction1()").CCM);
            Assert.AreEqual(4, IntegrationTests.GetByName(listener.Metrics, "outerFunction1()").CCM);
            Assert.AreEqual(1, IntegrationTests.GetByName(listener.Metrics, "localFunction2()").CCM);
            Assert.AreEqual(1, IntegrationTests.GetByName(listener.Metrics, "Monkey::feedMonkey()").CCM);
            Assert.AreEqual(1, IntegrationTests.GetByName(listener.Metrics, "afterMonkeyFeed()").CCM);

              }
        }
Esempio n. 15
0
 public void Setup()
 {
     this.listener = new SortedListener(100, new List<string>());
 }