fix test
git@c012ed0e396cbbb03cc03217485c0d6133da5817
https://github.com/srz-zumix/iutest/commit/c012ed0e396cbbb03cc03217485c0d6133da5817
update test
git@9d8a3422f85a7db48e51a326c32ddff0893ef38e
fix unused warning
git@85d451b57ec0d81cc66b9d722b71951bfef86bba
fix fileno error
git@51e33756bb6917eee69d9fe885c3fa8eb3500d49
fix: GetSize of file append mode
git@4213872eefe930e6bd91d8521799ed8b02c32969
update test
git@64c53817720945df26994de194387f287641998e
change file open flag name /OpenReadWrite/OpenAppend/
git@8626a58d268c52a7a8ed966ccdae07f06f83509f
@@ -918,6 +918,13 @@ | ||
918 | 918 | # endif |
919 | 919 | #endif |
920 | 920 | |
921 | +//! has fileno | |
922 | +#if !defined(IUTEST_HAS_FILENO) | |
923 | +# if !defined(IUTEST_OS_WINDOWS_MOBILE) && !defined(__STRICT_ANSI__) | |
924 | +# define IUTEST_HAS_FILENO 1 | |
925 | +# endif | |
926 | +#endif | |
927 | + | |
921 | 928 | //! explicit class member template specialization |
922 | 929 | #if !defined(IUTEST_HAS_CLASS_MEMBER_TEMPLATE_SPECIALIZATION) |
923 | 930 | # if defined(_MSC_VER) |
@@ -6,7 +6,7 @@ | ||
6 | 6 | * |
7 | 7 | * @author t.shirayanagi |
8 | 8 | * @par copyright |
9 | - * Copyright (C) 2011-2016, Takazumi Shirayanagi\n | |
9 | + * Copyright (C) 2011-2018, Takazumi Shirayanagi\n | |
10 | 10 | * This software is released under the new BSD License, |
11 | 11 | * see LICENSE |
12 | 12 | */ |
@@ -34,9 +34,9 @@ | ||
34 | 34 | //! ファイルオープンモードフラグ |
35 | 35 | enum OpenFlag |
36 | 36 | { |
37 | - OpenRead = 0x00000001, //!< 読み込み | |
38 | - OpenWrite = 0x00000002, //!< 書き込み | |
39 | - OpenReadWrite = 0x00000003 //!< 読み書き | |
37 | + OpenRead = 0x00000001, //!< 読み込み | |
38 | + OpenWrite = 0x00000002, //!< 書き込み | |
39 | + OpenAppend = 0x00000003 //!< 追記 | |
40 | 40 | }; |
41 | 41 | public: |
42 | 42 | virtual ~IFile() {} |
@@ -174,7 +174,7 @@ | ||
174 | 174 | case IFile::OpenWrite: |
175 | 175 | m_fp = fopen(filename, "wb"); |
176 | 176 | break; |
177 | - case IFile::OpenReadWrite: | |
177 | + case IFile::OpenAppend: | |
178 | 178 | m_fp = fopen(filename, "ab"); |
179 | 179 | break; |
180 | 180 | default: |
@@ -234,16 +234,27 @@ | ||
234 | 234 | const long pre = ftell(m_fp); |
235 | 235 | if( pre == -1 ) |
236 | 236 | { |
237 | - return 0; | |
237 | + return GetSize(m_fp); | |
238 | 238 | } |
239 | 239 | if( fseek(m_fp, 0, SEEK_END) != 0 ) |
240 | 240 | { |
241 | - return 0; | |
241 | + return GetSize(m_fp); | |
242 | 242 | } |
243 | 243 | const size_t size = static_cast<size_t>(ftell(m_fp)); |
244 | - fseek(m_fp, pre, SEEK_SET); | |
244 | + IUTEST_UNUSED_RETURN(fseek(m_fp, pre, SEEK_SET)); | |
245 | 245 | return size; |
246 | 246 | } |
247 | + | |
248 | +public: | |
249 | + static size_t GetSize(FILE* fp) | |
250 | + { | |
251 | + internal::posix::StatStruct st; | |
252 | + if (internal::posix::Stat(fp, &st) != 0) | |
253 | + { | |
254 | + return 0; | |
255 | + } | |
256 | + return st.st_size; | |
257 | + } | |
247 | 258 | }; |
248 | 259 | |
249 | 260 | class StdErrorFile : public StdioFile |
@@ -6,7 +6,7 @@ | ||
6 | 6 | * |
7 | 7 | * @author t.shirayanagi |
8 | 8 | * @par copyright |
9 | - * Copyright (C) 2012-2016, Takazumi Shirayanagi\n | |
9 | + * Copyright (C) 2012-2018, Takazumi Shirayanagi\n | |
10 | 10 | * This software is released under the new BSD License, |
11 | 11 | * see LICENSE |
12 | 12 | */ |
@@ -21,43 +21,9 @@ | ||
21 | 21 | // include |
22 | 22 | #include "iutest_port.hpp" |
23 | 23 | |
24 | -#if IUTEST_HAS_FILE_STAT | |
25 | -# include <sys/stat.h> | |
26 | -#endif | |
27 | - | |
28 | -#if defined(IUTEST_OS_WINDOWS) && !defined(IUTEST_OS_WINDOWS_MOBILE) | |
29 | -# include <direct.h> | |
30 | -#endif | |
31 | - | |
32 | -namespace iutest { | |
33 | - | |
34 | -namespace internal { | |
35 | -namespace posix | |
24 | +namespace iutest | |
36 | 25 | { |
37 | 26 | |
38 | -#if IUTEST_HAS_FILE_STAT | |
39 | - | |
40 | -#if defined(IUTEST_OS_WINDOWS) && !defined(IUTEST_OS_WINDOWS_WINE) | |
41 | - | |
42 | - typedef struct _stat StatStruct; | |
43 | - | |
44 | - inline int Stat(const char* path, StatStruct* buf) { return _stat(path, buf); } | |
45 | - inline bool IsDir(const StatStruct& st) { return (st.st_mode & _S_IFDIR) != 0; } | |
46 | - | |
47 | -#else | |
48 | - | |
49 | - typedef struct stat StatStruct; | |
50 | - | |
51 | - inline int Stat(const char* path, StatStruct* buf) { return stat(path, buf); } | |
52 | - inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); } | |
53 | - | |
54 | -#endif | |
55 | - | |
56 | -#endif | |
57 | - | |
58 | -} // end of namespace posix | |
59 | -} // end of namespace internal | |
60 | - | |
61 | 27 | namespace detail |
62 | 28 | { |
63 | 29 |
@@ -6,7 +6,7 @@ | ||
6 | 6 | * |
7 | 7 | * @author t.shirayanagi |
8 | 8 | * @par copyright |
9 | - * Copyright (C) 2011-2017, Takazumi Shirayanagi\n | |
9 | + * Copyright (C) 2011-2018, Takazumi Shirayanagi\n | |
10 | 10 | * This software is released under the new BSD License, |
11 | 11 | * see LICENSE |
12 | 12 | */ |
@@ -28,6 +28,10 @@ | ||
28 | 28 | # include <locale.h> |
29 | 29 | #endif |
30 | 30 | |
31 | +#if IUTEST_HAS_FILE_STAT | |
32 | +# include <sys/stat.h> | |
33 | +#endif | |
34 | + | |
31 | 35 | //====================================================================== |
32 | 36 | // define |
33 | 37 | #if !defined(IUTEST_MAX_PATH) |
@@ -92,6 +96,42 @@ | ||
92 | 96 | inline void Abort() { abort(); } |
93 | 97 | #endif |
94 | 98 | |
99 | +#if IUTEST_HAS_FILENO | |
100 | + | |
101 | +#if defined(_MSC_VER) | |
102 | +inline int Fileno(FILE* fp) { return _fileno(fp); } | |
103 | +#else | |
104 | +inline int Fileno(FILE* fp) { return fileno(fp); } | |
105 | +#endif | |
106 | + | |
107 | +#else | |
108 | + | |
109 | +inline int Fileno(FILE*) { return -1; } | |
110 | + | |
111 | +#endif | |
112 | + | |
113 | +#if IUTEST_HAS_FILE_STAT | |
114 | + | |
115 | +#if defined(IUTEST_OS_WINDOWS) && !defined(IUTEST_OS_WINDOWS_WINE) | |
116 | + | |
117 | +typedef struct _stat StatStruct; | |
118 | + | |
119 | +inline int Stat(FILE* fp, StatStruct* buf) { return _fstat(Fileno(fp), buf); } | |
120 | +inline int Stat(const char* path, StatStruct* buf) { return _stat(path, buf); } | |
121 | +inline bool IsDir(const StatStruct& st) { return (st.st_mode & _S_IFDIR) != 0; } | |
122 | + | |
123 | +#else | |
124 | + | |
125 | +typedef struct stat StatStruct; | |
126 | + | |
127 | +inline int Stat(FILE* fp, StatStruct* buf) { return fstat(Fileno(fp), buf); } | |
128 | +inline int Stat(const char* path, StatStruct* buf) { return stat(path, buf); } | |
129 | +inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); } | |
130 | + | |
131 | +#endif | |
132 | + | |
133 | +#endif | |
134 | + | |
95 | 135 | } // end of namespace posix |
96 | 136 | |
97 | 137 | inline void SleepMilliseconds(int n) { posix::SleepMillisec(static_cast<unsigned int>(n)); } |
@@ -6,7 +6,7 @@ | ||
6 | 6 | * |
7 | 7 | * @author t.shirayanagi |
8 | 8 | * @par copyright |
9 | - * Copyright (C) 2011-2016, Takazumi Shirayanagi\n | |
9 | + * Copyright (C) 2011-2018, Takazumi Shirayanagi\n | |
10 | 10 | * This software is released under the new BSD License, |
11 | 11 | * see LICENSE |
12 | 12 | */ |
@@ -76,6 +76,7 @@ | ||
76 | 76 | #endif |
77 | 77 | |
78 | 78 | #define IUTEST_UNUSED_VAR(x) (void)(x) |
79 | +#define IUTEST_UNUSED_RETURN(x) (void)(x) | |
79 | 80 | |
80 | 81 | // DEC |
81 | 82 | #define IUTEST_PP_DEC(n) IIUT_PP_DEC_I(n) |
@@ -6,7 +6,7 @@ | ||
6 | 6 | * |
7 | 7 | * @author t.shirayanagi |
8 | 8 | * @par copyright |
9 | - * Copyright (C) 2012-2017, Takazumi Shirayanagi\n | |
9 | + * Copyright (C) 2012-2018, Takazumi Shirayanagi\n | |
10 | 10 | * This software is released under the new BSD License, |
11 | 11 | * see LICENSE |
12 | 12 | */ |
@@ -508,6 +508,10 @@ | ||
508 | 508 | # define IUTEST_HAS_FILE_STAT 0 //!< stat が使用可能かどうか |
509 | 509 | #endif |
510 | 510 | |
511 | +#if !defined(IUTEST_HAS_FILENO) | |
512 | +# define IUTEST_HAS_FILENO 0 //!< fileno が使用可能かどうか | |
513 | +#endif | |
514 | + | |
511 | 515 | /** |
512 | 516 | * @} |
513 | 517 | */ |
@@ -17,11 +17,11 @@ | ||
17 | 17 | |
18 | 18 | //====================================================================== |
19 | 19 | // define |
20 | -#define IUTEST_VER 0x01160206u //!< iutest version 1.16.2.6 | |
20 | +#define IUTEST_VER 0x01160209u //!< iutest version 1.16.2.9 | |
21 | 21 | #define IUTEST_MAJORVER 0x01u //!< Major Version |
22 | 22 | #define IUTEST_MINORVER 0x16u //!< Minor Version |
23 | 23 | #define IUTEST_MICROVER 0x02u //!< Micro Version |
24 | -#define IUTEST_REVISION 0x06u //!< Revision | |
24 | +#define IUTEST_REVISION 0x09u //!< Revision | |
25 | 25 | |
26 | 26 | #define IUTEST_BUILD IUTEST_MICROVER //!< @deprecated |
27 | 27 |
@@ -6,7 +6,7 @@ | ||
6 | 6 | * |
7 | 7 | * @author t.shirayanagi |
8 | 8 | * @par copyright |
9 | - * Copyright (C) 2016, Takazumi Shirayanagi\n | |
9 | + * Copyright (C) 2016-2018, Takazumi Shirayanagi\n | |
10 | 10 | * This software is released under the new BSD License, |
11 | 11 | * see LICENSE |
12 | 12 | */ |
@@ -49,7 +49,7 @@ | ||
49 | 49 | |
50 | 50 | virtual bool FileOpen(const char* path) |
51 | 51 | { |
52 | - if( m_stderr.Open(path, IFile::OpenReadWrite) ) | |
52 | + if( m_stderr.Open(path, IFile::OpenAppend) ) | |
53 | 53 | { |
54 | 54 | this->m_fp = &m_stderr; |
55 | 55 | return true; |
@@ -6,7 +6,7 @@ | ||
6 | 6 | * |
7 | 7 | * @author t.shirayanagi |
8 | 8 | * @par copyright |
9 | - * Copyright (C) 2013-2016, Takazumi Shirayanagi\n | |
9 | + * Copyright (C) 2013-2018, Takazumi Shirayanagi\n | |
10 | 10 | * The new BSD License is applied to this software. |
11 | 11 | * see LICENSE |
12 | 12 | */ |
@@ -16,6 +16,7 @@ | ||
16 | 16 | //====================================================================== |
17 | 17 | // include |
18 | 18 | #include "iutest.hpp" |
19 | +#include "internal/iutest_filepath.hpp" | |
19 | 20 | |
20 | 21 | class Base {}; |
21 | 22 | class Derived : public Base {}; |
@@ -165,7 +166,20 @@ | ||
165 | 166 | IUTEST_EXPECT_FALSE( ::iutest::detail::GetEnvironmentVariable("PATH", NULL, 0) ); |
166 | 167 | } |
167 | 168 | |
169 | +#if IUTEST_HAS_FILENO && IUTEST_HAS_FOPEN | |
168 | 170 | |
171 | +IUTEST(StdFileUnitTest, AppendOpenedFileSize) | |
172 | +{ | |
173 | + ::iutest::StdioFile file; | |
174 | + ::iutest::internal::FilePath filename("unit_tests.cpp"); | |
175 | + IUTEST_ASSUME_TRUE( filename.FileOrDirectoryExists() ); | |
176 | + IUTEST_ASSERT_TRUE( file.Open(filename.c_str(), iutest::IFile::OpenAppend) ); | |
177 | + IUTEST_ASSERT_LT(0u, file.GetSize()); | |
178 | +} | |
179 | + | |
180 | +#endif | |
181 | + | |
182 | + | |
169 | 183 | #ifdef UNICODE |
170 | 184 | int wmain(int argc, wchar_t* argv[]) |
171 | 185 | #else |