Skip to content

Commit

Permalink
Update generated tests to not allocate Aws:: stl objects as static
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyRyabinin committed Apr 23, 2024
1 parent 99f54e4 commit a92347a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ namespace Aws
{
#ifdef USE_AWS_MEMORY_MANAGEMENT
Aws::Utils::Memory::MemorySystemInterface* memorySystem = Aws::Utils::Memory::GetMemorySystem();
assert(memorySystem && "Memory system is not initialized");
AWS_ASSERT(memorySystem && "Memory system is not initialized");
AWS_UNREFERENCED_PARAM(memorySystem);
#endif
AWS_UNREFERENCED_PARAM(allocationTag);

Expand Down
2 changes: 1 addition & 1 deletion src/aws-cpp-sdk-core/source/utils/memory/AWSMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void* Malloc(const char* allocationTag, size_t allocationSize)
Aws::Utils::Memory::MemorySystemInterface* memorySystem = Aws::Utils::Memory::GetMemorySystem();
#ifdef USE_AWS_MEMORY_MANAGEMENT
// Was InitAPI forgotten or ShutdownAPI already called?
assert(memorySystem && "Memory system is not initialized.");
AWS_ASSERT(memorySystem && "Memory system is not initialized.");
#endif

void* rawMemory = nullptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ using ExpEpProps = Aws::UnorderedMap<Aws::String, Aws::Vector<Aws::Vector<EpProp
using ExpEpAuthScheme = Aws::Vector<EpProp>;
using ExpEpHeaders = Aws::UnorderedMap<Aws::String, Aws::Vector<Aws::String>>;

class ${metadata.classNamePrefix}EndpointProviderTests : public ::testing::TestWithParam<size_t> {};

struct ${metadata.classNamePrefix}EndpointProviderEndpointTestCase
{
using OperationParamsFromTest = EndpointParameters;
Expand Down Expand Up @@ -57,7 +55,32 @@ struct ${metadata.classNamePrefix}EndpointProviderEndpointTestCase
// Aws::Vector<OperationInput> operationInput;
};

static const Aws::Vector<${metadata.classNamePrefix}EndpointProviderEndpointTestCase> TEST_CASES = {
class ${metadata.classNamePrefix}EndpointProviderTests : public ::testing::TestWithParam<size_t>
{
public:
static const size_t TEST_CASES_SZ;
protected:
static Aws::Vector<${metadata.classNamePrefix}EndpointProviderEndpointTestCase> getTestCase();
static Aws::UniquePtrSafeDeleted<Aws::Vector<${metadata.classNamePrefix}EndpointProviderEndpointTestCase>> TEST_CASES;
static void SetUpTestSuite()
{
TEST_CASES = Aws::MakeUniqueSafeDeleted<Aws::Vector<${metadata.classNamePrefix}EndpointProviderEndpointTestCase>>(ALLOCATION_TAG, getTestCase());
ASSERT_TRUE(TEST_CASES) << "Failed to allocate TEST_CASES table";
assert(TEST_CASES->size() == TEST_CASES_SZ);
}

static void TearDownTestSuite()
{
TEST_CASES.reset();
}
};

Aws::UniquePtrSafeDeleted<Aws::Vector<${metadata.classNamePrefix}EndpointProviderEndpointTestCase>> ${metadata.classNamePrefix}EndpointProviderTests::TEST_CASES;
const size_t ${metadata.classNamePrefix}EndpointProviderTests::TEST_CASES_SZ = ${testCases.size()};

Aws::Vector<${metadata.classNamePrefix}EndpointProviderEndpointTestCase> ${metadata.classNamePrefix}EndpointProviderTests::getTestCase() {

Aws::Vector<${metadata.classNamePrefix}EndpointProviderEndpointTestCase> test_cases = {
#foreach($testCase in $testCases)
/*TEST CASE ${foreach.index}*/
{"${testCase.documentation}", // documentation
Expand All @@ -68,7 +91,9 @@ static const Aws::Vector<${metadata.classNamePrefix}EndpointProviderEndpointTest
#if($foreach.hasNext) },#else }#end

#end
};
};
return test_cases;
}

Aws::String RulesToSdkSignerName(const Aws::String& rulesSignerName)
{
Expand Down Expand Up @@ -163,9 +188,10 @@ void ValidateOutcome(const ResolveEndpointOutcome& outcome, const ${metadata.cla
TEST_P(${metadata.classNamePrefix}EndpointProviderTests, EndpointProviderTest)
{
const size_t TEST_CASE_IDX = GetParam();
ASSERT_LT(TEST_CASE_IDX, TEST_CASES.size()) << "Something is wrong with the test fixture itself.";
const ${metadata.classNamePrefix}EndpointProviderEndpointTestCase& TEST_CASE = TEST_CASES.at(TEST_CASE_IDX);
ASSERT_LT(TEST_CASE_IDX, TEST_CASES->size()) << "Something is wrong with the test fixture itself.";
const ${metadata.classNamePrefix}EndpointProviderEndpointTestCase& TEST_CASE = TEST_CASES->at(TEST_CASE_IDX);
SCOPED_TRACE(Aws::String("\nTEST CASE # ") + Aws::Utils::StringUtils::to_string(TEST_CASE_IDX) + ": " + TEST_CASE.documentation);
SCOPED_TRACE(Aws::String("\n--gtest_filter=EndpointTestsFromModel/${metadata.classNamePrefix}EndpointProviderTests.EndpointProviderTest/") + Aws::Utils::StringUtils::to_string(TEST_CASE_IDX));

std::shared_ptr<${metadata.classNamePrefix}EndpointProvider> endpointProvider = Aws::MakeShared<${metadata.classNamePrefix}EndpointProvider>(ALLOCATION_TAG);
ASSERT_TRUE(endpointProvider) << "Failed to allocate/initialize ${metadata.classNamePrefix}EndpointProvider";
Expand Down Expand Up @@ -207,4 +233,4 @@ TEST_P(${metadata.classNamePrefix}EndpointProviderTests, EndpointProviderTest)

INSTANTIATE_TEST_SUITE_P(EndpointTestsFromModel,
${metadata.classNamePrefix}EndpointProviderTests,
::testing::Range((size_t) 0u, TEST_CASES.size()));
::testing::Range((size_t) 0u, ${metadata.classNamePrefix}EndpointProviderTests::TEST_CASES_SZ));

0 comments on commit a92347a

Please sign in to comment.