예제 #1
0
        public void TestCanParseLongDataTypeOfDifferentSize()
        {
            // Create a beacon parser
            var parser = new BeaconParser();

            parser.SetBeaconLayout("m:2-3=0118,i:4-7,p:8-8,d:9-16,d:18-21,d:22-25");

            // Generate sample beacon for test purpose.
            var sampleData = new List <Java.Lang.Long>();
            var now        = DateTimeOffset.Now.ToUnixTimeMilliseconds();

            sampleData.Add(new Java.Lang.Long(now));
            sampleData.Add(new Java.Lang.Long(1234L));
            sampleData.Add(new Java.Lang.Long(9876L));
            var beacon = new Beacon.Builder()
                         .SetManufacturer(0x0118)
                         .SetId1("02646576656c6f7065722e636f6d")
                         .SetTxPower(-59)
                         .SetDataFields(sampleData)
                         .Build();

            AssertEx.AreEqual("beacon contains a valid data on index 0", now, beacon.DataFields[0].LongValue());

            // Make byte array
            byte[] headerBytes = HexStringToByteArray("1bff1801");
            byte[] bodyBytes   = parser.GetBeaconAdvertisementData(beacon);
            byte[] bytes       = new byte[headerBytes.Length + bodyBytes.Length];
            Array.Copy(headerBytes, 0, bytes, 0, headerBytes.Length);
            Array.Copy(bodyBytes, 0, bytes, headerBytes.Length, bodyBytes.Length);

            // Try parsing the byte array
            Beacon parsedBeacon = parser.FromScanData(bytes, -59, null);

            AssertEx.AreEqual("parsed beacon should contain a valid data on index 0", now, parsedBeacon.DataFields[0].LongValue());
            AssertEx.AreEqual("parsed beacon should contain a valid data on index 1", Convert.ToInt64(1234L), parsedBeacon.DataFields[1].LongValue());
            AssertEx.AreEqual("parsed beacon should contain a valid data on index 2", Convert.ToInt64(9876L), parsedBeacon.DataFields[2].LongValue());
        }
예제 #2
0
        public void testToString()
        {
            Region region = new Region("myRegion", Identifier.Parse("1"), Identifier.Parse("2"), null);

            AssertEx.AreEqual("Not equal", "id1: 1 id2: 2 id3: null", region.ToString());
        }
        public void testToStringEqualsUuid()
        {
            Identifier identifier1 = Identifier.Parse("2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6");

            AssertEx.AreEqual("uuidString of Identifier should match", "2f234454-cf6d-4a0f-adf2-f4911ba9ffa6", identifier1.ToUuid().ToString());
        }
        public void testParseNonZeroPrefixedDecimalNumberAsDecimal()
        {
            Identifier id = Identifier.Parse("10");

            AssertEx.AreEqual("Should be treated as decimal", "10", id.ToString());
        }
        public void testParseZeroPrefixedDecimalNumberAsHex()
        {
            Identifier id = Identifier.Parse("0010");

            AssertEx.AreEqual("Should be treated as hex in parse, but converted back to decimal because it is small", "16", id.ToString());
        }
        public void testParseBigHexWithNoPrefix()
        {
            Identifier id = Identifier.Parse("123456789abcdef");

            AssertEx.AreEqual("Should parse and get prefixed hex value for big numbers", "0x0123456789abcdef", id.ToString());
        }
        public void testToStringNormalizesCase()
        {
            Identifier identifier1 = Identifier.Parse("2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6");

            AssertEx.AreEqual("Identifiers of different case should match", "2f234454-cf6d-4a0f-adf2-f4911ba9ffa6", identifier1.ToString());
        }
        public void testParseHexWithNoPrefix()
        {
            Identifier id = Identifier.Parse("abcd");

            AssertEx.AreEqual("Should parse and get back equivalent decimal value for small numbers", "43981", id.ToString());
        }
예제 #9
0
        public void TestLongToByteArray()
        {
            var bytes = BeaconParser.LongToByteArray(10, 1);

            AssertEx.AreEqual("first byte should be 10", 10, bytes[0]);
        }
예제 #10
0
        public void testSelectsDefaultModel()
        {
            ModelSpecificDistanceCalculator distanceCalculator = new ModelSpecificDistanceCalculator(null, null);

            AssertEx.AreEqual("Default model should be Nexus 5", "Nexus 5", distanceCalculator.Model.Model);
        }