Commit 45252e50 authored by Steven Murray's avatar Steven Murray
Browse files

Added cta::ByteArray::getAdler32()

parent 76c97216
......@@ -47,7 +47,8 @@ target_link_libraries (ctacommon
castorcommon
pthread
${SQLITE3_LIBRARY_RELEASE}
uuid)
uuid
z)
set (COMMON_UNIT_TESTS_LIB_SRC_FILES
checksum/ByteArrayTest.cpp
......
......@@ -19,6 +19,7 @@
#include "common/checksum/ByteArray.hpp"
#include <ostream>
#include <zlib.h>
//------------------------------------------------------------------------------
// constructor
......@@ -129,6 +130,14 @@ const uint8_t *cta::ByteArray::getBytes() const throw() {
return m_bytes;
}
//------------------------------------------------------------------------------
// getAdler32
//------------------------------------------------------------------------------
uint32_t cta::ByteArray::getAdler32() const {
const uint32_t checksum = adler32(0L, Z_NULL, 0);
return adler32(checksum, m_bytes, m_size);
}
//------------------------------------------------------------------------------
// operator<<
//------------------------------------------------------------------------------
......
......@@ -118,6 +118,11 @@ public:
*/
const uint8_t *getBytes() const throw();
/**
* Returns the adler 32 checksum of the array of bytes.
*/
uint32_t getAdler32() const;
private:
/**
......
......@@ -206,4 +206,17 @@ TEST_F(cta_ByteArrayTest, equality_operator_ne) {
ASSERT_NE(byteArray1, byteArray2);
}
TEST_F(cta_ByteArrayTest, adler32_empty_array) {
// The adler32 of an empty buffer is 1
cta::ByteArray byteArray;
ASSERT_EQ((uint32_t)1, byteArray.getAdler32());
}
TEST_F(cta_ByteArrayTest, adler32_array_of_character_1) {
// The adler32 of an empty buffer is 1
const uint8_t c = '1';
cta::ByteArray byteArray(1, &c);
ASSERT_EQ((uint32_t)0x320032, byteArray.getAdler32());
}
} // namespace unitTests
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment