Merge tag '0.8.4'

This commit is contained in:
Sebastian Messmer 2015-12-16 00:26:45 +01:00
commit 478a3600ae
26 changed files with 80 additions and 24 deletions

View File

@ -5,7 +5,7 @@ compiler:
before_install:
- wget https://raw.githubusercontent.com/smessmer/travis-utils/master/update_gcc_version.sh
&& chmod +x update_gcc_version.sh
&& ./update_gcc_version.sh 4.9
&& ./update_gcc_version.sh 4.8
&& rm update_gcc_version.sh
before_script:
- wget https://raw.githubusercontent.com/smessmer/travis-utils/master/setup_biicode_project.sh

View File

@ -4,10 +4,11 @@
#include <stdexcept>
#include <string>
#include "../macros.h"
namespace cpputils {
class AssertFailed : public std::exception {
class AssertFailed final: public std::exception {
public:
AssertFailed(const std::string &message) : _message(message) { }

View File

@ -9,7 +9,7 @@
messmer/spdlog: 1
[parent]
messmer/cpp-utils: 7
messmer/cpp-utils: 8
[paths]
# Local directories to look for headers (within block)
# /

View File

@ -7,7 +7,7 @@
namespace cpputils {
//TODO Test
class RandomPadding {
class RandomPadding final {
public:
static Data add(const Data &data, size_t targetSize);
static boost::optional<Data> remove(const Data &data);

View File

@ -8,7 +8,7 @@
namespace cpputils {
template<size_t KEY_LENGTH>
class DerivedKey {
class DerivedKey final {
public:
DerivedKey(DerivedKeyConfig config, const FixedSizeData<KEY_LENGTH> &key): _config(std::move(config)), _key(key) {}
DerivedKey(DerivedKey &&rhs) = default;

View File

@ -13,7 +13,7 @@ namespace cpputils {
//TODO Test operator==/!=
//TODO Use SCryptSettings as a member here instead of storing _N, _r, _p.
class DerivedKeyConfig {
class DerivedKeyConfig final {
public:
DerivedKeyConfig(Data salt, uint64_t N, uint32_t r, uint32_t p)
: _salt(std::move(salt)),

View File

@ -7,7 +7,7 @@
namespace cpputils {
class DataFixture {
class DataFixture final {
public:
static Data generate(size_t size, long long int seed = 1);

12
data/DataUtils.cpp Normal file
View File

@ -0,0 +1,12 @@
#include "DataUtils.h"
namespace cpputils {
namespace DataUtils {
Data resize(Data data, size_t newSize) {
Data newData(newSize);
newData.FillWithZeroes(); // TODO Only fill region after copied old data with zeroes
std::memcpy(newData.data(), data.data(), std::min(newData.size(), data.size()));
return newData;
}
}
}

17
data/DataUtils.h Normal file
View File

@ -0,0 +1,17 @@
#pragma once
#ifndef MESSMER_CPPUTILS_DATA_DATAUTILS_H
#define MESSMER_CPPUTILS_DATA_DATAUTILS_H
#include "Data.h"
namespace cpputils {
namespace DataUtils {
//TODO Test
//Return a new data object with the given size and initialize as much as possible with the given input data.
//If the new data object is larger, then the remaining bytes will be zero filled.
Data resize(Data data, size_t newSize);
}
}
#endif

View File

@ -94,7 +94,7 @@ namespace cpputils {
return _readData(size);
}
inline Data Deserializer::_readData(uint64_t size) {
inline Data Deserializer::_readData(size_t size) {
Data result(size);
std::memcpy(static_cast<char*>(result.data()), static_cast<const char*>(_source->dataOffset(_pos)), size);
_pos += size;

View File

@ -6,6 +6,7 @@
#include <vector>
#include <iostream>
#include <boost/optional.hpp>
#include "../macros.h"
namespace cpputils {
@ -17,7 +18,7 @@ public:
virtual void print(const std::string &output) = 0;
};
class IOStreamConsole: public Console {
class IOStreamConsole final: public Console {
public:
IOStreamConsole();
IOStreamConsole(std::ostream &output, std::istream &input);
@ -30,6 +31,8 @@ private:
std::ostream &_output;
std::istream &_input;
DISALLOW_COPY_AND_ASSIGN(IOStreamConsole);
};
}

View File

@ -53,7 +53,7 @@
namespace cpputils {
class pipestream : public std::streambuf {
class pipestream final : public std::streambuf {
private:
typedef std::streambuf::traits_type traits_type;
typedef std::string::size_type string_size_t;

View File

@ -4,6 +4,7 @@
#include <mutex>
#include <condition_variable>
#include "../macros.h"
//TODO Test
//TODO Merge lock folder with thread folder
@ -12,7 +13,7 @@ namespace cpputils {
// Like a condition variable, but without spurious wakeups.
// The waiting threads are only woken, when notify() is called.
// After a call to release(), future calls to wait() will not block anymore.
class ConditionBarrier {
class ConditionBarrier final {
public:
ConditionBarrier() :_mutex(), _cv(), _triggered(false) {
}
@ -33,6 +34,8 @@ namespace cpputils {
std::mutex _mutex;
std::condition_variable _cv;
bool _triggered;
DISALLOW_COPY_AND_ASSIGN(ConditionBarrier);
};
}

View File

@ -6,7 +6,7 @@
namespace cpputils {
template<class LockName>
class MutexPoolLock {
class MutexPoolLock final {
public:
MutexPoolLock(LockPool<LockName> *pool, const LockName &lockName): _pool(pool), _lockName(lockName) {
_pool->lock(_lockName);

View File

@ -7,7 +7,7 @@
namespace cpputils {
namespace logging {
class Logger {
class Logger final {
public:
void setLogger(std::shared_ptr<spdlog::logger> logger) {
_logger = logger;

View File

@ -10,14 +10,14 @@
//TODO Test that this solves the problem (add test unit file that doesn't compile without)
#include "unique_ref.h"
#include <boost/optional/optional_io.hpp>
//gtest/boost::optional workaround for working with optional<unique_ref<T>>
namespace boost {
namespace cpputils {
template<typename T>
inline std::ostream& operator<<(std::ostream& out, const cpputils::unique_ref<T> &ref) {
out << ref.get();
return out;
}
}
#include <boost/optional/optional_io.hpp>
#endif

View File

@ -1,6 +1,7 @@
#include "subprocess.h"
#include <cstdio>
#include <stdexcept>
#include <sys/wait.h>
using std::string;

View File

@ -3,15 +3,18 @@
#define MESSMER_CPPUTILS_PROCESS_SUBPROCESS_H
#include <string>
#include "../macros.h"
namespace cpputils {
//TODO Test
class Subprocess {
class Subprocess final {
public:
static std::string call(const std::string &command);
static int callAndGetReturnCode(const std::string &command);
private:
static FILE* _call(const std::string &command);
DISALLOW_COPY_AND_ASSIGN(Subprocess);
};
}

View File

@ -12,6 +12,9 @@ namespace cpputils {
protected:
void _get(void *target, size_t bytes) override;
private:
DISALLOW_COPY_AND_ASSIGN(OSRandomGenerator);
};
inline OSRandomGenerator::OSRandomGenerator() {}

View File

@ -9,7 +9,7 @@
#include <mutex>
namespace cpputils {
class Random {
class Random final {
public:
static PseudoRandomPool &PseudoRandom() {
std::unique_lock <std::mutex> lock(_mutex);
@ -25,6 +25,8 @@ namespace cpputils {
private:
static std::mutex _mutex;
DISALLOW_COPY_AND_ASSIGN(Random);
};
}

View File

@ -7,7 +7,7 @@
namespace cpputils {
//TODO Test
class RandomDataBuffer {
class RandomDataBuffer final {
public:
RandomDataBuffer();

View File

@ -7,6 +7,8 @@
namespace cpputils {
class RandomGenerator {
public:
RandomGenerator();
template<size_t SIZE> FixedSizeData<SIZE> getFixedSize();
Data get(size_t size);
@ -14,8 +16,13 @@ namespace cpputils {
virtual void _get(void *target, size_t bytes) = 0;
private:
static std::mutex _mutex;
DISALLOW_COPY_AND_ASSIGN(RandomGenerator);
};
inline RandomGenerator::RandomGenerator() {
}
template<size_t SIZE> inline FixedSizeData<SIZE> RandomGenerator::getFixedSize() {
FixedSizeData<SIZE> result = FixedSizeData<SIZE>::Null();
_get(result.data(), SIZE);

View File

@ -8,7 +8,7 @@
namespace cpputils {
//TODO Test
class RandomGeneratorThread {
class RandomGeneratorThread final {
public:
RandomGeneratorThread(ThreadsafeRandomDataBuffer *buffer, size_t minSize, size_t maxSize);

View File

@ -9,7 +9,7 @@
namespace cpputils {
//TODO Test
class ThreadsafeRandomDataBuffer {
class ThreadsafeRandomDataBuffer final {
public:
ThreadsafeRandomDataBuffer();

View File

@ -21,6 +21,6 @@ TEST(AssertTest_DebugBuild, DiesIfFalse) {
TEST(AssertTest_DebugBuild, AssertMessage) {
EXPECT_DEATH(
ASSERT(2==5, "my message"),
"Assertion \\[2==5\\] failed in .*/assert_debug_test.cpp:25: my message"
"Assertion \\[2==5\\] failed in .*/assert_debug_test.cpp:[0-9]+: my message"
);
}
}

View File

@ -191,12 +191,16 @@ TEST_F(DataTest, Inequality_DifferentLastByte) {
EXPECT_TRUE(data1 != data2);
}
//Needs 64bit for representation. This value isn't in the size param list, because the list is also used for read/write checks.
#ifdef __x86_64__
TEST_F(DataTest, LargesizeSize) {
size_t size = 10L*1024*1024*1024;
//Needs 64bit for representation. This value isn't in the size param list, because the list is also used for read/write checks.
uint64_t size = 4.5L*1024*1024*1024;
Data data(size);
EXPECT_EQ(size, data.size());
}
#else
#warning This is not a 64bit architecture. Large size data tests are disabled.
#endif
TEST_F(DataTest, LoadingNonexistingFile) {
TempFile file(false); // Pass false to constructor, so the tempfile is not created