mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-19 06:46:38 +00:00
Fix crash with unparsable files
This commit is contained in:
parent
9e3ebe40cd
commit
154a630c9b
2 changed files with 80 additions and 39 deletions
|
@ -581,8 +581,10 @@ class FilteredLogModel (FilteredLogModelBase):
|
|||
def super_model_changed_range (self):
|
||||
|
||||
range_model = self.super_model
|
||||
old_start, old_end = self.__old_super_model_range
|
||||
super_start, super_end = range_model.line_index_range
|
||||
old_start, old_stop = self.__old_super_model_range
|
||||
old_end = old_stop - 1
|
||||
super_start, super_stop = range_model.line_index_range
|
||||
super_end = super_stop - 1
|
||||
|
||||
super_start_offset = super_start - old_start
|
||||
if super_start_offset < 0:
|
||||
|
@ -630,7 +632,7 @@ class FilteredLogModel (FilteredLogModelBase):
|
|||
for i in range (len (self.super_index)):
|
||||
self.super_index[i] -= super_start_offset
|
||||
|
||||
self.__old_super_model_range = (super_start, super_end,)
|
||||
self.__old_super_model_range = (super_start, super_stop,)
|
||||
|
||||
def __remove_range (self, start, end):
|
||||
|
||||
|
@ -674,14 +676,16 @@ class CategoryFilter (Filter):
|
|||
|
||||
class SubRange (object):
|
||||
|
||||
def __init__ (self, l, start, end):
|
||||
__slots__ = ("l", "start", "stop",)
|
||||
|
||||
if start > end:
|
||||
raise ValueError ("need start <= end")
|
||||
def __init__ (self, l, start, stop):
|
||||
|
||||
if start > stop:
|
||||
raise ValueError ("need start <= stop (got %r, %r)" % (start, stop,))
|
||||
|
||||
self.l = l
|
||||
self.start = start
|
||||
self.end = end
|
||||
self.stop = stop
|
||||
|
||||
def __getitem__ (self, i):
|
||||
|
||||
|
@ -689,14 +693,14 @@ class SubRange (object):
|
|||
|
||||
def __len__ (self):
|
||||
|
||||
return self.end - self.start + 1
|
||||
return self.stop - self.start
|
||||
|
||||
def __iter__ (self):
|
||||
|
||||
# FIXME: Use itertools, should be faster!
|
||||
l = self.l
|
||||
i = self.start
|
||||
while i <= self.end:
|
||||
while i < self.stop:
|
||||
yield l[i]
|
||||
i += 1
|
||||
|
||||
|
@ -710,25 +714,25 @@ class RangeFilteredLogModel (FilteredLogModelBase):
|
|||
|
||||
self.line_index_range = None
|
||||
|
||||
def set_range (self, start_index, last_index):
|
||||
def set_range (self, start_index, stop_index):
|
||||
|
||||
self.logger.debug ("setting range to first = %i, last = %i",
|
||||
start_index, last_index)
|
||||
self.logger.debug ("setting range to start = %i, stop = %i",
|
||||
start_index, stop_index)
|
||||
|
||||
self.line_index_range = (start_index, last_index,)
|
||||
self.line_index_range = (start_index, stop_index,)
|
||||
self.line_offsets = SubRange (self.super_model.line_offsets,
|
||||
start_index, last_index)
|
||||
start_index, stop_index)
|
||||
self.line_levels = SubRange (self.super_model.line_levels,
|
||||
start_index, last_index)
|
||||
start_index, stop_index)
|
||||
|
||||
def reset (self):
|
||||
|
||||
self.logger.debug ("reset")
|
||||
|
||||
first_index = 0
|
||||
last_index = len (self.super_model) - 1
|
||||
start_index = 0
|
||||
stop_index = len (self.super_model)
|
||||
|
||||
self.set_range (first_index, last_index,)
|
||||
self.set_range (start_index, stop_index,)
|
||||
|
||||
def line_index_to_super (self, line_index):
|
||||
|
||||
|
@ -738,9 +742,9 @@ class RangeFilteredLogModel (FilteredLogModelBase):
|
|||
|
||||
def line_index_from_super (self, li):
|
||||
|
||||
start, end = self.line_index_range
|
||||
start, stop = self.line_index_range
|
||||
|
||||
if li < start or li > end:
|
||||
if li < start or li >= stop:
|
||||
raise IndexError ("not in range")
|
||||
|
||||
return li - start
|
||||
|
@ -1494,6 +1498,10 @@ class LineView (object):
|
|||
|
||||
def handle_log_view_selection_changed (self, selection):
|
||||
|
||||
line_model = self.line_view.props.model
|
||||
if line_model is None or len (line_model) == 0:
|
||||
return
|
||||
|
||||
model, tree_iter = selection.get_selected ()
|
||||
|
||||
if tree_iter is None:
|
||||
|
@ -1502,9 +1510,6 @@ class LineView (object):
|
|||
path = model.get_path (tree_iter)
|
||||
line_index = model.line_index_to_super (path[0])
|
||||
|
||||
line_model = self.line_view.props.model
|
||||
if line_model is None:
|
||||
return
|
||||
if len (line_model) == 0:
|
||||
line_model.insert_line (0, line_index)
|
||||
else:
|
||||
|
@ -1872,7 +1877,9 @@ class Window (object):
|
|||
last_index)
|
||||
|
||||
self.push_view_state ()
|
||||
self.log_range.set_range (first_index, last_index)
|
||||
start_index = first_index
|
||||
stop_index = last_index + 1
|
||||
self.log_range.set_range (start_index, stop_index)
|
||||
if self.log_filter:
|
||||
self.log_filter.super_model_changed_range ()
|
||||
self.update_model ()
|
||||
|
|
|
@ -31,6 +31,40 @@ from unittest import TestCase, main as test_main
|
|||
|
||||
from GstDebugViewer import Common, Data, GUI
|
||||
|
||||
class TestSubRange (TestCase):
|
||||
|
||||
def test_len (self):
|
||||
|
||||
l = range (20)
|
||||
|
||||
sr = GUI.SubRange (l, 0, 20)
|
||||
self.assertEquals (len (sr), 20)
|
||||
|
||||
sr = GUI.SubRange (l, 10, 20)
|
||||
self.assertEquals (len (sr), 10)
|
||||
|
||||
sr = GUI.SubRange (l, 0, 10)
|
||||
self.assertEquals (len (sr), 10)
|
||||
|
||||
sr = GUI.SubRange (l, 5, 15)
|
||||
self.assertEquals (len (sr), 10)
|
||||
|
||||
def test_iter (self):
|
||||
|
||||
l = range (20)
|
||||
|
||||
sr = GUI.SubRange (l, 0, 20)
|
||||
self.assertEquals (list (sr), l)
|
||||
|
||||
sr = GUI.SubRange (l, 10, 20)
|
||||
self.assertEquals (list (sr), range (10, 20))
|
||||
|
||||
sr = GUI.SubRange (l, 0, 10)
|
||||
self.assertEquals (list (sr), range (0, 10))
|
||||
|
||||
sr = GUI.SubRange (l, 5, 15)
|
||||
self.assertEquals (list (sr), range (5, 15))
|
||||
|
||||
class Model (GUI.LogModelBase):
|
||||
|
||||
def __init__ (self):
|
||||
|
@ -93,7 +127,7 @@ class TestDynamicFilter (TestCase):
|
|||
self.assertEquals (row_list (ranged_model), range (20))
|
||||
self.assertEquals (row_list (filtered_model), range (20))
|
||||
|
||||
ranged_model.set_range (5, 15)
|
||||
ranged_model.set_range (5, 16)
|
||||
filtered_model.super_model_changed_range ()
|
||||
|
||||
self.assertEquals (row_list (ranged_model), range (5, 16))
|
||||
|
@ -127,7 +161,7 @@ class TestDynamicFilter (TestCase):
|
|||
|
||||
filtered_model.add_filter (IdentityFilter (),
|
||||
Common.Data.DefaultDispatcher ())
|
||||
ranged_model.set_range (5, 15)
|
||||
ranged_model.set_range (5, 16)
|
||||
filtered_model.super_model_changed_range ()
|
||||
|
||||
self.assertEquals (row_list (ranged_model), range (5, 16))
|
||||
|
@ -174,8 +208,8 @@ class TestDynamicFilter (TestCase):
|
|||
for i in range (10)],
|
||||
range (1, 20, 2))
|
||||
|
||||
ranged_model.set_range (1, 19)
|
||||
self.__dump_model (ranged_model, "ranged (1, 19)")
|
||||
ranged_model.set_range (1, 20)
|
||||
self.__dump_model (ranged_model, "ranged (1, 20)")
|
||||
filtered_model.super_model_changed_range ()
|
||||
self.__dump_model (filtered_model, "filtered range")
|
||||
|
||||
|
@ -192,8 +226,8 @@ class TestDynamicFilter (TestCase):
|
|||
for i in range (10)],
|
||||
range (1, 20, 2))
|
||||
|
||||
ranged_model.set_range (2, 19)
|
||||
self.__dump_model (ranged_model, "ranged (2, 19)")
|
||||
ranged_model.set_range (2, 20)
|
||||
self.__dump_model (ranged_model, "ranged (2, 20)")
|
||||
filtered_model.super_model_changed_range ()
|
||||
self.__dump_model (filtered_model, "filtered range")
|
||||
|
||||
|
@ -257,8 +291,8 @@ class TestDynamicFilter (TestCase):
|
|||
for i in range (20)],
|
||||
range (20))
|
||||
|
||||
ranged_model.set_range (5, 15)
|
||||
self.__dump_model (ranged_model, "ranged model (5, 15)")
|
||||
ranged_model.set_range (5, 16)
|
||||
self.__dump_model (ranged_model, "ranged model (5, 16)")
|
||||
filtered_model.super_model_changed_range ()
|
||||
|
||||
rows_ranged = row_list (ranged_model)
|
||||
|
@ -309,8 +343,8 @@ class TestDynamicFilter (TestCase):
|
|||
for i in range (5, 16, 2)],
|
||||
range (6))
|
||||
|
||||
ranged_model.set_range (7, 12)
|
||||
self.__dump_model (ranged_model, "ranged model (7, 12)")
|
||||
ranged_model.set_range (7, 13)
|
||||
self.__dump_model (ranged_model, "ranged model (7, 13)")
|
||||
filtered_model.super_model_changed_range ()
|
||||
|
||||
self.assertEquals (row_list (ranged_model), range (7, 13))
|
||||
|
@ -362,14 +396,14 @@ class TestDynamicFilter (TestCase):
|
|||
random_rows = row_list (filtered_model)
|
||||
|
||||
self.__dump_model (filtered_model)
|
||||
ranged_model.set_range (10, 19)
|
||||
self.__dump_model (ranged_model, "ranged_model (10, 19)")
|
||||
ranged_model.set_range (10, 20)
|
||||
self.__dump_model (ranged_model, "ranged_model (10, 20)")
|
||||
self.assertEquals (row_list (ranged_model), range (10, 20))
|
||||
filtered_model.super_model_changed_range ()
|
||||
self.__dump_model (filtered_model)
|
||||
self.assertEquals (row_list (filtered_model), [x for x in range (10, 20) if x in random_rows])
|
||||
|
||||
ranged_model.set_range (0, 19)
|
||||
ranged_model.set_range (0, 20)
|
||||
self.assertEquals (row_list (ranged_model), range (0, 20))
|
||||
|
||||
ranged_model = GUI.RangeFilteredLogModel (full_model)
|
||||
|
@ -381,8 +415,8 @@ class TestDynamicFilter (TestCase):
|
|||
self.__dump_model (filtered_model, "filtered model")
|
||||
self.assertEquals (row_list (filtered_model), random_rows)
|
||||
|
||||
ranged_model.set_range (0, 9)
|
||||
self.__dump_model (ranged_model, "ranged model (0, 9)")
|
||||
ranged_model.set_range (0, 10)
|
||||
self.__dump_model (ranged_model, "ranged model (0, 10)")
|
||||
filtered_model.super_model_changed_range ()
|
||||
self.assertEquals (row_list (ranged_model), range (0, 10))
|
||||
self.__dump_model (filtered_model)
|
||||
|
|
Loading…
Reference in a new issue