00001
00002
00003
00004
00005
00006
00007
00008 #ifndef TESTTABLEDATAVIEW_H
00009 #define TESTTABLEDATAVIEW_H
00010
00011 #define BOOST_TEST_MODULE MediaTableTestSuite
00012 #include "boost/test/unit_test.hpp"
00013
00014 #include "../TableDataView.h"
00015
00016 typedef Impala::Application::MediaTable::TableDataView TableDataView;
00017 typedef TableDataSourceTests::TableDataSourceFixture TableDataSourceFixture;
00018
00019 BOOST_AUTO_TEST_SUITE( TableDataViewTests )
00020
00021 struct TableDataViewFixture : public TableDataSourceFixture {
00022 TableDataViewFixture() {view = new TableDataView(src);
00023 }
00024 ~TableDataViewFixture() {}
00025
00026 TableDataView* view;
00027 };
00028
00029 void IsValidTableDataViewTest(TableDataView* view) {
00030 BOOST_REQUIRE(view);
00031
00032 BOOST_WARN_GT(view->GetTotalRows(), 0);
00033
00034 BOOST_WARN_GT(view->GetFilteredRows(), 0);
00035
00036 BOOST_CHECK_GT(view->GetSortColumn().length(), 0);
00037
00038 BOOST_CHECK_NE(view->GetID(0), -1);
00039
00040 for(int i=0; i < view->GetTotalRows(); i++) {
00041 BOOST_CHECK_EQUAL(view->GetRowForID(view->GetID(i)), i);
00042 }
00043 }
00044
00045 BOOST_FIXTURE_TEST_CASE(TableDataViewTestCase, TableDataViewFixture) {
00046 IsValidTableDataViewTest(view);
00047 for(int i=0; i < view->GetTotalRows(); i++) {
00048 BOOST_CHECK_EQUAL(view->GetSortedIntData("id", i), i);
00049 BOOST_CHECK_EQUAL(view->GetSortedNormalizedData("red", i), i/(double)view->GetTotalRows());
00050 BOOST_CHECK_EQUAL(view->GetSortedNormalizedData("green", i), 1.0-view->GetSortedNormalizedData("red", i));
00051 BOOST_CHECK_EQUAL(view->GetSortedNormalizedData("blue", i), i%10 / 10.0);
00052 }
00053 view->SetSortColumn("red");
00054 for(int i=0; i < view->GetTotalRows(); i++) {
00055 BOOST_CHECK_EQUAL(view->GetSortedIntData("id", view->GetTotalRows()-1-i), i);
00056 BOOST_CHECK_EQUAL(view->GetSortedNormalizedData("red", view->GetTotalRows()-1-i), i/(double)view->GetTotalRows());
00057 BOOST_CHECK_EQUAL(view->GetSortedNormalizedData("green", view->GetTotalRows()-1-i), 1.0-view->GetSortedNormalizedData("red", view->GetTotalRows()-1-i));
00058 BOOST_CHECK_EQUAL(view->GetSortedNormalizedData("blue", view->GetTotalRows()-1-i), i%10 / 10.0);
00059 }
00060 view->SetSortColumn("red", false);
00061 for(int i=0; i < view->GetTotalRows(); i++) {
00062 BOOST_CHECK_EQUAL(view->GetSortedIntData("id", i), i);
00063 BOOST_CHECK_EQUAL(view->GetSortedNormalizedData("red", i), i/(double)view->GetTotalRows());
00064 BOOST_CHECK_EQUAL(view->GetSortedNormalizedData("green", i), 1.0-view->GetSortedNormalizedData("red", i));
00065 BOOST_CHECK_EQUAL(view->GetSortedNormalizedData("blue", i), i%10 / 10.0);
00066 }
00067 view->SetSortColumn("blue", false);
00068 for(int i=0; i < view->GetTotalRows(); i++) {
00069 BOOST_CHECK_EQUAL(view->GetSortedNormalizedData("green", i), 1.0-view->GetSortedNormalizedData("red", i));
00070 }
00071 }
00072
00073 BOOST_AUTO_TEST_SUITE_END()
00074
00075 #endif