/*
 * 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: feedsconfigfile_test.cc 2503 2006-01-27 16:47:42Z svntobi $
 *
 */

#include <fstream>
#include <cxxtest/TestSuite.h>
#include "feedsconfigfile.h"

using namespace std;

class FeedsConfigFileTest: public CxxTest::TestSuite
{
    private:
        void WriteConfigData(char* data)
        {
            ofstream configFile("test.config", ios_base::app);
            configFile << data << endl;
            configFile.close();
        }

    public:
        void setUp()
        {
            unlink("test.config");
        }

        void tearDown()
        {
            unlink("test.config");
        }

        void TestEmptyConfigFile()
        {
            FeedsConfigFile feedSources("test.config");
            FeedList feeds;
            feedSources.GetFeeds(feeds);
            TS_ASSERT_EQUALS(0, feeds.size());
        }

        void TestSingelFeed()
        {
            WriteConfigData("FEED_URL=foo\n");

            FeedsConfigFile feedSources("test.config");
            FeedList feeds;
            feedSources.GetFeeds(feeds);
            TS_ASSERT_EQUALS(1, feeds.size());
            TS_ASSERT_EQUALS("foo", feeds[0].GetUrl());
        }

        void TestMultipleFeedsWithComments()
        {
            WriteConfigData("FEED_URL=foo\n");
            WriteConfigData("# Comment\n");
            WriteConfigData("# FEED_URL=abc\n");
            WriteConfigData("FEED_URL=bar\n");

            FeedsConfigFile feedSources("test.config");
            FeedList feeds;
            feedSources.GetFeeds(feeds);
            TS_ASSERT_EQUALS(2, feeds.size());
            TS_ASSERT_EQUALS("foo", feeds[0].GetUrl());
            TS_ASSERT_EQUALS("bar", feeds[1].GetUrl());
        }
};
