From 5ef706ee24ccf6da81f480b956e5ee81c04cd99d Mon Sep 17 00:00:00 2001 From: Alvaro Date: Mon, 18 Mar 2024 23:32:59 +0100 Subject: [PATCH] Fixed StreamBuffer read 64bit little endian, use ByteArray name, Matrix4 moved functions to class body --- doc/doc.h | 6 +- include/asl/Http.h | 10 +-- include/asl/Matrix4.h | 121 ++++++++++++++++--------------------- include/asl/Path.h | 4 ++ include/asl/SHA1.h | 2 +- include/asl/SerialPort.h | 2 +- include/asl/Socket.h | 6 +- include/asl/StreamBuffer.h | 32 +++++----- include/asl/WebSocket.h | 14 ++--- include/asl/util.h | 6 +- src/File.cpp | 8 +-- src/Http.cpp | 10 +-- src/SHA1.cpp | 2 +- src/SerialPort.cpp | 4 +- src/Socket.cpp | 6 +- src/WebSocket.cpp | 4 +- src/util.cpp | 12 ++-- tests/unittests.cpp | 4 +- tests/unittests4.cpp | 18 +++--- 19 files changed, 130 insertions(+), 141 deletions(-) diff --git a/doc/doc.h b/doc/doc.h index f06c749..8ff9631 100644 --- a/doc/doc.h +++ b/doc/doc.h @@ -73,7 +73,7 @@ With CMake 3.14+, instead of using `find_package()`, you can download and build ~~~ include(FetchContent) -FetchContent_Declare(asl URL https://github.com/aslze/asl/archive/1.11.7.zip) +FetchContent_Declare(asl URL https://github.com/aslze/asl/archive/1.11.10.zip) FetchContent_MakeAvailable(asl) ~~~ @@ -310,7 +310,7 @@ Map, Dic, Stack, HashMap). These classes are reference-counted, so they are copied by reference. If a separate copy is required, use the `clone()` method: ~~~ -Array a = array(1, 2, 3); +Array a = { 1, 2, 3 }; Array b = a; // b is the same as a Array c = a.clone(); // c is a separate copy of a ~~~ @@ -613,7 +613,7 @@ that runs all defined tests. Use the `ASL_TEST_ENABLE()` macro if you will provi ~~~ #include -ASL_TEST_ENABLE_MAIN(); +ASL_TEST_ENABLE_MAIN() ASL_TEST(Car) { diff --git a/include/asl/Http.h b/include/asl/Http.h index 10912c9..65d4f4c 100644 --- a/include/asl/Http.h +++ b/include/asl/Http.h @@ -162,13 +162,13 @@ class ASL_API HttpMessage /** Sets the body of the message as a binary blob. */ - void put(const Array& data); + void put(const ByteArray& data); /** Sets the body of the message as a text string. */ void put(const String& body); - void put(const char* body) { put(Array((const byte*)body, (int)strlen(body))); } + void put(const char* body) { put(ByteArray((const byte*)body, (int)strlen(body))); } /** Sets the body of the message as a JSON document. */ @@ -180,7 +180,7 @@ class ASL_API HttpMessage /** Returns the binary body of the message. */ - const Array& body() const { return _body; } + const ByteArray& body() const { return _body; } /** Returns the message body as text */ @@ -224,7 +224,7 @@ class ASL_API HttpMessage String _command; String _proto; Dic<> _headers; - Array _body; + ByteArray _body; mutable Socket* _socket; Function _progress; Shared _sink; @@ -243,7 +243,7 @@ enum HttpMethod { HTTP_UNKNOWN, HTTP_GET, HTTP_POST, HTTP_PUT, HTTP_PATCH, HTTP_ An HTTP request that servers can read from. An HttpRequest has a method (such as GET or POST), optional headers, and optional body. The body can be a -String, an Array or a Var. In the case of a Var it will be encoded as JSON and the request content type +String, a ByteArray or a Var. In the case of a Var it will be encoded as JSON and the request content type header automatically set. \sa HttpServer diff --git a/include/asl/Matrix4.h b/include/asl/Matrix4.h index 34b4f8d..1191a07 100644 --- a/include/asl/Matrix4.h +++ b/include/asl/Matrix4.h @@ -161,24 +161,70 @@ class Matrix4_ /** Returns this matrix plus `B` */ - Matrix4_ operator+(const Matrix4_& B) const; + Matrix4_ operator+(const Matrix4_& B) const + { + Matrix4_ C; + for (int i = 0; i < 4; i++) + for (int j = 0; j < 4; j++) + C(i, j) = a[i][j] + B(i, j); + return C; + } /** Returns this matrix minus `B` */ - Matrix4_ operator-(const Matrix4_& B) const; + Matrix4_ operator-(const Matrix4_& B) const + { + Matrix4_ C; + for (int i = 0; i < 4; i++) + for (int j = 0; j < 4; j++) + C(i, j) = a[i][j] - B(i, j); + return C; + } /** Returns this matrix multiplied by `B` */ - Matrix4_ operator*(const Matrix4_& B) const; + Matrix4_ operator*(const Matrix4_& B) const + { + Matrix4_ C; + for (int i = 0; i < 4; i++) + for (int j = 0; j < 4; j++) + C(i, j) = a[i][0] * B(0, j) + a[i][1] * B(1, j) + a[i][2] * B(2, j) + a[i][3] * B(3, j); + return C; + } + /** + Multipies this matrix by `B` + */ + Matrix4_& operator*=(const Matrix4_& B) + { + Matrix4_ C; + for (int i = 0; i < 4; i++) + for (int j = 0; j < 4; j++) + C(i, j) = a[i][0] * B(0, j) + a[i][1] * B(1, j) + a[i][2] * B(2, j) + a[i][3] * B(3, j); + *this = C; + return *this; + } /** Returns this matrix multipled by scalar `t` */ - Matrix4_ operator*(T t) const; + Matrix4_ operator*(T t) const + { + Matrix4_ C; + for (int i = 0; i < 4; i++) + for (int j = 0; j < 4; j++) + C(i, j) = t * a[i][j]; + return C; + } friend Matrix4_ operator*(T t, const Matrix4_& m) {return m * t;} /** Multiplies this matrix by scalar `t` */ - Matrix4_& operator*=(T t); + Matrix4_& operator*=(T t) + { + for (int i = 0; i < 4; i++) + for (int j = 0; j < 4; j++) + a[i][j] *= t; + return *this; + } /** Returns vector `p` left-multiplied by this matrix. */ @@ -294,11 +340,6 @@ class Matrix4_ given as a string, such as "XYZ" or "XYZ*", equivalent to the fromEuler function */ Vec3_ eulerAngles(const char* a) const; - - /** - Multipies this matrix by `B` - */ - Matrix4_& operator*=(const Matrix4_& B); /** Returns the inverse of this matrix */ @@ -383,66 +424,6 @@ asl::Matrix4_ orthonormalize(const asl::Matrix4_& m) namespace asl { -template -Matrix4_ Matrix4_::operator+(const Matrix4_& B) const -{ - Matrix4_ C; - for (int i = 0; i < 4; i++) - for (int j = 0; j < 4; j++) - C(i, j) = a[i][j] + B(i, j); - return C; -} - -template -Matrix4_ Matrix4_::operator-(const Matrix4_& B) const -{ - Matrix4_ C; - for (int i = 0; i < 4; i++) - for (int j = 0; j < 4; j++) - C(i, j) = a[i][j] - B(i, j); - return C; -} - -template -inline Matrix4_ Matrix4_::operator*(const Matrix4_& B) const -{ - Matrix4_ C; - for (int i = 0; i < 4; i++) - for (int j = 0; j < 4; j++) - C(i, j) = a[i][0] * B(0, j) + a[i][1] * B(1, j) + a[i][2] * B(2, j) + a[i][3] * B(3, j); - return C; -} - -template -Matrix4_ Matrix4_::operator*(T t) const -{ - Matrix4_ C; - for (int i = 0; i < 4; i++) - for (int j = 0; j < 4; j++) - C(i, j) = t * a[i][j]; - return C; -} - -template -Matrix4_& Matrix4_::operator*=(T t) -{ - for (int i = 0; i < 4; i++) - for (int j = 0; j < 4; j++) - a[i][j] *= t; - return *this; -} - -template -inline Matrix4_& Matrix4_::operator*=(const Matrix4_& B) -{ - Matrix4_ C; - for (int i = 0; i < 4; i++) - for (int j = 0; j < 4; j++) - C(i, j) = a[i][0] * B(0, j) + a[i][1] * B(1, j) + a[i][2] * B(2, j) + a[i][3] * B(3, j); - *this = C; - return *this; -} - template Matrix4_ Matrix4_::identity() { diff --git a/include/asl/Path.h b/include/asl/Path.h index fcaa3f3..87f0bfd 100644 --- a/include/asl/Path.h +++ b/include/asl/Path.h @@ -94,6 +94,10 @@ class ASL_API Path */ bool isAbsolute() const; /** + Returns true if this has a parent directory and is not just a name + */ + bool hasDirectory() const { return name() == _path; } + /** Removes double dots in a path by stepping up one directory each time. */ Path& removeDDots(); diff --git a/include/asl/SHA1.h b/include/asl/SHA1.h index b0a61d4..3ea84c2 100644 --- a/include/asl/SHA1.h +++ b/include/asl/SHA1.h @@ -23,7 +23,7 @@ class SHA1 SHA1(); static Hash hash(const byte* data, int len); static Hash hash(const char* data) { return hash((const byte*)data, (int)strlen(data)); } - static Hash hash(const Array& data); + static Hash hash(const ByteArray& data); static Hash hash(const String& data); private: void transform(const byte buffer[64]); diff --git a/include/asl/SerialPort.h b/include/asl/SerialPort.h index 1d5f59f..1cf26cf 100644 --- a/include/asl/SerialPort.h +++ b/include/asl/SerialPort.h @@ -90,7 +90,7 @@ class ASL_API SerialPort */ int read(void* p, int n); - Array read(int n); + ByteArray read(int n); /** Writes the given string to the port diff --git a/include/asl/Socket.h b/include/asl/Socket.h index 5e082c9..ec6d4ab 100644 --- a/include/asl/Socket.h +++ b/include/asl/Socket.h @@ -90,7 +90,7 @@ class ASL_API InetAddress */ static Array lookup(const String& name); protected: - Array _data; + ByteArray _data; Type _type; }; @@ -128,7 +128,7 @@ ASL_SMART_CLASS(Socket, SmartObject) virtual int available(); virtual int read(void* data, int size); virtual int write(const void* data, int n); - Array read(int n = -1); + ByteArray read(int n = -1); void skip(int n); virtual bool waitInput(double timeout = 60); int error() const { return _error; } @@ -236,7 +236,7 @@ class ASL_API Socket : public SmartObject /** Reads n bytes and returns them as an array of bytes, or reads all available bytes if no argument is given. */ - Array read(int n = -1) { return _()->read(n); } + ByteArray read(int n = -1) { return _()->read(n); } /** Skips (reads and discards) the next n bytes from the socket. diff --git a/include/asl/StreamBuffer.h b/include/asl/StreamBuffer.h index d70254b..44cd2d4 100644 --- a/include/asl/StreamBuffer.h +++ b/include/asl/StreamBuffer.h @@ -22,7 +22,7 @@ struct AsBytes { union { T x; byte b[sizeof(T)]; }; AsBytes() {} - AsBytes(const T& a) : x(a) {} + AsBytes(const T& a) { memcpy(b, &a, sizeof(T)); } byte& operator[](int i) { return b[i]; } }; @@ -46,7 +46,7 @@ This class allows reading a memory buffer as a binary stream. It can read bytes, point numbers in big-endian or little-endian byte order. You have to make sure you don't read past the bounds of the buffer. ~~~ -Array data = File("data.bin").content(); +ByteArray data = File("data.bin").content(); StreamBufferReader buffer (data, ENDIAN_BIG); int n = buffer.read(); double x, y, z; @@ -62,7 +62,7 @@ class ASL_API StreamBufferReader /** Constructs a buffer reader from a byte array */ - StreamBufferReader(const Array& data, Endian e = ENDIAN_LITTLE) : _ptr(data.ptr()), _end(data.ptr() + data.length()), _endian(e) {} + StreamBufferReader(const ByteArray& data, Endian e = ENDIAN_LITTLE) : _ptr(data.data()), _end(data.data() + data.length()), _endian(e) {} /** Constructs a buffer reader from a raw byte array */ @@ -120,7 +120,7 @@ class ASL_API StreamBufferReader ? ((ULong)_ptr[0] << 56) | ((ULong)_ptr[1] << 48) | ((ULong)_ptr[2] << 40) | ((ULong)_ptr[3] << 32) | ((ULong)_ptr[4] << 24) | ((ULong)_ptr[5] << 16) | ((ULong)_ptr[6] << 8) | ((ULong)_ptr[7]) : ((ULong)_ptr[7] << 56) | ((ULong)_ptr[6] << 48) | ((ULong)_ptr[5] << 40) | ((ULong)_ptr[4] << 32) | - ((ULong)_ptr[3] << 24) | ((ULong)_ptr[2] << 16) | ((ULong)_ptr[1] << 8) | ((ULong)_ptr[3])); + ((ULong)_ptr[3] << 24) | ((ULong)_ptr[2] << 16) | ((ULong)_ptr[1] << 8) | ((ULong)_ptr[0])); x = a.other(); _ptr += 8; return *this; @@ -179,7 +179,7 @@ class ASL_API StreamBufferReader /** Reads n bytes into an Array (or all remaining bytes by default) */ - Array read(int n = -1) { if (n < 0) n = length(); Array a(n); memcpy(a.data(), _ptr, n); _ptr += n; return a; } + ByteArray read(int n = -1) { if (n < 0) n = length(); ByteArray a(n); memcpy(a.data(), _ptr, n); _ptr += n; return a; } protected: const byte* _ptr; @@ -193,7 +193,7 @@ typedef StreamBufferReader BufferReader; This class is a buffer that can be written to as a binary stream. The buffer is initially empty and grows as you append variables. You can change endianness at any moment. -You can then get the content as an Array and for example write it to a file or send it +You can then get the content as a ByteArray and for example write it to a file or send it through a socket. ~~~ StreamBuffer buffer(ENDIAN_BIG); @@ -212,8 +212,8 @@ class StreamBuffer : public Array public: ASL_EXPLICIT StreamBuffer(Endian e = ENDIAN_LITTLE) : _endian(e) {} - Array& operator*() { return (Array&)*this; } - const Array& operator*() const { return (const Array&)*this; } + ByteArray& operator*() { return (ByteArray&)*this; } + const ByteArray& operator*() const { return (const ByteArray&)*this; } /** Set endianness for binary writing @@ -227,8 +227,7 @@ class StreamBuffer : public Array template StreamBuffer& operator<<(const T& x) { - AsBytes y; - memcpy(y.b, &x, sizeof(T)); + AsBytes y(x); if (_endian == ASL_OTHER_ENDIAN) swapBytes(y); write(y.b, sizeof(T)); @@ -237,25 +236,25 @@ class StreamBuffer : public Array StreamBuffer& operator<<(const bool& x) { - (Array&)(*this) << byte(x? 1 : 0); + (ByteArray&)(*this) << byte(x ? 1 : 0); return *this; } StreamBuffer& operator<<(const byte& x) { - (Array&)(*this) << x; + (ByteArray&)(*this) << x; return *this; } StreamBuffer& operator<<(const char& x) { - (Array&)(*this) << *(byte*)&x; + (ByteArray&)(*this) << *(byte*)&x; return *this; } StreamBuffer& operator<<(const signed char& x) { - (Array&)(*this) << *(byte*)&x; + (ByteArray&)(*this) << *(byte*)&x; return *this; } @@ -272,7 +271,7 @@ class StreamBuffer : public Array return *this; } - StreamBuffer& operator<<(const Array& x) + StreamBuffer& operator<<(const ByteArray& x) { write(x.data(), x.length()); return *this; @@ -294,6 +293,9 @@ class StreamBuffer : public Array Endian _endian; }; +#ifdef _MSC_VER +#pragma warning(pop) +#endif } #endif diff --git a/include/asl/WebSocket.h b/include/asl/WebSocket.h index 9a09cb5..af0015c 100644 --- a/include/asl/WebSocket.h +++ b/include/asl/WebSocket.h @@ -17,18 +17,18 @@ struct WebSocketMsg { friend class WebSocket; WebSocketMsg() {} - WebSocketMsg(const Array& data) : _data(data) {} + WebSocketMsg(const ByteArray& data) : _data(data) {} operator String() const; operator Var() const; - operator Array() const { return _data; } + operator ByteArray() const { return _data; } int length() const { return _data.length(); } operator bool() const { return length() != 0; } bool operator!() const { return length() == 0; } const char* operator*() const; - void append(const Array& data) { _data.append(data); } + void append(const ByteArray& data) { _data.append(data); } private: WebSocketMsg& fix(); - Array _data; + ByteArray _data; }; /** @@ -78,7 +78,7 @@ class ASL_API WebSocket /** Sends a binary message to the peer */ - void send(const Array& m) { send(m.data(), m.length(), FRAME_BINARY); } + void send(const ByteArray& m) { send(m.data(), m.length(), FRAME_BINARY); } /** Sends a text message to the peer */ @@ -113,7 +113,7 @@ class ASL_API WebSocket bool closed(); protected: Socket _socket; - Array _buffer; + ByteArray _buffer; bool _isClient; bool _closed; int _code; @@ -173,7 +173,7 @@ class ASL_API WebSocketServer: public SocketServer const Array& clients() const { return _clients; } Mutex& mutex() { return _mutex; } protected: - Array readMessage(); + ByteArray readMessage(); private: void process(Socket& socket, const Dic& headers); void serve(Socket client); diff --git a/include/asl/util.h b/include/asl/util.h index 99b8c6b..9168dee 100644 --- a/include/asl/util.h +++ b/include/asl/util.h @@ -17,12 +17,12 @@ class Array_; @{ */ -ASL_API Array decodeBase64(const char* src, int n = -1); +ASL_API ByteArray decodeBase64(const char* src, int n = -1); /** Decodes a base64 encoded string into a byte array; the string can contain whitespace. */ -inline Array decodeBase64(const String& s) +inline ByteArray decodeBase64(const String& s) { return decodeBase64((const char*)s, s.length()); } @@ -62,7 +62,7 @@ String encodeHex(const Array_& src) { return encodeHex((const byte*)src /** Decodes a hexadecimal encoded string into a byte array */ -ASL_API Array decodeHex(const String& src); +ASL_API ByteArray decodeHex(const String& src); /**@}*/ diff --git a/src/File.cpp b/src/File.cpp index 15146b4..0f84abc 100644 --- a/src/File.cpp +++ b/src/File.cpp @@ -274,21 +274,21 @@ bool File::setLastModified(const Date& t) #endif } -Array File::content() +ByteArray File::content() { return firstBytes((int)size()); } -bool File::put(const Array& data) +bool File::put(const ByteArray& data) { if(!_file && !open(_path, WRITE)) return false; return write(data.data(), data.length()) == data.length(); } -Array File::firstBytes(int n) +ByteArray File::firstBytes(int n) { - Array data(n); + ByteArray data(n); if (!_file && !open(_path)) { data.clear(); return data; diff --git a/src/Http.cpp b/src/Http.cpp index 472a1a2..2cf22e4 100644 --- a/src/Http.cpp +++ b/src/Http.cpp @@ -137,8 +137,8 @@ Url::Url(const String& url) struct HttpSinkArray : public HttpSink { - Array* a; - HttpSinkArray(Array& a) : a(&a) {} + ByteArray* a; + HttpSinkArray(ByteArray& a) : a(&a) {} int write(byte* p, int n) { a->append(p, n); @@ -146,7 +146,7 @@ struct HttpSinkArray : public HttpSink } void use(HttpMessage* m) { - a = (Array*)&m->body(); + a = (ByteArray*)&m->body(); } void init(int n) { @@ -186,11 +186,11 @@ Var HttpMessage::json() const void HttpMessage::put(const String& body) { - _body = Array((byte*)*body, body.length()); + _body = ByteArray((const byte*)*body, body.length()); setHeader("Content-Length", _body.length()); } -void HttpMessage::put(const Array& data) +void HttpMessage::put(const ByteArray& data) { _body = data; setHeader("Content-Length", _body.length()); diff --git a/src/SHA1.cpp b/src/SHA1.cpp index 292b6d3..b009e58 100644 --- a/src/SHA1.cpp +++ b/src/SHA1.cpp @@ -211,7 +211,7 @@ SHA1::Hash SHA1::hash(const byte* data, int len) return sha.end(); } -SHA1::Hash SHA1::hash(const Array& data) +SHA1::Hash SHA1::hash(const ByteArray& data) { return hash(data.data(), data.length()); } diff --git a/src/SerialPort.cpp b/src/SerialPort.cpp index 5815b3c..6abb87e 100644 --- a/src/SerialPort.cpp +++ b/src/SerialPort.cpp @@ -163,9 +163,9 @@ int SerialPort::read(void *p, int n) return bytes; } -Array SerialPort::read(int n) +ByteArray SerialPort::read(int n) { - Array a(n); + ByteArray a(n); n = read(a.data(), n); a.resize(max(0, n)); return a; diff --git a/src/Socket.cpp b/src/Socket.cpp index 991ce4a..8346f8d 100644 --- a/src/Socket.cpp +++ b/src/Socket.cpp @@ -622,16 +622,16 @@ int Socket_::write(const void* data, int n) #endif } -Array Socket_::read(int n) +ByteArray Socket_::read(int n) { - Array a((n < 0) ? available() : n); + ByteArray a((n < 0) ? available() : n); n = read(&a[0], a.length()); return a.resize(max(0, n)); } void Socket_::skip(int n) { - Array a(n); + ByteArray a(n); read(a.data(), a.length()); } diff --git a/src/WebSocket.cpp b/src/WebSocket.cpp index 5fddb27..28cabd1 100644 --- a/src/WebSocket.cpp +++ b/src/WebSocket.cpp @@ -265,7 +265,7 @@ WebSocketMsg WebSocket::receive() bool haveMsg = false; while (!haveMsg) { - Array buffer; + ByteArray buffer; byte b0, mlen; DEBUG_LOG("receive\n"); if (closed()) { @@ -371,7 +371,7 @@ void WebSocket::send(const byte* p, int length, FrameType type) mask = _random.get(); buf << mask; } - Array data(p, length); + ByteArray data(p, length); if (mask != 0){ swapBytes(mask); data.resize(data.length() + 4); diff --git a/src/util.cpp b/src/util.cpp index dcd9e49..bbcc749 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -256,12 +256,12 @@ String encodeBase64(const byte* data, int n) #ifdef ASL_B64_NOWS -Array decodeBase64(const char* src0, int n) +ByteArray decodeBase64(const char* src0, int n) { const byte* src = (const byte*)src0; int len = n < 0? (int)strlen(src0) : n; int len2 = len / 4 * 3; - Array result(len2); + ByteArray result(len2); if (len & 3) { result.clear(); return result; @@ -288,12 +288,12 @@ Array decodeBase64(const char* src0, int n) #else -Array decodeBase64(const char* src0, int n) +ByteArray decodeBase64(const char* src0, int n) { const byte* src = (const byte*)src0; int len = n < 0 ? (int)strlen(src0) : n; int len2 = len / 4 * 3; - Array result(len2); + ByteArray result(len2); if (len < 4) { result.clear(); return result; @@ -334,9 +334,9 @@ String encodeHex(const byte* data, int n) return h; } -Array decodeHex(const String& s) +ByteArray decodeHex(const String& s) { - Array a(s.length()/2); + ByteArray a(s.length() / 2); for (int i = 0; i < s.length(); i += 2) a[i/2] = (byte)s.substring(i, i + 2).hexToInt(); return a; diff --git a/tests/unittests.cpp b/tests/unittests.cpp index 46511a0..d55cdc2 100644 --- a/tests/unittests.cpp +++ b/tests/unittests.cpp @@ -620,13 +620,13 @@ ASL_TEST(Base64) ASL_ASSERT(b64 == "MjAwMS1BIFNwYWNlIE9keXNzZXk="); String c = decodeBase64(b64); ASL_ASSERT(c == input); - Array data = array(0x05, 0xf0, 0x7a, 0x45); + ByteArray data = array(0x05, 0xf0, 0x7a, 0x45); b64 = encodeBase64(data); ASL_ASSERT(b64 == "BfB6RQ=="); ASL_ASSERT(decodeBase64(b64) == data); String h = encodeHex(data); ASL_ASSERT(h == "05f07a45"); - Array data2 = decodeHex(h); + ByteArray data2 = decodeHex(h); ASL_ASSERT(data == data2); String b64w = " MjAwMS\n1BIFN\n\twYWNlIE 9keXNzZXk = \n"; // with whitespace ASL_ASSERT(String(decodeBase64(b64w)) == input); diff --git a/tests/unittests4.cpp b/tests/unittests4.cpp index b1c5d6d..64edebe 100644 --- a/tests/unittests4.cpp +++ b/tests/unittests4.cpp @@ -102,9 +102,9 @@ ASL_TEST(StreamBuffer) { StreamBuffer b; b.setEndian(ENDIAN_LITTLE); - b << 'a' << 4 << 3.5 << true << 0.5f; + b << 'a' << 4 << 3.5 << true << 0.5f << 90000000000000009ll; - ASL_ASSERT(b.length() == 18); + ASL_ASSERT(b.length() == 26); ASL_ASSERT(b[0] == 'a' && b[1] == 0x04 && b[2] == 0 && b[3] == 0 && b[4] == 0) StreamBufferReader c(b.data(), b.length()); @@ -113,26 +113,28 @@ ASL_TEST(StreamBuffer) double y; bool f; float x; - c >> a >> i >> y >> f >> x; + Long l; + c >> a >> i >> y >> f >> x >> l; - ASL_ASSERT(a == 'a' && i == 4 && y == 3.5 && f == true && x == 0.5f); + ASL_ASSERT(a == 'a' && i == 4 && y == 3.5 && f == true && x == 0.5f && l == 90000000000000009ll); StreamBuffer b2; b2.setEndian(ENDIAN_BIG); - b2 << 'a' << 4 << 3.5 << 0.25f; + b2 << 'a' << 4 << 3.5 << 0.25f << l; a = ' '; i = 0; y = 0; x = 0; + l = 0; - ASL_ASSERT(b2.length() == 17); + ASL_ASSERT(b2.length() == 25); ASL_ASSERT(b2[0] == 'a' && b2[1] == 0 && b2[2] == 0 && b2[3] == 0 && b2[4] == 4) StreamBufferReader c2(b2.data(), b2.length(), ENDIAN_BIG); - c2 >> a >> i >> y >> x; + c2 >> a >> i >> y >> x >> l; - ASL_ASSERT(a == 'a' && i == 4 && y == 3.5 && x == 0.25f); + ASL_ASSERT(a == 'a' && i == 4 && y == 3.5 && x == 0.25f && l == 90000000000000009ll); } ASL_TEST(Array2)