00001
00002
00003
00004
00005
00006
00007
00008 #ifndef TESTWRITABLETABLEDATASOURCE_H
00009 #define TESTWRITABLETABLEDATASOURCE_H
00010
00011 #define BOOST_TEST_MODULE MediaTableTestSuite
00012 #include "boost/test/unit_test.hpp"
00013
00014 #include "../WritableTableDataSource.h"
00015
00016 #include "testTableDataSource.h"
00017
00018 typedef Impala::Application::MediaTable::TableDataSource TableDataSource;
00019 typedef Impala::Application::MediaTable::WritableTableDataSource WritableTableDataSource;
00020
00021 BOOST_AUTO_TEST_SUITE( WritableTableDataSourceTests )
00022
00023 struct WritableTableDataSourceFixture {
00024
00025 WritableTableDataSourceFixture() {
00026 src = new WritableTableDataSource();
00027 }
00028
00029 ~WritableTableDataSourceFixture() {}
00030
00031 WritableTableDataSource* src;
00032 };
00033
00034 BOOST_FIXTURE_TEST_CASE(WritableTableDataSourceTest, WritableTableDataSourceFixture) {
00035
00036 BOOST_REQUIRE(src);
00037
00038 BOOST_CHECK_EQUAL(src->GetTotalRows(), 0);
00039
00040 BOOST_CHECK_EQUAL(src->GetColumns(true, true).size(), 0);
00041
00042 src->AddColumn("id", TableDataSource::TYPE_INT);
00043 src->AddColumn("image", TableDataSource::TYPE_IMAGE);
00044 src->AddColumn("name", TableDataSource::TYPE_TEXT);
00045 src->AddColumn("rank", TableDataSource::TYPE_NORMALIZEDVALUE);
00046
00047 BOOST_CHECK_EQUAL(src->GetColumns(true, true).size(), 4);
00048
00049 BOOST_CHECK_EQUAL(src->GetTotalRows(), 0);
00050
00051 for(uint i=0; i < 100; i++) {
00052 src->AddIntData("id", i);
00053 src->AddImageData("image", 0);
00054 src->AddTextData("name", "Test row "+ i);
00055 src->AddDoubleData("rank", ((double) i) /100);
00056 }
00057 BOOST_CHECK_EQUAL(src->GetTotalRows(), 100);
00058 for(int i=0; i < 100; i++) {
00059 BOOST_CHECK_EQUAL(src->GetIntDataByID("id", i), i);
00060 BOOST_CHECK(0 == src->GetImageDataByID("image", i));
00061 BOOST_CHECK_EQUAL(src->GetTextDataByID("name", i), "Test row "+ i);
00062 BOOST_CHECK_EQUAL(src->GetDoubleDataByID("rank", i), ((double) i)/100);
00063 }
00064 BOOST_CHECK_EQUAL(src->GetDoubleDataByID("rank", 50), 0.5);
00065
00066 TableDataSourceTests::IsValidTableDataSourceTest(src);
00067
00068
00069 }
00070
00071 BOOST_AUTO_TEST_SUITE_END()
00072
00073 #endif