Created
July 13, 2013 10:18
-
-
Save philsquared/5990252 to your computer and use it in GitHub Desktop.
Using Catch to implement parameterised tests in https://github.com/maidsafe/MaidSafe-Common/blob/catch/src/maidsafe/common/tests/key_value_buffer_test.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct MaxUsage { int memory, disk; }; | |
TEST_CASE( "KeyValueBuffer disk memory usage" ) | |
{ | |
using namespace Catch::Generators; | |
MaxUsage params[] = { | |
{ 1, 2 }, | |
{ 1, 1024 }, | |
{ 8, 1024 }, | |
{ 1024, 2048 }, | |
{ 1024, 1024 }, | |
{ 16, 16 * 1024 }, | |
{ 32, 32 }, | |
{ 1000, 10000 }, | |
{ 10000, 1000000 } }; | |
MaxUsage* maxUsage = GENERATE( between( params, ¶ms[sizeof(params)/sizeof(MaxUsage)-1] ) ); | |
std::unique_ptr<KeyValueBuffer> key_value_buffer_; | |
SECTION( "BEH_Store" ) { | |
uint64_t disk_usage(maxUsage->disk), memory_usage(maxUsage->memory), | |
total_usage(disk_usage + memory_usage); | |
while (total_usage != 0) { | |
NonEmptyString value(std::string(RandomAlphaNumericString( | |
static_cast<uint32_t>(maxUsage->memory)))); | |
Identity key(crypto::Hash<crypto::SHA512>(value)); | |
REQUIRE_NOTHROW(key_value_buffer_->Store(key, value)); | |
NonEmptyString recovered; | |
REQUIRE_NOTHROW(recovered = key_value_buffer_->Get(key)); | |
REQUIRE(value == recovered); | |
if (disk_usage != 0) { | |
disk_usage -= maxUsage->memory; | |
total_usage -= maxUsage->memory; | |
} else { | |
total_usage -= maxUsage->memory; | |
} | |
} | |
} | |
SECTION( "BEH_Delete" ) { /*...*/ } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment