public void TestVisibleRowsEvenBiggerScroll()
        {
            MockCellEntry[] cells = new MockCellEntry[15];
            for (int i = 0; i < cells.Length; ++i)
            {
                cells[i] = new MockCellEntry(typeof(TableViewCellMock), 10);
            }

            TableViewAdapter adapter = new TestCellsHeightTableAdapter(cells);

            TableViewMock table = new TableViewMock(320, 50);

            table.DataSource = adapter;
            table.Delegate   = adapter;
            table.ReloadData();

            table.Scroll(100);
            Assert.AreEqual(10, table.FirstVisibleCellIndex);
            Assert.AreEqual(14, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 10, 11, 12, 13, 14);

            table.Scroll(-100);
            Assert.AreEqual(0, table.FirstVisibleCellIndex);
            Assert.AreEqual(4, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 0, 1, 2, 3, 4);
        }
예제 #2
0
        public void TestReusableCellsMultipleOccurrenceBigScroll()
        {
            MockCellEntry[] cells = new MockCellEntry[15];
            for (int i = 0; i < cells.Length; ++i)
            {
                cells[i] = new MockCellEntry(typeof(TableViewCellMock1), 10);
            }
            ;

            TableViewAdapter adapter = new TestCellsHeightTableAdapter(cells);

            TableViewMock table = new TableViewMock(320, 50);

            table.DataSource = adapter;
            table.Delegate   = adapter;
            table.ReloadData();

            CTableViewCell a1 = table.FirstVisibleCell;
            CTableViewCell a2 = a1.NextCell;
            CTableViewCell a3 = a2.NextCell;
            CTableViewCell a4 = a3.NextCell;
            CTableViewCell a5 = a4.NextCell;

            table.Scroll(100);

            CTableViewCell b1 = table.FirstVisibleCell;
            CTableViewCell b2 = b1.NextCell;
            CTableViewCell b3 = b2.NextCell;
            CTableViewCell b4 = b3.NextCell;
            CTableViewCell b5 = b4.NextCell;

            Assert.AreSame(a1, b5);
            Assert.AreSame(a2, b4);
            Assert.AreSame(a3, b3);
            Assert.AreSame(a4, b2);
            Assert.AreSame(a5, b1);

            table.Scroll(-100);

            b1 = table.FirstVisibleCell;
            b2 = b1.NextCell;
            b3 = b2.NextCell;
            b4 = b3.NextCell;
            b5 = b4.NextCell;

            Assert.AreSame(a1, b1);
            Assert.AreSame(a2, b2);
            Assert.AreSame(a3, b3);
            Assert.AreSame(a4, b4);
            Assert.AreSame(a5, b5);

            Assert.AreEqual(5, TableViewCellMock1.instanceCount);
        }
예제 #3
0
        public void TestAddMultipleRowsAndScroll()
        {
            TableViewMock  table = new TableViewMock(320, 15);
            CTableViewCell c1    = new TableViewCellMock1(table.Width, 10);
            CTableViewCell c2    = new TableViewCellMock2(table.Width, 15);
            CTableViewCell c3    = new TableViewCellMock1(table.Width, 10);
            CTableViewCell c4    = new TableViewCellMock2(table.Width, 15);
            CTableViewCell c5    = new TableViewCellMock1(table.Width, 10);
            CTableViewCell c6    = new TableViewCellMock2(table.Width, 15);

            TestCellPredefinedAdapter adapter = new TestCellPredefinedAdapter(new CTableViewCell[0]);

            table.DataSource = adapter;
            table.Delegate   = adapter;

            adapter.Add(c1, c2, c3, c4, c5, c6);

            table.ReloadNewData();
            AssertVisibleRows(table, c1, c2);

            table.Scroll(15);
            AssertVisibleRows(table, c2, c3);

            table.Scroll(10);
            AssertVisibleRows(table, c3, c4);

            table.Scroll(15);
            AssertVisibleRows(table, c4, c5);

            table.Scroll(10);
            AssertVisibleRows(table, c5, c6);

            table.Scroll(15);
            AssertVisibleRows(table, c6);

            table.Scroll(-15);
            AssertVisibleRows(table, c5, c6);

            table.Scroll(-10);
            AssertVisibleRows(table, c4, c5);

            table.Scroll(-15);
            AssertVisibleRows(table, c3, c4);

            table.Scroll(-10);
            AssertVisibleRows(table, c2, c3);

            table.Scroll(-15);
            AssertVisibleRows(table, c1, c2);
        }
        public void TestAddMultipleRowsAndScroll()
        {
            TableViewMock table = new TableViewMock(320, 15);
            TableViewCell c1 = new TableViewCellMock1(table.Width, 10);
            TableViewCell c2 = new TableViewCellMock2(table.Width, 15);
            TableViewCell c3 = new TableViewCellMock1(table.Width, 10);
            TableViewCell c4 = new TableViewCellMock2(table.Width, 15);
            TableViewCell c5 = new TableViewCellMock1(table.Width, 10);
            TableViewCell c6 = new TableViewCellMock2(table.Width, 15);

            TestCellPredefinedAdapter adapter = new TestCellPredefinedAdapter(new TableViewCell[0]);
            table.DataSource = adapter;
            table.Delegate = adapter;

            adapter.Add(c1, c2, c3, c4, c5, c6);

            table.ReloadNewData();
            AssertVisibleRows(table, c1, c2);

            table.Scroll(15);
            AssertVisibleRows(table, c2, c3);

            table.Scroll(10);
            AssertVisibleRows(table, c3, c4);

            table.Scroll(15);
            AssertVisibleRows(table, c4, c5);

            table.Scroll(10);
            AssertVisibleRows(table, c5, c6);

            table.Scroll(15);
            AssertVisibleRows(table, c6);

            table.Scroll(-15);
            AssertVisibleRows(table, c5, c6);

            table.Scroll(-10);
            AssertVisibleRows(table, c4, c5);

            table.Scroll(-15);
            AssertVisibleRows(table, c3, c4);

            table.Scroll(-10);
            AssertVisibleRows(table, c2, c3);

            table.Scroll(-15);
            AssertVisibleRows(table, c1, c2);
        }
        public void TestVisibleRows()
        {
            TableViewAdapter adapter = new TestCellsHeightTableAdapter(new MockCellEntry[] {
                new MockCellEntry(typeof(TableViewCellMock), 10)
            });

            TableViewMock table = new TableViewMock(320, 15);
            table.DataSource = adapter;
            table.Delegate = adapter;
            table.ReloadData();

            Assert.AreEqual(0, table.FirstVisibleCellIndex);
            Assert.AreEqual(0, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 0);
        }
예제 #6
0
        public void TestResizeChangeWidth()
        {
            MockCellEntry[] entries = new MockCellEntry[]
            {
                new MockCellEntry(typeof(TableViewCellMock), 10),
                new MockCellEntry(typeof(TableViewCellMock), 15),
                new MockCellEntry(typeof(TableViewCellMock), 10),
                new MockCellEntry(typeof(TableViewCellMock), 15),
                new MockCellEntry(typeof(TableViewCellMock), 10),
                new MockCellEntry(typeof(TableViewCellMock), 15)
            };

            TableViewAdapter adapter = new TestCellsHeightTableAdapter(entries);

            TableViewMock table = new TableViewMock(320, 60);

            table.DataSource = adapter;
            table.Delegate   = adapter;
            table.ReloadData();

            // descrease width
            for (int i = 0; i < entries.Length; ++i)
            {
                if (entries[i].height == 10)
                {
                    entries[i].height = 20;
                }
            }
            table.Resize(300, 60);

            AssertVisibleRows(table, 1, 2, 3, 4);
            Assert.AreEqual(30, table.ScrollPosTop);
            Assert.AreEqual(90, table.ScrollPosBottom);

            // increase width
            for (int i = 0; i < entries.Length; ++i)
            {
                if (entries[i].height == 20)
                {
                    entries[i].height = 10;
                }
            }
            table.Resize(320, 60);

            AssertVisibleRows(table, 0, 1, 2, 3, 4);
            Assert.AreEqual(0, table.ScrollPosTop);
            Assert.AreEqual(60, table.ScrollPosBottom);
        }
        public void TestVisibleRows()
        {
            TableViewAdapter adapter = new TestCellsHeightTableAdapter(new MockCellEntry[] {
                new MockCellEntry(typeof(TableViewCellMock), 10)
            });

            TableViewMock table = new TableViewMock(320, 15);

            table.DataSource = adapter;
            table.Delegate   = adapter;
            table.ReloadData();

            Assert.AreEqual(0, table.FirstVisibleCellIndex);
            Assert.AreEqual(0, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 0);
        }
예제 #8
0
        public void TestAddItemsScrollLock()
        {
            TestCellPredefinedAdapter adapter = new TestCellPredefinedAdapter(new CTableViewCell[0]);

            TableViewMock table = new TableViewMock(320, 30);

            table.DataSource     = adapter;
            table.Delegate       = adapter;
            table.IsScrollLocked = true;
            table.ReloadData();

            adapter.Add(new TableViewCellMock(table.Width, 10));
            table.ReloadNewData();
            AssertVisibleRows(table, 0);
            Assert.AreEqual(0, table.ScrollPosTop);
            Assert.AreEqual(30, table.ScrollPosBottom);

            adapter.Add(new TableViewCellMock(table.Width, 15));
            table.ReloadNewData();
            AssertVisibleRows(table, 0, 1);
            Assert.AreEqual(0, table.ScrollPosTop);
            Assert.AreEqual(30, table.ScrollPosBottom);

            adapter.Add(new TableViewCellMock(table.Width, 10));
            table.ReloadNewData();
            AssertVisibleRows(table, 0, 1, 2);
            Assert.AreEqual(5, table.ScrollPosTop);
            Assert.AreEqual(35, table.ScrollPosBottom);

            adapter.Add(new TableViewCellMock(table.Width, 15));
            table.ReloadNewData();
            AssertVisibleRows(table, 1, 2, 3);
            Assert.AreEqual(20, table.ScrollPosTop);
            Assert.AreEqual(50, table.ScrollPosBottom);

            adapter.Add(new TableViewCellMock(table.Width, 10));
            table.ReloadNewData();
            AssertVisibleRows(table, 2, 3, 4);
            Assert.AreEqual(30, table.ScrollPosTop);
            Assert.AreEqual(60, table.ScrollPosBottom);

            adapter.Add(new TableViewCellMock(table.Width, 15));
            table.ReloadNewData();
            AssertVisibleRows(table, 3, 4, 5);
            Assert.AreEqual(45, table.ScrollPosTop);
            Assert.AreEqual(75, table.ScrollPosBottom);
        }
        public void TestAddItemsScrollLock()
        {
            TestCellPredefinedAdapter adapter = new TestCellPredefinedAdapter(new TableViewCell[0]);

            TableViewMock table = new TableViewMock(320, 30);
            table.DataSource = adapter;
            table.Delegate = adapter;
            table.IsScrollLocked = true;
            table.ReloadData();

            adapter.Add(new TableViewCellMock(table.Width, 10));
            table.ReloadNewData();
            AssertVisibleRows(table, 0);
            Assert.AreEqual(0, table.ScrollPosTop);
            Assert.AreEqual(30, table.ScrollPosBottom);

            adapter.Add(new TableViewCellMock(table.Width, 15));
            table.ReloadNewData();
            AssertVisibleRows(table, 0, 1);
            Assert.AreEqual(0, table.ScrollPosTop);
            Assert.AreEqual(30, table.ScrollPosBottom);

            adapter.Add(new TableViewCellMock(table.Width, 10));
            table.ReloadNewData();
            AssertVisibleRows(table, 0, 1, 2);
            Assert.AreEqual(5, table.ScrollPosTop);
            Assert.AreEqual(35, table.ScrollPosBottom);

            adapter.Add(new TableViewCellMock(table.Width, 15));
            table.ReloadNewData();
            AssertVisibleRows(table, 1, 2, 3);
            Assert.AreEqual(20, table.ScrollPosTop);
            Assert.AreEqual(50, table.ScrollPosBottom);

            adapter.Add(new TableViewCellMock(table.Width, 10));
            table.ReloadNewData();
            AssertVisibleRows(table, 2, 3, 4);
            Assert.AreEqual(30, table.ScrollPosTop);
            Assert.AreEqual(60, table.ScrollPosBottom);

            adapter.Add(new TableViewCellMock(table.Width, 15));
            table.ReloadNewData();
            AssertVisibleRows(table, 3, 4, 5);
            Assert.AreEqual(45, table.ScrollPosTop);
            Assert.AreEqual(75, table.ScrollPosBottom);
        }
        public void TestAddMultipleRows()
        {
            TableViewMock table = new TableViewMock(320, 15);
            TableViewCell a1 = new TableViewCellMock1(table.Width, 10);
            TableViewCell a2 = new TableViewCellMock2(table.Width, 15);
            TableViewCell a3 = new TableViewCellMock3(table.Width, 10);

            TestCellPredefinedAdapter adapter = new TestCellPredefinedAdapter(new TableViewCell[] { a1 });

            table.DataSource = adapter;
            table.Delegate = adapter;
            table.ReloadData();

            adapter.Add(a2);
            adapter.Add(a3);
            table.ReloadNewData();

            AssertVisibleRows(table, a1, a2);
        }
예제 #11
0
        public void TestAddMultipleRows()
        {
            TableViewMock  table = new TableViewMock(320, 15);
            CTableViewCell a1    = new TableViewCellMock1(table.Width, 10);
            CTableViewCell a2    = new TableViewCellMock2(table.Width, 15);
            CTableViewCell a3    = new TableViewCellMock3(table.Width, 10);

            TestCellPredefinedAdapter adapter = new TestCellPredefinedAdapter(new CTableViewCell[] { a1 });

            table.DataSource = adapter;
            table.Delegate   = adapter;
            table.ReloadData();

            adapter.Add(a2);
            adapter.Add(a3);
            table.ReloadNewData();

            AssertVisibleRows(table, a1, a2);
        }
예제 #12
0
        public void TestAddTwoRows()
        {
            TableViewMock  table = new TableViewMock(320, 15);
            CTableViewCell a1    = new TableViewCellMock1(table.Width, 10);
            CTableViewCell a2    = new TableViewCellMock2(table.Width, 15);

            TestCellPredefinedAdapter adapter = new TestCellPredefinedAdapter(new CTableViewCell[] { a1 });

            table.DataSource = adapter;
            table.Delegate   = adapter;
            table.ReloadData();

            adapter.Add(a2);
            table.ReloadNewData();

            CTableViewCell b1 = table.FirstVisibleCell;
            CTableViewCell b2 = b1.NextCell;

            Assert.AreSame(a1, b1);
            Assert.AreSame(a2, b2);
            AssertVisibleRows(table, 0, 1);
        }
        public void TestVisibleRowsScroll()
        {
            MockCellEntry[] cells = new MockCellEntry[10];
            for (int i = 0; i < cells.Length; ++i)
            {
                cells[i] = new MockCellEntry(typeof(TableViewCellMock), i % 2 == 0 ? 10 : 15);
            }

            TableViewAdapter adapter = new TestCellsHeightTableAdapter(cells);

            TableViewMock table = new TableViewMock(320, 15);
            table.DataSource = adapter;
            table.Delegate = adapter;
            table.ReloadData();

            Assert.AreEqual(0, table.FirstVisibleCellIndex);
            Assert.AreEqual(1, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 0, 1);

            table.Scroll(10);
            Assert.AreEqual(1, table.FirstVisibleCellIndex);
            Assert.AreEqual(1, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 1);

            table.Scroll(10);
            Assert.AreEqual(1, table.FirstVisibleCellIndex);
            Assert.AreEqual(2, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 1, 2);

            table.Scroll(10);
            Assert.AreEqual(2, table.FirstVisibleCellIndex);
            Assert.AreEqual(3, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 2, 3);

            table.Scroll(10);
            Assert.AreEqual(3, table.FirstVisibleCellIndex);
            Assert.AreEqual(4, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 3, 4);

            table.Scroll(10);
            Assert.AreEqual(4, table.FirstVisibleCellIndex);
            Assert.AreEqual(5, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 4, 5);

            table.Scroll(10);
            Assert.AreEqual(5, table.FirstVisibleCellIndex);
            Assert.AreEqual(5, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 5);

            table.Scroll(10);
            Assert.AreEqual(5, table.FirstVisibleCellIndex);
            Assert.AreEqual(6, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 5, 6);

            table.Scroll(10);
            Assert.AreEqual(6, table.FirstVisibleCellIndex);
            Assert.AreEqual(7, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 6, 7);

            table.Scroll(10);
            Assert.AreEqual(7, table.FirstVisibleCellIndex);
            Assert.AreEqual(8, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 7, 8);

            table.Scroll(10);
            Assert.AreEqual(8, table.FirstVisibleCellIndex);
            Assert.AreEqual(9, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 8, 9);

            table.Scroll(10);
            Assert.AreEqual(9, table.FirstVisibleCellIndex);
            Assert.AreEqual(9, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 9);

            table.Scroll(-10);
            Assert.AreEqual(8, table.FirstVisibleCellIndex);
            Assert.AreEqual(9, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 8, 9);

            table.Scroll(-10);
            Assert.AreEqual(7, table.FirstVisibleCellIndex);
            Assert.AreEqual(8, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 7, 8);

            table.Scroll(-10);
            Assert.AreEqual(6, table.FirstVisibleCellIndex);
            Assert.AreEqual(7, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 6, 7);

            table.Scroll(-10);
            Assert.AreEqual(5, table.FirstVisibleCellIndex);
            Assert.AreEqual(6, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 5, 6);

            table.Scroll(-10);
            Assert.AreEqual(5, table.FirstVisibleCellIndex);
            Assert.AreEqual(5, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 5);

            table.Scroll(-10);
            Assert.AreEqual(4, table.FirstVisibleCellIndex);
            Assert.AreEqual(5, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 4, 5);

            table.Scroll(-10);
            Assert.AreEqual(3, table.FirstVisibleCellIndex);
            Assert.AreEqual(4, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 3, 4);

            table.Scroll(-10);
            Assert.AreEqual(2, table.FirstVisibleCellIndex);
            Assert.AreEqual(3, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 2, 3);

            table.Scroll(-10);
            Assert.AreEqual(1, table.FirstVisibleCellIndex);
            Assert.AreEqual(2, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 1, 2);

            table.Scroll(-10);
            Assert.AreEqual(1, table.FirstVisibleCellIndex);
            Assert.AreEqual(1, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 1);

            table.Scroll(-10);
            Assert.AreEqual(0, table.FirstVisibleCellIndex);
            Assert.AreEqual(1, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 0, 1);
        }
        public void TestReusableCellsMultipleOccurrenceBigScroll()
        {
            MockCellEntry[] cells = new MockCellEntry[15];
            for (int i = 0; i < cells.Length; ++i)
            {
                cells[i] = new MockCellEntry(typeof(TableViewCellMock1), 10);
            };

            TableViewAdapter adapter = new TestCellsHeightTableAdapter(cells);

            TableViewMock table = new TableViewMock(320, 50);
            table.DataSource = adapter;
            table.Delegate = adapter;
            table.ReloadData();

            TableViewCell a1 = table.FirstVisibleCell;
            TableViewCell a2 = a1.NextCell;
            TableViewCell a3 = a2.NextCell;
            TableViewCell a4 = a3.NextCell;
            TableViewCell a5 = a4.NextCell;

            table.Scroll(100);

            TableViewCell b1 = table.FirstVisibleCell;
            TableViewCell b2 = b1.NextCell;
            TableViewCell b3 = b2.NextCell;
            TableViewCell b4 = b3.NextCell;
            TableViewCell b5 = b4.NextCell;

            Assert.AreSame(a1, b5);
            Assert.AreSame(a2, b4);
            Assert.AreSame(a3, b3);
            Assert.AreSame(a4, b2);
            Assert.AreSame(a5, b1);

            table.Scroll(-100);

            b1 = table.FirstVisibleCell;
            b2 = b1.NextCell;
            b3 = b2.NextCell;
            b4 = b3.NextCell;
            b5 = b4.NextCell;

            Assert.AreSame(a1, b1);
            Assert.AreSame(a2, b2);
            Assert.AreSame(a3, b3);
            Assert.AreSame(a4, b4);
            Assert.AreSame(a5, b5);

            Assert.AreEqual(5, TableViewCellMock1.instanceCount);
        }
예제 #15
0
        public void TestReusableCells()
        {
            MockCellEntry[] cells =
            {
                new MockCellEntry(typeof(TableViewCellMock1), 10),
                new MockCellEntry(typeof(TableViewCellMock2), 10),
                new MockCellEntry(typeof(TableViewCellMock3), 10),
                new MockCellEntry(typeof(TableViewCellMock1), 10),
                new MockCellEntry(typeof(TableViewCellMock2), 10),
                new MockCellEntry(typeof(TableViewCellMock3), 10),
            };

            TableViewAdapter adapter = new TestCellsHeightTableAdapter(cells);

            TableViewMock table = new TableViewMock(320, 25);

            table.DataSource = adapter;
            table.Delegate   = adapter;
            table.ReloadData();

            CTableViewCell a1 = table.FirstVisibleCell;
            CTableViewCell a2 = a1.NextCell;
            CTableViewCell a3 = a2.NextCell;

            Assert.AreEqual(typeof(TableViewCellMock1), a1.GetType());
            Assert.AreEqual(typeof(TableViewCellMock2), a2.GetType());
            Assert.AreEqual(typeof(TableViewCellMock3), a3.GetType());

            table.Scroll(10);

            CTableViewCell b1 = table.FirstVisibleCell;
            CTableViewCell b2 = b1.NextCell;
            CTableViewCell b3 = b2.NextCell;

            Assert.AreSame(a2, b1);
            Assert.AreSame(a3, b2);
            Assert.AreSame(a1, b3);

            table.Scroll(10);

            b1 = table.FirstVisibleCell;
            b2 = b1.NextCell;
            b3 = b2.NextCell;

            Assert.AreSame(a3, b1);
            Assert.AreSame(a1, b2);
            Assert.AreSame(a2, b3);

            table.Scroll(10);

            b1 = table.FirstVisibleCell;
            b2 = b1.NextCell;
            b3 = b2.NextCell;

            Assert.AreSame(a1, b1);
            Assert.AreSame(a2, b2);
            Assert.AreSame(a3, b3);

            table.Scroll(5);

            b1 = table.FirstVisibleCell;
            b2 = b1.NextCell;
            b3 = b2.NextCell;

            Assert.AreSame(a1, b1);
            Assert.AreSame(a2, b2);
            Assert.AreSame(a3, b3);

            table.Scroll(-5);

            b1 = table.FirstVisibleCell;
            b2 = b1.NextCell;
            b3 = b2.NextCell;

            Assert.AreSame(a1, b1);
            Assert.AreSame(a2, b2);
            Assert.AreSame(a3, b3);

            table.Scroll(-10);

            b1 = table.FirstVisibleCell;
            b2 = b1.NextCell;
            b3 = b2.NextCell;

            Assert.AreSame(a3, b1);
            Assert.AreSame(a1, b2);
            Assert.AreSame(a2, b3);

            table.Scroll(-10);

            b1 = table.FirstVisibleCell;
            b2 = b1.NextCell;
            b3 = b2.NextCell;

            Assert.AreSame(a2, b1);
            Assert.AreSame(a3, b2);
            Assert.AreSame(a1, b3);

            table.Scroll(-10);

            b1 = table.FirstVisibleCell;
            b2 = b1.NextCell;
            b3 = b2.NextCell;

            Assert.AreSame(a1, b1);
            Assert.AreSame(a2, b2);
            Assert.AreSame(a3, b3);

            Assert.AreEqual(1, TableViewCellMock1.instanceCount);
            Assert.AreEqual(1, TableViewCellMock2.instanceCount);
            Assert.AreEqual(1, TableViewCellMock3.instanceCount);
        }
        public void TestReusableCells()
        {
            MockCellEntry[] cells =
            {
                new MockCellEntry(typeof(TableViewCellMock1), 10),
                new MockCellEntry(typeof(TableViewCellMock2), 10),
                new MockCellEntry(typeof(TableViewCellMock3), 10),
                new MockCellEntry(typeof(TableViewCellMock1), 10),
                new MockCellEntry(typeof(TableViewCellMock2), 10),
                new MockCellEntry(typeof(TableViewCellMock3), 10),
            };

            TableViewAdapter adapter = new TestCellsHeightTableAdapter(cells);

            TableViewMock table = new TableViewMock(320, 25);
            table.DataSource = adapter;
            table.Delegate = adapter;
            table.ReloadData();

            TableViewCell a1 = table.FirstVisibleCell;
            TableViewCell a2 = a1.NextCell;
            TableViewCell a3 = a2.NextCell;

            Assert.AreEqual(typeof(TableViewCellMock1), a1.GetType());
            Assert.AreEqual(typeof(TableViewCellMock2), a2.GetType());
            Assert.AreEqual(typeof(TableViewCellMock3), a3.GetType());

            table.Scroll(10);

            TableViewCell b1 = table.FirstVisibleCell;
            TableViewCell b2 = b1.NextCell;
            TableViewCell b3 = b2.NextCell;

            Assert.AreSame(a2, b1);
            Assert.AreSame(a3, b2);
            Assert.AreSame(a1, b3);

            table.Scroll(10);

            b1 = table.FirstVisibleCell;
            b2 = b1.NextCell;
            b3 = b2.NextCell;

            Assert.AreSame(a3, b1);
            Assert.AreSame(a1, b2);
            Assert.AreSame(a2, b3);

            table.Scroll(10);

            b1 = table.FirstVisibleCell;
            b2 = b1.NextCell;
            b3 = b2.NextCell;

            Assert.AreSame(a1, b1);
            Assert.AreSame(a2, b2);
            Assert.AreSame(a3, b3);

            table.Scroll(5);

            b1 = table.FirstVisibleCell;
            b2 = b1.NextCell;
            b3 = b2.NextCell;

            Assert.AreSame(a1, b1);
            Assert.AreSame(a2, b2);
            Assert.AreSame(a3, b3);

            table.Scroll(-5);

            b1 = table.FirstVisibleCell;
            b2 = b1.NextCell;
            b3 = b2.NextCell;

            Assert.AreSame(a1, b1);
            Assert.AreSame(a2, b2);
            Assert.AreSame(a3, b3);

            table.Scroll(-10);

            b1 = table.FirstVisibleCell;
            b2 = b1.NextCell;
            b3 = b2.NextCell;

            Assert.AreSame(a3, b1);
            Assert.AreSame(a1, b2);
            Assert.AreSame(a2, b3);

            table.Scroll(-10);

            b1 = table.FirstVisibleCell;
            b2 = b1.NextCell;
            b3 = b2.NextCell;

            Assert.AreSame(a2, b1);
            Assert.AreSame(a3, b2);
            Assert.AreSame(a1, b3);

            table.Scroll(-10);

            b1 = table.FirstVisibleCell;
            b2 = b1.NextCell;
            b3 = b2.NextCell;

            Assert.AreSame(a1, b1);
            Assert.AreSame(a2, b2);
            Assert.AreSame(a3, b3);

            Assert.AreEqual(1, TableViewCellMock1.instanceCount);
            Assert.AreEqual(1, TableViewCellMock2.instanceCount);
            Assert.AreEqual(1, TableViewCellMock3.instanceCount);
        }
예제 #17
0
        public void TestItemsScroll()
        {
            TestCellPredefinedAdapter adapter = new TestCellPredefinedAdapter(new CTableViewCell[0]);

            adapter.Add(new TableViewCellMock(320, 10));
            adapter.Add(new TableViewCellMock(320, 15));
            adapter.Add(new TableViewCellMock(320, 10));
            adapter.Add(new TableViewCellMock(320, 15));
            adapter.Add(new TableViewCellMock(320, 10));
            adapter.Add(new TableViewCellMock(320, 15));

            TableViewMock table = new TableViewMock(320, 30);

            table.DataSource = adapter;
            table.Delegate   = adapter;
            table.ReloadData();

            // scroll forward

            table.ScrollUntilRowVisible(0);
            AssertVisibleRows(table, 0, 1, 2);
            Assert.AreEqual(0, table.ScrollPosTop);
            Assert.AreEqual(30, table.ScrollPosBottom);

            table.ScrollUntilRowVisible(1);
            AssertVisibleRows(table, 0, 1, 2);
            Assert.AreEqual(0, table.ScrollPosTop);
            Assert.AreEqual(30, table.ScrollPosBottom);

            table.ScrollUntilRowVisible(2);
            AssertVisibleRows(table, 0, 1, 2);
            Assert.AreEqual(5, table.ScrollPosTop);
            Assert.AreEqual(35, table.ScrollPosBottom);

            table.ScrollUntilRowVisible(3);
            AssertVisibleRows(table, 1, 2, 3);
            Assert.AreEqual(20, table.ScrollPosTop);
            Assert.AreEqual(50, table.ScrollPosBottom);

            table.ScrollUntilRowVisible(4);
            AssertVisibleRows(table, 2, 3, 4);
            Assert.AreEqual(30, table.ScrollPosTop);
            Assert.AreEqual(60, table.ScrollPosBottom);

            table.ScrollUntilRowVisible(5);
            AssertVisibleRows(table, 3, 4, 5);
            Assert.AreEqual(45, table.ScrollPosTop);
            Assert.AreEqual(75, table.ScrollPosBottom);

            // scroll back

            table.ScrollUntilRowVisible(5);
            AssertVisibleRows(table, 3, 4, 5);
            Assert.AreEqual(45, table.ScrollPosTop);
            Assert.AreEqual(75, table.ScrollPosBottom);

            table.ScrollUntilRowVisible(4);
            AssertVisibleRows(table, 3, 4, 5);
            Assert.AreEqual(45, table.ScrollPosTop);
            Assert.AreEqual(75, table.ScrollPosBottom);

            table.ScrollUntilRowVisible(3);
            AssertVisibleRows(table, 3, 4, 5);
            Assert.AreEqual(35, table.ScrollPosTop);
            Assert.AreEqual(65, table.ScrollPosBottom);

            table.ScrollUntilRowVisible(2);
            AssertVisibleRows(table, 2, 3, 4);
            Assert.AreEqual(25, table.ScrollPosTop);
            Assert.AreEqual(55, table.ScrollPosBottom);

            table.ScrollUntilRowVisible(1);
            AssertVisibleRows(table, 1, 2, 3);
            Assert.AreEqual(10, table.ScrollPosTop);
            Assert.AreEqual(40, table.ScrollPosBottom);

            table.ScrollUntilRowVisible(0);
            AssertVisibleRows(table, 0, 1, 2);
            Assert.AreEqual(0, table.ScrollPosTop);
            Assert.AreEqual(30, table.ScrollPosBottom);
        }
예제 #18
0
        public void TestOverflowNoScrollLock()
        {
            int   capacity    = 7;
            float cellHeight  = 16;
            float tableHeight = 85.5f;

            TestCellCapacityAdapter adapter = new TestCellCapacityAdapter(capacity);

            TableViewMock table = new TableViewMock(capacity, 320, tableHeight);

            table.IsScrollLocked = false;
            table.DataSource     = adapter;
            table.Delegate       = adapter;
            table.ReloadData();

            adapter.Add(new TableViewCell(320, cellHeight)); // 0
            table.ReloadNewData();

            AssertVisibleRows(table, 0);
            Assert.AreEqual(1, table.RowsCount);
            Assert.AreEqual(0, table.ScrollPosTop);
            Assert.AreEqual(0, table.ScrollGUIPosTop);

            adapter.Add(new TableViewCell(320, cellHeight)); // 1
            table.ReloadNewData();

            AssertVisibleRows(table, 0, 1);
            Assert.AreEqual(2, table.RowsCount);
            Assert.AreEqual(0, table.ScrollPosTop);
            Assert.AreEqual(0, table.ScrollGUIPosTop);

            adapter.Add(new TableViewCell(320, cellHeight)); // 2
            table.ReloadNewData();

            AssertVisibleRows(table, 0, 1, 2);
            Assert.AreEqual(3, table.RowsCount);
            Assert.AreEqual(0, table.ScrollPosTop);
            Assert.AreEqual(0, table.ScrollGUIPosTop);

            adapter.Add(new TableViewCell(320, cellHeight)); // 3
            table.ReloadNewData();

            AssertVisibleRows(table, 0, 1, 2, 3);
            Assert.AreEqual(4, table.RowsCount);
            Assert.AreEqual(0, table.ScrollPosTop);
            Assert.AreEqual(0, table.ScrollGUIPosTop);

            adapter.Add(new TableViewCell(320, cellHeight)); // 4
            table.ReloadNewData();

            AssertVisibleRows(table, 0, 1, 2, 3, 4);
            Assert.AreEqual(5, table.RowsCount);
            Assert.AreEqual(0, table.ScrollPosTop);
            Assert.AreEqual(0, table.ScrollGUIPosTop);

            adapter.Add(new TableViewCell(320, cellHeight)); // 5
            table.ReloadNewData();

            AssertVisibleRows(table, 0, 1, 2, 3, 4, 5);
            Assert.AreEqual(6, table.RowsCount);
            Assert.AreEqual(0, table.ScrollPosTop);
            Assert.AreEqual(0, table.ScrollGUIPosTop);

            adapter.Add(new TableViewCell(320, cellHeight)); // 6
            table.ReloadNewData();

            AssertVisibleRows(table, 0, 1, 2, 3, 4, 5);
            Assert.AreEqual(7, table.RowsCount);
            Assert.AreEqual(0, table.ScrollPosTop);
            Assert.AreEqual(0, table.ScrollGUIPosTop);

            adapter.Add(new TableViewCell(320, cellHeight)); // 7
            table.ReloadNewData();

            AssertVisibleRows(table, 1, 2, 3, 4, 5, 6);
            Assert.AreEqual(8, table.RowsCount);
            Assert.AreEqual(cellHeight, table.ScrollPosTop);
            Assert.AreEqual(0, table.ScrollGUIPosTop);

            adapter.Add(new TableViewCell(320, cellHeight)); // 8
            table.ReloadNewData();

            AssertVisibleRows(table, 2, 3, 4, 5, 6, 7);
            Assert.AreEqual(9, table.RowsCount);
            Assert.AreEqual(2 * cellHeight, table.ScrollPosTop);
            Assert.AreEqual(0, table.ScrollGUIPosTop);

            adapter.Add(new TableViewCell(320, cellHeight)); // 9
            table.ReloadNewData();

            AssertVisibleRows(table, 3, 4, 5, 6, 7, 8);
            Assert.AreEqual(10, table.RowsCount);
            Assert.AreEqual(3 * cellHeight, table.ScrollPosTop);
            Assert.AreEqual(0, table.ScrollGUIPosTop);

            adapter.Add(new TableViewCell(320, cellHeight)); // 10
            table.ReloadNewData();

            AssertVisibleRows(table, 4, 5, 6, 7, 8, 9);
            Assert.AreEqual(11, table.RowsCount);
            Assert.AreEqual(4 * cellHeight, table.ScrollPosTop);
            Assert.AreEqual(0, table.ScrollGUIPosTop);

            adapter.Add(new TableViewCell(320, cellHeight)); // 11
            table.ReloadNewData();

            AssertVisibleRows(table, 5, 6, 7, 8, 9, 10);
            Assert.AreEqual(12, table.RowsCount);
            Assert.AreEqual(5 * cellHeight, table.ScrollPosTop);
            Assert.AreEqual(0, table.ScrollGUIPosTop);

            adapter.Add(new TableViewCell(320, cellHeight)); // 12
            table.ReloadNewData();

            AssertVisibleRows(table, 6, 7, 8, 9, 10, 11);
            Assert.AreEqual(13, table.RowsCount);
            Assert.AreEqual(6 * cellHeight, table.ScrollPosTop);
            Assert.AreEqual(0, table.ScrollGUIPosTop);

            adapter.Add(new TableViewCell(320, cellHeight)); // 13
            table.ReloadNewData();

            AssertVisibleRows(table, 7, 8, 9, 10, 11, 12);
            Assert.AreEqual(14, table.RowsCount);
            Assert.AreEqual(7 * cellHeight, table.ScrollPosTop);
            Assert.AreEqual(0, table.ScrollGUIPosTop);

            adapter.Add(new TableViewCell(320, cellHeight)); // 14
            table.ReloadNewData();

            AssertVisibleRows(table, 8, 9, 10, 11, 12, 13);
            Assert.AreEqual(15, table.RowsCount);
            Assert.AreEqual(8 * cellHeight, table.ScrollPosTop);
            Assert.AreEqual(0, table.ScrollGUIPosTop);

            adapter.Add(new TableViewCell(320, cellHeight)); // 15
            table.ReloadNewData();

            AssertVisibleRows(table, 9, 10, 11, 12, 13, 14);
            Assert.AreEqual(16, table.RowsCount);
            Assert.AreEqual(9 * cellHeight, table.ScrollPosTop);
            Assert.AreEqual(0, table.ScrollGUIPosTop);
        }
        public void TestResizeChangeHeight()
        {
            TableViewAdapter adapter = new TestCellsHeightTableAdapter(new MockCellEntry[] {
                new MockCellEntry(typeof(TableViewCellMock), 10),
                new MockCellEntry(typeof(TableViewCellMock), 15),
                new MockCellEntry(typeof(TableViewCellMock), 10),
                new MockCellEntry(typeof(TableViewCellMock), 15),
                new MockCellEntry(typeof(TableViewCellMock), 10),
                new MockCellEntry(typeof(TableViewCellMock), 15)
            });

            TableViewMock table = new TableViewMock(320, 30);
            table.DataSource = adapter;
            table.Delegate = adapter;
            table.ReloadData();

            Assert.AreEqual(0, table.FirstVisibleCellIndex);
            Assert.AreEqual(2, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 0, 1, 2);

            table.Resize(320, 35);

            AssertVisibleRows(table, 0, 1, 2);

            table.Resize(320, 45);

            AssertVisibleRows(table, 0, 1, 2, 3);

            table.Resize(320, 55);

            AssertVisibleRows(table, 0, 1, 2, 3, 4);

            table.Resize(320, 65);

            AssertVisibleRows(table, 0, 1, 2, 3, 4, 5);

            table.Resize(320, 75);

            AssertVisibleRows(table, 0, 1, 2, 3, 4, 5);

            table.Resize(320, 80);

            AssertVisibleRows(table, 0, 1, 2, 3, 4, 5);

            table.Resize(320, 85);

            AssertVisibleRows(table, 0, 1, 2, 3, 4, 5);

            table.Resize(320, 80);

            AssertVisibleRows(table, 0, 1, 2, 3, 4, 5);

            table.Resize(320, 75);

            AssertVisibleRows(table, 0, 1, 2, 3, 4, 5);

            table.Resize(320, 65);

            AssertVisibleRows(table, 0, 1, 2, 3, 4, 5);

            table.Resize(320, 55);

            AssertVisibleRows(table, 0, 1, 2, 3, 4);

            table.Resize(320, 45);

            AssertVisibleRows(table, 0, 1, 2, 3);

            table.Resize(320, 35);

            AssertVisibleRows(table, 0, 1, 2);

            table.Resize(320, 30);

            AssertVisibleRows(table, 0, 1, 2);

            table.Resize(320, 25);

            AssertVisibleRows(table, 0, 1);

            table.Resize(320, 20);

            AssertVisibleRows(table, 0, 1);

            table.Resize(320, 10);

            AssertVisibleRows(table, 0);

            table.Resize(320, 5);

            AssertVisibleRows(table, 0);

            table.Resize(320, 0);

            AssertVisibleRows(table, new int[0]);
        }
        public void TestItemsScroll()
        {
            TestCellPredefinedAdapter adapter = new TestCellPredefinedAdapter(new TableViewCell[0]);
            adapter.Add(new TableViewCellMock(320, 10));
            adapter.Add(new TableViewCellMock(320, 15));
            adapter.Add(new TableViewCellMock(320, 10));
            adapter.Add(new TableViewCellMock(320, 15));
            adapter.Add(new TableViewCellMock(320, 10));
            adapter.Add(new TableViewCellMock(320, 15));

            TableViewMock table = new TableViewMock(320, 30);
            table.DataSource = adapter;
            table.Delegate = adapter;
            table.ReloadData();

            // scroll forward

            table.ScrollUntilRowVisible(0);
            AssertVisibleRows(table, 0, 1, 2);
            Assert.AreEqual(0, table.ScrollPosTop);
            Assert.AreEqual(30, table.ScrollPosBottom);

            table.ScrollUntilRowVisible(1);
            AssertVisibleRows(table, 0, 1, 2);
            Assert.AreEqual(0, table.ScrollPosTop);
            Assert.AreEqual(30, table.ScrollPosBottom);

            table.ScrollUntilRowVisible(2);
            AssertVisibleRows(table, 0, 1, 2);
            Assert.AreEqual(5, table.ScrollPosTop);
            Assert.AreEqual(35, table.ScrollPosBottom);

            table.ScrollUntilRowVisible(3);
            AssertVisibleRows(table, 1, 2, 3);
            Assert.AreEqual(20, table.ScrollPosTop);
            Assert.AreEqual(50, table.ScrollPosBottom);

            table.ScrollUntilRowVisible(4);
            AssertVisibleRows(table, 2, 3, 4);
            Assert.AreEqual(30, table.ScrollPosTop);
            Assert.AreEqual(60, table.ScrollPosBottom);

            table.ScrollUntilRowVisible(5);
            AssertVisibleRows(table, 3, 4, 5);
            Assert.AreEqual(45, table.ScrollPosTop);
            Assert.AreEqual(75, table.ScrollPosBottom);

            // scroll back

            table.ScrollUntilRowVisible(5);
            AssertVisibleRows(table, 3, 4, 5);
            Assert.AreEqual(45, table.ScrollPosTop);
            Assert.AreEqual(75, table.ScrollPosBottom);

            table.ScrollUntilRowVisible(4);
            AssertVisibleRows(table, 3, 4, 5);
            Assert.AreEqual(45, table.ScrollPosTop);
            Assert.AreEqual(75, table.ScrollPosBottom);

            table.ScrollUntilRowVisible(3);
            AssertVisibleRows(table, 3, 4, 5);
            Assert.AreEqual(35, table.ScrollPosTop);
            Assert.AreEqual(65, table.ScrollPosBottom);

            table.ScrollUntilRowVisible(2);
            AssertVisibleRows(table, 2, 3, 4);
            Assert.AreEqual(25, table.ScrollPosTop);
            Assert.AreEqual(55, table.ScrollPosBottom);

            table.ScrollUntilRowVisible(1);
            AssertVisibleRows(table, 1, 2, 3);
            Assert.AreEqual(10, table.ScrollPosTop);
            Assert.AreEqual(40, table.ScrollPosBottom);

            table.ScrollUntilRowVisible(0);
            AssertVisibleRows(table, 0, 1, 2);
            Assert.AreEqual(0, table.ScrollPosTop);
            Assert.AreEqual(30, table.ScrollPosBottom);
        }
        public void TestAddTwoRows()
        {
            TableViewMock table = new TableViewMock(320, 15);
            TableViewCell a1 = new TableViewCellMock1(table.Width, 10);
            TableViewCell a2 = new TableViewCellMock2(table.Width, 15);

            TestCellPredefinedAdapter adapter = new TestCellPredefinedAdapter(new TableViewCell[] { a1 });

            table.DataSource = adapter;
            table.Delegate = adapter;
            table.ReloadData();

            adapter.Add(a2);
            table.ReloadNewData();

            TableViewCell b1 = table.FirstVisibleCell;
            TableViewCell b2 = b1.NextCell;

            Assert.AreSame(a1, b1);
            Assert.AreSame(a2, b2);
            AssertVisibleRows(table, 0, 1);
        }
        public void TestVisibleRowsScroll()
        {
            MockCellEntry[] cells = new MockCellEntry[10];
            for (int i = 0; i < cells.Length; ++i)
            {
                cells[i] = new MockCellEntry(typeof(TableViewCellMock), i % 2 == 0 ? 10 : 15);
            }

            TableViewAdapter adapter = new TestCellsHeightTableAdapter(cells);

            TableViewMock table = new TableViewMock(320, 15);

            table.DataSource = adapter;
            table.Delegate   = adapter;
            table.ReloadData();

            Assert.AreEqual(0, table.FirstVisibleCellIndex);
            Assert.AreEqual(1, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 0, 1);

            table.Scroll(10);
            Assert.AreEqual(1, table.FirstVisibleCellIndex);
            Assert.AreEqual(1, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 1);

            table.Scroll(10);
            Assert.AreEqual(1, table.FirstVisibleCellIndex);
            Assert.AreEqual(2, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 1, 2);

            table.Scroll(10);
            Assert.AreEqual(2, table.FirstVisibleCellIndex);
            Assert.AreEqual(3, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 2, 3);

            table.Scroll(10);
            Assert.AreEqual(3, table.FirstVisibleCellIndex);
            Assert.AreEqual(4, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 3, 4);

            table.Scroll(10);
            Assert.AreEqual(4, table.FirstVisibleCellIndex);
            Assert.AreEqual(5, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 4, 5);

            table.Scroll(10);
            Assert.AreEqual(5, table.FirstVisibleCellIndex);
            Assert.AreEqual(5, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 5);

            table.Scroll(10);
            Assert.AreEqual(5, table.FirstVisibleCellIndex);
            Assert.AreEqual(6, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 5, 6);

            table.Scroll(10);
            Assert.AreEqual(6, table.FirstVisibleCellIndex);
            Assert.AreEqual(7, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 6, 7);

            table.Scroll(10);
            Assert.AreEqual(7, table.FirstVisibleCellIndex);
            Assert.AreEqual(8, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 7, 8);

            table.Scroll(10);
            Assert.AreEqual(8, table.FirstVisibleCellIndex);
            Assert.AreEqual(9, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 8, 9);

            table.Scroll(10);
            Assert.AreEqual(9, table.FirstVisibleCellIndex);
            Assert.AreEqual(9, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 9);

            table.Scroll(-10);
            Assert.AreEqual(8, table.FirstVisibleCellIndex);
            Assert.AreEqual(9, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 8, 9);

            table.Scroll(-10);
            Assert.AreEqual(7, table.FirstVisibleCellIndex);
            Assert.AreEqual(8, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 7, 8);

            table.Scroll(-10);
            Assert.AreEqual(6, table.FirstVisibleCellIndex);
            Assert.AreEqual(7, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 6, 7);

            table.Scroll(-10);
            Assert.AreEqual(5, table.FirstVisibleCellIndex);
            Assert.AreEqual(6, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 5, 6);

            table.Scroll(-10);
            Assert.AreEqual(5, table.FirstVisibleCellIndex);
            Assert.AreEqual(5, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 5);

            table.Scroll(-10);
            Assert.AreEqual(4, table.FirstVisibleCellIndex);
            Assert.AreEqual(5, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 4, 5);

            table.Scroll(-10);
            Assert.AreEqual(3, table.FirstVisibleCellIndex);
            Assert.AreEqual(4, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 3, 4);

            table.Scroll(-10);
            Assert.AreEqual(2, table.FirstVisibleCellIndex);
            Assert.AreEqual(3, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 2, 3);

            table.Scroll(-10);
            Assert.AreEqual(1, table.FirstVisibleCellIndex);
            Assert.AreEqual(2, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 1, 2);

            table.Scroll(-10);
            Assert.AreEqual(1, table.FirstVisibleCellIndex);
            Assert.AreEqual(1, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 1);

            table.Scroll(-10);
            Assert.AreEqual(0, table.FirstVisibleCellIndex);
            Assert.AreEqual(1, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 0, 1);
        }
        public void TestResizeChangeWidth()
        {
            MockCellEntry[] entries = new MockCellEntry[]
            {
                new MockCellEntry(typeof(TableViewCellMock), 10),
                new MockCellEntry(typeof(TableViewCellMock), 15),
                new MockCellEntry(typeof(TableViewCellMock), 10),
                new MockCellEntry(typeof(TableViewCellMock), 15),
                new MockCellEntry(typeof(TableViewCellMock), 10),
                new MockCellEntry(typeof(TableViewCellMock), 15)
            };

            TableViewAdapter adapter = new TestCellsHeightTableAdapter(entries);

            TableViewMock table = new TableViewMock(320, 60);
            table.DataSource = adapter;
            table.Delegate = adapter;
            table.ReloadData();

            // descrease width
            for (int i = 0; i < entries.Length; ++i)
            {
                if (entries[i].height == 10)
                {
                    entries[i].height = 20;
                }
            }
            table.Resize(300, 60);

            AssertVisibleRows(table, 1, 2, 3, 4);
            Assert.AreEqual(30, table.ScrollPosTop);
            Assert.AreEqual(90, table.ScrollPosBottom);

            // increase width
            for (int i = 0; i < entries.Length; ++i)
            {
                if (entries[i].height == 20)
                {
                    entries[i].height = 10;
                }
            }
            table.Resize(320, 60);

            AssertVisibleRows(table, 0, 1, 2, 3, 4);
            Assert.AreEqual(0, table.ScrollPosTop);
            Assert.AreEqual(60, table.ScrollPosBottom);
        }
        public void TestVisibleRowsBigScroll()
        {
            MockCellEntry[] cells = new MockCellEntry[10];
            for (int i = 0; i < cells.Length; ++i)
            {
                cells[i] = new MockCellEntry(typeof(TableViewCellMock), 10);
            }

            TableViewAdapter adapter = new TestCellsHeightTableAdapter(cells);

            TableViewMock table = new TableViewMock(320, 50);
            table.DataSource = adapter;
            table.Delegate = adapter;
            table.ReloadData();

            table.Scroll(50);
            Assert.AreEqual(5, table.FirstVisibleCellIndex);
            Assert.AreEqual(9, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 5, 6, 7, 8, 9);

            table.Scroll(-50);
            Assert.AreEqual(0, table.FirstVisibleCellIndex);
            Assert.AreEqual(4, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 0, 1, 2, 3, 4);
        }
        public void TestOverflowNoScrollLock()
        {
            int capacity = 7;
            float cellHeight = 16;
            float tableHeight = 85.5f;

            TestCellCapacityAdapter adapter = new TestCellCapacityAdapter(capacity);

            TableViewMock table = new TableViewMock(capacity, 320, tableHeight);
            table.IsScrollLocked = false;
            table.DataSource = adapter;
            table.Delegate = adapter;
            table.ReloadData();

            adapter.Add(new TableViewCell(320, cellHeight)); // 0
            table.ReloadNewData();

            AssertVisibleRows(table, 0);
            Assert.AreEqual(1, table.RowsCount);
            Assert.AreEqual(0, table.ScrollPosTop);
            Assert.AreEqual(0, table.ScrollGUIPosTop);

            adapter.Add(new TableViewCell(320, cellHeight)); // 1
            table.ReloadNewData();

            AssertVisibleRows(table, 0, 1);
            Assert.AreEqual(2, table.RowsCount);
            Assert.AreEqual(0, table.ScrollPosTop);
            Assert.AreEqual(0, table.ScrollGUIPosTop);

            adapter.Add(new TableViewCell(320, cellHeight)); // 2
            table.ReloadNewData();

            AssertVisibleRows(table, 0, 1, 2);
            Assert.AreEqual(3, table.RowsCount);
            Assert.AreEqual(0, table.ScrollPosTop);
            Assert.AreEqual(0, table.ScrollGUIPosTop);

            adapter.Add(new TableViewCell(320, cellHeight)); // 3
            table.ReloadNewData();

            AssertVisibleRows(table, 0, 1, 2, 3);
            Assert.AreEqual(4, table.RowsCount);
            Assert.AreEqual(0, table.ScrollPosTop);
            Assert.AreEqual(0, table.ScrollGUIPosTop);

            adapter.Add(new TableViewCell(320, cellHeight)); // 4
            table.ReloadNewData();

            AssertVisibleRows(table, 0, 1, 2, 3, 4);
            Assert.AreEqual(5, table.RowsCount);
            Assert.AreEqual(0, table.ScrollPosTop);
            Assert.AreEqual(0, table.ScrollGUIPosTop);

            adapter.Add(new TableViewCell(320, cellHeight)); // 5
            table.ReloadNewData();

            AssertVisibleRows(table, 0, 1, 2, 3, 4, 5);
            Assert.AreEqual(6, table.RowsCount);
            Assert.AreEqual(0, table.ScrollPosTop);
            Assert.AreEqual(0, table.ScrollGUIPosTop);

            adapter.Add(new TableViewCell(320, cellHeight)); // 6
            table.ReloadNewData();

            AssertVisibleRows(table, 0, 1, 2, 3, 4, 5);
            Assert.AreEqual(7, table.RowsCount);
            Assert.AreEqual(0, table.ScrollPosTop);
            Assert.AreEqual(0, table.ScrollGUIPosTop);

            adapter.Add(new TableViewCell(320, cellHeight)); // 7
            table.ReloadNewData();

            AssertVisibleRows(table, 1, 2, 3, 4, 5, 6);
            Assert.AreEqual(8, table.RowsCount);
            Assert.AreEqual(cellHeight, table.ScrollPosTop);
            Assert.AreEqual(0, table.ScrollGUIPosTop);

            adapter.Add(new TableViewCell(320, cellHeight)); // 8
            table.ReloadNewData();

            AssertVisibleRows(table, 2, 3, 4, 5, 6, 7);
            Assert.AreEqual(9, table.RowsCount);
            Assert.AreEqual(2 * cellHeight, table.ScrollPosTop);
            Assert.AreEqual(0, table.ScrollGUIPosTop);

            adapter.Add(new TableViewCell(320, cellHeight)); // 9
            table.ReloadNewData();

            AssertVisibleRows(table, 3, 4, 5, 6, 7, 8);
            Assert.AreEqual(10, table.RowsCount);
            Assert.AreEqual(3 * cellHeight, table.ScrollPosTop);
            Assert.AreEqual(0, table.ScrollGUIPosTop);

            adapter.Add(new TableViewCell(320, cellHeight)); // 10
            table.ReloadNewData();

            AssertVisibleRows(table, 4, 5, 6, 7, 8, 9);
            Assert.AreEqual(11, table.RowsCount);
            Assert.AreEqual(4 * cellHeight, table.ScrollPosTop);
            Assert.AreEqual(0, table.ScrollGUIPosTop);

            adapter.Add(new TableViewCell(320, cellHeight)); // 11
            table.ReloadNewData();

            AssertVisibleRows(table, 5, 6, 7, 8, 9, 10);
            Assert.AreEqual(12, table.RowsCount);
            Assert.AreEqual(5 * cellHeight, table.ScrollPosTop);
            Assert.AreEqual(0, table.ScrollGUIPosTop);

            adapter.Add(new TableViewCell(320, cellHeight)); // 12
            table.ReloadNewData();

            AssertVisibleRows(table, 6, 7, 8, 9, 10, 11);
            Assert.AreEqual(13, table.RowsCount);
            Assert.AreEqual(6 * cellHeight, table.ScrollPosTop);
            Assert.AreEqual(0, table.ScrollGUIPosTop);

            adapter.Add(new TableViewCell(320, cellHeight)); // 13
            table.ReloadNewData();

            AssertVisibleRows(table, 7, 8, 9, 10, 11, 12);
            Assert.AreEqual(14, table.RowsCount);
            Assert.AreEqual(7 * cellHeight, table.ScrollPosTop);
            Assert.AreEqual(0, table.ScrollGUIPosTop);

            adapter.Add(new TableViewCell(320, cellHeight)); // 14
            table.ReloadNewData();

            AssertVisibleRows(table, 8, 9, 10, 11, 12, 13);
            Assert.AreEqual(15, table.RowsCount);
            Assert.AreEqual(8 * cellHeight, table.ScrollPosTop);
            Assert.AreEqual(0, table.ScrollGUIPosTop);

            adapter.Add(new TableViewCell(320, cellHeight)); // 15
            table.ReloadNewData();

            AssertVisibleRows(table, 9, 10, 11, 12, 13, 14);
            Assert.AreEqual(16, table.RowsCount);
            Assert.AreEqual(9 * cellHeight, table.ScrollPosTop);
            Assert.AreEqual(0, table.ScrollGUIPosTop);
        }
예제 #26
0
        public void TestResizeChangeHeight()
        {
            TableViewAdapter adapter = new TestCellsHeightTableAdapter(new MockCellEntry[] {
                new MockCellEntry(typeof(TableViewCellMock), 10),
                new MockCellEntry(typeof(TableViewCellMock), 15),
                new MockCellEntry(typeof(TableViewCellMock), 10),
                new MockCellEntry(typeof(TableViewCellMock), 15),
                new MockCellEntry(typeof(TableViewCellMock), 10),
                new MockCellEntry(typeof(TableViewCellMock), 15)
            });

            TableViewMock table = new TableViewMock(320, 30);

            table.DataSource = adapter;
            table.Delegate   = adapter;
            table.ReloadData();

            Assert.AreEqual(0, table.FirstVisibleCellIndex);
            Assert.AreEqual(2, table.LastVisibleCellIndex);
            AssertVisibleRows(table, 0, 1, 2);

            table.Resize(320, 35);

            AssertVisibleRows(table, 0, 1, 2);

            table.Resize(320, 45);

            AssertVisibleRows(table, 0, 1, 2, 3);

            table.Resize(320, 55);

            AssertVisibleRows(table, 0, 1, 2, 3, 4);

            table.Resize(320, 65);

            AssertVisibleRows(table, 0, 1, 2, 3, 4, 5);

            table.Resize(320, 75);

            AssertVisibleRows(table, 0, 1, 2, 3, 4, 5);

            table.Resize(320, 80);

            AssertVisibleRows(table, 0, 1, 2, 3, 4, 5);

            table.Resize(320, 85);

            AssertVisibleRows(table, 0, 1, 2, 3, 4, 5);

            table.Resize(320, 80);

            AssertVisibleRows(table, 0, 1, 2, 3, 4, 5);

            table.Resize(320, 75);

            AssertVisibleRows(table, 0, 1, 2, 3, 4, 5);

            table.Resize(320, 65);

            AssertVisibleRows(table, 0, 1, 2, 3, 4, 5);

            table.Resize(320, 55);

            AssertVisibleRows(table, 0, 1, 2, 3, 4);

            table.Resize(320, 45);

            AssertVisibleRows(table, 0, 1, 2, 3);

            table.Resize(320, 35);

            AssertVisibleRows(table, 0, 1, 2);

            table.Resize(320, 30);

            AssertVisibleRows(table, 0, 1, 2);

            table.Resize(320, 25);

            AssertVisibleRows(table, 0, 1);

            table.Resize(320, 20);

            AssertVisibleRows(table, 0, 1);

            table.Resize(320, 10);

            AssertVisibleRows(table, 0);

            table.Resize(320, 5);

            AssertVisibleRows(table, 0);

            table.Resize(320, 0);

            AssertVisibleRows(table, new int[0]);
        }