00001
00002
00003
00004
00005
00006
00007 #ifndef testTableDataSourceCombinedViews_h
00008 #define testTableDataSourceCombinedViews_h
00009
00010
00011 #define BOOST_TEST_MODULE MediaTableTestSuite
00012 #include "boost/test/unit_test.hpp"
00013
00014 #include "testTableDataSource.h"
00015 #include "testTableDataView.h"
00016 #include "../TableDataSource.h"
00017 #include "../TableDataSourceCombinedViews.h"
00018
00019 typedef Impala::Application::MediaTable::TableDataSource TableDataSource;
00020 typedef Impala::Application::MediaTable::TableDataSourceCombinedViews TableDataSourceCombinedViews;
00021
00022 class AlternativeTableDataSourceTest : public TableDataSource {
00023
00024 public:
00025 AlternativeTableDataSourceTest(): TableDataSource()
00026 {
00027 Init();
00028 }
00029
00030 int GetTotalRows() {
00031 return mTotalRows;
00032 }
00033
00034
00035 virtual int
00036 GetIntDataByID(String column, int row)
00037 {
00038 if (column == "id")
00039 return row;
00040 return 0;
00041 }
00042
00043 virtual double
00044 GetNormalizedDataByID(String column, int row)
00045 {
00046 double v = row / (double)mTotalRows;
00047 if (column == "purple")
00048 return v;
00049 if (column == "orange")
00050 return 1.0 - v;
00051 if (column == "yellow") {
00052 return (row % 10) / 10.0;
00053 }
00054 return 0.0;
00055 }
00056
00057 private:
00058
00059 void Init()
00060 {
00061 mTotalRows = 50;
00062
00063 AddStaticColumn("id", TYPE_INT, 50);
00064
00065 AddColumn("yellow", TYPE_NORMALIZEDVALUE, 50, 1);
00066 AddColumn("orange", TYPE_NORMALIZEDVALUE, 50, 2);
00067 AddColumn("purple", TYPE_NORMALIZEDVALUE, 50, 3);
00068 }
00069
00070 int mTotalRows;
00071 };
00072
00073 BOOST_AUTO_TEST_SUITE( TableDataSourceCombinedViewsTests )
00074
00075 struct TableDataSourceCombinedViewsFixture : public TableDataViewTests::TableDataViewFixture {
00076 TableDataSourceCombinedViewsFixture() {
00077 asrc = new AlternativeTableDataSourceTest();
00078 aview = new TableDataView(asrc);
00079 }
00080
00081 TableDataSourceCombinedViewsFixture(TableDataView* v) {
00082 aview = v;
00083 }
00084
00085 ~TableDataSourceCombinedViewsFixture() {}
00086
00087 TableDataSource* asrc;
00088 TableDataView* aview;
00089 };
00090
00091 BOOST_FIXTURE_TEST_CASE(TableDataSourceCombinedViewsTestCase, TableDataSourceCombinedViewsFixture) {
00092 TableDataSourceTests::IsValidTableDataSourceTest(src);
00093 TableDataSourceTests::IsValidTableDataSourceTest(asrc);
00094 TableDataViewTests::IsValidTableDataViewTest(view);
00095 TableDataViewTests::IsValidTableDataViewTest(aview);
00096
00097 TableDataSourceCombinedViews* csrc = new TableDataSourceCombinedViews();
00098 TableDataViewTests::IsValidTableDataViewTest(view);
00099
00100 BOOST_CHECK_EQUAL(csrc->GetTotalRows(), 0);
00101 BOOST_CHECK_EQUAL(csrc->GetColumns(true, true).size(), 0);
00102
00103 BOOST_CHECK(!csrc->AddTableDataView(view));
00104 BOOST_CHECK_EQUAL(csrc->GetTotalRows(), 0);
00105 BOOST_CHECK_EQUAL(csrc->GetColumns(true, true).size(), 0);
00106
00107 BOOST_CHECK(csrc->AddTableDataView(view, "id"));
00108 BOOST_CHECK_EQUAL(csrc->GetTotalRows(), view->GetTotalRows());
00109 BOOST_CHECK_EQUAL(csrc->GetColumns(true, true).size(), view->GetColumns(true,true).size());
00110 BOOST_CHECK_GT(csrc->GetColumns(true, true).size(), 0);
00111
00112 BOOST_REQUIRE_EQUAL(csrc->GetTotalRows(), aview->GetTotalRows());
00113
00114 BOOST_CHECK(csrc->AddTableDataView(aview));
00115 BOOST_CHECK_EQUAL(csrc->GetTotalRows(), view->GetTotalRows());
00116 BOOST_CHECK_EQUAL(csrc->GetTotalRows(), aview->GetTotalRows());
00117 BOOST_CHECK_EQUAL(csrc->GetColumns(true, true).size(), view->GetColumns(true,true).size()+aview->GetColumns(true,true).size()-1);
00118 BOOST_CHECK_GT(csrc->GetColumns(true, true).size(), 0);
00119
00120 TableDataView* cview = new TableDataView(csrc);
00121 BOOST_REQUIRE(cview);
00122 TableDataViewTests::IsValidTableDataViewTest(cview);
00123 BOOST_CHECK_GT(cview->GetColumns(true, true).size(), 0);
00124 BOOST_WARN_GT(cview->GetColumns(true, false).size(), 0);
00125
00126 cview->SetSortColumn("id");
00127 for(int i=0; i < cview->GetTotalRows(); i++) {
00128 BOOST_CHECK_EQUAL(cview->GetSortedIntData("id", i), i);
00129 BOOST_CHECK_EQUAL(cview->GetSortedNormalizedData("red", i), cview->GetSortedNormalizedData("purple", i));
00130 BOOST_CHECK_EQUAL(cview->GetSortedNormalizedData("green", i), cview->GetSortedNormalizedData("orange", i));
00131 BOOST_CHECK_EQUAL(cview->GetSortedNormalizedData("blue", i), cview->GetSortedNormalizedData("yellow", i));
00132 }
00133 cview->SetSortColumn("red", false);
00134 for(int i=0; i < cview->GetTotalRows(); i++) {
00135 BOOST_CHECK_EQUAL(cview->GetSortedIntData("id", i), i);
00136 BOOST_CHECK_EQUAL(cview->GetSortedNormalizedData("red", i), cview->GetSortedNormalizedData("purple", i));
00137 BOOST_CHECK_EQUAL(cview->GetSortedNormalizedData("green", i), cview->GetSortedNormalizedData("orange", i));
00138 BOOST_CHECK_EQUAL(cview->GetSortedNormalizedData("blue", i), cview->GetSortedNormalizedData("yellow", i));
00139 }
00140 cview->SetSortColumn("purple", false);
00141 for(int i=0; i < cview->GetTotalRows(); i++) {
00142 BOOST_CHECK_EQUAL(cview->GetSortedIntData("id", i), i);
00143 BOOST_CHECK_EQUAL(cview->GetSortedNormalizedData("red", i), cview->GetSortedNormalizedData("purple", i));
00144 BOOST_CHECK_EQUAL(cview->GetSortedNormalizedData("green", i), cview->GetSortedNormalizedData("orange", i));
00145 BOOST_CHECK_EQUAL(cview->GetSortedNormalizedData("blue", i), cview->GetSortedNormalizedData("yellow", i));
00146 }
00147 cview->SetSortColumn("orange", false);
00148 double last = 0;
00149 for(int i=0; i < cview->GetTotalRows(); i++) {
00150 BOOST_CHECK_EQUAL(cview->GetSortedNormalizedData("red", i), cview->GetSortedNormalizedData("purple", i));
00151 BOOST_CHECK_EQUAL(cview->GetSortedNormalizedData("green", i), cview->GetSortedNormalizedData("orange", i));
00152 BOOST_CHECK_EQUAL(cview->GetSortedNormalizedData("blue", i), cview->GetSortedNormalizedData("yellow", i));
00153 BOOST_CHECK_GE(cview->GetSortedNormalizedData("green", i), last);
00154 last = cview->GetSortedNormalizedData("green", i);
00155 }
00156 }
00157
00158 BOOST_AUTO_TEST_SUITE_END()
00159
00160 #endif // testTableDataSourceCombinedViews_h