Exemplo n.º 1
0
    def testFlush(self):
        """Tests the Flush function."""
        output_mediator = self._CreateOutputMediator()
        output_writer = cli_test_lib.TestOutputWriter()
        output_module = test_lib.TestOutputModule(output_mediator)
        output_module.SetOutputWriter(output_writer)
        event_buffer_object = event_buffer.EventBuffer(output_module, False)

        event_buffer_object.Append(TestEvent(123456, u'Now is now'))
        self._CheckBufferLength(event_buffer_object, 1)

        event_buffer_object.Append(TestEvent(123456, u'OMG I AM DIFFERENT'))
        event_buffer_object.Append(TestEvent(123456, u'Now is now'))
        event_buffer_object.Append(TestEvent(123456, u'Now is now'))
        self._CheckBufferLength(event_buffer_object, 2)

        event_buffer_object.Flush()
        self._CheckBufferLength(event_buffer_object, 0)

        event_buffer_object.Append(TestEvent(123456, u'Now is now'))
        event_buffer_object.Append(TestEvent(123456, u'Now is now'))
        event_buffer_object.Append(TestEvent(123456, u'Different again :)'))
        self._CheckBufferLength(event_buffer_object, 2)
        event_buffer_object.Append(TestEvent(123457, u'Now is different'))
        self._CheckBufferLength(event_buffer_object, 1)
Exemplo n.º 2
0
  def testFlush(self):
    """Test to ensure we empty our buffers and sends to output properly."""
    output_mediator = self._CreateOutputMediator()
    output_writer = cli_test_lib.TestOutputWriter()
    output_module = test_lib.TestOutputModule(output_mediator)
    output_module.SetOutputWriter(output_writer)
    event_buffer_object = event_buffer.EventBuffer(output_module, False)

    event_buffer_object.Append(TestEvent(123456, u'Now is now'))
    self._CheckBufferLength(event_buffer_object, 1)

    # Add three events.
    event_buffer_object.Append(TestEvent(123456, u'OMG I AM DIFFERENT'))
    event_buffer_object.Append(TestEvent(123456, u'Now is now'))
    event_buffer_object.Append(TestEvent(123456, u'Now is now'))
    self._CheckBufferLength(event_buffer_object, 2)

    event_buffer_object.Flush()
    self._CheckBufferLength(event_buffer_object, 0)

    event_buffer_object.Append(TestEvent(123456, u'Now is now'))
    event_buffer_object.Append(TestEvent(123456, u'Now is now'))
    event_buffer_object.Append(TestEvent(123456, u'Different again :)'))
    self._CheckBufferLength(event_buffer_object, 2)
    event_buffer_object.Append(TestEvent(123457, u'Now is different'))
    self._CheckBufferLength(event_buffer_object, 1)
Exemplo n.º 3
0
    def testOutput(self):
        """Tests an implementation of output module."""
        events = [
            TestEvent(123456, 'My Event Is Now!'),
            TestEvent(123458, 'There is no tomorrow.'),
            TestEvent(123462, 'Tomorrow is now.'),
            TestEvent(123489, 'This is just some stuff to fill the line.')
        ]

        output_mediator = self._CreateOutputMediator()
        output_writer = cli_test_lib.TestOutputWriter()
        output_module = test_lib.TestOutputModule(output_mediator)
        output_module.SetOutputWriter(output_writer)
        output_module.WriteHeader()
        for event in events:
            output_module.WriteEvent(event)
        output_module.WriteFooter()

        expected_output = (
            '<EventFile>\n'
            '<Event>\n'
            '\t<Date>03/01/2012</Date>\n'
            '\t<Time>123456</Time>\n'
            '\t<Entry>My Event Is Now!</Entry>\n'
            '</Event>\n'
            '<Event>\n'
            '\t<Date>03/01/2012</Date>\n'
            '\t<Time>123458</Time>\n'
            '\t<Entry>There is no tomorrow.</Entry>\n'
            '</Event>\n'
            '<Event>\n'
            '\t<Date>03/01/2012</Date>\n'
            '\t<Time>123462</Time>\n'
            '\t<Entry>Tomorrow is now.</Entry>\n'
            '</Event>\n'
            '<Event>\n'
            '\t<Date>03/01/2012</Date>\n'
            '\t<Time>123489</Time>\n'
            '\t<Entry>This is just some stuff to fill the line.</Entry>\n'
            '</Event>\n'
            '</EventFile>\n')

        output = output_writer.ReadOutput()
        self.assertEqual(output, expected_output)
Exemplo n.º 4
0
  def testOutput(self):
    """Tests an implementation of output module."""
    output_mediator = self._CreateOutputMediator()
    output_writer = cli_test_lib.TestOutputWriter()
    output_module = test_lib.TestOutputModule(output_mediator)
    output_module.SetOutputWriter(output_writer)
    output_module.WriteHeader()

    for event_values in self._TEST_EVENTS:
      event, event_data = containers_test_lib.CreateEventFromValues(
          event_values)
      output_module.WriteEvent(event, event_data, None)

    output_module.WriteFooter()

    expected_output = (
        '<EventFile>\n'
        '<Event>\n'
        '\t<DateTime>2012-06-27T18:17:01+00:00</DateTime>\n'
        '\t<Entry>My Event Is Now!</Entry>\n'
        '</Event>\n'
        '<Event>\n'
        '\t<DateTime>2012-06-27T18:18:23+00:00</DateTime>\n'
        '\t<Entry>There is no tomorrow.</Entry>\n'
        '</Event>\n'
        '<Event>\n'
        '\t<DateTime>2012-06-27T19:11:54+00:00</DateTime>\n'
        '\t<Entry>Tomorrow is now.</Entry>\n'
        '</Event>\n'
        '<Event>\n'
        '\t<DateTime>2012-06-27T19:12:03+00:00</DateTime>\n'
        '\t<Entry>This is just some stuff to fill the line.</Entry>\n'
        '</Event>\n'
        '</EventFile>\n')

    output = output_writer.ReadOutput()
    self.assertEqual(output, expected_output)