00001
00002
00003
00004
00005
00006
00007 #ifndef testTableDataSource_h
00008 #define testTableDataSource_h
00009
00010
00011 #define BOOST_TEST_MODULE MediaTableTestSuite
00012 #include "boost/test/unit_test.hpp"
00013
00014 #include "../TableDataSource.h"
00015
00016 typedef Impala::Application::MediaTable::TableDataSource TableDataSource;
00017 typedef Impala::String String;
00018
00019 class TableDataSourceTest : public TableDataSource {
00020
00021 public:
00022 TableDataSourceTest(): TableDataSource()
00023 {
00024 Init();
00025 }
00026
00027 int GetTotalRows() {
00028 return mTotalRows;
00029 }
00030
00031
00032 virtual int
00033 GetIntDataByID(String column, int row)
00034 {
00035 if (column == "id")
00036 return row;
00037 return 0;
00038 }
00039
00040 virtual double
00041 GetNormalizedDataByID(String column, int row)
00042 {
00043 double v = row / (double)mTotalRows;
00044 if (column == "red")
00045 return v;
00046 if (column == "green")
00047 return 1.0 - v;
00048 if (column == "blue") {
00049 return (row % 10) / 10.0;
00050 }
00051 return 0.0;
00052 }
00053
00054 private:
00055
00056 void Init()
00057 {
00058 mTotalRows = 50;
00059
00060 AddStaticColumn("id", TYPE_INT, 50);
00061
00062 AddColumn("red", TYPE_NORMALIZEDVALUE, 50, 1);
00063 AddColumn("green", TYPE_NORMALIZEDVALUE, 50, 2);
00064 AddColumn("blue", TYPE_NORMALIZEDVALUE, 50, 3);
00065 }
00066
00067 int mTotalRows;
00068 };
00069
00070 BOOST_AUTO_TEST_SUITE( TableDataSourceTests )
00071
00072 struct TableDataSourceFixture {
00073 TableDataSourceFixture() {
00074 src = new TableDataSourceTest();
00075 }
00076
00077 TableDataSourceFixture(TableDataSource* s) {
00078 src = s;
00079 }
00080
00081 ~TableDataSourceFixture() {}
00082
00083 TableDataSource* src;
00084 };
00085
00086 void IsValidTableDataSourceTest(TableDataSource* src) {
00087 BOOST_REQUIRE(src);
00088 BOOST_CHECK_GT(src->GetTotalRows(), 0);
00089
00090 BOOST_CHECK_EQUAL(src->GetColumns(false, false).size(), 0);
00091 BOOST_WARN_GT(src->GetColumns(true, false).size(), 0);
00092 BOOST_WARN_GT (src->GetColumns(true, true).size(), 0);
00093 BOOST_CHECK_GE(src->GetColumns(true, true).size(), src->GetColumns(true, false).size());
00094 }
00095
00096 BOOST_FIXTURE_TEST_CASE(TableDataSourceTestCase, TableDataSourceFixture) {
00097 IsValidTableDataSourceTest(src);
00098
00099 BOOST_CHECK_EQUAL(src->GetColumns(true, false).size(), 1);
00100 BOOST_CHECK_EQUAL(src->GetColumns(false, true).size(), 3);
00101 BOOST_CHECK_EQUAL(src->GetColumns(true, true).size(), 4);
00102
00103 for(int i=0; i < src->GetTotalRows(); i++) {
00104 BOOST_CHECK_EQUAL(src->GetIntDataByID("id", i), i);
00105 BOOST_CHECK_EQUAL(src->GetNormalizedDataByID("red", i), i/(double)src->GetTotalRows());
00106 BOOST_CHECK_EQUAL(src->GetNormalizedDataByID("green", i), 1.0-src->GetNormalizedDataByID("red", i));
00107 BOOST_CHECK_EQUAL(src->GetNormalizedDataByID("blue", i), i%10 / 10.0);
00108 }
00109
00110 }
00111
00112 BOOST_AUTO_TEST_SUITE_END()
00113
00114 #endif // testTableDataSource_h