tizen 2.3 release
[framework/web/wearable/wrt-commons.git] / tests / core / test_scoped_dir.cpp
1 /*
2  * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 /*
17  * @file        test_scoped_dir.cpp
18  * @author      Iwanek Tomasz (t.iwanek@smasung.com)
19  * @version     1.0
20  * @brief       Scoped directory test
21  */
22 #include <dpl/test/test_runner.h>
23 #include <dpl/scoped_dir.h>
24
25 #include <cstdio>
26 #include <sstream>
27 #include <cstdlib>
28
29 #include <unistd.h>
30
31 RUNNER_TEST_GROUP_INIT(DPL)
32
33 /*
34 Name: ScopedDir_Basic
35 Description: tests if scoped directory is working
36 Expected: directory created and removed
37 */
38 RUNNER_TEST(ScopedDir_Basic)
39 {
40     const char * path = "/tmp/wrttest123456";
41     if(access(path, F_OK) == 0)
42     {
43         RUNNER_ASSERT_MSG(!remove(path), "Cannot remove test directory");
44     }
45
46     {
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");
53     }
54     RUNNER_ASSERT_MSG(access(path, F_OK) != 0, "Directory should not exists");
55 }