Example #1
0
        public void repeat3()
        {
            // timeout
            AlarmManager am = new AlarmManager();

            am.Start();

            MyAlarmListener listener = new MyAlarmListener(0);

            listener.delay = Q2;
            am.Add(listener, null, Q2);

            listener.wake.WaitUntilEqAndSet(true, Q3, false);

            listener.wake.WaitUntilEqAndSet(true, Q3, false);

            listener.wake.WaitUntilEqAndSet(true, Q3, false);

            Thread.Sleep(Q1);
            listener.delay = 0;

            listener.wake.WaitUntilEqAndSet(true, Q3, false);
            // alarm is now canceled

            // this should timeout...
            listener.wake.WaitUntilEqAndSet(true, Q3, false);
        }
Example #2
0
        public void remove1()
        {
            // is not started
            AlarmManager am = new AlarmManager();

            MyAlarmListener listener = new MyAlarmListener(0);

            am.Remove(listener);
        }
Example #3
0
        public void add1()
        {
            // is not started
            AlarmManager am = new AlarmManager();

            MyAlarmListener listener = new MyAlarmListener(0);

            am.Add(listener, null, Q1);
        }
Example #4
0
        public void remove2()
        {
            AlarmManager am = new AlarmManager();

            am.Start();

            MyAlarmListener listener = new MyAlarmListener(0);

            am.Remove(listener);
        }
Example #5
0
        public void add3()
        {
            // delay <= 0
            AlarmManager am = new AlarmManager();

            am.Start();

            MyAlarmListener listener = new MyAlarmListener(0);

            am.Add(listener, null, -1);
        }
Example #6
0
        public void add5()
        {
            AlarmManager am = new AlarmManager();

            am.Start();

            MyAlarmListener listener = new MyAlarmListener(0);

            am.Add(listener, s1, Q1);
            Assert.IsFalse(listener.wake.Get());
            Assert.IsNull(listener.state);

            Thread.Sleep(Q2);
            Assert.IsTrue(listener.wake.Get());
            Assert.AreSame(s1, listener.state);
        }
Example #7
0
        public void repeat2()
        {
            AlarmManager am = new AlarmManager();

            am.Start();

            MyAlarmListener listener = new MyAlarmListener(0);

            listener.delay = -Q2;
            am.Add(listener, null, Q2);

            listener.wake.WaitUntilEqAndSet(true, Q3, false);
            Console.WriteLine("due0 = {0}", listener.due);
            long t0 = listener.due;

            listener.wake.WaitUntilEqAndSet(true, Q3, false);
            Console.WriteLine("due1 = {0}", listener.due);
            long d1 = listener.due - t0;

            listener.wake.WaitUntilEqAndSet(true, Q3, false);
            Console.WriteLine("due2 = {0}", listener.due);
            long d2 = listener.due - t0;

            listener.wake.WaitUntilEqAndSet(true, Q3, false);
            Console.WriteLine("due3 = {0}", listener.due);
            long d3 = listener.due - t0;

            Thread.Sleep(Q1);
            listener.delay = 0;

            listener.wake.WaitUntilEqAndSet(true, Q3, false);
            Console.WriteLine("due4 = {0}", listener.due);
            long d4 = listener.due - t0;

            long m1 = (long)Math.Round(d1 / (double)d1);
            long m2 = (long)Math.Round(d2 / (double)d1);
            long m3 = (long)Math.Round(d3 / (double)d1);
            long m4 = (long)Math.Round(d4 / (double)d1);

            Console.WriteLine("times {0} {1} {2} {3} {4}", t0, d1, d2, d3, d4);

            Assert.AreEqual(1, m1);
            Assert.AreEqual(2, m2);
            Assert.AreEqual(3, m3);
            Assert.AreEqual(4, m4);
        }
Example #8
0
        public void add4()
        {
            AlarmManager am = new AlarmManager();

            am.Start();

            MyAlarmListener listener = new MyAlarmListener(0);

            //Log("Adding");
            am.Add(listener, null, Q1);
            //Log("Added");
            Assert.IsFalse(listener.wake.Get());
            Assert.IsNull(listener.state);

            Thread.Sleep(Q2);
            Assert.IsTrue(listener.wake.Get());
            Assert.IsNull(listener.state);
        }
Example #9
0
        public void remove3()
        {
            AlarmManager am = new AlarmManager();

            am.Start();

            MyAlarmListener listener = new MyAlarmListener(0);

            am.Add(listener, null, Q1);
            Assert.IsFalse(listener.wake.Get());
            Assert.IsNull(listener.state);

            am.Remove(listener);
            Assert.IsFalse(listener.wake.Get());
            Assert.IsNull(listener.state);

            Thread.Sleep(Q2);
            Assert.IsFalse(listener.wake.Get());
            Assert.IsNull(listener.state);
        }
Example #10
0
        public void listener1()
        {
            MyAlarmListener listener = new MyAlarmListener(0);

            Assert.AreEqual(0, listener.delay);
            Assert.IsFalse(listener.wake.Get());
            Assert.IsNull(listener.state);

            listener.Wakeup(null, null, 12345);
            Assert.AreEqual(0, listener.delay);
            Assert.IsTrue(listener.wake.Get());
            Assert.IsNull(listener.state);

            listener.Wakeup(null, s1, 23456);
            Assert.AreEqual(0, listener.delay);
            Assert.IsTrue(listener.wake.Get());
            Assert.AreSame(s1, listener.state);

            MyAlarmListener listener1 = new MyAlarmListener(1);

            Assert.AreEqual(1, listener1.delay);
        }