# Path: chirp/stream/message.py
# CONNECTED = "Connected"        # New connection initiated.
# RESPONSE = "Response"          # HTTP response received.
# BLOCK = "Block"                # A chunk of raw data.
# FRAME = "Frame"                # An MP3 frame.
# ERROR = "Error"                # An error.
# CONNECT_TIMEOUT_ERROR = "Connect Timeout Error"
# CONNECT_ERROR = "Connect Error"
# REQUEST_ERROR = "Request Error"
# READ_TIMEOUT_ERROR = "Read Timeout Error"
# READ_ERROR = "Read Error"
# MISSING_HEADERS_ERROR = "Missing HTTP Headers Error"
# MALFORMED_HEADERS_ERROR = "Malformed HTTP Headers Error"
# BAD_REDIRECT_ERROR = "Bad Redirect Error"
# END_OF_STREAM_ERROR = "End of Stream Error"
# class Message(object):
# class MessageSource(object):
# class MessageConsumer(looper.Looper):
# class MessageTee(MessageConsumer):
#     def payload_sha1(self):
#     def payload_hex_sha1(self):
#     def __str__(self):
#     def set_error(self, error_type, err):
#     def is_error(self):
#     def is_end_of_stream(self):
#     def __init__(self):
#     def _add_message(self, msg):
#     def _add_stop_message(self):
#     def get_next_message(self, timeout=None):
#     def get_all_messages(self):
#     def wait_until_empty(self):
#     def __init__(self, src):
#     def _process_message(self, msg):
#     def _loop_once(self):
#     def __init__(self, input_src, num_outputs):
#     def _process_message(self, msg):


import unittest
from chirp.stream import message


class MessageTestCase(unittest.TestCase):

    def test_sha1(self):
        msg = message.Message()
        # We should start out with no payload
        self.assertTrue(msg.payload is None)
        # No payload == no sha1
        self.assertTrue(msg.payload_sha1 is None)
        self.assertTrue(msg.payload_hex_sha1 is None)
        # Now set a payload, and make sure that we get the expected SHA1.
        # This example is from Wikipedia's page on the SHA hash functions.
        msg.payload = "The quick brown fox jumps over the lazy dog"
        expected_hex_sha1 = "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12"
        # Convert the expected SHA1 from hex to binary.
        expected_sha1 = "".join([chr(int(expected_hex_sha1[2*i:2*i+2], 16))
                                 for i in xrange(len(expected_hex_sha1)/2)])
        self.assertEqual(expected_sha1, msg.payload_sha1)
        self.assertEqual(expected_hex_sha1, msg.payload_hex_sha1)

    def test_error_helpers(self):
        msg = message.Message()
        msg.message_type = message.BLOCK
        self.assertFalse(msg.is_error())
        self.assertFalse(msg.is_end_of_stream())
        msg.set_error(message.READ_ERROR, ("foo", "bar"))
        self.assertTrue(msg.is_error())
        self.assertFalse(msg.is_end_of_stream())
        msg.set_error(message.END_OF_STREAM_ERROR, ("foo", "bar"))

# Path: chirp/stream/message.py
# CONNECTED = "Connected"        # New connection initiated.
# RESPONSE = "Response"          # HTTP response received.
# BLOCK = "Block"                # A chunk of raw data.
# FRAME = "Frame"                # An MP3 frame.
# ERROR = "Error"                # An error.
# CONNECT_TIMEOUT_ERROR = "Connect Timeout Error"
# CONNECT_ERROR = "Connect Error"
# REQUEST_ERROR = "Request Error"
# READ_TIMEOUT_ERROR = "Read Timeout Error"
# READ_ERROR = "Read Error"
# MISSING_HEADERS_ERROR = "Missing HTTP Headers Error"
# MALFORMED_HEADERS_ERROR = "Malformed HTTP Headers Error"
# BAD_REDIRECT_ERROR = "Bad Redirect Error"
# END_OF_STREAM_ERROR = "End of Stream Error"
# class Message(object):
# class MessageSource(object):
# class MessageConsumer(looper.Looper):
# class MessageTee(MessageConsumer):
#     def payload_sha1(self):
#     def payload_hex_sha1(self):
#     def __str__(self):
#     def set_error(self, error_type, err):
#     def is_error(self):
#     def is_end_of_stream(self):
#     def __init__(self):
#     def _add_message(self, msg):
#     def _add_stop_message(self):
#     def get_next_message(self, timeout=None):
#     def get_all_messages(self):
#     def wait_until_empty(self):
#     def __init__(self, src):
#     def _process_message(self, msg):
#     def _loop_once(self):
#     def __init__(self, input_src, num_outputs):
#     def _process_message(self, msg):


# Path: chirp/stream/message_test.py
import unittest
from chirp.stream import message



class MessageTestCase(unittest.TestCase):

    def test_sha1(self):
        msg = message.Message()
        # We should start out with no payload
        self.assertTrue(msg.payload is None)
        # No payload == no sha1
        self.assertTrue(msg.payload_sha1 is None)
        self.assertTrue(msg.payload_hex_sha1 is None)
        # Now set a payload, and make sure that we get the expected SHA1.
        # This example is from Wikipedia's page on the SHA hash functions.
        msg.payload = "The quick brown fox jumps over the lazy dog"
        expected_hex_sha1 = "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12"
        # Convert the expected SHA1 from hex to binary.
        expected_sha1 = "".join([chr(int(expected_hex_sha1[2*i:2*i+2], 16))
                                 for i in xrange(len(expected_hex_sha1)/2)])
        self.assertEqual(expected_sha1, msg.payload_sha1)
        self.assertEqual(expected_hex_sha1, msg.payload_hex_sha1)

    def test_error_helpers(self):
        msg = message.Message()
        msg.message_type = message.BLOCK
        self.assertFalse(msg.is_error())
        self.assertFalse(msg.is_end_of_stream())
        msg.set_error(message.READ_ERROR, ("foo", "bar"))
        self.assertTrue(msg.is_error())
        self.assertFalse(msg.is_end_of_stream())
        msg.set_error(message.END_OF_STREAM_ERROR, ("foo", "bar"))

        self.assertTrue(msg.is_error())