/*
 * 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: podcatchercommandline_test.cc 2255 2006-01-23 19:05:08Z svntobi $
 *
 */

#include <string>
#include <iostream>
#include <cxxtest/TestSuite.h>
#include "podcatcherplugin.h"
#include "stderrmock.h"

using namespace std;

class PodcatcherCommandLineTest: public CxxTest::TestSuite
{
    private:
        PodcatcherPlugin* plugin;
        StdErrMock* stdErrMock;

    private:
        void RedirectStdErr()
        {
            stdErrMock = new StdErrMock();
        }

        void RestoreStdErr()
        {
            delete stdErrMock;
        }

    public:
        void TestCommandLineHelp()
        {
            PodcatcherPlugin plugin;
            TS_ASSERT_EQUALS(string("  -c, --cache=CACHE_DIR    specify cache "
              "dir, defaults to /var/cache/podcatcher"),
              plugin.CommandLineHelp());
        }

        void TestDefaultCommandLineParameters()
        {
            PodcatcherPlugin plugin;
            char* argv[1] = {"dummy"};

            TS_ASSERT(plugin.ProcessArgs(0, argv));
            TS_ASSERT_EQUALS("/var/cache/podcatcher", plugin.GetCacheDirName());
        }

        void TestWrongCommandLineParameters()
        {
            PodcatcherPlugin plugin;
            StdErrMock stdErrMock;
            char* argv[2] = {"dummy", "--foo"};

            stdErrMock.Expect("dummy: invalid option --foo\n");
            TS_ASSERT(!plugin.ProcessArgs(2, argv));
            stdErrMock.Verify();
        }

        void TestShortCacheDirParameter()
        {
            PodcatcherPlugin plugin;
            char* argv[3] = {"dummy", "-c", "/foo"};

            TS_ASSERT(plugin.ProcessArgs(3, argv));
            TS_ASSERT_EQUALS("/foo", plugin.GetCacheDirName());
        }

        void TestLongCacheDirParameter()
        {
            PodcatcherPlugin plugin;
            char* argv[2] = {"dummy", "--cache=/foo"};

            TS_ASSERT(plugin.ProcessArgs(2, argv));
            TS_ASSERT_EQUALS("/foo", plugin.GetCacheDirName());
        }
};
