#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (C) 2009 Adriano Monteiro Marques.
#
# Author: Bartosz SKOWRON <getxsick at gmail dot com>
#
# This library is free software; you can redistribute it and/or modify 
# it under the terms of the GNU Lesser General Public License as published 
# by the Free Software Foundation; either version 2.1 of the License, or 
# (at your option) any later version.
#
# This library is distributed in the hope that it will be useful, but 
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
# License for more details.
#
# You should have received a copy of the GNU Lesser General Public License 
# along with this library; if not, write to the Free Software Foundation, 
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 

from umpa import Packet
from umpa.utils.exceptions import UMPAException

import py.test

class TestUMPAPacketsBasic(object):
    def test_default_options(self):
        p = Packet()
        assert p.strict is True
        assert p.warn is True

    def test_overwrite_options(self):
        p = Packet(strict=False, warn=True)
        assert p.strict is False
        assert p.warn is True

    def test_broken_options(self):
        py.test.raises(UMPAException, Packet, foo=False)
        py.test.raises(UMPAException, Packet, strict=True, foo=False, bar=True)

@@ -898,16 +898,65 @@
  Packet%0A
+from umpa.protocols import IP, TCP, UDP, Payload%0A
 from ump
@@ -994,16 +994,37 @@
 xception
+, UMPAStrictException
 %0A%0Aimport
@@ -1427,16 +1427,16 @@
 =False)%0A
-
         
@@ -1503,12 +1503,871 @@
 , bar=True)%0A
+%0Aclass TestUMPAPackets(object):%0A    def test_add_new_protocols__strict(self):%0A        py.test.raises(UMPAStrictException, Packet, TCP(), IP())%0A        py.test.raises(UMPAStrictException, Packet, TCP(), IP(), strict=True)%0A        py.test.raises(UMPAStrictException, Packet, TCP(), Payload(), IP())%0A        py.test.raises(UMPAStrictException, Packet, TCP(),  IP(), Payload())%0A        py.test.raises(UMPAStrictException, Packet, Payload(), TCP())%0A        py.test.raises(UMPAStrictException, Packet, Payload(), TCP())%0A        py.test.raises(UMPAStrictException, Packet, UDP(), TCP())%0A%0A        p = Packet(TCP())%0A        py.test.raises(UMPAStrictException, p.include, IP())%0A        py.test.raises(UMPAStrictException, p.include, UDP())%0A%0A        p = Packet(strict=False)%0A        p.strict = True %0A        py.test.raises(UMPAStrictException, p.include, UDP(), TCP())%0A%0A

add protocols to a Protocol's object with strict option