BadRecordFormatTests.cs :  » Business-Application » 32feet.NET » InTheHand » Net » Tests » Sdp2 » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Business Application » 32feet.NET 
32feet.NET » InTheHand » Net » Tests » Sdp2 » BadRecordFormatTests.cs
using System;
using NUnit.Framework;
using System.Net;
using InTheHand.Net.Bluetooth;

namespace InTheHand.Net.Tests.Sdp2{

    [TestFixture]
    public class BadRecordFormatTests_OverrunsBuffer
    {
        public static readonly byte[] DataSeq = { 0x35, 8, 
                0x09, 0x00, 0x00, 
                0x35, 6, /**/0x09, 0x11, 0x05, /**/0x08, 0xFF };
        public static readonly byte[] DataAlt = { 0x35, 8, 
                0x09, 0x00, 0x00, 
                0x3D, 6, /**/0x09, 0x11, 0x05, /**/0x08, 0xFF };
        public static readonly byte[] DataTopSeq = { 0x35, 7, 
                0x09, 0x00, 0x00, 
                0x09, 0x11, 0x05 };

        private static void DoTest(byte[] bytes)
        {
            new ServiceRecordParser().Parse(bytes);
        }

        private static void DoTestOffsetInput(byte[] bytes)
        {
            int Offset = 100;
            byte[] atOffset = new byte[bytes.Length+Offset];
            bytes.CopyTo(atOffset, Offset);
            new ServiceRecordParser().Parse(atOffset, Offset, bytes.Length);
        }


        [Test]
        [ExpectedException(typeof(ProtocolViolationException), ServiceRecordParser.ErrorMsgElementOverrunsBufferPrefix + "5.")]
        public void Seq()
        {
            DoTest(DataSeq);
        }

        [Test]
        [ExpectedException(typeof(ProtocolViolationException), ServiceRecordParser.ErrorMsgElementOverrunsBufferPrefix + "5.")]
        public void Alt()
        {
            DoTest(DataAlt);
        }

        [Test]
        [ExpectedException(typeof(ProtocolViolationException), ServiceRecordParser.ErrorMsgElementOverrunsBufferPrefix + "0.")]
        public void TopSeq()
        {
            DoTest(DataTopSeq);
        }

        [Test]
        [ExpectedException(typeof(ProtocolViolationException), ServiceRecordParser.ErrorMsgElementOverrunsBufferPrefix + "105.")]
        public void Seq_Offset()
        {
            DoTestOffsetInput(DataSeq);
        }

        [Test]
        [ExpectedException(typeof(ProtocolViolationException), ServiceRecordParser.ErrorMsgElementOverrunsBufferPrefix + "105.")]
        public void Alt_Offset()
        {
            DoTestOffsetInput(DataAlt);
        }

        [Test]
        [ExpectedException(typeof(ProtocolViolationException), ServiceRecordParser.ErrorMsgElementOverrunsBufferPrefix + "100.")]
        public void TopSeq_Offset()
        {
            DoTestOffsetInput(DataTopSeq);
        }

    }//class


    [TestFixture]
    public class BadRecordFormatTests_ElementOverrunsSeqOrAlt
    {
        public static readonly byte[] DataUInt32OverrunsSeq = {
            0x35,10,    //this is correct, include all the UInt16's bytes
                0x09,0x70,0x00,
                0x35,4, // this is one byte too small
                    0x0A,0x01,0x02,0x03,/*]*/0x04
        };
        public static readonly byte[] DataUInt8OverrunsSeq = {
            0x35,7,
                0x09,0x70,0x00,
                0x35,1,
                    0x08,/*]*/0x01,
        };
        public static readonly byte[] DataSecondUInt32OverrunsSeq = {
            0x35,15,    //this is correct, include all the UInt16's bytes
                0x09,0x70,0x00,
                0x35,9, // this is one byte too small
                    0x0A,0x01,0x02,0x03,0x04,
                    0x0A,0x01,0x02,0x03,/*]*/0x04
        };
        public static readonly byte[] DataSecondUInt8OverrunsSeq = {
            0x35,9,
                0x09,0x70,0x00,
                0x35,3,
                    0x08, 0x01,
                    0x08,/*]*/0x01,
        };

        //--------------------------------------------------------------

        private void DoTest(byte[] buffer)
        {
            new ServiceRecordParser().Parse(buffer);
        }

        
        [Test]
        [ExpectedException(typeof(System.Net.ProtocolViolationException), "Element overruns buffer section, from index 7.")]
        public void UInt32OverrunsSeq()
        {
            DoTest(DataUInt32OverrunsSeq);
        }

        [Test]
        [ExpectedException(typeof(System.Net.ProtocolViolationException), "Element overruns buffer section, from index 7.")]
        public void UInt8OverrunsSeq()
        {
            DoTest(DataUInt8OverrunsSeq);
        }

        [Test]
        [ExpectedException(typeof(System.Net.ProtocolViolationException), "Element overruns buffer section, from index 12.")]
        public void SecondUInt32OverrunsSeq()
        {
            DoTest(DataSecondUInt32OverrunsSeq);
        }

        [Test]
        [ExpectedException(typeof(System.Net.ProtocolViolationException), "Element overruns buffer section, from index 9.")]
        public void SecondUInt8OverrunsSeq()
        {
            DoTest(DataSecondUInt8OverrunsSeq);
        }

    }//class


    [TestFixture]
    public class BadRecordFormatTests_BadContent
    {
        public static readonly byte[] DataTwiceWrappedFromACoulter = {
            0x36, 0x00, 0x30, 
            0x36, 0x00, 0x2D, 0x09, 0x00,  0x00, 0x0A, 0x00, 0x01, 0x00, 0x00, 0x09, 0x00, 0x01, 0x35, 0x03, 
            0x19, 0x11, 0x01, 0x09, 0x00,  0x04, 0x35, 0x0C, 0x35, 0x03, 0x19, 0x01, 0x00, 0x35, 0x05, 0x19, 
            0x00, 0x03, 0x08, 0x01, 0x09,  0x01, 0x00, 0x25, 0x07, 0x50, 0x52, 0x49, 0x4E, 0x54, 0x45, 0x52
        };

        //--------
        private static void DoTest(byte[] bytes)
        {
            new ServiceRecordParser().Parse(bytes);
        }

        //--------

        [Test]
        [ExpectedException(typeof(System.Net.ProtocolViolationException),
            "The Attribute Id at index 3 is not of type Uint16.")]
        public void TwiceWrappedFromACoulter()
        {
            DoTest(DataTwiceWrappedFromACoulter);
        }

    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.