2 * Copyright (c) 2013 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 test_process_pipe.cpp
18 * @author Tomasz Iwanek (t.iwanek@samsung.com)
20 * @brief This file is the implementation file of ProcessPipe tests
23 #include <dpl/test/test_runner.h>
24 #include <dpl/test/process_pipe.h>
25 #include <dpl/binary_queue.h>
26 #include <dpl/log/wrt_log.h>
32 RUNNER_TEST_GROUP_INIT(DPL)
35 void readAll(ProcessPipe & npp, BinaryQueue & result)
39 BinaryQueueAutoPtr dataptr = npp.Read(4096);
41 RUNNER_ASSERT_MSG(dataptr.get() != NULL, "Cannot read from pipe subprocess");
43 WrtLogD("Size: %i", dataptr->Size());
45 if(dataptr->Empty()) break;
46 result.AppendMoveFrom(*dataptr);
52 RUNNER_TEST(ProcessPipe_echo)
55 npp.Open("echo -e \"Test echo text\\nAnd new line\"");
60 char buffer[100] = "";
61 result.FlattenConsume(buffer, std::min(result.Size(), sizeof(buffer)));
63 RUNNER_ASSERT_MSG(strcmp(buffer, "Test echo text\nAnd new line\n") == 0, "Echoed text in not equal");
66 RUNNER_TEST(ProcessPipe_double_open)
69 npp.Open("echo \"Test \"");
72 npp.Open("echo \"Test\"");
74 Catch(DPL::ProcessPipe::Exception::DoubleOpen)
80 RUNNER_ASSERT_MSG(false, "DoubleOpen not thrown");
83 RUNNER_TEST(ProcessPipe_double_close)
86 npp.Open("echo \"Test invalid\"");
94 RUNNER_ASSERT_MSG(false, "Second Close throws exception");
98 RUNNER_TEST(ProcessPipe_pipeerror_off)
100 ProcessPipe npp(ProcessPipe::PipeErrorPolicy::OFF);
101 npp.Open("ls /nonexistingdirectory");
103 readAll(npp, result); //TODO: fix this test
107 RUNNER_TEST(ProcessPipe_pipeerror_pipe)
109 //ls output dependent...
110 ProcessPipe npp(ProcessPipe::PipeErrorPolicy::PIPE);
111 npp.Open("ls /nonexistingdirectory");
113 readAll(npp, result);
115 char buffer[100] = "";
116 result.FlattenConsume(buffer, std::min(result.Size(), sizeof(buffer)));
118 RUNNER_ASSERT_MSG(strcmp(buffer, "ls: cannot access /nonexistingdirectory: No such file or directory\n") == 0, "Ls error text in not equal");