Bug Summary

File:core/class/IdentifiableTest.cc
Location:line 25, column 21
Description:Potential memory leak

Annotated Source Code

1#include <gtest/gtest.h>
2#include "core/CoreIncludes.h"
3#include "core/class/Identifiable.h"
4#include "core/module/ModuleInstance.h"
5
6namespace orxonox
7{
8 namespace
9 {
10 class IdentifiableClass : public Identifiable
11 {
12 public:
13 IdentifiableClass() { RegisterObject(IdentifiableClass)if (ClassIdentifier<IdentifiableClass>::getIdentifier()
->initializeObject(this)) return; else ((void)0)
; }
14 };
15
16 RegisterClassNoArgs(IdentifiableClass)orxonox::SI_I& _IdentifiableClassIdentifier = (*new orxonox
::SI_I(orxonox::registerClass<IdentifiableClass>("IdentifiableClass"
, new orxonox::ClassFactoryNoArgs<IdentifiableClass>(),
true)))
;
17
18 // Fixture
19 class IdentifiableTest : public ::testing::Test
20 {
21 public:
22 virtual void SetUp() override
23 {
24 new IdentifierManager();
1
Memory is allocated
25 ModuleInstance::getCurrentModuleInstance()->loadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER);
2
Potential memory leak
26 }
27
28 virtual void TearDown() override
29 {
30 ModuleInstance::getCurrentModuleInstance()->unloadAllStaticallyInitializedInstances(StaticInitialization::IDENTIFIER);
31 delete &IdentifierManager::getInstance();
32 }
33 };
34 }
35
36 TEST_F(IdentifiableTest, CanCreate)class IdentifiableTest_CanCreate_Test : public IdentifiableTest
{ public: IdentifiableTest_CanCreate_Test() {} private: virtual
void TestBody(); static ::testing::TestInfo* const test_info_
__attribute__ ((unused)); IdentifiableTest_CanCreate_Test(IdentifiableTest_CanCreate_Test
const &); void operator=(IdentifiableTest_CanCreate_Test
const &);};::testing::TestInfo* const IdentifiableTest_CanCreate_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"IdentifiableTest", "CanCreate", __null, __null, (::testing::
internal::GetTypeId<IdentifiableTest>()), IdentifiableTest
::SetUpTestCase, IdentifiableTest::TearDownTestCase, new ::testing
::internal::TestFactoryImpl< IdentifiableTest_CanCreate_Test
>);void IdentifiableTest_CanCreate_Test::TestBody()
37 {
38 IdentifiableClass* test = new IdentifiableClass();
39 ASSERT_TRUE(test != nullptr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(test != nullptr)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/class/IdentifiableTest.cc"
, 39, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "test != nullptr", "false", "true").c_str()) = ::testing::Message
()
;
40 delete test;
41 }
42
43 TEST_F(IdentifiableTest, HasIdentifierAssigned)class IdentifiableTest_HasIdentifierAssigned_Test : public IdentifiableTest
{ public: IdentifiableTest_HasIdentifierAssigned_Test() {} private
: virtual void TestBody(); static ::testing::TestInfo* const test_info_
__attribute__ ((unused)); IdentifiableTest_HasIdentifierAssigned_Test
(IdentifiableTest_HasIdentifierAssigned_Test const &); void
operator=(IdentifiableTest_HasIdentifierAssigned_Test const &
);};::testing::TestInfo* const IdentifiableTest_HasIdentifierAssigned_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo(
"IdentifiableTest", "HasIdentifierAssigned", __null, __null,
(::testing::internal::GetTypeId<IdentifiableTest>()), IdentifiableTest
::SetUpTestCase, IdentifiableTest::TearDownTestCase, new ::testing
::internal::TestFactoryImpl< IdentifiableTest_HasIdentifierAssigned_Test
>);void IdentifiableTest_HasIdentifierAssigned_Test::TestBody
()
44 {
45 IdentifiableClass test;
46 EXPECT_TRUE(test.getIdentifier())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(test.getIdentifier())
) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/class/IdentifiableTest.cc"
, 46, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "test.getIdentifier()", "false", "true").c_str()) = ::testing
::Message()
;
47 }
48
49 TEST_F(IdentifiableTest, CanBeIdentified)class IdentifiableTest_CanBeIdentified_Test : public IdentifiableTest
{ public: IdentifiableTest_CanBeIdentified_Test() {} private
: virtual void TestBody(); static ::testing::TestInfo* const test_info_
__attribute__ ((unused)); IdentifiableTest_CanBeIdentified_Test
(IdentifiableTest_CanBeIdentified_Test const &); void operator
=(IdentifiableTest_CanBeIdentified_Test const &);};::testing
::TestInfo* const IdentifiableTest_CanBeIdentified_Test ::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "IdentifiableTest"
, "CanBeIdentified", __null, __null, (::testing::internal::GetTypeId
<IdentifiableTest>()), IdentifiableTest::SetUpTestCase,
IdentifiableTest::TearDownTestCase, new ::testing::internal::
TestFactoryImpl< IdentifiableTest_CanBeIdentified_Test>
);void IdentifiableTest_CanBeIdentified_Test::TestBody()
50 {
51 IdentifiableClass test;
52 EXPECT_TRUE(test.isA(Class(IdentifiableClass)))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(test.isA(orxonox::ClassIdentifier
<IdentifiableClass>::getIdentifier()))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "/home/jenkins/workspace/orxonox_qc_trunk_checks/test/core/class/IdentifiableTest.cc"
, 52, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "test.isA(Class(IdentifiableClass))", "false", "true").c_str
()) = ::testing::Message()
;
53 }
54}