summaryrefslogtreecommitdiff
path: root/test/endian_str_test.cpp
diff options
context:
space:
mode:
authorljfa-ag <ljfa-ag@web.de>2015-07-28 19:56:08 +0200
committerljfa-ag <ljfa-ag@web.de>2015-07-28 20:27:01 +0200
commit1d51c9a541361693e5d7113f8bef47c63a246436 (patch)
tree0f462d14c546ae149f72366c69d263fdec5c480c /test/endian_str_test.cpp
parent4fbfca378926bdcff3fc18c2d8dbaccdae3afccf (diff)
downloadProject-Tick-1d51c9a541361693e5d7113f8bef47c63a246436.tar.gz
Project-Tick-1d51c9a541361693e5d7113f8bef47c63a246436.zip
Implement endian stream i/o for float
Diffstat (limited to 'test/endian_str_test.cpp')
-rw-r--r--test/endian_str_test.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/test/endian_str_test.cpp b/test/endian_str_test.cpp
index 213d3030b8..37cee685a5 100644
--- a/test/endian_str_test.cpp
+++ b/test/endian_str_test.cpp
@@ -19,6 +19,7 @@
*/
#include "microtest.h"
#include "endian_str.h"
+#include <cstdlib>
#include <sstream>
using namespace endian;
@@ -129,8 +130,40 @@ void test_sint()
ASSERT(str); //Check if stream has failed
}
+void test_float()
+{
+ std::stringstream str(std::ios::in | std::ios::out | std::ios::binary);
+
+ //C99 has hexadecimal floating point literals, C++ doesn't...
+ const float fconst = strtof("-0xCDEF01p-63", nullptr); //-1.46325e-012
+ const double dconst = strtod("-0x1DEF0102030405p-375", nullptr); //-1.09484e-097
+ //We will be assuming IEEE 754 here
+
+ write_little(str, fconst);
+ write_big (str, fconst);
+
+ const char expected[] = {
+ '\x01', '\xEF', '\xCD', '\xAB',
+
+ '\xAB', '\xCD', '\xEF', '\x01',
+ 0}; //Null terminator
+ ASSERT(str.str() == expected);
+
+ float f;
+ double d;
+
+ read_little(str, f);
+ ASSERT(f == fconst);
+
+ read_big(str, f);
+ ASSERT(f == fconst);
+
+ ASSERT(str); //Check if stream has failed
+}
+
int main()
{
test_uint();
test_sint();
+ test_float();
}