/*
 * vdr-podcatcher - A plugin for the Linux Video Disk Recorder
 * Copyright (c) 2006 Tobias Grimm <vdr@e-tobi.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * $Id: feedupdaterimpl_test.cc 3211 2006-04-14 21:01:37Z svntobi $
 *
 */

#include <cxxtest/TestSuite.h>
#include "feedupdaterimpl.h"
#include "downloadpoolmock.h"
#include "feedsources.h"
#include "downloadcachemock.h"

using namespace std;

class FeedSourcesStub: public IFeedSources
{
    public:
        // <IFeedSources>
        void GetFeeds(FeedList& feeds)
        {
            Feed feed1("foo");
            Feed feed2("bar");
            feeds.push_back(feed1);
            feeds.push_back(feed2);
        }
        // </IFeedSources>
};

class FeedUpdaterImplTest: public CxxTest::TestSuite
{
    private:
        FeedSourcesStub feedSources;
        DownloadPoolMock downloadPool;
        DownloadCacheMock downloadCache;
        FeedUpdaterImpl* feedUpdater;

    public:
        void setUp()
        {
            downloadPool.ResetMock();
            feedUpdater = new FeedUpdaterImpl(feedSources, downloadPool, downloadCache);
        }

        void tearDown()
        {
            delete feedUpdater;
        }

        void TestDownloadNewFeeds()
        {
            downloadCache.filesAreCached = false;
            downloadCache.fileAge = 99;
            downloadPool.ExpectMethod("AddDownload", "foo");
            downloadPool.ExpectMethod("AddDownload", "bar");

            feedUpdater->Update();

            downloadPool.Verify();
        }

        void TestDontDownloadUptodateFeeds()
        {
            downloadCache.filesAreCached = true;
            downloadCache.fileAge = 1;

            feedUpdater->Update();

            downloadPool.Verify();
        }

        void TestRefreshOldFeeds()
        {
            downloadCache.filesAreCached = true;
            downloadCache.fileAge = 3;
            downloadPool.ExpectMethod("AddDownload", "foo");
            downloadPool.ExpectMethod("AddDownload", "bar");

            feedUpdater->Update();

            downloadPool.Verify();
        }
};
