public void testEqualsNormalizationIgnoresCase()
        {
            Identifier identifier1 = Identifier.Parse("2f234454-cf6d-4a0f-adf2-f4911ba9ffa6");
            Identifier identifier2 = Identifier.Parse("2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6");

            AssertEx.True("Identifiers of different case should match", identifier1.Equals(identifier2));
        }
Exemplo n.º 2
0
        public void TestCalculateAccuracyWithRssiLessThanPower()
        {
            Beacon.DistanceCalculator = new ModelSpecificDistanceCalculator(null, null);
            double accuracy = Beacon.DistanceCalculator.CalculateDistance(-55, -60);

            AssertEx.True("Distance should be over one meter if mRssi is less negative than power. Accuracy was " + accuracy, accuracy > 1.0);
        }
Exemplo n.º 3
0
        public void testBeaconMatchesRegionWithSameBluetoothMac()
        {
            Beacon beacon = new AltBeacon.Builder().SetId1("1").SetId2("2").SetId3("3").SetRssi(4)
                            .SetBeaconTypeCode(5).SetTxPower(6).SetBluetoothAddress("01:02:03:04:05:06").Build();
            Region region = new Region("myRegion", "01:02:03:04:05:06");

            AssertEx.True("Beacon should match region with mac the same", region.MatchesBeacon(beacon));
        }
Exemplo n.º 4
0
        public void testBeaconDoesMatchRegionWithLongerIdentifierListWithSomeNull()
        {
            Beacon beacon = new Beacon.Builder().SetId1("1").SetId2("2").SetRssi(4)
                            .SetBeaconTypeCode(5).SetTxPower(6).SetBluetoothAddress("1:2:3:4:5:6").Build();
            Region region = new Region("myRegion", null, null, null);

            AssertEx.True("Beacon should match region with more identifers than the beacon, if the region identifiers are null", region.MatchesBeacon(beacon));
        }
Exemplo n.º 5
0
        public void testBeaconMatchesRegionWithDifferentIdentifier1()
        {
            Beacon beacon = new AltBeacon.Builder().SetId1("1").SetId2("2").SetId3("3").SetRssi(4)
                            .SetBeaconTypeCode(5).SetTxPower(6).SetBluetoothAddress("1:2:3:4:5:6").Build();
            Region region = new Region("myRegion", Identifier.Parse("22222"), null, null);

            AssertEx.True("Beacon should not match region with first identifier different", !region.MatchesBeacon(beacon));
        }
Exemplo n.º 6
0
        public void testBeaconMatchesRegionWithSameIdentifiers()
        {
            Beacon beacon = new AltBeacon.Builder().SetId1("1").SetId2("2").SetId3("3").SetRssi(4)
                            .SetBeaconTypeCode(5).SetTxPower(6).SetBluetoothAddress("1:2:3:4:5:6").Build();
            Region region = new Region("myRegion", Identifier.Parse("1"), Identifier.Parse("2"), Identifier.Parse("3"));

            AssertEx.True("Beacon should match region with all identifiers the same", region.MatchesBeacon(beacon));
        }
        public void testSamePacketForDifferentMacIsDistinct()
        {
            DistinctPacketDetector dpd = new DistinctPacketDetector();

            dpd.IsPacketDistinct("01:02:03:04:05:06", new byte[] { 0x01, 0x02 });
            bool secondResult = dpd.IsPacketDistinct("01:01:01:01:01:01", new byte[] { 0x01, 0x02 });

            AssertEx.True("second packet with different mac should be distinct", secondResult);
        }
        public void testSecondNonDuplicatePacketIsDistinct()
        {
            DistinctPacketDetector dpd = new DistinctPacketDetector();

            dpd.IsPacketDistinct("01:02:03:04:05:06", new byte[] { 0x01, 0x02 });
            bool secondResult = dpd.IsPacketDistinct("01:02:03:04:05:06", new byte[] { 0x03, 0x04 });

            AssertEx.True("second call with different packet should be distinct", secondResult);
        }
Exemplo n.º 9
0
        public void TestHashCodeWithNullIdentifier()
        {
            Beacon beacon = new AltBeacon.Builder()
                            .SetIdentifiers(new List <Identifier> {
                Identifier.Parse("0x1234"), null
            })
                            .Build();

            AssertEx.True("hashCode() should not throw exception", beacon.GetHashCode() >= int.MinValue);
        }
Exemplo n.º 10
0
        public void testBeaconMatchesRegionWithShorterIdentifierList()
        {
            Beacon beacon = new AltBeacon.Builder().SetId1("1").SetId2("2").SetId3("3").SetRssi(4)
                            .SetBeaconTypeCode(5).SetTxPower(6).SetBluetoothAddress("1:2:3:4:5:6").Build();
            Region region = new Region("myRegion", new List <Identifier> {
                Identifier.Parse("1")
            });

            AssertEx.True("Beacon should match region with first identifier equal and shorter Identifier list", region.MatchesBeacon(beacon));
        }
        public void clearingDetectionsPreventsDistinctDetection()
        {
            DistinctPacketDetector dpd = new DistinctPacketDetector();

            dpd.IsPacketDistinct("01:02:03:04:05:06", new byte[] { 0x01, 0x02 });
            dpd.ClearDetections();
            bool secondResult = dpd.IsPacketDistinct("01:02:03:04:05:06", new byte[] { 0x01, 0x02 });

            AssertEx.True("second call with same packet after clear should be distinct", secondResult);
        }
Exemplo n.º 12
0
        public void TestBeaconsWithDifferentId3AreNotEqual()
        {
            Beacon beacon1 = new AltBeacon.Builder().SetMfgReserved(7).SetId1("1").SetId2("2").SetId3("3").SetRssi(4)
                             .SetBeaconTypeCode(5).SetTxPower(6)
                             .SetBluetoothAddress("1:2:3:4:5:6").Build();
            Beacon beacon2 = new AltBeacon.Builder().SetMfgReserved(7).SetId1("1").SetId2("2").SetId3("13").SetRssi(4)
                             .SetBeaconTypeCode(5).SetTxPower(6)
                             .SetBluetoothAddress("1:2:3:4:5:6").Build();

            AssertEx.True("Beacons with different id3 are not equal", !beacon1.Equals(beacon2));
        }
Exemplo n.º 13
0
        public void testBeaconMatchesRegionWithSingleNullIdentifierList()
        {
            Beacon beacon = new AltBeacon.Builder().SetId1("1").SetId2("2").SetId3("3").SetRssi(4)
                            .SetBeaconTypeCode(5).SetTxPower(6).SetBluetoothAddress("1:2:3:4:5:6").Build();
            var identifiers = new List <Identifier>();

            identifiers.Add(null);
            Region region = new Region("all-beacons-region", identifiers);

            AssertEx.True("Beacon should match region with first identifier null and shorter Identifier list", region.MatchesBeacon(beacon));
        }
Exemplo n.º 14
0
        public void TestBeaconsWithSameIdentifersAreEqual()
        {
            Beacon beacon1 = new AltBeacon.Builder().SetMfgReserved(7).SetId1("1").SetId2("2").SetId3("3").SetRssi(4)
                             .SetBeaconTypeCode(5).SetTxPower(6)
                             .SetBluetoothAddress("1:2:3:4:5:6").Build();
            Beacon beacon2 = new AltBeacon.Builder().SetMfgReserved(7).SetId1("1").SetId2("2").SetId3("3").SetRssi(4)
                             .SetBeaconTypeCode(5).SetTxPower(6)
                             .SetBluetoothAddress("1:2:3:4:5:6").Build();

            //AssertEx.AreEqual("Beacons with same identifiers are equal", beacon1, beacon2);
            AssertEx.True("Beacons with same identifiers are equal", beacon1.Equals(beacon2));
        }
Exemplo n.º 15
0
        public void NoDoubleWrappingOfExtraDataFields()
        {
            Beacon beacon = new AltBeacon.Builder().SetId1("1").SetId2("2").SetId3("3").SetRssi(4)
                            .SetBeaconTypeCode(5).SetTxPower(6).SetBluetoothName("xx")
                            .SetBluetoothAddress("1:2:3:4:5:6").SetDataFields(new List <Java.Lang.Long> {
                new Java.Lang.Long(100L)
            }).Build();
            var list = beacon.ExtraDataFields;

            beacon.ExtraDataFields = list;
            AssertEx.True("getter should return same object after first wrap ", beacon.ExtraDataFields == list);
        }
Exemplo n.º 16
0
 public void rejectsInvalidMac()
 {
     try {
         Region region = new Region("myRegion", "this string is not a valid mac address!");
         AssertEx.True("IllegalArgumentException should have been thrown", false);
     }
     catch (IllegalArgumentException e) {
         AssertEx.AreEqual("Error message should be as expected",
                           "Invalid mac address: 'this string is not a valid mac address!' Must be 6 hex bytes separated by colons.",
                           e.Message);
     }
 }
Exemplo n.º 17
0
        public void TestBeaconsWithSameMacsAreEqual()
        {
            Beacon.SetHardwareEqualityEnforced(true);
            Beacon beacon1 = new AltBeacon.Builder().SetMfgReserved(7).SetId1("1").SetId2("2").SetId3("3").SetRssi(4)
                             .SetBeaconTypeCode(5).SetTxPower(6)
                             .SetBluetoothAddress("1:2:3:4:5:6").Build();
            Beacon beacon2 = new AltBeacon.Builder().SetMfgReserved(7).SetId1("1").SetId2("2").SetId3("3").SetRssi(4)
                             .SetBeaconTypeCode(5).SetTxPower(6)
                             .SetBluetoothAddress("1:2:3:4:5:6").Build();

            AssertEx.True("Beacons with same same macs are equal", beacon1.Equals(beacon2));
        }
        public void testToByteArrayFromByteArray()
        {
            byte[]     byteVal     = new byte[] { (byte)0xFF, (byte)0xAB, 0x12, 0x25 };
            Identifier identifier1 = Identifier.FromBytes(byteVal, 0, byteVal.Length, false);

            byte[] bytes = identifier1.ToByteArrayOfSpecifiedEndianness(true);

            AssertEx.AreEqual("byte array is correct length", bytes.Length, 4);
            AssertEx.AreEqual("correct string representation", identifier1.ToString(), "0xffab1225");
            AssertEx.True("arrays equal", Arrays.Equals(byteVal, bytes));
            AssertEx.AreNotSame("arrays are copied", bytes, byteVal);
        }