2 * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file bash_utils.cpp
18 * @author Iwanek Tomasz
21 #include <dpl/test/test_runner.h>
22 #include <dpl/utils/bash_utils.h>
23 #include <dpl/log/log.h>
25 using namespace BashUtils;
27 RUNNER_TEST_GROUP_INIT(DPL_BASH_UTILS)
30 Name: Bash_Utils_escape_arg
31 Description:tests ecaping bash special characters for command arguments
32 Expected: matching string
34 RUNNER_TEST(Bash_Utils_escape_arg)
36 RUNNER_ASSERT_MSG(escape_arg(std::string(
37 "valid")) == "\"valid\"",
38 "Valid argument failed");
39 LogDebug("\"val\\!d\"" << " " << escape_arg(std::string("val!d")));
40 RUNNER_ASSERT_MSG(escape_arg(std::string(
41 "val!d")) == "\"val\\!d\"",
42 "Single escaped character in argument failed");
43 LogDebug("\"v\\$l\\$\\$\"" << " " << escape_arg(std::string("v$l$$")));
44 RUNNER_ASSERT_MSG(escape_arg(std::string(
45 "v$l$$")) == "\"v\\$l\\$\\$\"",
46 "Multiple occurences of single special character in argument failed");
47 LogDebug("\"v\\`\\$\\\"\\!d\\`\"" << " " <<
48 escape_arg(std::string("v`$\"!d`")));
49 RUNNER_ASSERT_MSG(escape_arg(std::string(
50 "v`$\"!d`")) == "\"v\\`\\$\\\"\\!d\\`\"",
51 "Multiple occurences of multiple special character in argument failed");