Changeset View
Standalone View
source/simulation2/tests/test_ComponentDataHolder.h
- This file was added.
/* Copyright (C) 2022 Wildfire Games. | |||||||||||
* This file is part of 0 A.D. | |||||||||||
* | |||||||||||
* 0 A.D. is free software: you can redistribute it and/or modify | |||||||||||
* it under the terms of the GNU General Public License as published by | |||||||||||
* the Free Software Foundation, either version 2 of the License, or | |||||||||||
* (at your option) any later version. | |||||||||||
* | |||||||||||
* 0 A.D. is distributed in the hope that it will be useful, | |||||||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||||||||
* GNU General Public License for more details. | |||||||||||
* | |||||||||||
* You should have received a copy of the GNU General Public License | |||||||||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | |||||||||||
*/ | |||||||||||
#include "lib/self_test.h" | |||||||||||
#include "simulation2/system/IComponent.h" | |||||||||||
#include "simulation2/system/ComponentDataHolder.h" | |||||||||||
Stan: Anything that can be forward declared?
Bit weird not to have CComponentDataHolder.h isn't it? | |||||||||||
Done Inline ActionsAdded include for ComponentDataHolder.h What would we want to forward declare? Mercury: Added include for ComponentDataHolder.h
What would we want to forward declare? | |||||||||||
#include "ps/CLogger.h" | |||||||||||
Done Inline ActionsDoes that print something? If so, it should use TestLogger, and probably some checks. Stan: Does that print something? If so, it should use TestLogger, and probably some checks. | |||||||||||
Done Inline ActionsI'm not sure I understand the question, but the include does not print anything. Mercury: I'm not sure I understand the question, but the include does not print anything. | |||||||||||
Done Inline ActionsI mean does the code in the test use CLogger somewhere, if so, can we add assertion to check whatever its printing. E.g error message etc. Stan: I mean does the code in the test use CLogger somewhere, if so, can we add assertion to check… | |||||||||||
Done Inline ActionsAh, no it doesn't. Mercury: Ah, no it doesn't. | |||||||||||
Done Inline ActionsIt's a bit strange that you need that header then. Stan: It's a bit strange that you need that header then. | |||||||||||
Done Inline ActionsIf the logger isn't initialized the test system fails an ensure after the tests complete. Does seem odd. Mercury: If the logger isn't initialized the test system fails an ensure after the tests complete. Does… | |||||||||||
#include <cstddef> | |||||||||||
class TestComponentDataHolder : public CxxTest::TestSuite | |||||||||||
jprahmanUnsubmitted Done Inline ActionsI'd consider tests for:
jprahman: I'd consider tests for:
1. Multiple allocations then multiple deallocations
2. Allocation ->… | |||||||||||
{ | |||||||||||
public: | |||||||||||
void test_SetUp() | |||||||||||
{ | |||||||||||
CComponentDataHolder cdh = CComponentDataHolder(32,8); | |||||||||||
TS_ASSERT_EQUALS(cdh.Pools()[0], cdh.Back()); | |||||||||||
} | |||||||||||
void test_Allocate() | |||||||||||
{ | |||||||||||
CComponentDataHolder cdh = CComponentDataHolder(32,8); | |||||||||||
std::byte* ptr = cdh.Allocate(); | |||||||||||
TS_ASSERT_EQUALS(ptr, cdh.Pools()[0]); | |||||||||||
TS_ASSERT_EQUALS(cdh.Pools()[0] + cdh.SlotSize(), cdh.Back()); | |||||||||||
} | |||||||||||
void test_Deallocate() | |||||||||||
{ | |||||||||||
CComponentDataHolder cdh = CComponentDataHolder(32,8); | |||||||||||
std::byte* ptr = cdh.Allocate(); | |||||||||||
cdh.Deallocate(reinterpret_cast<IComponent*>(ptr)); | |||||||||||
std::byte* ptr2 = cdh.Allocate(); | |||||||||||
// Verify slot is reused. | |||||||||||
TS_ASSERT_EQUALS(ptr, ptr2); | |||||||||||
Done Inline Actions
Stan: | |||||||||||
Done Inline ActionsCaps and final dot please, and no whitespace :D Stan: Caps and final dot please, and no whitespace :D | |||||||||||
} | |||||||||||
}; | |||||||||||
Done Inline ActionsThink you need an include for that. #include <cstdint> ++i in the whole file. Stan: Think you need an include for that. `#include <cstdint>`
++i in the whole file.
space after… | |||||||||||
Done Inline Actionsdoes it actually make a difference to use ++i vs. i++? Seems like something the compiler should be able to handle. Mercury: does it actually make a difference to use ++i vs. i++? Seems like something the compiler should… | |||||||||||
Done Inline ActionsIn most cases no. For non trivial types it can prevent a copy but we mostly do it as a convention rather than an actual perf boost. Stan: In most cases no. For non trivial types it can prevent a copy but we mostly do it as a… |
Anything that can be forward declared?
Bit weird not to have CComponentDataHolder.h isn't it?