Beispiel #1
0
    def testParse(self):
        """Tests the Parse function."""
        parser_object = oxml.OpenXMLParser()

        test_file = self._GetTestFilePath([u'Document.docx'])
        event_queue_consumer = self._ParseFile(parser_object, test_file)
        event_objects = self._GetEventObjectsFromQueue(event_queue_consumer)

        self.assertEqual(len(event_objects), 2)

        event_object = event_objects[0]

        expected_timestamp = timelib.Timestamp.CopyFromString(
            u'2012-11-07 23:29:00')
        self.assertEqual(event_object.timestamp, expected_timestamp)
        self.assertEqual(event_object.timestamp_desc,
                         eventdata.EventTimestamp.CREATION_TIME)

        event_object = event_objects[1]

        self.assertEqual(event_object.number_of_characters, u'13')
        self.assertEqual(event_object.total_time, u'1385')
        self.assertEqual(event_object.number_of_characters_with_spaces, u'14')
        self.assertEqual(event_object.i4, u'1')
        self.assertEqual(event_object.app_version, u'14.0000')
        self.assertEqual(event_object.number_of_lines, u'1')
        self.assertEqual(event_object.scale_crop, u'false')
        self.assertEqual(event_object.number_of_pages, u'1')
        self.assertEqual(event_object.number_of_words, u'2')
        self.assertEqual(event_object.links_up_to_date, u'false')
        self.assertEqual(event_object.number_of_paragraphs, u'1')
        self.assertEqual(event_object.doc_security, u'0')
        self.assertEqual(event_object.hyperlinks_changed, u'false')
        self.assertEqual(event_object.revision_number, u'3')
        self.assertEqual(event_object.last_saved_by, u'Nides')
        self.assertEqual(event_object.author, u'Nides')
        self.assertEqual(event_object.creating_app, u'Microsoft Office Word')
        self.assertEqual(event_object.template, u'Normal.dotm')

        expected_msg = (u'Creating App: Microsoft Office Word '
                        u'App version: 14.0000 '
                        u'Last saved by: Nides '
                        u'Author: Nides '
                        u'Revision number: 3 '
                        u'Template: Normal.dotm '
                        u'Number of pages: 1 '
                        u'Number of words: 2 '
                        u'Number of characters: 13 '
                        u'Number of characters with spaces: 14 '
                        u'Number of lines: 1 '
                        u'Hyperlinks changed: false '
                        u'Links up to date: false '
                        u'Scale crop: false')
        expected_msg_short = (u'Author: Nides')

        self._TestGetMessageStrings(event_object, expected_msg,
                                    expected_msg_short)
Beispiel #2
0
    def testParseRelationshipsXMLFile(self):
        """Tests the _ParseRelationshipsXMLFile function."""
        parser = oxml.OpenXMLParser()

        expected_property_files = ['docProps/core.xml', 'docProps/app.xml']

        property_files = parser._ParseRelationshipsXMLFile(
            self._RELATIONSHIPS_XML_DATA)
        self.assertEqual(property_files, expected_property_files)
Beispiel #3
0
  def testParseFileObject(self):
    """Tests the ParseFileObject function."""
    parser = oxml.OpenXMLParser()
    storage_writer = self._ParseFile(['Document.docx'], parser)

    self.assertEqual(storage_writer.number_of_events, 2)

    events = list(storage_writer.GetEvents())

    event = events[0]

    expected_timestamp = timelib.Timestamp.CopyFromString('2012-11-07 23:29:00')
    self.assertEqual(event.timestamp, expected_timestamp)
    self.assertEqual(
        event.timestamp_desc, definitions.TIME_DESCRIPTION_CREATION)

    event = events[1]

    self.assertEqual(event.number_of_characters, '13')
    self.assertEqual(event.total_time, '1385')
    self.assertEqual(event.number_of_characters_with_spaces, '14')
    self.assertEqual(event.i4, '1')
    self.assertEqual(event.app_version, '14.0000')
    self.assertEqual(event.number_of_lines, '1')
    self.assertEqual(event.scale_crop, 'false')
    self.assertEqual(event.number_of_pages, '1')
    self.assertEqual(event.number_of_words, '2')
    self.assertEqual(event.links_up_to_date, 'false')
    self.assertEqual(event.number_of_paragraphs, '1')
    self.assertEqual(event.doc_security, '0')
    self.assertEqual(event.hyperlinks_changed, 'false')
    self.assertEqual(event.revision_number, '3')
    self.assertEqual(event.last_saved_by, 'Nides')
    self.assertEqual(event.author, 'Nides')
    self.assertEqual(event.creating_app, 'Microsoft Office Word')
    self.assertEqual(event.template, 'Normal.dotm')

    expected_message = (
        'Creating App: Microsoft Office Word '
        'App version: 14.0000 '
        'Last saved by: Nides '
        'Author: Nides '
        'Revision number: 3 '
        'Template: Normal.dotm '
        'Number of pages: 1 '
        'Number of words: 2 '
        'Number of characters: 13 '
        'Number of characters with spaces: 14 '
        'Number of lines: 1 '
        'Hyperlinks changed: false '
        'Links up to date: false '
        'Scale crop: false')
    expected_short_message = (
        'Author: Nides')

    self._TestGetMessageStrings(event, expected_message, expected_short_message)
Beispiel #4
0
  def testParsePropertiesXMLFile(self):
    """Tests the _ParsePropertiesXMLFile function."""
    parser = oxml.OpenXMLParser()

    expected_properties = {
        'author': 'Nides',
        'created': '2012-11-07T23:29:00.1234567Z',
        'last_saved_by': 'Nides',
        'modified': '2013-08-25T22:18:00Z',
        'revision_number': '3'}

    properties = parser._ParsePropertiesXMLFile(self._PROPERTIES_XML_DATA)
    self.assertEqual(properties, expected_properties)
Beispiel #5
0
  def testProduceEvent(self):
    """Tests the _ProduceEvent function."""
    storage_writer = self._CreateStorageWriter()
    parser_mediator = self._CreateParserMediator(storage_writer)
    event_data = oxml.OpenXMLEventData()

    parser = oxml.OpenXMLParser()

    properties = parser._ParsePropertiesXMLFile(self._PROPERTIES_XML_DATA)

    # Test parsing a date and time string in intervals of 1 s.
    parser._ProduceEvent(
        parser_mediator, event_data, properties, 'modified',
        definitions.TIME_DESCRIPTION_MODIFICATION, 'modification time')

    self.assertEqual(storage_writer.number_of_events, 1)

    # Test parsing a date and time string in intervals of 100 ns.
    parser._ProduceEvent(
        parser_mediator, event_data, properties, 'created',
        definitions.TIME_DESCRIPTION_CREATION, 'creation time')

    self.assertEqual(storage_writer.number_of_events, 2)
Beispiel #6
0
 def setUp(self):
     """Sets up the needed objects used throughout the test."""
     self._parser = oxml.OpenXMLParser()
Beispiel #7
0
 def setUp(self):
     """Makes preparations before running an individual test."""
     self._parser = oxml.OpenXMLParser()
Beispiel #8
0
 def setUp(self):
     """Sets up the needed objects used throughout the test."""
     pre_obj = event.PreprocessObject()
     self._parser = oxml.OpenXMLParser(pre_obj)