Fix clang-tidy warnings
This commit is contained in:
parent
f4945fcfbe
commit
68a4c5646a
@ -29,6 +29,7 @@ Checks: |
|
||||
-cppcoreguidelines-avoid-magic-numbers,
|
||||
-cppcoreguidelines-macro-usage,
|
||||
-cppcoreguidelines-non-private-member-variables-in-classes,
|
||||
-cppcoreguidelines-avoid-non-const-global-variables,
|
||||
-clang-analyzer-optin.cplusplus.VirtualCall,
|
||||
-clang-analyzer-cplusplus.NewDeleteLeaks,
|
||||
-misc-macro-parentheses,
|
||||
|
@ -104,6 +104,7 @@ void DataNodeStore::removeSubtree(unique_ref<DataNode> node) {
|
||||
remove(std::move(*inner));
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(misc-no-recursion)
|
||||
void DataNodeStore::removeSubtree(uint8_t depth, const BlockId &blockId) {
|
||||
if (depth == 0) {
|
||||
remove(blockId);
|
||||
|
@ -101,6 +101,7 @@ uint32_t DataTree::forceComputeNumLeaves() const {
|
||||
return numLeaves();
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(misc-no-recursion)
|
||||
DataTree::SizeCache DataTree::_computeSizeCache(const DataNode &node) const {
|
||||
const DataLeafNode *leaf = dynamic_cast<const DataLeafNode*>(&node);
|
||||
if (leaf != nullptr) {
|
||||
|
@ -28,6 +28,7 @@ namespace blobstore {
|
||||
_traverseAndUpdateRoot(root, beginIndex, endIndex, true, onExistingLeaf, onCreateLeaf, onBacktrackFromSubtree);
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(misc-no-recursion)
|
||||
void LeafTraverser::_traverseAndUpdateRoot(unique_ref<DataNode>* root, uint32_t beginIndex, uint32_t endIndex, bool isLeftBorderOfTraversal, function<void (uint32_t index, bool isRightBorderLeaf, LeafHandle leaf)> onExistingLeaf, function<Data (uint32_t index)> onCreateLeaf, function<void (DataInnerNode *node)> onBacktrackFromSubtree) {
|
||||
ASSERT(beginIndex <= endIndex, "Invalid parameters");
|
||||
|
||||
@ -83,6 +84,7 @@ namespace blobstore {
|
||||
return DataNode::convertToNewInnerNode(std::move(root), _nodeStore->layout(), *copyOfOldRoot);
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(misc-no-recursion)
|
||||
void LeafTraverser::_traverseExistingSubtree(const blockstore::BlockId &blockId, uint8_t depth, uint32_t beginIndex, uint32_t endIndex, uint32_t leafOffset, bool isLeftBorderOfTraversal, bool isRightBorderNode, bool growLastLeaf, function<void (uint32_t index, bool isRightBorderLeaf, LeafHandle leaf)> onExistingLeaf, function<Data (uint32_t index)> onCreateLeaf, function<void (DataInnerNode *node)> onBacktrackFromSubtree) {
|
||||
if (depth == 0) {
|
||||
ASSERT(beginIndex <= 1 && endIndex <= 1,
|
||||
@ -111,6 +113,7 @@ namespace blobstore {
|
||||
}
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(misc-no-recursion)
|
||||
void LeafTraverser::_traverseExistingSubtree(DataInnerNode *root, uint32_t beginIndex, uint32_t endIndex, uint32_t leafOffset, bool isLeftBorderOfTraversal, bool isRightBorderNode, bool growLastLeaf, function<void (uint32_t index, bool isRightBorderLeaf, LeafHandle leaf)> onExistingLeaf, function<Data (uint32_t index)> onCreateLeaf, function<void (DataInnerNode *node)> onBacktrackFromSubtree) {
|
||||
ASSERT(beginIndex <= endIndex, "Invalid parameters");
|
||||
|
||||
@ -169,6 +172,7 @@ namespace blobstore {
|
||||
}
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(misc-no-recursion)
|
||||
unique_ref<DataNode> LeafTraverser::_createNewSubtree(uint32_t beginIndex, uint32_t endIndex, uint32_t leafOffset, uint8_t depth, function<Data (uint32_t index)> onCreateLeaf, function<void (DataInnerNode *node)> onBacktrackFromSubtree) {
|
||||
ASSERT(!_readOnlyTraversal, "Can't create a new subtree in a read-only traversal");
|
||||
|
||||
@ -242,6 +246,7 @@ namespace blobstore {
|
||||
}
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(misc-no-recursion)
|
||||
unique_ref<DataNode> LeafTraverser::_whileRootHasOnlyOneChildRemoveRootReturnChild(const blockstore::BlockId &blockId) {
|
||||
ASSERT(!_readOnlyTraversal, "Can't decrease tree depth in a read-only traversal");
|
||||
|
||||
|
@ -80,11 +80,11 @@ public:
|
||||
private:
|
||||
class Entry final {
|
||||
public:
|
||||
Entry(Entry *prev_, Entry *next_): prev(prev_), next(next_), key(nullptr), __value() {
|
||||
Entry(Entry *prev_, Entry *next_): prev(prev_), next(next_), key(nullptr), _value_() {
|
||||
}
|
||||
void init(const Key *key_, Value value_) {
|
||||
key = key_;
|
||||
new(__value.data()) Value(std::move(value_));
|
||||
new(_value_.data()) Value(std::move(value_));
|
||||
}
|
||||
Value release() {
|
||||
Value value = std::move(*_value());
|
||||
@ -99,9 +99,9 @@ private:
|
||||
const Key *key;
|
||||
private:
|
||||
Value *_value() {
|
||||
return reinterpret_cast<Value*>(__value.data());
|
||||
return reinterpret_cast<Value*>(_value_.data());
|
||||
}
|
||||
alignas(Value) std::array<char, sizeof(Value)> __value;
|
||||
alignas(Value) std::array<char, sizeof(Value)> _value_;
|
||||
DISALLOW_COPY_AND_ASSIGN(Entry);
|
||||
};
|
||||
|
||||
|
@ -29,7 +29,7 @@ public:
|
||||
void forEachBlock(std::function<void (const BlockId &)> callback) const override;
|
||||
|
||||
//This function should only be used by test cases
|
||||
void __setKey(const typename Cipher::EncryptionKey &encKey);
|
||||
void _setKey(const typename Cipher::EncryptionKey &encKey);
|
||||
|
||||
private:
|
||||
|
||||
@ -188,7 +188,7 @@ uint16_t EncryptedBlockStore2<Cipher>::_readFormatHeader(const cpputils::Data &d
|
||||
}
|
||||
|
||||
template<class Cipher>
|
||||
void EncryptedBlockStore2<Cipher>::__setKey(const typename Cipher::EncryptionKey &encKey) {
|
||||
void EncryptedBlockStore2<Cipher>::_setKey(const typename Cipher::EncryptionKey &encKey) {
|
||||
_encKey = encKey;
|
||||
}
|
||||
|
||||
|
@ -31,12 +31,12 @@ public:
|
||||
virtual void store(const BlockId &blockId, const cpputils::Data &data) = 0;
|
||||
|
||||
BlockId create(const cpputils::Data& data) {
|
||||
BlockId blockId = createBlockId();
|
||||
bool success = tryCreate(blockId, data);
|
||||
if (success) {
|
||||
return blockId;
|
||||
} else {
|
||||
return create(data);
|
||||
while (true) {
|
||||
BlockId blockId = createBlockId();
|
||||
bool success = tryCreate(blockId, data);
|
||||
if (success) {
|
||||
return blockId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,9 +6,9 @@
|
||||
|
||||
namespace blockstore {
|
||||
|
||||
struct _BlockIdTag final {};
|
||||
struct BlockIdTag final {};
|
||||
// TODO Split from a BlobId (i.e. IdWrapper<BlobIdTag>)
|
||||
using BlockId = IdWrapper<_BlockIdTag>;
|
||||
using BlockId = IdWrapper<BlockIdTag>;
|
||||
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ using cpputils::Data;
|
||||
namespace cpputils {
|
||||
Data SCryptParameters::serialize() const {
|
||||
Serializer serializer(_serializedSize());
|
||||
serializer.writeUint64(_N);
|
||||
serializer.writeUint64(_n);
|
||||
serializer.writeUint32(_r);
|
||||
serializer.writeUint32(_p);
|
||||
serializer.writeTailData(_salt);
|
||||
@ -20,21 +20,21 @@ namespace cpputils {
|
||||
|
||||
SCryptParameters SCryptParameters::deserialize(const cpputils::Data &data) {
|
||||
Deserializer deserializer(&data);
|
||||
uint64_t N = deserializer.readUint64();
|
||||
uint64_t n = deserializer.readUint64();
|
||||
uint32_t r = deserializer.readUint32();
|
||||
uint32_t p = deserializer.readUint32();
|
||||
Data salt = deserializer.readTailData();
|
||||
deserializer.finished();
|
||||
return SCryptParameters(std::move(salt), N, r, p);
|
||||
return SCryptParameters(std::move(salt), n, r, p);
|
||||
}
|
||||
|
||||
#ifndef CRYFS_NO_COMPATIBILITY
|
||||
SCryptParameters SCryptParameters::deserializeOldFormat(Deserializer *source) {
|
||||
uint64_t N = source->readUint64();
|
||||
uint64_t n = source->readUint64();
|
||||
uint32_t r = source->readUint32();
|
||||
uint32_t p = source->readUint32();
|
||||
Data salt = source->readData();
|
||||
return SCryptParameters(std::move(salt), N, r, p);
|
||||
return SCryptParameters(std::move(salt), n, r, p);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -15,13 +15,13 @@ namespace cpputils {
|
||||
|
||||
class SCryptParameters final {
|
||||
public:
|
||||
SCryptParameters(Data salt, uint64_t N, uint32_t r, uint32_t p)
|
||||
SCryptParameters(Data salt, uint64_t n, uint32_t r, uint32_t p)
|
||||
: _salt(std::move(salt)),
|
||||
_N(N), _r(r), _p(p) { }
|
||||
_n(n), _r(r), _p(p) { }
|
||||
|
||||
SCryptParameters(const SCryptParameters &rhs)
|
||||
:_salt(rhs._salt.copy()),
|
||||
_N(rhs._N), _r(rhs._r), _p(rhs._p) { }
|
||||
_n(rhs._n), _r(rhs._r), _p(rhs._p) { }
|
||||
|
||||
SCryptParameters(SCryptParameters &&rhs) = default;
|
||||
|
||||
@ -31,7 +31,7 @@ namespace cpputils {
|
||||
}
|
||||
|
||||
_salt = rhs._salt.copy();
|
||||
_N = rhs._N;
|
||||
_n = rhs._n;
|
||||
_r = rhs._r;
|
||||
_p = rhs._p;
|
||||
return *this;
|
||||
@ -43,8 +43,8 @@ namespace cpputils {
|
||||
return _salt;
|
||||
}
|
||||
|
||||
size_t N() const {
|
||||
return _N;
|
||||
size_t n() const {
|
||||
return _n;
|
||||
}
|
||||
|
||||
size_t r() const {
|
||||
@ -69,13 +69,13 @@ namespace cpputils {
|
||||
size_t _serializedSize() const;
|
||||
|
||||
Data _salt;
|
||||
uint64_t _N;
|
||||
uint64_t _n;
|
||||
uint32_t _r;
|
||||
uint32_t _p;
|
||||
};
|
||||
|
||||
inline bool operator==(const SCryptParameters &lhs, const SCryptParameters &rhs) {
|
||||
return lhs.salt() == rhs.salt() && lhs.N() == rhs.N() && lhs.r() == rhs.r() && lhs.p() == rhs.p();
|
||||
return lhs.salt() == rhs.salt() && lhs.n() == rhs.n() && lhs.r() == rhs.r() && lhs.p() == rhs.p();
|
||||
}
|
||||
|
||||
inline bool operator!=(const SCryptParameters &lhs, const SCryptParameters &rhs) {
|
||||
|
@ -17,7 +17,7 @@ EncryptionKey _derive(size_t keySize, const std::string& password, const SCryptP
|
||||
static_cast<uint8_t*>(result.data()), result.binaryLength(),
|
||||
reinterpret_cast<const uint8_t*>(password.c_str()), password.size(),
|
||||
static_cast<const uint8_t*>(kdfParameters.salt().data()), kdfParameters.salt().size(),
|
||||
kdfParameters.N(), kdfParameters.r(), kdfParameters.p()
|
||||
kdfParameters.n(), kdfParameters.r(), kdfParameters.p()
|
||||
);
|
||||
if (status != 1) {
|
||||
throw std::runtime_error("Error running scrypt key derivation. Error code: "+std::to_string(status));
|
||||
|
@ -10,12 +10,12 @@
|
||||
|
||||
namespace cpputils {
|
||||
|
||||
template<class CryptoPPCipher, unsigned int _KEY_SIZE, unsigned int _IV_SIZE, unsigned int _TAG_SIZE>
|
||||
template<class CryptoPPCipher, unsigned int KEYSIZE_, unsigned int IV_SIZE_, unsigned int TAG_SIZE_>
|
||||
class AEADCipher {
|
||||
public:
|
||||
using EncryptionKey = cpputils::EncryptionKey;
|
||||
|
||||
static constexpr unsigned int KEYSIZE = _KEY_SIZE;
|
||||
static constexpr unsigned int KEYSIZE = KEYSIZE_;
|
||||
static constexpr unsigned int STRING_KEYSIZE = 2 * KEYSIZE;
|
||||
|
||||
static constexpr unsigned int ciphertextSize(unsigned int plaintextBlockSize) {
|
||||
@ -30,17 +30,17 @@ public:
|
||||
static boost::optional<Data> decrypt(const CryptoPP::byte *ciphertext, unsigned int ciphertextSize, const EncryptionKey &encKey);
|
||||
|
||||
private:
|
||||
static constexpr unsigned int IV_SIZE = _IV_SIZE;
|
||||
static constexpr unsigned int TAG_SIZE = _TAG_SIZE;
|
||||
static constexpr unsigned int IV_SIZE = IV_SIZE_;
|
||||
static constexpr unsigned int TAG_SIZE = TAG_SIZE_;
|
||||
};
|
||||
|
||||
template<class CryptoPPCipher, unsigned int _KEY_SIZE, unsigned int _IV_SIZE, unsigned int _TAG_SIZE>
|
||||
constexpr unsigned int AEADCipher<CryptoPPCipher, _KEY_SIZE, _IV_SIZE, _TAG_SIZE>::KEYSIZE;
|
||||
template<class CryptoPPCipher, unsigned int _KEY_SIZE, unsigned int _IV_SIZE, unsigned int _TAG_SIZE>
|
||||
constexpr unsigned int AEADCipher<CryptoPPCipher, _KEY_SIZE, _IV_SIZE, _TAG_SIZE>::STRING_KEYSIZE;
|
||||
template<class CryptoPPCipher, unsigned int KEYSIZE_, unsigned int IV_SIZE_, unsigned int TAG_SIZE_>
|
||||
constexpr unsigned int AEADCipher<CryptoPPCipher, KEYSIZE_, IV_SIZE_, TAG_SIZE_>::KEYSIZE;
|
||||
template<class CryptoPPCipher, unsigned int KEYSIZE_, unsigned int IV_SIZE_, unsigned int TAG_SIZE_>
|
||||
constexpr unsigned int AEADCipher<CryptoPPCipher, KEYSIZE_, IV_SIZE_, TAG_SIZE_>::STRING_KEYSIZE;
|
||||
|
||||
template<class CryptoPPCipher, unsigned int _KEY_SIZE, unsigned int _IV_SIZE, unsigned int _TAG_SIZE>
|
||||
Data AEADCipher<CryptoPPCipher, _KEY_SIZE, _IV_SIZE, _TAG_SIZE>::encrypt(const CryptoPP::byte *plaintext, unsigned int plaintextSize, const EncryptionKey &encKey) {
|
||||
template<class CryptoPPCipher, unsigned int KEYSIZE_, unsigned int IV_SIZE_, unsigned int TAG_SIZE_>
|
||||
Data AEADCipher<CryptoPPCipher, KEYSIZE_, IV_SIZE_, TAG_SIZE_>::encrypt(const CryptoPP::byte *plaintext, unsigned int plaintextSize, const EncryptionKey &encKey) {
|
||||
ASSERT(encKey.binaryLength() == AEADCipher::KEYSIZE, "Wrong key size");
|
||||
|
||||
FixedSizeData<IV_SIZE> iv = Random::PseudoRandom().getFixedSize<IV_SIZE>();
|
||||
@ -58,8 +58,8 @@ Data AEADCipher<CryptoPPCipher, _KEY_SIZE, _IV_SIZE, _TAG_SIZE>::encrypt(const C
|
||||
return ciphertext;
|
||||
}
|
||||
|
||||
template<class CryptoPPCipher, unsigned int _KEY_SIZE, unsigned int _IV_SIZE, unsigned int _TAG_SIZE>
|
||||
boost::optional<Data> AEADCipher<CryptoPPCipher, _KEY_SIZE, _IV_SIZE, _TAG_SIZE>::decrypt(const CryptoPP::byte *ciphertext, unsigned int ciphertextSize, const EncryptionKey &encKey) {
|
||||
template<class CryptoPPCipher, unsigned int KEYSIZE_, unsigned int IV_SIZE_, unsigned int TAG_SIZE_>
|
||||
boost::optional<Data> AEADCipher<CryptoPPCipher, KEYSIZE_, IV_SIZE_, TAG_SIZE_>::decrypt(const CryptoPP::byte *ciphertext, unsigned int ciphertextSize, const EncryptionKey &encKey) {
|
||||
ASSERT(encKey.binaryLength() == AEADCipher::KEYSIZE, "Wrong key size");
|
||||
|
||||
if (ciphertextSize < IV_SIZE + TAG_SIZE) {
|
||||
|
@ -36,7 +36,7 @@ public:
|
||||
|
||||
private:
|
||||
FixedSizeData(): _data() {}
|
||||
template<size_t _SIZE> friend class FixedSizeData;
|
||||
template<size_t SIZE_> friend class FixedSizeData;
|
||||
|
||||
std::array<unsigned char, BINARY_LENGTH> _data;
|
||||
};
|
||||
|
@ -8,23 +8,23 @@
|
||||
namespace cpputils {
|
||||
namespace details {
|
||||
|
||||
class _DontEchoStdinToStdoutRAII final {
|
||||
class DontEchoStdinToStdoutRAII final {
|
||||
public:
|
||||
_DontEchoStdinToStdoutRAII() : _old_state() {
|
||||
DontEchoStdinToStdoutRAII() : _old_state() {
|
||||
tcgetattr(STDIN_FILENO, &_old_state);
|
||||
termios new_state = _old_state;
|
||||
new_state.c_lflag &= ~ECHO;
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &new_state);
|
||||
}
|
||||
|
||||
~_DontEchoStdinToStdoutRAII() {
|
||||
~DontEchoStdinToStdoutRAII() {
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &_old_state);
|
||||
}
|
||||
|
||||
private:
|
||||
termios _old_state;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(_DontEchoStdinToStdoutRAII);
|
||||
DISALLOW_COPY_AND_ASSIGN(DontEchoStdinToStdoutRAII);
|
||||
};
|
||||
|
||||
}
|
||||
@ -66,7 +66,7 @@ using cpputils::make_unique_ref;
|
||||
namespace cpputils {
|
||||
|
||||
DontEchoStdinToStdoutRAII::DontEchoStdinToStdoutRAII()
|
||||
: raii(make_unique_ref<details::_DontEchoStdinToStdoutRAII>()) {}
|
||||
: raii(make_unique_ref<details::DontEchoStdinToStdoutRAII>()) {}
|
||||
|
||||
DontEchoStdinToStdoutRAII::~DontEchoStdinToStdoutRAII() {}
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
namespace cpputils {
|
||||
|
||||
namespace details {
|
||||
class _DontEchoStdinToStdoutRAII;
|
||||
class DontEchoStdinToStdoutRAII;
|
||||
}
|
||||
|
||||
class DontEchoStdinToStdoutRAII final {
|
||||
@ -22,7 +22,7 @@ public:
|
||||
DontEchoStdinToStdoutRAII();
|
||||
~DontEchoStdinToStdoutRAII();
|
||||
private:
|
||||
cpputils::unique_ref<details::_DontEchoStdinToStdoutRAII> raii;
|
||||
cpputils::unique_ref<details::DontEchoStdinToStdoutRAII> raii;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(DontEchoStdinToStdoutRAII);
|
||||
};
|
||||
|
@ -54,7 +54,8 @@ boost::optional<unique_ref<FsBlob>> FsBlobStore::load(const blockstore::BlockId
|
||||
|
||||
return fsBlobStore;
|
||||
}
|
||||
|
||||
|
||||
// NOLINTNEXTLINE(misc-no-recursion)
|
||||
void FsBlobStore::_migrate(unique_ref<blobstore::Blob> node, const blockstore::BlockId &parentId, SignalCatcher* signalCatcher, std::function<void(uint32_t numNodes)> perBlobCallback) {
|
||||
FsBlobView::migrate(node.get(), parentId);
|
||||
perBlobCallback(node->numNodes());
|
||||
|
@ -102,7 +102,7 @@ private:
|
||||
size_t _numBlocks;
|
||||
};
|
||||
|
||||
std::vector<BlockId> _getKnownBlobIds(const path& basedir, const CryConfigLoader::ConfigLoadResult& config, LocalStateDir& localStateDir) {
|
||||
std::vector<BlockId> getKnownBlobIds(const path& basedir, const CryConfigLoader::ConfigLoadResult& config, LocalStateDir& localStateDir) {
|
||||
auto blockStore = makeBlockStore(basedir, config, localStateDir);
|
||||
auto fsBlobStore = make_unique_ref<FsBlobStore>(make_unique_ref<BlobStoreOnBlocks>(std::move(blockStore), config.configFile->config()->BlocksizeBytes()));
|
||||
|
||||
@ -116,8 +116,8 @@ std::vector<BlockId> _getKnownBlobIds(const path& basedir, const CryConfigLoader
|
||||
return knownBlobIds.blockIds();
|
||||
}
|
||||
|
||||
std::vector<BlockId> _getKnownBlockIds(const path& basedir, const CryConfigLoader::ConfigLoadResult& config, LocalStateDir& localStateDir) {
|
||||
auto knownBlobIds = _getKnownBlobIds(basedir, config, localStateDir);
|
||||
std::vector<BlockId> getKnownBlockIds(const path& basedir, const CryConfigLoader::ConfigLoadResult& config, LocalStateDir& localStateDir) {
|
||||
auto knownBlobIds = getKnownBlobIds(basedir, config, localStateDir);
|
||||
|
||||
auto blockStore = makeBlockStore(basedir, config, localStateDir);
|
||||
auto nodeStore = make_unique_ref<DataNodeStore>(std::move(blockStore), config.configFile->config()->BlocksizeBytes());
|
||||
@ -135,7 +135,7 @@ std::vector<BlockId> _getKnownBlockIds(const path& basedir, const CryConfigLoade
|
||||
return knownBlockIds.blockIds();
|
||||
}
|
||||
|
||||
set<BlockId> _getAllBlockIds(const path& basedir, const CryConfigLoader::ConfigLoadResult& config, LocalStateDir& localStateDir) {
|
||||
set<BlockId> getAllBlockIds(const path& basedir, const CryConfigLoader::ConfigLoadResult& config, LocalStateDir& localStateDir) {
|
||||
auto blockStore = makeBlockStore(basedir, config, localStateDir);
|
||||
AccumulateBlockIds allBlockIds;
|
||||
allBlockIds.reserve(blockStore->numBlocks());
|
||||
@ -218,10 +218,10 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
|
||||
cout << "Listing all blocks..." << flush;
|
||||
set<BlockId> unaccountedBlocks = _getAllBlockIds(basedir, config.right(), localStateDir);
|
||||
set<BlockId> unaccountedBlocks = getAllBlockIds(basedir, config.right(), localStateDir);
|
||||
cout << "done" << endl;
|
||||
|
||||
vector<BlockId> accountedBlocks = _getKnownBlockIds(basedir, config.right(), localStateDir);
|
||||
vector<BlockId> accountedBlocks = getKnownBlockIds(basedir, config.right(), localStateDir);
|
||||
for (const BlockId& blockId : accountedBlocks) {
|
||||
auto num_erased = unaccountedBlocks.erase(blockId);
|
||||
ASSERT(1 == num_erased, "Blob id referenced by directory entry but didn't found it on disk? This can't happen.");
|
||||
|
@ -24,6 +24,7 @@ void forEachBlock(BlockStore* blockStore, const vector<function<void (const Bloc
|
||||
});
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(misc-no-recursion)
|
||||
void forEachReachableBlob(FsBlobStore* blobStore, const BlockId& rootId, const vector<function<void (const BlockId& blobId)>>& callbacks) {
|
||||
for (const auto& callback : callbacks) {
|
||||
callback(rootId);
|
||||
@ -47,6 +48,7 @@ void forEachReachableBlob(FsBlobStore* blobStore, const BlockId& rootId, const v
|
||||
}
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(misc-no-recursion)
|
||||
void forEachReachableBlockInBlob(DataNodeStore* nodeStore, const BlockId& rootId, const vector<function<void (const BlockId& blockId)>>& callbacks) {
|
||||
for (const auto& callback : callbacks) {
|
||||
callback(rootId);
|
||||
|
@ -64,6 +64,7 @@ public:
|
||||
return CreateTree(CreateFourLevelMinDataWithLastLeafSize(size));
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(misc-no-recursion)
|
||||
void EXPECT_IS_LEFTMAXDATA_TREE(const BlockId &blockId) {
|
||||
auto root = nodeStore->load(blockId).value();
|
||||
DataInnerNode *inner = dynamic_cast<DataInnerNode*>(root.get());
|
||||
@ -75,6 +76,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(misc-no-recursion)
|
||||
void EXPECT_IS_MAXDATA_TREE(const BlockId &blockId) {
|
||||
auto root = nodeStore->load(blockId).value();
|
||||
DataInnerNode *inner = dynamic_cast<DataInnerNode*>(root.get());
|
||||
@ -118,6 +120,7 @@ public:
|
||||
tree->flush();
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(misc-no-recursion)
|
||||
unique_ref<DataLeafNode> LastLeaf(const BlockId &blockId) {
|
||||
auto root = nodeStore->load(blockId).value();
|
||||
auto leaf = dynamic_pointer_move<DataLeafNode>(root);
|
||||
|
@ -64,6 +64,7 @@ public:
|
||||
return CreateTree(CreateFourLevelMinDataWithLastLeafSize(size));
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(misc-no-recursion)
|
||||
void EXPECT_IS_LEFTMAXDATA_TREE(const BlockId &blockId) {
|
||||
auto root = nodeStore->load(blockId).value();
|
||||
DataInnerNode *inner = dynamic_cast<DataInnerNode*>(root.get());
|
||||
@ -75,6 +76,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(misc-no-recursion)
|
||||
void EXPECT_IS_MAXDATA_TREE(const BlockId &blockId) {
|
||||
auto root = nodeStore->load(blockId).value();
|
||||
DataInnerNode *inner = dynamic_cast<DataInnerNode*>(root.get());
|
||||
@ -107,6 +109,7 @@ public:
|
||||
treeStore.load(blockId).get()->resizeNumBytes(size);
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(misc-no-recursion)
|
||||
unique_ref<DataLeafNode> LastLeaf(const BlockId &blockId) {
|
||||
auto root = nodeStore->load(blockId).value();
|
||||
auto leaf = dynamic_pointer_move<DataLeafNode>(root);
|
||||
|
@ -2,7 +2,6 @@
|
||||
#include <blobstore/implementations/onblocks/datatreestore/impl/LeafTraverser.h>
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
using ::testing::_;
|
||||
using ::testing::Invoke;
|
||||
using ::testing::Eq;
|
||||
|
||||
@ -68,8 +67,8 @@ public:
|
||||
}
|
||||
|
||||
void EXPECT_DONT_TRAVERSE_ANY_LEAVES() {
|
||||
EXPECT_CALL(traversor, calledExistingLeaf(_, _, _)).Times(0);
|
||||
EXPECT_CALL(traversor, calledCreateLeaf(_)).Times(0);
|
||||
EXPECT_CALL(traversor, calledExistingLeaf(testing::_, testing::_, testing::_)).Times(0);
|
||||
EXPECT_CALL(traversor, calledCreateLeaf(testing::_)).Times(0);
|
||||
}
|
||||
|
||||
void TraverseLeaves(unique_ref<DataNode> root, uint32_t beginIndex, uint32_t endIndex, bool expectReadOnly) {
|
||||
|
@ -228,6 +228,7 @@ void DataTreeTest::EXPECT_IS_FULL_THREELEVEL_TREE(const BlockId &blockId) {
|
||||
}
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(misc-no-recursion)
|
||||
void DataTreeTest::CHECK_DEPTH(int depth, const BlockId &blockId) {
|
||||
if (depth == 0) {
|
||||
EXPECT_IS_LEAF_NODE(blockId);
|
||||
|
@ -39,6 +39,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
// NOLINTNEXTLINE(misc-no-recursion)
|
||||
int ForEachLeaf(blobstore::onblocks::datanodestore::DataNode *node, int firstLeafIndex, int endLeafIndex, std::function<void (blobstore::onblocks::datanodestore::DataLeafNode*, int)> action) {
|
||||
if (firstLeafIndex == endLeafIndex) {
|
||||
return firstLeafIndex;
|
||||
|
@ -78,14 +78,14 @@ TEST_F(EncryptedBlockStoreTest, LoadingWithSameKeyWorks_WriteSeparately) {
|
||||
|
||||
TEST_F(EncryptedBlockStoreTest, LoadingWithDifferentKeyDoesntWork_WriteOnCreate) {
|
||||
auto blockId = CreateBlockDirectlyWithFixtureAndReturnKey();
|
||||
blockStore->__setKey(FakeAuthenticatedCipher::Key2());
|
||||
blockStore->_setKey(FakeAuthenticatedCipher::Key2());
|
||||
auto loaded = blockStore->load(blockId);
|
||||
EXPECT_EQ(boost::none, loaded);
|
||||
}
|
||||
|
||||
TEST_F(EncryptedBlockStoreTest, LoadingWithDifferentKeyDoesntWork_WriteSeparately) {
|
||||
auto blockId = CreateBlockWriteFixtureToItAndReturnKey();
|
||||
blockStore->__setKey(FakeAuthenticatedCipher::Key2());
|
||||
blockStore->_setKey(FakeAuthenticatedCipher::Key2());
|
||||
auto loaded = blockStore->load(blockId);
|
||||
EXPECT_EQ(boost::none, loaded);
|
||||
}
|
||||
|
@ -4,7 +4,6 @@
|
||||
#include <cpp-utils/data/DataFixture.h>
|
||||
|
||||
using ::testing::Test;
|
||||
using ::testing::_;
|
||||
using ::testing::Return;
|
||||
using ::testing::Invoke;
|
||||
using ::testing::Eq;
|
||||
@ -60,28 +59,28 @@ public:
|
||||
TEST_F(BlockStore2Test, DataIsPassedThrough0) {
|
||||
Data data = createDataWithSize(0);
|
||||
EXPECT_CALL(blockStoreMock, createBlockId()).WillOnce(Return(blockId1));
|
||||
EXPECT_CALL(blockStoreMock, tryCreate(_, Eq(ByRef(data)))).WillOnce(Return(true));
|
||||
EXPECT_CALL(blockStoreMock, tryCreate(testing::_, Eq(ByRef(data)))).WillOnce(Return(true));
|
||||
EXPECT_EQ(blockId1, blockStore.create(data));
|
||||
}
|
||||
|
||||
TEST_F(BlockStore2Test, DataIsPassedThrough1) {
|
||||
Data data = createDataWithSize(1);
|
||||
EXPECT_CALL(blockStoreMock, createBlockId()).WillOnce(Return(blockId1));
|
||||
EXPECT_CALL(blockStoreMock, tryCreate(_, Eq(ByRef(data)))).WillOnce(Return(true));
|
||||
EXPECT_CALL(blockStoreMock, tryCreate(testing::_, Eq(ByRef(data)))).WillOnce(Return(true));
|
||||
EXPECT_EQ(blockId1, blockStore.create(data));
|
||||
}
|
||||
|
||||
TEST_F(BlockStore2Test, DataIsPassedThrough1024) {
|
||||
Data data = createDataWithSize(1024);
|
||||
EXPECT_CALL(blockStoreMock, createBlockId()).WillOnce(Return(blockId1));
|
||||
EXPECT_CALL(blockStoreMock, tryCreate(_, Eq(ByRef(data)))).WillOnce(Return(true));
|
||||
EXPECT_CALL(blockStoreMock, tryCreate(testing::_, Eq(ByRef(data)))).WillOnce(Return(true));
|
||||
EXPECT_EQ(blockId1, blockStore.create(data));
|
||||
}
|
||||
|
||||
TEST_F(BlockStore2Test, BlockIdIsCorrect) {
|
||||
Data data = createDataWithSize(1024);
|
||||
EXPECT_CALL(blockStoreMock, createBlockId()).WillOnce(Return(blockId1));
|
||||
EXPECT_CALL(blockStoreMock, tryCreate(blockId1, _)).WillOnce(Return(true));
|
||||
EXPECT_CALL(blockStoreMock, tryCreate(blockId1, testing::_)).WillOnce(Return(true));
|
||||
EXPECT_EQ(blockId1, blockStore.create(data));
|
||||
}
|
||||
|
||||
@ -89,7 +88,7 @@ TEST_F(BlockStore2Test, TwoBlocksGetDifferentIds) {
|
||||
EXPECT_CALL(blockStoreMock, createBlockId())
|
||||
.WillOnce(Return(blockId1))
|
||||
.WillOnce(Return(blockId2));
|
||||
EXPECT_CALL(blockStoreMock, tryCreate(_, _))
|
||||
EXPECT_CALL(blockStoreMock, tryCreate(testing::_, testing::_))
|
||||
.WillOnce(Invoke([this](const BlockId &blockId, const Data &) {
|
||||
EXPECT_EQ(blockId1, blockId);
|
||||
return true;
|
||||
@ -109,7 +108,7 @@ TEST_F(BlockStore2Test, WillTryADifferentIdIfKeyAlreadyExists) {
|
||||
EXPECT_CALL(blockStoreMock, createBlockId())
|
||||
.WillOnce(Return(blockId1))
|
||||
.WillOnce(Return(blockId2));
|
||||
EXPECT_CALL(blockStoreMock, tryCreate(_, Eq(ByRef(data))))
|
||||
EXPECT_CALL(blockStoreMock, tryCreate(testing::_, Eq(ByRef(data))))
|
||||
.WillOnce(Invoke([this](const BlockId &blockId, const Data &) {
|
||||
EXPECT_EQ(blockId1, blockId);
|
||||
return false;
|
||||
@ -128,7 +127,7 @@ TEST_F(BlockStore2Test, WillTryADifferentIdIfIdAlreadyExistsTwoTimes) {
|
||||
.WillOnce(Return(blockId1))
|
||||
.WillOnce(Return(blockId2))
|
||||
.WillOnce(Return(blockId3));
|
||||
EXPECT_CALL(blockStoreMock, tryCreate(_, Eq(ByRef(data))))
|
||||
EXPECT_CALL(blockStoreMock, tryCreate(testing::_, Eq(ByRef(data))))
|
||||
.WillOnce(Invoke([this](const BlockId &blockId, const Data &) {
|
||||
EXPECT_EQ(blockId1, blockId);
|
||||
return false;
|
||||
|
@ -5,7 +5,6 @@
|
||||
#include <cpp-utils/pointer/unique_ref_boost_optional_gtest_workaround.h>
|
||||
|
||||
using ::testing::Test;
|
||||
using ::testing::_;
|
||||
using ::testing::Return;
|
||||
using ::testing::Invoke;
|
||||
using ::testing::Eq;
|
||||
@ -74,28 +73,28 @@ const Action<optional<unique_ref<Block>>(const BlockId &, cpputils::Data)> Retur
|
||||
TEST_F(BlockStoreTest, DataIsPassedThrough0) {
|
||||
Data data = createDataWithSize(0);
|
||||
EXPECT_CALL(blockStoreMock, createBlockId()).WillOnce(Return(blockId1));
|
||||
EXPECT_CALL(blockStoreMock, tryCreate(_, Eq(ByRef(data)))).WillOnce(ReturnNewBlockMock);
|
||||
EXPECT_CALL(blockStoreMock, tryCreate(testing::_, Eq(ByRef(data)))).WillOnce(ReturnNewBlockMock);
|
||||
blockStore.create(data);
|
||||
}
|
||||
|
||||
TEST_F(BlockStoreTest, DataIsPassedThrough1) {
|
||||
Data data = createDataWithSize(1);
|
||||
EXPECT_CALL(blockStoreMock, createBlockId()).WillOnce(Return(blockId1));
|
||||
EXPECT_CALL(blockStoreMock, tryCreate(_, Eq(ByRef(data)))).WillOnce(ReturnNewBlockMock);
|
||||
EXPECT_CALL(blockStoreMock, tryCreate(testing::_, Eq(ByRef(data)))).WillOnce(ReturnNewBlockMock);
|
||||
blockStore.create(data);
|
||||
}
|
||||
|
||||
TEST_F(BlockStoreTest, DataIsPassedThrough1024) {
|
||||
Data data = createDataWithSize(1024);
|
||||
EXPECT_CALL(blockStoreMock, createBlockId()).WillOnce(Return(blockId1));
|
||||
EXPECT_CALL(blockStoreMock, tryCreate(_, Eq(ByRef(data)))).WillOnce(ReturnNewBlockMock);
|
||||
EXPECT_CALL(blockStoreMock, tryCreate(testing::_, Eq(ByRef(data)))).WillOnce(ReturnNewBlockMock);
|
||||
blockStore.create(data);
|
||||
}
|
||||
|
||||
TEST_F(BlockStoreTest, BlockIdIsCorrect) {
|
||||
Data data = createDataWithSize(1024);
|
||||
EXPECT_CALL(blockStoreMock, createBlockId()).WillOnce(Return(blockId1));
|
||||
EXPECT_CALL(blockStoreMock, tryCreate(blockId1, _)).WillOnce(ReturnNewBlockMock);
|
||||
EXPECT_CALL(blockStoreMock, tryCreate(blockId1, testing::_)).WillOnce(ReturnNewBlockMock);
|
||||
blockStore.create(data);
|
||||
}
|
||||
|
||||
@ -103,7 +102,7 @@ TEST_F(BlockStoreTest, TwoBlocksGetDifferentIds) {
|
||||
EXPECT_CALL(blockStoreMock, createBlockId())
|
||||
.WillOnce(Return(blockId1))
|
||||
.WillOnce(Return(blockId2));
|
||||
EXPECT_CALL(blockStoreMock, tryCreate(_, _))
|
||||
EXPECT_CALL(blockStoreMock, tryCreate(testing::_, testing::_))
|
||||
.WillOnce(Invoke([this](const BlockId &blockId, Data) {
|
||||
EXPECT_EQ(blockId1, blockId);
|
||||
return optional<unique_ref<Block>>(unique_ref<Block>(make_unique_ref<BlockMock>()));
|
||||
@ -123,7 +122,7 @@ TEST_F(BlockStoreTest, WillTryADifferentIdIfKeyAlreadyExists) {
|
||||
EXPECT_CALL(blockStoreMock, createBlockId())
|
||||
.WillOnce(Return(blockId1))
|
||||
.WillOnce(Return(blockId2));
|
||||
EXPECT_CALL(blockStoreMock, tryCreate(_, Eq(ByRef(data))))
|
||||
EXPECT_CALL(blockStoreMock, tryCreate(testing::_, Eq(ByRef(data))))
|
||||
.WillOnce(Invoke([this](const BlockId &blockId, Data ) {
|
||||
EXPECT_EQ(blockId1, blockId);
|
||||
return boost::none;
|
||||
@ -142,7 +141,7 @@ TEST_F(BlockStoreTest, WillTryADifferentIdIfIdAlreadyExistsTwoTimes) {
|
||||
.WillOnce(Return(blockId1))
|
||||
.WillOnce(Return(blockId2))
|
||||
.WillOnce(Return(blockId3));
|
||||
EXPECT_CALL(blockStoreMock, tryCreate(_, Eq(ByRef(data))))
|
||||
EXPECT_CALL(blockStoreMock, tryCreate(testing::_, Eq(ByRef(data))))
|
||||
.WillOnce(Invoke([this](const BlockId &blockId, Data) {
|
||||
EXPECT_EQ(blockId1, blockId);
|
||||
return boost::none;
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
#ifdef NDEBUG
|
||||
#define _REAL_NDEBUG
|
||||
#define REAL_NDEBUG_
|
||||
#endif
|
||||
|
||||
//Include the ASSERT macro for a debug build
|
||||
@ -41,7 +41,7 @@ TEST(AssertTest_DebugBuild, AssertMessage) {
|
||||
);
|
||||
}
|
||||
|
||||
#if !(defined(_MSC_VER) && defined(_REAL_NDEBUG))
|
||||
#if !(defined(_MSC_VER) && defined(REAL_NDEBUG_))
|
||||
TEST(AssertTest_DebugBuild, AssertMessageContainsBacktrace) {
|
||||
EXPECT_DEATH(
|
||||
ASSERT(2==5, "my message"),
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include <regex>
|
||||
|
||||
#ifdef NDEBUG
|
||||
#define _REAL_NDEBUG
|
||||
#define REAL_NDEBUG_
|
||||
#endif
|
||||
|
||||
//Include the ASSERT macro for a release build
|
||||
@ -39,7 +39,7 @@ TEST(AssertTest_ReleaseBuild, AssertMessage) {
|
||||
}
|
||||
}
|
||||
|
||||
#if !(defined(_MSC_VER) && defined(_REAL_NDEBUG))
|
||||
#if !(defined(_MSC_VER) && defined(REAL_NDEBUG_))
|
||||
TEST(AssertTest_ReleaseBuild, AssertMessageContainsBacktrace) {
|
||||
try {
|
||||
ASSERT(2==5, "my message");
|
||||
|
@ -32,19 +32,19 @@ TEST_F(SCryptParametersTest, Salt_SaveAndLoad) {
|
||||
|
||||
TEST_F(SCryptParametersTest, N) {
|
||||
SCryptParameters cfg(Data(0), 1024, 0, 0);
|
||||
EXPECT_EQ(1024u, cfg.N());
|
||||
EXPECT_EQ(1024u, cfg.n());
|
||||
}
|
||||
|
||||
TEST_F(SCryptParametersTest, N_Move) {
|
||||
SCryptParameters cfg(Data(0), 1024, 0, 0);
|
||||
SCryptParameters moved = std::move(cfg);
|
||||
EXPECT_EQ(1024u, moved.N());
|
||||
EXPECT_EQ(1024u, moved.n());
|
||||
}
|
||||
|
||||
TEST_F(SCryptParametersTest, N_SaveAndLoad) {
|
||||
SCryptParameters cfg(Data(0), 1024, 0, 0);
|
||||
SCryptParameters loaded = SaveAndLoad(cfg);
|
||||
EXPECT_EQ(1024u, loaded.N());
|
||||
EXPECT_EQ(1024u, loaded.n());
|
||||
}
|
||||
|
||||
TEST_F(SCryptParametersTest, r) {
|
||||
|
@ -52,7 +52,7 @@ TEST_F(SCryptTest, UsesCorrectSettings) {
|
||||
auto derivedKey = scrypt.deriveNewKey(16, "mypassword");
|
||||
auto parameters = SCryptParameters::deserialize(derivedKey.kdfParameters);
|
||||
EXPECT_EQ(SCrypt::TestSettings.SALT_LEN, parameters.salt().size());
|
||||
EXPECT_EQ(SCrypt::TestSettings.N, parameters.N());
|
||||
EXPECT_EQ(SCrypt::TestSettings.N, parameters.n());
|
||||
EXPECT_EQ(SCrypt::TestSettings.r, parameters.r());
|
||||
EXPECT_EQ(SCrypt::TestSettings.p, parameters.p());
|
||||
}
|
||||
@ -62,7 +62,7 @@ TEST_F(SCryptTest, UsesCorrectDefaultSettings) {
|
||||
auto derivedKey = scrypt.deriveNewKey(16, "mypassword");
|
||||
auto parameters = SCryptParameters::deserialize(derivedKey.kdfParameters);
|
||||
EXPECT_EQ(SCrypt::DefaultSettings.SALT_LEN, parameters.salt().size());
|
||||
EXPECT_EQ(SCrypt::DefaultSettings.N, parameters.N());
|
||||
EXPECT_EQ(SCrypt::DefaultSettings.N, parameters.n());
|
||||
EXPECT_EQ(SCrypt::DefaultSettings.r, parameters.r());
|
||||
EXPECT_EQ(SCrypt::DefaultSettings.p, parameters.p());
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ using ::testing::Test;
|
||||
using ::testing::WithParamInterface;
|
||||
using ::testing::Values;
|
||||
using ::testing::Return;
|
||||
using ::testing::_;
|
||||
|
||||
using cpputils::TempFile;
|
||||
|
||||
@ -276,7 +275,7 @@ TEST_F(DataTestWithMockAllocator, whenMoveAssigning_thenOnlyFreesOnce) {
|
||||
|
||||
TEST_F(DataTestWithMockAllocator, whenMoveConstructing_thenOnlyFreesWhenSecondIsDestructed) {
|
||||
EXPECT_CALL(*allocator, allocate(5)).Times(1).WillOnce(Return(&ptr_target));
|
||||
EXPECT_CALL(*allocator_ptr, free(_, _)).Times(0);
|
||||
EXPECT_CALL(*allocator_ptr, free(testing::_, testing::_)).Times(0);
|
||||
|
||||
auto data = std::make_unique<Data>(5, std::move(allocator));
|
||||
Data data2 = std::move(*data);
|
||||
@ -287,7 +286,7 @@ TEST_F(DataTestWithMockAllocator, whenMoveConstructing_thenOnlyFreesWhenSecondIs
|
||||
|
||||
TEST_F(DataTestWithMockAllocator, whenMoveAssigning_thenOnlyFreesWhenSecondIsDestructed) {
|
||||
EXPECT_CALL(*allocator, allocate(5)).Times(1).WillOnce(Return(&ptr_target));
|
||||
EXPECT_CALL(*allocator_ptr, free(_, _)).Times(0);
|
||||
EXPECT_CALL(*allocator_ptr, free(testing::_, testing::_)).Times(0);
|
||||
|
||||
auto data = std::make_unique<Data>(5, std::move(allocator));
|
||||
Data data2(3);
|
||||
|
@ -34,6 +34,7 @@ bool readingFileIsSuccessful(const bf::path& filename) {
|
||||
return file.good();
|
||||
}
|
||||
|
||||
// NOLINTNEXTLINE(misc-no-recursion)
|
||||
void recursive_copy(const bf::path &src, const bf::path &dst) {
|
||||
if (bf::exists(dst)) {
|
||||
throw std::runtime_error(dst.generic_string() + " already exists");
|
||||
|
@ -6,7 +6,6 @@ namespace bf = boost::filesystem;
|
||||
using ::testing::Values;
|
||||
using ::testing::WithParamInterface;
|
||||
using ::testing::Return;
|
||||
using ::testing::_;
|
||||
using std::vector;
|
||||
using cpputils::TempFile;
|
||||
using cryfs::ErrorCode;
|
||||
@ -122,7 +121,7 @@ TEST_P(CliTest_WrongEnvironment, MountDirIsBaseDir_BothRelative) {
|
||||
TEST_P(CliTest_WrongEnvironment, BaseDir_DoesntExist) {
|
||||
_basedir.remove();
|
||||
// ON_CALL and not EXPECT_CALL, because this is a death test (i.e. it is forked) and gmock EXPECT_CALL in fork children don't report to parents.
|
||||
ON_CALL(*console, askYesNo("Could not find base directory. Do you want to create it?", _)).WillByDefault(Return(false));
|
||||
ON_CALL(*console, askYesNo("Could not find base directory. Do you want to create it?", testing::_)).WillByDefault(Return(false));
|
||||
Test_Run_Error("Error 16: base directory not found", ErrorCode::InaccessibleBaseDir);
|
||||
}
|
||||
|
||||
@ -130,7 +129,7 @@ TEST_P(CliTest_WrongEnvironment, BaseDir_DoesntExist_Noninteractive) {
|
||||
_basedir.remove();
|
||||
// We can't set an EXPECT_CALL().Times(0), because this is a death test (i.e. it is forked) and gmock EXPECT_CALL in fork children don't report to parents.
|
||||
// So we set a default answer that shouldn't crash and check it's not called by checking that it crashes.
|
||||
ON_CALL(*console, askYesNo("Could not find base directory. Do you want to create it?", _)).WillByDefault(Return(true));
|
||||
ON_CALL(*console, askYesNo("Could not find base directory. Do you want to create it?", testing::_)).WillByDefault(Return(true));
|
||||
cpputils::setenv("CRYFS_FRONTEND", "noninteractive");
|
||||
Test_Run_Error("Error 16: base directory not found", ErrorCode::InaccessibleBaseDir);
|
||||
cpputils::unsetenv("CRYFS_FRONTEND");
|
||||
@ -139,7 +138,7 @@ TEST_P(CliTest_WrongEnvironment, BaseDir_DoesntExist_Noninteractive) {
|
||||
TEST_P(CliTest_WrongEnvironment, BaseDir_DoesntExist_Create) {
|
||||
if (!GetParam().runningInForeground) {return;} // TODO Make this work also if run in background (see CliTest::EXPECT_RUN_SUCCESS)
|
||||
_basedir.remove();
|
||||
ON_CALL(*console, askYesNo("Could not find base directory. Do you want to create it?", _)).WillByDefault(Return(true));
|
||||
ON_CALL(*console, askYesNo("Could not find base directory. Do you want to create it?", testing::_)).WillByDefault(Return(true));
|
||||
Test_Run_Success();
|
||||
EXPECT_TRUE(bf::exists(_basedir.path()) && bf::is_directory(_basedir.path()));
|
||||
}
|
||||
@ -183,7 +182,7 @@ TEST_P(CliTest_WrongEnvironment, BaseDir_NoPermission) {
|
||||
TEST_P(CliTest_WrongEnvironment, MountDir_DoesntExist) {
|
||||
_mountdir.remove();
|
||||
// ON_CALL and not EXPECT_CALL, because this is a death test (i.e. it is forked) and gmock EXPECT_CALL in fork children don't report to parents.
|
||||
ON_CALL(*console, askYesNo("Could not find mount directory. Do you want to create it?", _)).WillByDefault(Return(false));
|
||||
ON_CALL(*console, askYesNo("Could not find mount directory. Do you want to create it?", testing::_)).WillByDefault(Return(false));
|
||||
Test_Run_Error("mount directory not found", ErrorCode::InaccessibleMountDir);
|
||||
}
|
||||
|
||||
@ -191,7 +190,7 @@ TEST_P(CliTest_WrongEnvironment, MountDir_DoesntExist_Noninteractive) {
|
||||
_mountdir.remove();
|
||||
// We can't set an EXPECT_CALL().Times(0), because this is a death test (i.e. it is forked) and gmock EXPECT_CALL in fork children don't report to parents.
|
||||
// So we set a default answer that shouldn't crash and check it's not called by checking that it crashes.
|
||||
ON_CALL(*console, askYesNo("Could not find base directory. Do you want to create it?", _)).WillByDefault(Return(true));
|
||||
ON_CALL(*console, askYesNo("Could not find base directory. Do you want to create it?", testing::_)).WillByDefault(Return(true));
|
||||
cpputils::setenv("CRYFS_FRONTEND", "noninteractive");
|
||||
Test_Run_Error("mount directory not found", ErrorCode::InaccessibleMountDir);
|
||||
cpputils::unsetenv("CRYFS_FRONTEND");
|
||||
@ -200,7 +199,7 @@ TEST_P(CliTest_WrongEnvironment, MountDir_DoesntExist_Noninteractive) {
|
||||
TEST_P(CliTest_WrongEnvironment, MountDir_DoesntExist_Create) {
|
||||
if (!GetParam().runningInForeground) {return;} // TODO Make this work also if run in background (see CliTest::EXPECT_RUN_SUCCESS)
|
||||
_mountdir.remove();
|
||||
ON_CALL(*console, askYesNo("Could not find mount directory. Do you want to create it?", _)).WillByDefault(Return(true));
|
||||
ON_CALL(*console, askYesNo("Could not find mount directory. Do you want to create it?", testing::_)).WillByDefault(Return(true));
|
||||
Test_Run_Success();
|
||||
EXPECT_TRUE(bf::exists(_mountdir.path()) && bf::is_directory(_mountdir.path()));
|
||||
}
|
||||
|
@ -38,11 +38,11 @@ public:
|
||||
const auto &actualCipher = CryCiphers::find(cipherName);
|
||||
Data dataFixture = DataFixture::generate(1024);
|
||||
string encKey = ExpectedCipher::EncryptionKey::CreateKey(Random::PseudoRandom(), ExpectedCipher::KEYSIZE).ToString();
|
||||
_EXPECT_ENCRYPTS_WITH_ACTUAL_BLOCKSTORE_DECRYPTS_CORRECTLY_WITH_EXPECTED_BLOCKSTORE<ExpectedCipher>(actualCipher, encKey, std::move(dataFixture));
|
||||
EXPECT_ENCRYPTS_WITH_ACTUAL_BLOCKSTORE_DECRYPTS_CORRECTLY_WITH_EXPECTED_BLOCKSTORE_<ExpectedCipher>(actualCipher, encKey, std::move(dataFixture));
|
||||
}
|
||||
|
||||
template<class ExpectedCipher>
|
||||
void _EXPECT_ENCRYPTS_WITH_ACTUAL_BLOCKSTORE_DECRYPTS_CORRECTLY_WITH_EXPECTED_BLOCKSTORE(const CryCipher &actualCipher, const std::string &encKey, Data dataFixture) {
|
||||
void EXPECT_ENCRYPTS_WITH_ACTUAL_BLOCKSTORE_DECRYPTS_CORRECTLY_WITH_EXPECTED_BLOCKSTORE_(const CryCipher &actualCipher, const std::string &encKey, Data dataFixture) {
|
||||
blockstore::BlockId blockId = blockstore::BlockId::Random();
|
||||
Data encrypted = _encryptUsingEncryptedBlockStoreWithCipher(actualCipher, encKey, blockId, dataFixture.copy());
|
||||
Data decrypted = _decryptUsingEncryptedBlockStoreWithCipher<ExpectedCipher>(encKey, blockId, std::move(encrypted));
|
||||
|
@ -14,7 +14,6 @@ using cpputils::NoninteractiveConsole;
|
||||
using std::string;
|
||||
using std::shared_ptr;
|
||||
using std::make_shared;
|
||||
using ::testing::_;
|
||||
using ::testing::NiceMock;
|
||||
using ::testing::Return;
|
||||
using ::testing::ValuesIn;
|
||||
@ -37,16 +36,16 @@ public:
|
||||
class CryConfigConsoleTest_Cipher: public CryConfigConsoleTest {};
|
||||
|
||||
#define EXPECT_ASK_FOR_CIPHER() \
|
||||
EXPECT_CALL(*console, askYesNo("Use default settings?", _)).Times(1).WillOnce(Return(false)); \
|
||||
EXPECT_CALL(*console, askYesNo("Use default settings?", testing::_)).Times(1).WillOnce(Return(false)); \
|
||||
EXPECT_CALL(*console, ask(HasSubstr("block cipher"), UnorderedElementsAreArray(CryCiphers::supportedCipherNames()))).Times(1)
|
||||
|
||||
#define EXPECT_ASK_FOR_BLOCKSIZE() \
|
||||
EXPECT_CALL(*console, askYesNo("Use default settings?", _)).Times(1).WillOnce(Return(false)); \
|
||||
EXPECT_CALL(*console, ask(HasSubstr("block size"), _)).Times(1)
|
||||
EXPECT_CALL(*console, askYesNo("Use default settings?", testing::_)).Times(1).WillOnce(Return(false)); \
|
||||
EXPECT_CALL(*console, ask(HasSubstr("block size"), testing::_)).Times(1)
|
||||
|
||||
#define EXPECT_ASK_FOR_MISSINGBLOCKISINTEGRITYVIOLATION() \
|
||||
EXPECT_CALL(*console, askYesNo("Use default settings?", _)).Times(1).WillOnce(Return(false)); \
|
||||
EXPECT_CALL(*console, askYesNo(HasSubstr("missing block"), _)).Times(1)
|
||||
EXPECT_CALL(*console, askYesNo("Use default settings?", testing::_)).Times(1).WillOnce(Return(false)); \
|
||||
EXPECT_CALL(*console, askYesNo(HasSubstr("missing block"), testing::_)).Times(1)
|
||||
|
||||
TEST_F(CryConfigConsoleTest_Cipher, AsksForCipher) {
|
||||
EXPECT_ASK_FOR_CIPHER().WillOnce(ChooseAnyCipher());
|
||||
@ -54,15 +53,15 @@ TEST_F(CryConfigConsoleTest_Cipher, AsksForCipher) {
|
||||
}
|
||||
|
||||
TEST_F(CryConfigConsoleTest_Cipher, ChooseDefaultCipher) {
|
||||
EXPECT_CALL(*console, askYesNo("Use default settings?", _)).Times(1).WillOnce(Return(true));
|
||||
EXPECT_CALL(*console, ask(HasSubstr("block cipher"), _)).Times(0);
|
||||
EXPECT_CALL(*console, askYesNo("Use default settings?", testing::_)).Times(1).WillOnce(Return(true));
|
||||
EXPECT_CALL(*console, ask(HasSubstr("block cipher"), testing::_)).Times(0);
|
||||
string cipher = cryconsole.askCipher();
|
||||
EXPECT_EQ(CryConfigConsole::DEFAULT_CIPHER, cipher);
|
||||
}
|
||||
|
||||
TEST_F(CryConfigConsoleTest_Cipher, ChooseDefaultCipherWhenNoninteractiveEnvironment) {
|
||||
EXPECT_CALL(*console, askYesNo(HasSubstr("default"), _)).Times(0);
|
||||
EXPECT_CALL(*console, ask(HasSubstr("block cipher"), _)).Times(0);
|
||||
EXPECT_CALL(*console, askYesNo(HasSubstr("default"), testing::_)).Times(0);
|
||||
EXPECT_CALL(*console, ask(HasSubstr("block cipher"), testing::_)).Times(0);
|
||||
string cipher = noninteractiveCryconsole.askCipher();
|
||||
EXPECT_EQ(CryConfigConsole::DEFAULT_CIPHER, cipher);
|
||||
}
|
||||
@ -78,8 +77,8 @@ TEST_F(CryConfigConsoleTest_Cipher, AsksForMissingBlockIsIntegrityViolation) {
|
||||
}
|
||||
|
||||
TEST_F(CryConfigConsoleTest_Cipher, ChooseDefaultBlocksizeWhenNoninteractiveEnvironment) {
|
||||
EXPECT_CALL(*console, askYesNo(HasSubstr("default"), _)).Times(0);
|
||||
EXPECT_CALL(*console, ask(HasSubstr("block size"), _)).Times(0);
|
||||
EXPECT_CALL(*console, askYesNo(HasSubstr("default"), testing::_)).Times(0);
|
||||
EXPECT_CALL(*console, ask(HasSubstr("block size"), testing::_)).Times(0);
|
||||
uint32_t blocksize = noninteractiveCryconsole.askBlocksizeBytes();
|
||||
EXPECT_EQ(CryConfigConsole::DEFAULT_BLOCKSIZE_BYTES, blocksize);
|
||||
}
|
||||
@ -90,11 +89,11 @@ public:
|
||||
optional<string> cipherWarning = CryCiphers::find(cipherName).warning();
|
||||
|
||||
void EXPECT_DONT_SHOW_WARNING() {
|
||||
EXPECT_CALL(*console, askYesNo(_, _)).Times(0);
|
||||
EXPECT_CALL(*console, askYesNo(testing::_, testing::_)).Times(0);
|
||||
}
|
||||
|
||||
void EXPECT_SHOW_WARNING(const string &warning) {
|
||||
EXPECT_CALL(*console, askYesNo(HasSubstr(warning), _)).WillOnce(Return(true));
|
||||
EXPECT_CALL(*console, askYesNo(HasSubstr(warning), testing::_)).WillOnce(Return(true));
|
||||
}
|
||||
};
|
||||
|
||||
|