Explorar o código

Do not do actual work into ca_assert

Daniele Bartolini %!s(int64=12) %!d(string=hai) anos
pai
achega
d0f677908e

+ 4 - 2
src/core/streams/FileStream.cpp

@@ -80,7 +80,8 @@ void FileStream::read(void* buffer, size_t size)
 		m_file.seek(0);
 	}
 
-	ce_assert(m_file.read(buffer, size) == size, "Failed to read from file");
+	size_t bytes_read = m_file.read(buffer, size);
+	ce_assert(bytes_read == size, "Failed to read from file");
 }
 
 //-----------------------------------------------------------------------------
@@ -94,7 +95,8 @@ void FileStream::write(const void* buffer, size_t size)
 		m_file.seek(0);
 	}
 
-	ce_assert(m_file.write(buffer, size) == size, "Failed to write to file");
+	size_t bytes_written = m_file.write(buffer, size);
+	ce_assert(bytes_written == size, "Failed to write to file");
 }
 
 //-----------------------------------------------------------------------------

+ 1 - 3
src/core/streams/Stream.h

@@ -49,10 +49,8 @@ class Stream
 {
 public:
 
-	/// Constructor
+	/// Opens the stream with the given @mode
 						Stream(StreamOpenMode mode) : m_open_mode(mode) {}
-
-	/// Destructor
 	virtual				~Stream() {};
 
 	/// Sets the position indicator of the stream to position.

+ 7 - 4
src/os/android/File.cpp

@@ -68,7 +68,7 @@ bool File::is_open() const
 }
 
 //-----------------------------------------------------------------------------
-StreamOpenMode File::mode()
+StreamOpenMode File::mode() const
 {
 	return m_mode;
 }
@@ -100,19 +100,22 @@ size_t File::write(const void* data, size_t size)
 //-----------------------------------------------------------------------------
 void File::seek(size_t position)
 {
-	ce_assert(AAsset_seek(m_asset, (off_t)position, SEEK_SET) != (off_t) -1);
+	off_t seek_result = AAsset_seek(m_asset, (off_t)position, SEEK_SET);
+	ce_assert(seek_result != (off_t) -1, "Failed to seek");
 }
 
 //-----------------------------------------------------------------------------
 void File::seek_to_end()
 {
-	ce_assert(AAsset_seek(m_asset, 0, SEEK_END) != (off_t) -1);
+	off_t seek_result = AAsset_seek(m_asset, 0, SEEK_END);
+	ce_assert(seek_result != (off_t) -1, "Failed to seek");
 }
 
 //-----------------------------------------------------------------------------
 void File::skip(size_t bytes)
 {
-	ce_assert(AAsset_seek(m_asset, (off_t) bytes, SEEK_CUR) != (off_t) -1);
+	off_t seek_result = AAsset_seek(m_asset, (off_t) bytes, SEEK_CUR);
+	ce_assert(seek_result != (off_t) -1, "Failed to seek");
 }
 
 //-----------------------------------------------------------------------------

+ 1 - 1
src/os/android/File.h

@@ -52,7 +52,7 @@ public:
 	size_t					size() const;
 
 	/// Returs the mode used to open the file.
-	StreamOpenMode			mode();
+	StreamOpenMode			mode() const;
 
 	/// Reads @size bytes from the file and stores it into @data.
 	/// Returns the number of bytes read.

+ 13 - 8
src/os/posix/File.cpp

@@ -73,15 +73,17 @@ StreamOpenMode File::mode()
 //-----------------------------------------------------------------------------
 size_t File::size() const
 {
-	long pos = ftell(m_file_handle);
+	size_t pos = position();
 
-	fseek(m_file_handle, 0, SEEK_END);
+	int fseek_result = fseek(m_file_handle, 0, SEEK_END);
+	ce_assert(fseek_result == 0, "Failed to seek");
 
-	long size = ftell(m_file_handle);
+	size_t size = position();
 
-	fseek(m_file_handle, pos, SEEK_SET);
+	fseek_result = fseek(m_file_handle, (long) pos, SEEK_SET);
+	ce_assert(fseek_result == 0, "Failed to seek");
 
-	return (size_t) size;
+	return size;
 }
 
 //-----------------------------------------------------------------------------
@@ -103,19 +105,22 @@ size_t File::write(const void* data, size_t size)
 //-----------------------------------------------------------------------------
 void File::seek(size_t position)
 {
-	ce_assert(fseek(m_file_handle, (long) position, SEEK_SET) == 0, "Failed to seek");
+	int fseek_result = fseek(m_file_handle, (long) position, SEEK_SET);
+	ce_assert(fseek_result == 0, "Failed to seek");
 }
 
 //-----------------------------------------------------------------------------
 void File::seek_to_end()
 {
-	ce_assert(fseek(m_file_handle, 0, SEEK_END) == 0, "Failed to seek");
+	int fseek_result = fseek(m_file_handle, 0, SEEK_END);
+	ce_assert(fseek_result == 0, "Failed to seek");
 }
 
 //-----------------------------------------------------------------------------
 void File::skip(size_t bytes)
 {
-	ce_assert(fseek(m_file_handle, bytes, SEEK_CUR) == 0, "Failed to seek");
+	int fseek_result = fseek(m_file_handle, bytes, SEEK_CUR);
+	ce_assert(fseek_result == 0, "Failed to seek");
 }
 
 //-----------------------------------------------------------------------------