tizen 2.4 release
[framework/web/wrt-commons.git] / tests / core / test_scoped_fclose.cpp
1 /*
2  * Copyright (c) 2011 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_fclose.cpp
18  * @author      Piotr Marcinkiewicz (p.marcinkiew@samsung.com)
19  * @version     1.0
20  * @brief       This file is the implementation file of test scoped fclose
21  */
22
23 #include <cstdio>
24 #include <cerrno>
25
26 #include <dpl/test/test_runner.h>
27 #include <dpl/scoped_fclose.h>
28
29 RUNNER_TEST_GROUP_INIT(DPL)
30
31 namespace {
32 FILE* MakeTmp()
33 {
34     FILE* result = NULL;
35     do {
36         result = tmpfile();
37     } while (NULL != result && EINTR == errno);
38     return result;
39 }
40 } //anonymous namespace
41
42 /*
43 Name: ScopedFClose_Zero
44 Description: tests if operator ! works correct for closed file
45 Expected: file should be closed
46 */
47 RUNNER_TEST(ScopedFClose_Zero)
48 {
49     DPL::ScopedFClose file;
50
51     RUNNER_ASSERT(!file);
52     RUNNER_ASSERT(!!!file);
53 }
54
55 /*
56 Name: ScopedFClose_NonZero
57 Description: tests if operator ! works correct for open file
58 Expected: file should be open
59 */
60 RUNNER_TEST(ScopedFClose_NonZero)
61 {
62     DPL::ScopedFClose file(MakeTmp());
63
64     RUNNER_ASSERT(file);
65     RUNNER_ASSERT(!!file);
66 }
67
68 /*
69 Name: ScopedFClose_Reset
70 Description: tests reseting of scoped file
71 Expected: file should be closed after reset
72 */
73 RUNNER_TEST(ScopedFClose_Reset)
74 {
75     DPL::ScopedFClose file(MakeTmp());
76     file.Reset();
77
78     RUNNER_ASSERT(!file);
79
80     file.Reset(MakeTmp());
81     RUNNER_ASSERT(file);
82 }
83