Ejemplo n.º 1
0
 public void FactoryConstructorThrowsIfInstanceIsNull()
 {
     Assert.Throws <ArgumentNullException>(() =>
     {
         var _ = new SharedHandle <MockResource>((Func <MockResource>)null);
     });
 }
Ejemplo n.º 2
0
        public void AccessAcquiresResourceOnlyOnce()
        {
            var resource = new MockResource();
            var handle   = new SharedHandle <MockResource>(() => resource);

            handle.Access();
            handle.Access();

            Assert.AreEqual(1, resource.AcquireCalls);
        }
Ejemplo n.º 3
0
 private static void Display(SharedHandle <StdVector <Datum> > datumsPtr)
 {
     // User's displaying/saving/other processing here
     // datum.cvOutputData: rendered frame with pose or heatmaps
     // datum.poseKeypoints: Array<float> with the estimated pose
     if (datumsPtr != null && datumsPtr.GetData(out var data) && !data.Empty)
     {
         // Display image
         var temp = data.ToArray();
         Cv.ImShow("User worker GUI", temp[0].CvOutputData);
         Cv.WaitKey();
     }
Ejemplo n.º 4
0
        public void TokenDisposeDoesNotReleaseResourceIfTokensLeft()
        {
            var resource = new MockResource();
            var handle   = new SharedHandle <MockResource>(() => resource);

            var first = handle.Access();
            var _     = handle.Access();

            first.Dispose();

            Assert.AreEqual(0, resource.ReleaseCalls);
        }
Ejemplo n.º 5
0
        public void ResourceAccessOnTokenThrowsIfTokenIsDisposed()
        {
            var handle = new SharedHandle <MockResource>(new MockResource());

            var token = handle.Access();

            token.Dispose();

            Assert.Throws <ObjectDisposedException>(() =>
            {
                var _ = token.Resource;
            });
        }
Ejemplo n.º 6
0
        public void AccessCreatesAndAcquiredResource()
        {
            var resource = new MockResource();
            var handle   = new SharedHandle <MockResource>(resource);

            var _ = handle.Access();

            Assert.Multiple(() =>
            {
                Assert.AreEqual(1, handle.Tokens);

                Assert.AreEqual(1, resource.AcquireCalls);
            });
        }
Ejemplo n.º 7
0
        public void ResourceIsReacquiredAfterIsWasReleased()
        {
            var resource = new MockResource();
            var handle   = new SharedHandle <MockResource>(() => resource);

            //This acquires the resource
            var first = handle.Access();

            //This releases the resource
            first.Dispose();

            //This should now reacquire the resource
            first = handle.Access();

            Assert.AreEqual(2, resource.AcquireCalls);
        }
Ejemplo n.º 8
0
        public void LastTokenReleasesResource()
        {
            var resource = new MockResource();
            var handle   = new SharedHandle <MockResource>(resource);

            var token = handle.Access();

            token.Dispose();

            Assert.Multiple(() =>
            {
                Assert.AreEqual(1, resource.ReleaseCalls);

                Assert.AreEqual(0, handle.Tokens);
            });
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Creates another reference to the file referenced by existing reference
 /// </summary>
 /// <param name="another"></param>
 public LocalFile(LocalFile another)
 {
     fileControllerHandle = another.fileControllerHandle.Duplicate();
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Creates new reference to specified file
 /// </summary>
 /// <param name="path">The path to the file</param>
 /// <param name="deleteOnDispose">Whether file should be deleted when the reference gets disposed</param>
 public LocalFile([NotNull] string path, bool deleteOnDispose = false)
 {
     fileControllerHandle = SharedHandle.NewHandle(new FileController(path, deleteOnDispose));
 }