summaryrefslogtreecommitdiff
path: root/src/VodcatcherPluginCommandline_test.cc
blob: 442c33e4689728f788046ac1270bbdb4805ef87f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
 * vdr-vodcatcher - A plugin for the Linux Video Disk Recorder
 * Copyright (c) 2007 - 2008 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.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 *
 * $Id: VodcatcherPluginCommandline_test.cc 7652 2008-08-05 21:37:57Z svntobi $
 *
 */

#include <string>
#include <iostream>
#include <cxxtest/TestSuite.h>
#include "VodcatcherPlugin.h"
#include "StderrMock.h"

using namespace std;

namespace
{

class VodcatcherPluginCommandLineTest : public CxxTest::TestSuite
{
private:
    VodcatcherPlugin* plugin;
    StdErrMock* stdErrMock;

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

    void RestoreStdErr()
    {
        delete stdErrMock;
    }

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

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

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

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

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

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

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

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

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

}
;