CoverArgException.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 » CoverArgException.cs
using System;
using NUnit.Framework;
using System.Text;
#if FX1_1
using IList_ServiceElementSystem.Collections.IList;
using List_ServiceElementSystem.Collections.ArrayList;
using IList_ServiceAttributeSystem.Collections.IList;
using List_ServiceAttributeSystem.Collections.ArrayList;
#else
using IList_ServiceElementSystem.Collections.Generic.IListInTheHand.Net.Bluetooth.ServiceElement;
using List_ServiceElementSystem.Collections.Generic.ListInTheHand.Net.Bluetooth.ServiceElement;
using IList_ServiceAttributeSystem.Collections.Generic.IListInTheHand.Net.Bluetooth.ServiceAttribute;
using List_ServiceAttributeSystem.Collections.Generic.ListInTheHand.Net.Bluetooth.ServiceAttribute;
#endif
using InTheHand.Net.Bluetooth;
using InTheHand.Net.Bluetooth.AttributeIds;

namespace InTheHand.Net.Tests.Sdp2{
    [TestFixture]
    public class CoverArgException
    {
        //public delegate void CoverStreamLikeReadOrWriteMethod(byte[]buf, int offset, int length);
        public delegate object CoverStreamLikeReadOrWriteMethod(byte[] buf, int offset, int length);

        public static void CoverStreamLikeReadOrWrite(CoverStreamLikeReadOrWriteMethod method)
        {
            byte[] data = null;
            try {
                method(null, 0, 1);
                Assert.Fail("buf=null did not throw!");
            } catch (ArgumentNullException) { }
            data = new byte[5];
            try {
                method(data, 0, 0);
                Assert.Fail("length=0 did not throw!");
            } catch (ArgumentOutOfRangeException) { }
            try {
                method(data, -1, 1);
                Assert.Fail("offset=-1 did not throw!");
            } catch (ArgumentOutOfRangeException) { }
            try {
                method(data, 0, 6);
                Assert.Fail("overrun did not throw!");
            } catch (ArgumentException) { }
            try {
                method(data, 2, 4);
                Assert.Fail("overrun with offset did not throw!");
            } catch (ArgumentException) { }
        }

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

        [Test, ExpectedException(typeof(ArgumentNullException))]
        public void Parser_Parse1Null() { new ServiceRecordParser().Parse(null); }

#if ! FX1_1
        [Test]
        public void Parser_ParseNull() {
            CoverStreamLikeReadOrWriteMethod method = new ServiceRecordParser().Parse;
            CoverStreamLikeReadOrWrite(method);
        }
#endif

        [Test]
        [ExpectedException(typeof(System.Net.ProtocolViolationException), "The top element must be a Element Sequence type.")]
        public void Parser_ParseNonElementSeqThusNotCompleteRecord()
        {
            byte[] buf = { 0x09, 0x12, 0x34 };
            new ServiceRecordParser().Parse(buf);
        }

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

        [Test]
        [ExpectedException(typeof(ArgumentOutOfRangeException), "Unknown ElementType 'Unknown'."
            +"\r\nParameter name: type")]
        public void EtdFromTypeUnknown()
        {
            ServiceRecordParser.GetEtdForType(ElementType.Unknown);
        }

        [Test]
        [ExpectedException(typeof(ArgumentOutOfRangeException), "Unknown ElementType '10000'."
            + "\r\nParameter name: type")]
        public void EtdFromTypeInvalid()
        {
            ServiceRecordParser.GetEtdForType((ElementType)10000);
        }

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

        [Test]
        [ExpectedException(typeof(ArgumentException), "Type ElementSequence and ElementAlternative need an list of ServiceElement.")]
        public void Element_Ctor_NonListForElementSeqAlt()
        {
            new ServiceElement(ElementType.ElementSequence, "booooom");
        }

        [Test]
        [ExpectedException(typeof(ArgumentException), "Type ElementSequence and ElementAlternative must be used for an list of ServiceElement.")]
        public void Element_Ctor_ListForNonElementSeqAlt()
        {
            new ServiceElement(ElementType.Int16, new List_ServiceElement());
        }

        private ServiceElement CreateInt16ServiceElement()
        {
            return new ServiceElement(ElementType.Int16, (Int16)11);
        }

        [Test, ExpectedException(typeof(ArgumentNullException))]
        public void Element_GetStringENull()
        {
            Encoding enc = null;
            CreateInt16ServiceElement().GetValueAsString(enc);
        }

        [Test, ExpectedException(typeof(ArgumentNullException))]
        public void Element_GetStringLNull()
        {
            LanguageBaseItem enc = null;
            CreateInt16ServiceElement().GetValueAsString(enc);
        }

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

        [Test, ExpectedException(typeof(InvalidOperationException))]
        public void Element_GetWrongType_String()
        {
            Encoding enc = Encoding.UTF8;
            CreateInt16ServiceElement().GetValueAsString(enc);
        }

        [Test, ExpectedException(typeof(InvalidOperationException))]
        public void Element_GetWrongType_Uuid()
        {
            CreateInt16ServiceElement().GetValueAsUuid();
        }

        [Test, ExpectedException(typeof(InvalidOperationException))]
        public void Element_GetWrongType_ElemArray()
        {
            object foo = CreateInt16ServiceElement().GetValueAsElementArray();
        }

        [Test, ExpectedException(typeof(InvalidOperationException))]
        public void Element_GetWrongType_ElemList()
        {
            object foo = CreateInt16ServiceElement().GetValueAsElementList();
        }

        [Test, ExpectedException(typeof(InvalidOperationException))]
        public void Element_GetWrongType_Uri()
        {
            object foo = CreateInt16ServiceElement().GetValueAsUri();
        }

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

        [Test, ExpectedException(typeof(ArgumentNullException))]
        public void Utils_Dump_NullWriter()
        {
            ServiceRecord rec = new ServiceRecord(new List_ServiceAttribute());
            ServiceRecordUtilities.Dump(null, rec);
        }

        [Test, ExpectedException(typeof(ArgumentNullException))]
        public void Utils_Dump_NullRecord()
        {
            ServiceRecordUtilities.Dump(new System.IO.StringWriter(), null);
        }

        [Test, ExpectedException(typeof(ArgumentNullException))]
        public void Utils_DumpRaw_NullWriter()
        {
            ServiceRecord rec = new ServiceRecord(new List_ServiceAttribute());
            ServiceRecordUtilities.DumpRaw(null, rec);
        }

        [Test, ExpectedException(typeof(ArgumentNullException))]
        public void Utils_DumpRaw_NullRecord()
        {
            ServiceRecordUtilities.DumpRaw(new System.IO.StringWriter(), null);
        }

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

        [Test, ExpectedException(typeof(ArgumentNullException))]
        public void AttributeIdLookup_NullType()
        {
            LanguageBaseItem langBase;
            AttributeIdLookup.GetName(UniversalAttributeId.ProtocolDescriptorList,
                null, new LanguageBaseItem[0], out langBase);
        }

        [Test, ExpectedException(typeof(ArgumentNullException))]
        public void AttributeIdLookup_NullLangBaseList()
        {
            LanguageBaseItem langBase;
            AttributeIdLookup.GetName(UniversalAttributeId.ProtocolDescriptorList,
                new Type[] { typeof(UniversalAttributeId) },
                null, out langBase);
        }

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