File: TestExecString.cpp

package info (click to toggle)
kodi 2%3A20.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 143,820 kB
  • sloc: cpp: 664,925; xml: 68,398; ansic: 37,223; python: 6,903; sh: 4,209; javascript: 2,325; makefile: 1,754; perl: 969; java: 513; cs: 390; objc: 340
file content (118 lines) | stat: -rw-r--r-- 4,459 bytes parent folder | download | duplicates (3)
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
113
114
115
116
117
118
/*
 *  Copyright (C) 2022 Team Kodi
 *  This file is part of Kodi - https://kodi.tv
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 *  See LICENSES/README.md for more information.
 */

#include "FileItem.h"
#include "utils/ExecString.h"

#include <gtest/gtest.h>

TEST(TestExecString, ctor_1)
{
  {
    const CExecString exec("ActivateWindow(Video, \"C:\\test\\foo\")");
    EXPECT_EQ(exec.IsValid(), true);
    EXPECT_EQ(exec.GetFunction(), "activatewindow");
    EXPECT_EQ(exec.GetParams().size(), 2U);
    EXPECT_EQ(exec.GetParams()[0], "Video");
    EXPECT_EQ(exec.GetParams()[1], "C:\\test\\foo");
    EXPECT_EQ(exec.GetExecString(), "ActivateWindow(Video, \"C:\\test\\foo\")");
  }
  {
    const CExecString exec("ActivateWindow(Video, \"C:\\test\\foo\\\")");
    EXPECT_EQ(exec.IsValid(), true);
    EXPECT_EQ(exec.GetFunction(), "activatewindow");
    EXPECT_EQ(exec.GetParams().size(), 2U);
    EXPECT_EQ(exec.GetParams()[0], "Video");
    EXPECT_EQ(exec.GetParams()[1], "C:\\test\\foo");
    EXPECT_EQ(exec.GetExecString(), "ActivateWindow(Video, \"C:\\test\\foo\\\")");
  }
  {
    const CExecString exec("ActivateWindow(Video, \"C:\\\\test\\\\foo\\\\\")");
    EXPECT_EQ(exec.IsValid(), true);
    EXPECT_EQ(exec.GetFunction(), "activatewindow");
    EXPECT_EQ(exec.GetParams().size(), 2U);
    EXPECT_EQ(exec.GetParams()[0], "Video");
    EXPECT_EQ(exec.GetParams()[1], "C:\\test\\foo\\");
    EXPECT_EQ(exec.GetExecString(), "ActivateWindow(Video, \"C:\\\\test\\\\foo\\\\\")");
  }
  {
    const CExecString exec("ActivateWindow(Video, \"C:\\\\\\\\test\\\\\\foo\\\\\")");
    EXPECT_EQ(exec.IsValid(), true);
    EXPECT_EQ(exec.GetFunction(), "activatewindow");
    EXPECT_EQ(exec.GetParams().size(), 2U);
    EXPECT_EQ(exec.GetParams()[0], "Video");
    EXPECT_EQ(exec.GetParams()[1], "C:\\\\test\\\\foo\\");
    EXPECT_EQ(exec.GetExecString(), "ActivateWindow(Video, \"C:\\\\\\\\test\\\\\\foo\\\\\")");
  }
  {
    const CExecString exec("SetProperty(Foo,\"\")");
    EXPECT_EQ(exec.IsValid(), true);
    EXPECT_EQ(exec.GetFunction(), "setproperty");
    EXPECT_EQ(exec.GetParams().size(), 2U);
    EXPECT_EQ(exec.GetParams()[0], "Foo");
    EXPECT_EQ(exec.GetParams()[1], "");
    EXPECT_EQ(exec.GetExecString(), "SetProperty(Foo,\"\")");
  }
  {
    const CExecString exec("SetProperty(foo,ba(\"ba black )\",sheep))");
    EXPECT_EQ(exec.IsValid(), true);
    EXPECT_EQ(exec.GetFunction(), "setproperty");
    EXPECT_EQ(exec.GetParams().size(), 2U);
    EXPECT_EQ(exec.GetParams()[0], "foo");
    EXPECT_EQ(exec.GetParams()[1], "ba(\"ba black )\",sheep)");
    EXPECT_EQ(exec.GetExecString(), "SetProperty(foo,ba(\"ba black )\",sheep))");
  }
}

TEST(TestExecString, ctor_2)
{
  {
    const CExecString exec("ActivateWindow", {"Video", "C:\\test\\foo"});
    EXPECT_EQ(exec.IsValid(), true);
    EXPECT_EQ(exec.GetFunction(), "activatewindow");
    EXPECT_EQ(exec.GetParams().size(), 2U);
    EXPECT_EQ(exec.GetParams()[0], "Video");
    EXPECT_EQ(exec.GetParams()[1], "C:\\test\\foo");
    EXPECT_EQ(exec.GetExecString(), "ActivateWindow(Video,C:\\test\\foo)");
  }
}

TEST(TestExecString, ctor_3)
{
  {
    const CFileItem item("C:\\test\\foo", true);
    const CExecString exec(item, "Video");
    EXPECT_EQ(exec.IsValid(), true);
    EXPECT_EQ(exec.GetFunction(), "activatewindow");
    EXPECT_EQ(exec.GetParams().size(), 3U);
    EXPECT_EQ(exec.GetParams()[0], "Video");
    EXPECT_EQ(exec.GetParams()[1], "\"C:\\\\test\\\\foo\\\\\"");
    EXPECT_EQ(exec.GetParams()[2], "return");
    EXPECT_EQ(exec.GetExecString(), "ActivateWindow(Video,\"C:\\\\test\\\\foo\\\\\",return)");
  }
  {
    const CFileItem item("C:\\test\\foo\\", true);
    const CExecString exec(item, "Video");
    EXPECT_EQ(exec.IsValid(), true);
    EXPECT_EQ(exec.GetFunction(), "activatewindow");
    EXPECT_EQ(exec.GetParams().size(), 3U);
    EXPECT_EQ(exec.GetParams()[0], "Video");
    EXPECT_EQ(exec.GetParams()[1], "\"C:\\\\test\\\\foo\\\\\"");
    EXPECT_EQ(exec.GetParams()[2], "return");
    EXPECT_EQ(exec.GetExecString(), "ActivateWindow(Video,\"C:\\\\test\\\\foo\\\\\",return)");
  }
  {
    const CFileItem item("C:\\test\\foo", false);
    const CExecString exec(item, "Video");
    EXPECT_EQ(exec.IsValid(), true);
    EXPECT_EQ(exec.GetFunction(), "playmedia");
    EXPECT_EQ(exec.GetParams().size(), 1U);
    EXPECT_EQ(exec.GetParams()[0], "\"C:\\\\test\\\\foo\"");
    EXPECT_EQ(exec.GetExecString(), "PlayMedia(\"C:\\\\test\\\\foo\")");
  }
}