public void TestAssertAllWhenRegisteredWithConstantMessageAndPropertyMismatchesCustomConstraint()
        {
            const string RemainingPropertyMismatchMessage = @"The remaining value must be the negative progress.";

            var testee = MappingAccordances
                         .From <SampleSource>
                         .To <SampleDestination>()
                         .Register(
                source => source.Progress,
                destination => destination.Remaining,
                expectedValue => Is.EqualTo(-expectedValue),
                RemainingPropertyMismatchMessage);

            var sampleSource = new SampleSource
            {
                Progress = 17
            };

            var sampleDestination = new SampleDestination
            {
                Remaining = sampleSource.Progress
            };

            Assert.That(
                () => testee.AssertAll(sampleSource, sampleDestination),
                Throws.TypeOf <AssertionException>()
                .With
                .Property(nameof(AssertionException.Message))
                .ContainsSubstring(RemainingPropertyMismatchMessage));
        }
        public void TestAssertAllWhenInnerComplexPropertyMismatches()
        {
            var testee = CreateTestee();

            var source = new SampleSource
            {
                Name     = "Job4",
                Progress = 4,
                Data     = new SampleInnerSource {
                    Text = "Text"
                },
                Items = null
            };

            var destination = new SampleDestination
            {
                FullName  = source.Name,
                Remaining = 100 - source.Progress,
                Info      = new SampleInnerDestination {
                    Message = "Message"
                },
                Datas = null
            };

            Assert.That(
                () => testee.AssertAll(source, destination),
                Throws.TypeOf <AssertionException>()
                .With
                .Property(nameof(AssertionException.Message))
                .ContainsSubstring($".{nameof(SampleInnerSource.Text)}")
                .And
                .Property(nameof(AssertionException.Message))
                .ContainsSubstring($".{nameof(SampleInnerDestination.Message)}"));
        }
        public void TestAssertAllWhenPropertyValueIsNotEqual()
        {
            var testee = CreateTestee();

            var source = new SampleSource
            {
                Name     = "Job3",
                Progress = 3,
                Data     = null,
                Items    = null
            };

            var destination = new SampleDestination
            {
                FullName  = "System" + source.Name,
                Remaining = 100 - source.Progress,
                Info      = null,
                Datas     = null
            };

            Assert.That(
                () => testee.AssertAll(source, destination),
                Throws.TypeOf <AssertionException>()
                .With
                .Property(nameof(AssertionException.Message))
                .ContainsSubstring($".{nameof(SampleSource.Name)}")
                .And
                .Property(nameof(AssertionException.Message))
                .ContainsSubstring($".{nameof(SampleDestination.FullName)}")
                .And
                .Property(nameof(AssertionException.Message))
                .ContainsSubstring("The values are expected to be equal:"));
        }
        public void TestAssertAllWhenObjectsMatch()
        {
            var testee = CreateTestee();

            var source = new SampleSource
            {
                Name     = "Job1",
                Progress = 1,
                Data     = new SampleInnerSource {
                    Text = "Hello World!"
                },
                Items = new[] { new SampleSourceItem {
                                    Text = "Item text"
                                } }
            };

            var destination = new SampleDestination
            {
                FullName  = source.Name,
                Remaining = 100 - source.Progress,
                Info      = new SampleInnerDestination {
                    Message = source.Data.Text
                },
                Datas = new[] { new SampleDestinationItem {
                                    TextData = source.Items[0].Text
                                } }
            };

            Assert.That(() => testee.AssertAll(source, destination), Throws.Nothing);
        }
示例#5
0
        public void btnOpen_NetworkSource(object sender, EventArgs e)
        {
            try
            {
                Source = new NetworkDeviceControl();
                Source.OpenTuner();
                if (!Source.Connected)
                {
                    return;
                }

                SampleSource = Source.SampleSource;
                SampleSource.SamplingRateChanged += new EventHandler(SampleSource_SamplingRateChanged);

                Processing    = true;
                ProcessThread = new Thread(ProcessMain);
                ProcessThread.Start();

                btnOpen.Text = "Close";
            }
            catch (BadImageFormatException ex)
            {
                MessageBox.Show("There is a wrong shmemchain.dll in your working directory.", "Error while setting up shmem");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Exception occured while trying to set up shmem: " + ex.GetType(), "Error while setting up shmem");
            }
        }
        public void TestAssertAllWhenPropertyMismatchesCustomConstraint()
        {
            var testee = CreateTestee();

            var source = new SampleSource
            {
                Name     = "Job2",
                Progress = 2,
                Data     = null,
                Items    = null
            };

            var destination = new SampleDestination
            {
                FullName  = source.Name,
                Remaining = source.Progress,
                Info      = null,
                Datas     = null
            };

            Assert.That(
                () => testee.AssertAll(source, destination),
                Throws.TypeOf <AssertionException>()
                .With
                .Property(nameof(AssertionException.Message))
                .ContainsSubstring(PercentageValuesMismatchMessage));
        }
示例#7
0
 public void CloseTuner()
 {
     DeviceClosed?.Invoke(this, EventArgs.Empty);
     SampleSource.Close();
     CloseTuner();
     Close();
 }
示例#8
0
 public void CloseControl()
 {
     CloseConnection();
     NetShmemSink.Close();
     SampleSource.Close();
     CloseTuner();
     Close();
 }
示例#9
0
 private void radioAcqOff_CheckedChanged(object sender, EventArgs e)
 {
     if (radioAcqOff.Checked)
     {
         SampleSource.Flush();
         TransferMode = eTransferMode.Stopped;
     }
 }
示例#10
0
        public bool ReadBlock()
        {
            bool ret;

            ret = SampleSource.Read();

            return(ret);
        }
示例#11
0
        public void TakesSamplesFromStream()
        {
            var sut          = new ReservoirSampling();
            var sampleSource = new SampleSource(1000);

            var sample = sut.GetReservoirSample(sampleSource, 10);

            Assert.True(sample.All(arg => arg > 0));
        }
示例#12
0
        public void TakesFirstMSamples()
        {
            var sut          = new ReservoirSampling();
            var sampleSource = new SampleSource(2);

            var sample = sut.GetReservoirSample(sampleSource, 2);

            Assert.True(sample.All(arg => arg > 0));
        }
        /// <summary>
        ///     This method is called when Sample load is requested, if you return a Sample
        ///     it will return it from the user else it will keep trying all the other SampleLoaders
        ///     until it does get one
        /// </summary>
        /// <param name="path">File path of the sound to load.</param>
        /// <param name="streamed">If set to true the sound will be loaded in piece by piece rather than all at once.</param>
        /// <returns>New Sample instance or NULL if this factory can't load the given audio sample file format.</returns>
        protected override Sample RequestLoad(object path, bool streamed)
        {
            // Load in the audio file's data.
            Stream stream = StreamFactory.RequestStream(path, StreamMode.Open);

            if (stream == null)
            {
                return(null);
            }
            if (stream.ReadByte() != 'O' || stream.ReadByte() != 'g' || stream.ReadByte() != 'g' || stream.ReadByte() != 'S')
            {
                stream.Close();
                return(null);
            }
            stream.Position = 0;

            byte[] data = new byte[stream.Length];
            stream.Read(data, 0, (int)stream.Length);
            stream.Close();

            // Create an audiere memory file to place our data into.
            ManagedAudiere.File file          = Audiere.CreateMemoryFile(new MemoryFileBuffer(data, data.Length));
            SampleSource        audiereSample = Audiere.OpenSampleSource(file);
            SampleFormatData    sampleFormat  = audiereSample.GetFormat();

            int size = audiereSample.Length * (Audiere.GetSampleSize(sampleFormat.sample_format) * sampleFormat.channel_count);
            MemoryFileBuffer audiereBuffer = new MemoryFileBuffer(new byte[size], size);

            audiereSample.Read(audiereSample.Length, audiereBuffer);

            // Put the audiere audio buffer into a new sample buffer.
            byte[] pcmBuffer = audiereBuffer.GetBuffer();
            Sample sample    = null;

            if (sampleFormat.channel_count == 1)
            {
                sample = new Sample(SampleFormat.MONO16LE, pcmBuffer.Length);
            }
            else
            {
                sample = new Sample(SampleFormat.STEREO16LE, pcmBuffer.Length);
            }

            sample.SampleRate    = sampleFormat.sample_rate;
            sample.ChannelCount  = sampleFormat.channel_count;
            sample.BlockAlign    = Audiere.GetSampleSize(sampleFormat.sample_format) * sampleFormat.channel_count;
            sample.ByteRate      = sample.SampleRate * sample.BlockAlign;
            sample.BitsPerSample = Audiere.GetSampleSize(sampleFormat.sample_format) * 8;

            for (int i = 0; i < pcmBuffer.Length; i++)
            {
                sample.Data[i] = pcmBuffer[i];
            }

            return(sample);
        }
示例#14
0
 public void CloseSource()
 {
     if (ProcessThread != null)
     {
         Processing = false;
         ProcessThread.Join(1000);
         ProcessThread = null;
     }
     if (SampleSource != null)
     {
         SampleSource.Close();
         SampleSource = null;
     }
 }
示例#15
0
        public bool ReadBlock()
        {
            bool success;

            do
            {
                /* will loop every 100ms (timeout set up in SharedMem object) */
                success = SampleSource.Read();
            } while (success && SampleSource.SamplesRead == 0);

            /* collect as many samples as the current read block size has */
            if (success)
            {
                SamplesThisBlock += SampleSource.SamplesPerBlock;
            }

            if (SamplesThisBlock >= SamplesPerBlock)
            {
                //RX_FFT.Components.GDI.Log.AddMessage("ShmemSampleSource", "Full block");
                SamplesThisBlock = 0;
                SampleSource.Flush();

                /* transfer done, if needed start next one */
                if (success)
                {
                    if (TransferMode == eTransferMode.Block)
                    {
                        USBRX.ReadBlockReceived();
                    }
                }
                else
                {
                    if (USBRX.DeviceLost)
                    {
                        RX_FFT.Components.GDI.Log.AddMessage("USBRX -> DeviceLost");
                        if (DeviceDisappeared != null)
                        {
                            DeviceDisappeared(this, null);
                        }
                    }
                }
            }

            return(success);
        }
        public void TestAssertAllWhenInnerListPropertyMismatchesByCount()
        {
            var testee = CreateTestee();

            var source = new SampleSource
            {
                Name     = "Job6",
                Progress = 6,
                Data     = null,
                Items    =
                    new[]
                {
                    new SampleSourceItem {
                        Text = "ItemText5"
                    },
                    new SampleSourceItem {
                        Text = "ItemText5-A"
                    }
                }
            };

            var destination = new SampleDestination
            {
                FullName  = source.Name,
                Remaining = 100 - source.Progress,
                Info      = null,
                Datas     = new[] { new SampleDestinationItem {
                                        TextData = source.Items[0].Text
                                    } }
            };

            Assert.That(
                () => testee.AssertAll(source, destination),
                Throws.TypeOf <AssertionException>()
                .With
                .Property(nameof(AssertionException.Message))
                .ContainsSubstring($".{nameof(SampleSource.Items)}")
                .And
                .Property(nameof(AssertionException.Message))
                .ContainsSubstring($".{nameof(SampleDestination.Datas)}")
                .And
                .Property(nameof(AssertionException.Message))
                .ContainsSubstring("The source and destination must have the same item count"));
        }
示例#17
0
        public void OpenSharedMem(int srcChan)
        {
            try
            {
                SampleSource = new ShmemSampleSource("RX-Oscilloscope", srcChan, 1, 0);

                SampleSource.DataFormat           = ByteUtil.eSampleFormat.Direct16BitIQFixedPointLE;
                SampleSource.SamplingRateChanged += new EventHandler(SampleSource_SamplingRateChanged);

                Processing    = true;
                ProcessThread = new Thread(ProcessMain);
                ProcessThread.Start();

                btnOpen.Text = "Close";
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to open shared memory. Is the correct shmemchain.dll in the program directory?");
            }
        }
示例#18
0
        public virtual bool OpenTuner()
        {
            /* display the wait message */
#if false
            WaitDialog waitDlg = new WaitDialog();
            waitDlg.Show();
            waitDlg.Refresh();
#endif

            USBRX = new USBRXDevice();
            //USBRX.ShowConsole(true);
            USBRX.TunerCombination = TunerCombination;

            try
            {
                if (!USBRX.Init())
                {
                    ErrorMessage = "Could not find USB-RX on USB.";
#if false
                    waitDlg.Close();
#endif
                    base.Close();
                    return(false);
                }
            }
            catch (BadImageFormatException e)
            {
                ErrorMessage = "Unsupported architecture.";
#if false
                waitDlg.Close();
#endif
                base.Close();
                return(false);
            }
            catch (Exception e)
            {
                ErrorMessage = "Unhandled exception." + Environment.NewLine + e;
#if false
                waitDlg.Close();
#endif
                base.Close();
                return(false);
            }
            ErrorMessage = "";

            FilterList.NCOFreq = USBRX.Atmel.TCXOFreq;
            FilterList.UpdateFilters("Filter");
            FilterList.AddFilters("..\\..\\..\\Filter");
            FilterList.FilterSelected += new EventHandler(FilterList_FilterSelected);

            USBRX.Tuner.SamplingRateChanged     += new EventHandler(Tuner_FilterRateChanged);
            USBRX.Tuner.FilterWidthChanged      += new EventHandler(Tuner_FilterWidthChanged);
            USBRX.Tuner.InvertedSpectrumChanged += new EventHandler(Tuner_InvertedSpectrumChanged);
            USBRX.Tuner.DeviceDisappeared       += new EventHandler(Tuner_DeviceDisappeared);

            frequencySelector1.UpperLimit = USBRX.Tuner.HighestFrequency;
            frequencySelector1.LowerLimit = USBRX.Tuner.LowestFrequency;
            CurrentFrequency = USBRX.Tuner.GetFrequency();
            SetFreqTextbox(CurrentFrequency);

            _SampleSource = new ShmemSampleSource("USB-RX Device Control", USBRX.ShmemChannel, 1, 0);
            _SampleSource.InvertedSpectrum = InvertedSpectrum;
            _SampleSource.DataFormat       = ByteUtil.eSampleFormat.Direct16BitIQFixedPointLE;

            ToolTip ttFreq = new ToolTip();
            ttFreq.SetToolTip(frequencySelector1, "Min Freq: " + FrequencyFormatter.FreqToStringAccurate(USBRX.Tuner.LowestFrequency) + Environment.NewLine + "Max Freq: " + FrequencyFormatter.FreqToStringAccurate(USBRX.Tuner.HighestFrequency));
            ttFreq.AutomaticDelay = 500;

            UpdateAtmelFilters();
            SelectFiles(true);

            Connected = true;

            /* small hack to select first (widest) filter */
            FilterList.FilterSelect(FilterList.FirstFilter);

            /* close wait dialog and show ours */
#if false
            waitDlg.Close();
#endif

            Show();

            radioAcqOff.Checked   = true;
            radioTunerInt.Checked = true;
            radioAgcOff.Checked   = true;
            chkAtt.Checked        = false;
            chkPreAmp.Checked     = false;

            radioTunerInt_CheckedChanged(null, null);
            chkAtt_CheckedChanged(null, null);
            chkPreAmp_CheckedChanged(null, null);
            radioAgcOff_CheckedChanged(null, null);

            radioAcqBlock.Checked = true;


            DeviceOpened?.Invoke(this, EventArgs.Empty);

            return(true);
        }
        public void TestAssertAllWithRegisterAllMatchingProperties()
        {
            var testeeImplicitCaseSensitive =
                MappingAccordances.From <SampleSource> .To <SampleDestination>().RegisterAllMatchingProperties();

            var testeeExplicitCaseSensitive =
                MappingAccordances.From <SampleSource> .To <SampleDestination>().RegisterAllMatchingProperties(false);

            var testeeCaseInsensitive =
                MappingAccordances.From <SampleSource> .To <SampleDestination>().RegisterAllMatchingProperties(true);

            Assert.That(testeeImplicitCaseSensitive.Count, Is.EqualTo(1));
            Assert.That(testeeExplicitCaseSensitive.Count, Is.EqualTo(1));
            Assert.That(testeeCaseInsensitive.Count, Is.EqualTo(2));

            var sampleSource = new SampleSource
            {
                Name         = "John",
                MatchingName = "matching",
                MatchingTextCaseInsensitive = "Text"
            };

            var sampleDestination1 = new SampleDestination
            {
                FullName     = "FullName",
                MatchingName = sampleSource.MatchingName,
                matchingtextcaseinsensitive = sampleSource.MatchingTextCaseInsensitive
            };

            Assert.That(() => testeeImplicitCaseSensitive.AssertAll(sampleSource, sampleDestination1), Throws.Nothing);
            Assert.That(() => testeeExplicitCaseSensitive.AssertAll(sampleSource, sampleDestination1), Throws.Nothing);
            Assert.That(() => testeeCaseInsensitive.AssertAll(sampleSource, sampleDestination1), Throws.Nothing);

            var sampleDestination2 = new SampleDestination
            {
                FullName     = sampleSource.Name,
                MatchingName = "no match",
                matchingtextcaseinsensitive = sampleSource.MatchingTextCaseInsensitive
            };

            const string SourcePrefix      = "source.";
            const string DestinationPrefix = "destination.";

            Assert.That(
                () => testeeImplicitCaseSensitive.AssertAll(sampleSource, sampleDestination2),
                Throws.TypeOf <AssertionException>()
                .With
                .Property(nameof(AssertionException.Message))
                .ContainsSubstring(SourcePrefix + nameof(SampleSource.MatchingName))
                .And
                .Property(nameof(AssertionException.Message))
                .ContainsSubstring(DestinationPrefix + nameof(SampleDestination.MatchingName)));

            Assert.That(
                () => testeeExplicitCaseSensitive.AssertAll(sampleSource, sampleDestination2),
                Throws.TypeOf <AssertionException>()
                .With
                .Property(nameof(AssertionException.Message))
                .ContainsSubstring(SourcePrefix + nameof(SampleSource.MatchingName))
                .And
                .Property(nameof(AssertionException.Message))
                .ContainsSubstring(DestinationPrefix + nameof(SampleDestination.MatchingName)));

            Assert.That(
                () => testeeCaseInsensitive.AssertAll(sampleSource, sampleDestination2),
                Throws.TypeOf <AssertionException>()
                .With
                .Property(nameof(AssertionException.Message))
                .ContainsSubstring(SourcePrefix + nameof(SampleSource.MatchingName))
                .And
                .Property(nameof(AssertionException.Message))
                .ContainsSubstring(DestinationPrefix + nameof(SampleDestination.MatchingName)));

            var sampleDestination3 = new SampleDestination
            {
                FullName     = sampleSource.Name,
                MatchingName = sampleSource.MatchingName,
                matchingtextcaseinsensitive = "nothing"
            };

            Assert.That(() => testeeImplicitCaseSensitive.AssertAll(sampleSource, sampleDestination3), Throws.Nothing);
            Assert.That(() => testeeExplicitCaseSensitive.AssertAll(sampleSource, sampleDestination3), Throws.Nothing);

            Assert.That(
                () => testeeCaseInsensitive.AssertAll(sampleSource, sampleDestination3),
                Throws.TypeOf <AssertionException>()
                .With
                .Property(nameof(AssertionException.Message))
                .ContainsSubstring(SourcePrefix + nameof(SampleSource.MatchingTextCaseInsensitive))
                .And
                .Property(nameof(AssertionException.Message))
                .ContainsSubstring(DestinationPrefix + nameof(SampleDestination.matchingtextcaseinsensitive)));
        }
        public void TestAssertAllWhenInnerListPropertyMismatchesByNullReferenceCheck()
        {
            const string ExpectedMessagePart =
                "Both the source and destination values must be either null or non-null";

            var testee = CreateTestee();

            var source1 = new SampleSource
            {
                Name     = "Job6A",
                Progress = 6,
                Data     = null,
                Items    = new[] { new SampleSourceItem {
                                       Text = "Text6"
                                   } }
            };

            var destination1 = new SampleDestination
            {
                FullName  = source1.Name,
                Remaining = 100 - source1.Progress,
                Info      = null,
                Datas     = null
            };

            Assert.That(
                () => testee.AssertAll(source1, destination1),
                Throws.TypeOf <AssertionException>()
                .With
                .Property(nameof(AssertionException.Message))
                .ContainsSubstring($".{nameof(SampleSource.Items)}")
                .And
                .Property(nameof(AssertionException.Message))
                .ContainsSubstring($".{nameof(SampleDestination.Datas)}")
                .And
                .Property(nameof(AssertionException.Message))
                .ContainsSubstring(ExpectedMessagePart));

            var source2 = new SampleSource
            {
                Name     = "Job6B",
                Progress = 6,
                Data     = null,
                Items    = null
            };

            var destination2 = new SampleDestination
            {
                FullName  = source2.Name,
                Remaining = 100 - source2.Progress,
                Info      = null,
                Datas     = new[] { new SampleDestinationItem {
                                        TextData = "Text6"
                                    } }
            };

            Assert.That(
                () => testee.AssertAll(source2, destination2),
                Throws.TypeOf <AssertionException>()
                .With
                .Property(nameof(AssertionException.Message))
                .ContainsSubstring($".{nameof(SampleSource.Items)}")
                .And
                .Property(nameof(AssertionException.Message))
                .ContainsSubstring($".{nameof(SampleDestination.Datas)}")
                .And
                .Property(nameof(AssertionException.Message))
                .ContainsSubstring(ExpectedMessagePart));
        }