sapling/eden/fs/testharness/TestUtil.cpp
Andres Suarez fbdb46f5cb Tidy up license headers
Reviewed By: chadaustin

Differential Revision: D17872966

fbshipit-source-id: cd60a364a2146f0dadbeca693b1d4a5d7c97ff63
2019-10-11 05:28:23 -07:00

31 lines
834 B
C++

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/
#include "TestUtil.h"
#include <cstring>
#include <stdexcept>
#include "eden/fs/model/Hash.h"
namespace facebook {
namespace eden {
Hash makeTestHash(folly::StringPiece value) {
constexpr size_t ASCII_SIZE = 2 * Hash::RAW_SIZE;
if (value.size() > ASCII_SIZE) {
throw std::invalid_argument(value.toString() + " is too big for Hash");
}
std::array<char, ASCII_SIZE> fullValue;
memset(fullValue.data(), '0', fullValue.size());
memcpy(
fullValue.data() + fullValue.size() - value.size(),
value.data(),
value.size());
return Hash{folly::StringPiece{folly::range(fullValue)}};
}
} // namespace eden
} // namespace facebook