• R/O
  • SSH
  • HTTPS

iutest: Commit


Commit MetaInfo

Revision1307 (tree)
Time2018-02-17 21:32:33
Authorsrz_zumix

Log Message

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

Change Summary

Incremental Difference

--- trunk/include/internal/iutest_compiler.hpp (revision 1306)
+++ trunk/include/internal/iutest_compiler.hpp (revision 1307)
@@ -918,6 +918,13 @@
918918 # endif
919919 #endif
920920
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+
921928 //! explicit class member template specialization
922929 #if !defined(IUTEST_HAS_CLASS_MEMBER_TEMPLATE_SPECIALIZATION)
923930 # if defined(_MSC_VER)
--- trunk/include/internal/iutest_file.hpp (revision 1306)
+++ trunk/include/internal/iutest_file.hpp (revision 1307)
@@ -6,7 +6,7 @@
66 *
77 * @author t.shirayanagi
88 * @par copyright
9- * Copyright (C) 2011-2016, Takazumi Shirayanagi\n
9+ * Copyright (C) 2011-2018, Takazumi Shirayanagi\n
1010 * This software is released under the new BSD License,
1111 * see LICENSE
1212 */
@@ -34,9 +34,9 @@
3434 //! ファイルオープンモードフラグ
3535 enum OpenFlag
3636 {
37- OpenRead = 0x00000001, //!< 読み込み
38- OpenWrite = 0x00000002, //!< 書き込み
39- OpenReadWrite = 0x00000003 //!< 読み書き
37+ OpenRead = 0x00000001, //!< 読み込み
38+ OpenWrite = 0x00000002, //!< 書き込み
39+ OpenAppend = 0x00000003 //!< 追記
4040 };
4141 public:
4242 virtual ~IFile() {}
@@ -174,7 +174,7 @@
174174 case IFile::OpenWrite:
175175 m_fp = fopen(filename, "wb");
176176 break;
177- case IFile::OpenReadWrite:
177+ case IFile::OpenAppend:
178178 m_fp = fopen(filename, "ab");
179179 break;
180180 default:
@@ -234,16 +234,27 @@
234234 const long pre = ftell(m_fp);
235235 if( pre == -1 )
236236 {
237- return 0;
237+ return GetSize(m_fp);
238238 }
239239 if( fseek(m_fp, 0, SEEK_END) != 0 )
240240 {
241- return 0;
241+ return GetSize(m_fp);
242242 }
243243 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));
245245 return size;
246246 }
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+ }
247258 };
248259
249260 class StdErrorFile : public StdioFile
--- trunk/include/internal/iutest_filepath.hpp (revision 1306)
+++ trunk/include/internal/iutest_filepath.hpp (revision 1307)
@@ -6,7 +6,7 @@
66 *
77 * @author t.shirayanagi
88 * @par copyright
9- * Copyright (C) 2012-2016, Takazumi Shirayanagi\n
9+ * Copyright (C) 2012-2018, Takazumi Shirayanagi\n
1010 * This software is released under the new BSD License,
1111 * see LICENSE
1212 */
@@ -21,43 +21,9 @@
2121 // include
2222 #include "iutest_port.hpp"
2323
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
3625 {
3726
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-
6127 namespace detail
6228 {
6329
--- trunk/include/internal/iutest_port.hpp (revision 1306)
+++ trunk/include/internal/iutest_port.hpp (revision 1307)
@@ -6,7 +6,7 @@
66 *
77 * @author t.shirayanagi
88 * @par copyright
9- * Copyright (C) 2011-2017, Takazumi Shirayanagi\n
9+ * Copyright (C) 2011-2018, Takazumi Shirayanagi\n
1010 * This software is released under the new BSD License,
1111 * see LICENSE
1212 */
@@ -28,6 +28,10 @@
2828 # include <locale.h>
2929 #endif
3030
31+#if IUTEST_HAS_FILE_STAT
32+# include <sys/stat.h>
33+#endif
34+
3135 //======================================================================
3236 // define
3337 #if !defined(IUTEST_MAX_PATH)
@@ -92,6 +96,42 @@
9296 inline void Abort() { abort(); }
9397 #endif
9498
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+
95135 } // end of namespace posix
96136
97137 inline void SleepMilliseconds(int n) { posix::SleepMillisec(static_cast<unsigned int>(n)); }
--- trunk/include/internal/iutest_pp.hpp (revision 1306)
+++ trunk/include/internal/iutest_pp.hpp (revision 1307)
@@ -6,7 +6,7 @@
66 *
77 * @author t.shirayanagi
88 * @par copyright
9- * Copyright (C) 2011-2016, Takazumi Shirayanagi\n
9+ * Copyright (C) 2011-2018, Takazumi Shirayanagi\n
1010 * This software is released under the new BSD License,
1111 * see LICENSE
1212 */
@@ -76,6 +76,7 @@
7676 #endif
7777
7878 #define IUTEST_UNUSED_VAR(x) (void)(x)
79+#define IUTEST_UNUSED_RETURN(x) (void)(x)
7980
8081 // DEC
8182 #define IUTEST_PP_DEC(n) IIUT_PP_DEC_I(n)
--- trunk/include/iutest_config.hpp (revision 1306)
+++ trunk/include/iutest_config.hpp (revision 1307)
@@ -6,7 +6,7 @@
66 *
77 * @author t.shirayanagi
88 * @par copyright
9- * Copyright (C) 2012-2017, Takazumi Shirayanagi\n
9+ * Copyright (C) 2012-2018, Takazumi Shirayanagi\n
1010 * This software is released under the new BSD License,
1111 * see LICENSE
1212 */
@@ -508,6 +508,10 @@
508508 # define IUTEST_HAS_FILE_STAT 0 //!< stat が使用可能かどうか
509509 #endif
510510
511+#if !defined(IUTEST_HAS_FILENO)
512+# define IUTEST_HAS_FILENO 0 //!< fileno が使用可能かどうか
513+#endif
514+
511515 /**
512516 * @}
513517 */
--- trunk/include/iutest_ver.hpp (revision 1306)
+++ trunk/include/iutest_ver.hpp (revision 1307)
@@ -17,11 +17,11 @@
1717
1818 //======================================================================
1919 // define
20-#define IUTEST_VER 0x01160206u //!< iutest version 1.16.2.6
20+#define IUTEST_VER 0x01160209u //!< iutest version 1.16.2.9
2121 #define IUTEST_MAJORVER 0x01u //!< Major Version
2222 #define IUTEST_MINORVER 0x16u //!< Minor Version
2323 #define IUTEST_MICROVER 0x02u //!< Micro Version
24-#define IUTEST_REVISION 0x06u //!< Revision
24+#define IUTEST_REVISION 0x09u //!< Revision
2525
2626 #define IUTEST_BUILD IUTEST_MICROVER //!< @deprecated
2727
--- trunk/include/listener/iutest_stderr_xml_generator.hpp (revision 1306)
+++ trunk/include/listener/iutest_stderr_xml_generator.hpp (revision 1307)
@@ -6,7 +6,7 @@
66 *
77 * @author t.shirayanagi
88 * @par copyright
9- * Copyright (C) 2016, Takazumi Shirayanagi\n
9+ * Copyright (C) 2016-2018, Takazumi Shirayanagi\n
1010 * This software is released under the new BSD License,
1111 * see LICENSE
1212 */
@@ -49,7 +49,7 @@
4949
5050 virtual bool FileOpen(const char* path)
5151 {
52- if( m_stderr.Open(path, IFile::OpenReadWrite) )
52+ if( m_stderr.Open(path, IFile::OpenAppend) )
5353 {
5454 this->m_fp = &m_stderr;
5555 return true;
--- trunk/test/unit_tests.cpp (revision 1306)
+++ trunk/test/unit_tests.cpp (revision 1307)
@@ -6,7 +6,7 @@
66 *
77 * @author t.shirayanagi
88 * @par copyright
9- * Copyright (C) 2013-2016, Takazumi Shirayanagi\n
9+ * Copyright (C) 2013-2018, Takazumi Shirayanagi\n
1010 * The new BSD License is applied to this software.
1111 * see LICENSE
1212 */
@@ -16,6 +16,7 @@
1616 //======================================================================
1717 // include
1818 #include "iutest.hpp"
19+#include "internal/iutest_filepath.hpp"
1920
2021 class Base {};
2122 class Derived : public Base {};
@@ -165,7 +166,20 @@
165166 IUTEST_EXPECT_FALSE( ::iutest::detail::GetEnvironmentVariable("PATH", NULL, 0) );
166167 }
167168
169+#if IUTEST_HAS_FILENO && IUTEST_HAS_FOPEN
168170
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+
169183 #ifdef UNICODE
170184 int wmain(int argc, wchar_t* argv[])
171185 #else
Show on old repository browser