# Path: dtformats/errors.py
# class ParseError(Exception):
# 
# Path: dtformats/safari_cookies.py
# class BinaryCookiesFile(data_format.BinaryDataFile):
#   _FABRIC = data_format.BinaryDataFile.ReadDefinitionFile('safari_cookies.yaml')
#   def __init__(self, debug=False, output_writer=None):
#   def _DebugPrintFileHeader(self, file_header):
#   def _DebugPrintRecordHeader(self, record_header):
#   def _ReadCString(self, page_data, string_offset):
#   def _ReadFileFooter(self, file_object):
#   def _ReadFileHeader(self, file_object):
#   def _ReadPage(self, file_object, file_offset, page_size):
#   def _ReadPages(self, file_object):
#   def _ReadRecord(self, page_data, record_offset):
#   def ReadFileObject(self, file_object):
# 
# Path: tests/test_lib.py
# class BaseTestCase(unittest.TestCase):
# class TestOutputWriter(output_writers.OutputWriter):
#   _TEST_DATA_PATH = os.path.join(os.getcwd(), 'test_data')
#   def _GetTestFilePath(self, path_segments):
#   def _SkipIfPathNotExists(self, path):
#   def __init__(self):
#   def Close(self):
#   def Open(self):
#   def WriteText(self, text):


import io
import os
import unittest
from dtformats import errors
from dtformats import safari_cookies
from tests import test_lib

    cstring = test_file._ReadCString(page_data, 0)
    self.assertEqual(cstring, 'string')

    with self.assertRaises(errors.ParseError):
      test_file._ReadCString(page_data[:-1], 0)

  def testReadFileFooter(self):
    """Tests the _ReadFileFooter function."""
    output_writer = test_lib.TestOutputWriter()
    test_file = safari_cookies.BinaryCookiesFile(output_writer=output_writer)

    test_file_path = self._GetTestFilePath(['Cookies.binarycookies'])
    self._SkipIfPathNotExists(test_file_path)

    with open(test_file_path, 'rb') as file_object:
      file_object.seek(-8, os.SEEK_END)
      test_file._ReadFileFooter(file_object)

  def testReadFileHeader(self):
    """Tests the _ReadFileHeader function."""
    output_writer = test_lib.TestOutputWriter()
    test_file = safari_cookies.BinaryCookiesFile(output_writer=output_writer)

    file_object = io.BytesIO(self._FILE_HEADER_DATA)

    test_file._ReadFileHeader(file_object)

    file_object = io.BytesIO(self._FILE_HEADER_DATA_BAD_SIGNATURE)


# Path: dtformats/errors.py
# class ParseError(Exception):
# 
# Path: dtformats/safari_cookies.py
# class BinaryCookiesFile(data_format.BinaryDataFile):
#   _FABRIC = data_format.BinaryDataFile.ReadDefinitionFile('safari_cookies.yaml')
#   def __init__(self, debug=False, output_writer=None):
#   def _DebugPrintFileHeader(self, file_header):
#   def _DebugPrintRecordHeader(self, record_header):
#   def _ReadCString(self, page_data, string_offset):
#   def _ReadFileFooter(self, file_object):
#   def _ReadFileHeader(self, file_object):
#   def _ReadPage(self, file_object, file_offset, page_size):
#   def _ReadPages(self, file_object):
#   def _ReadRecord(self, page_data, record_offset):
#   def ReadFileObject(self, file_object):
# 
# Path: tests/test_lib.py
# class BaseTestCase(unittest.TestCase):
# class TestOutputWriter(output_writers.OutputWriter):
#   _TEST_DATA_PATH = os.path.join(os.getcwd(), 'test_data')
#   def _GetTestFilePath(self, path_segments):
#   def _SkipIfPathNotExists(self, path):
#   def __init__(self):
#   def Close(self):
#   def Open(self):
#   def WriteText(self, text):


# Path: tests/safari_cookies.py
import io
import os
import unittest
from dtformats import errors
from dtformats import safari_cookies
from tests import test_lib


    cstring = test_file._ReadCString(page_data, 0)
    self.assertEqual(cstring, 'string')

    with self.assertRaises(errors.ParseError):
      test_file._ReadCString(page_data[:-1], 0)

  def testReadFileFooter(self):
    """Tests the _ReadFileFooter function."""
    output_writer = test_lib.TestOutputWriter()
    test_file = safari_cookies.BinaryCookiesFile(output_writer=output_writer)

    test_file_path = self._GetTestFilePath(['Cookies.binarycookies'])
    self._SkipIfPathNotExists(test_file_path)

    with open(test_file_path, 'rb') as file_object:
      file_object.seek(-8, os.SEEK_END)
      test_file._ReadFileFooter(file_object)

  def testReadFileHeader(self):
    """Tests the _ReadFileHeader function."""
    output_writer = test_lib.TestOutputWriter()
    test_file = safari_cookies.BinaryCookiesFile(output_writer=output_writer)

    file_object = io.BytesIO(self._FILE_HEADER_DATA)

    test_file._ReadFileHeader(file_object)

    file_object = io.BytesIO(self._FILE_HEADER_DATA_BAD_SIGNATURE)


    with self.assertRaises(errors.ParseError):