DLLMainTest.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <AzCore/PlatformIncl.h>
  9. #include <AzCore/base.h>
  10. #include <AzCore/Module/Environment.h>
  11. #include <AzCore/Module/Module.h>
  12. #include <AzCore/Component/TransformBus.h>
  13. #include <AzCore/Component/Entity.h>
  14. #include <AzCore/RTTI/ReflectContext.h>
  15. #include <AzCore/Serialization/SerializeContext.h>
  16. #include <Tests/DLLTestVirtualClass.h>
  17. #include "ModuleTestBus.h"
  18. class ReflectedClass
  19. {
  20. public:
  21. AZ_TYPE_INFO(ReflectedClass, "{277E3FC1-5BE3-4890-A2CF-D389162F8D05}")
  22. ReflectedClass()
  23. : m_float(1.f)
  24. , m_int(2) {}
  25. float m_float;
  26. int m_int;
  27. static void Reflect(AZ::ReflectContext* context)
  28. {
  29. AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
  30. if (serializeContext)
  31. {
  32. serializeContext->Class<ReflectedClass>()->
  33. Field("FloatField", &ReflectedClass::m_float)->
  34. Field("IntField", &ReflectedClass::m_int);
  35. }
  36. }
  37. };
  38. class DllModule
  39. : public AZ::Module
  40. , public ModuleTestRequestBus::Handler
  41. {
  42. public:
  43. AZ_RTTI(DllModule, "{99C6BF95-847F-4EEE-BB60-9B26D02FF577}", AZ::Module);
  44. AZ_CLASS_ALLOCATOR(DllModule, AZ::SystemAllocator);
  45. DllModule()
  46. {
  47. ModuleTestRequestBus::Handler::BusConnect();
  48. }
  49. ~DllModule() override
  50. {
  51. ModuleTestRequestBus::Handler::BusDisconnect();
  52. }
  53. /*void Reflect(AZ::ReflectContext* context) override
  54. {
  55. AZ_Printf("DLL", "Reflect called");
  56. ReflectedClass::Reflect(context);
  57. }*/
  58. const char* GetModuleName() override
  59. {
  60. return "DllModule";
  61. }
  62. };
  63. //==============================================================================
  64. // Execute DLL tests
  65. //==============================================================================
  66. extern "C" AZ_DLL_EXPORT void DoTests()
  67. {
  68. // Allocate memory from the system allocator and pass it with a bus call to be freed from another module
  69. void* address = azmalloc(128);
  70. // Use the bus to fire a message on the bus to verify it works across modules
  71. AZ::EntityId hackEntityIdAddress((AZ::u64)address); // HACK to pass the address to another module, otherwise we need to create a common EBus
  72. AZ::TransformNotificationBus::Broadcast(&AZ::TransformNotificationBus::Events::OnParentChanged, AZ::EntityId(), hackEntityIdAddress);
  73. }
  74. //////////////////////////////////////////////////////////////////////////
  75. /// DLL Test shared environment variable test
  76. AZ::EnvironmentVariable<UnitTest::DLLTestVirtualClass> s_dllTestVar;
  77. extern "C" AZ_DLL_EXPORT void CreateDLLTestVirtualClass(const char* variableName)
  78. {
  79. s_dllTestVar = AZ::Environment::CreateVariable<UnitTest::DLLTestVirtualClass>(variableName);
  80. }
  81. extern "C" AZ_DLL_EXPORT void DestroyDLLTestVirtualClass()
  82. {
  83. s_dllTestVar.Reset();
  84. }
  85. //////////////////////////////////////////////////////////////////////////
  86. extern "C" AZ_DLL_EXPORT void InitializeDynamicModule()
  87. {
  88. AZ_Printf("DLL", "InitializeDynamicModule called");
  89. }
  90. extern "C" AZ_DLL_EXPORT AZ::Module * CreateModuleClass()
  91. {
  92. AZ_Printf("DLL", "CreateModuleClass called");
  93. return new DllModule();
  94. }
  95. extern "C" AZ_DLL_EXPORT void DestroyModuleClass(AZ::Module* module)
  96. {
  97. AZ_Printf("DLL", "DestroyModuleClass called");
  98. delete module;
  99. }
  100. extern "C" AZ_DLL_EXPORT void UninitializeDynamicModule()
  101. {
  102. AZ_Printf("DLL", "UninitializeDynamicModule called");
  103. }