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_scoped_dir.cpp
18 * @author Iwanek Tomasz (t.iwanek@smasung.com)
20 * @brief Scoped directory test
22 #include <dpl/test/test_runner.h>
23 #include <dpl/scoped_dir.h>
31 RUNNER_TEST_GROUP_INIT(DPL)
35 Description: tests if scoped directory is working
36 Expected: directory created and removed
38 RUNNER_TEST(ScopedDir_Basic)
40 const char * path = "/tmp/wrttest123456";
41 if(access(path, F_OK) == 0)
43 RUNNER_ASSERT_MSG(!remove(path), "Cannot remove test directory");
47 DPL::ScopedDir dir(path, S_IRUSR | S_IWUSR);
48 std::ostringstream command;
49 command << "touch " << path << "/" << "file.txt";
50 (void)system(command.str().c_str());
51 RUNNER_ASSERT_MSG(access(path, R_OK) == 0, "Directory should be accessible");
52 RUNNER_ASSERT_MSG(access(path, W_OK) == 0, "Directory should be writable");
54 RUNNER_ASSERT_MSG(access(path, F_OK) != 0, "Directory should not exists");