Skip to content

Commit 2847fa6

Browse files
authored
Bundle GTest (#8)
Bundle GTest - also fixes some sign warnings in comparisons for tests, and updates README.md to the most recent version
1 parent 991dd55 commit 2847fa6

File tree

210 files changed

+87863
-99
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

210 files changed

+87863
-99
lines changed

.travis.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,6 @@ matrix:
2323
env: COMPILER=clang++-3.6 C_COMPILER=clang-3.6
2424

2525
before_install:
26-
- sudo apt-get update -qq
27-
- sudo apt-get install -y libgtest-dev
28-
- sudo wget https://github.com/google/googletest/archive/release-1.7.0.tar.gz
29-
- sudo tar xf release-1.7.0.tar.gz
30-
- cd googletest-release-1.7.0
31-
- sudo cmake -DBUILD_SHARED_LIBS=ON -DCMAKE_C_COMPILER=$C_COMPILER -DCMAKE_CXX_COMPILER=$COMPILER .
32-
- sudo make
33-
- sudo cp -a include/gtest /usr/include
34-
- sudo cp -a libgtest_main.so libgtest.so /usr/lib/
3526
- cd "${TRAVIS_BUILD_DIR}"
3627

3728
script:

CMakeLists.txt

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ endif()
4949

5050
set(CMAKE_CXX_FLAGS_BASE "${CMAKE_CXX_FLAGS_BASE} ${dialect} ${warnings} ${flags}")
5151

52-
include_directories(include test)
52+
include_directories("include")
5353

5454
file(GLOB_RECURSE ASHLEY_CPP_SOURCES ${PROJECT_SOURCE_DIR}/src/*.cpp)
5555
file(GLOB ASHLEY_CPP_HEADERS ${PROJECT_SOURCE_DIR}/include/*.hpp)
@@ -67,26 +67,24 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_BASE} ${ASHLEY_RELEASE_FLAGS}")
6767
add_library(${ASHLEY_LIB_NAME} ${ASHLEY_CPP_SOURCES})
6868

6969
if (NOT EXCLUDE_TESTS)
70-
find_package(GTest)
71-
72-
if( NOT GTEST_FOUND )
73-
message ("Skipping tests; GTest was not found")
70+
if ( NOT MSVC )
71+
set(ASHLEY_TEST_FLAGS "-pthread")
7472
else ()
75-
file (GLOB_RECURSE ASHLEY_TEST_SOURCES ${PROJECT_SOURCE_DIR}/test/*.cpp)
76-
77-
if ( NOT MSVC )
78-
set(ASHLEY_TEST_FLAGS "-pthread")
79-
else ()
80-
set(ASHLEY_TEST_FLAGS "")
81-
endif ()
82-
83-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ASHLEY_TEST_FLAGS}")
84-
85-
include_directories(${GTEST_INCLUDE_DIRS})
86-
87-
add_executable(AshleyCPPTest ${ASHLEY_TEST_SOURCES})
88-
target_link_libraries(AshleyCPPTest ${ASHLEY_LIB_NAME} ${GTEST_BOTH_LIBRARIES})
89-
endif()
73+
set(ASHLEY_TEST_FLAGS "")
74+
endif ()
75+
76+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ASHLEY_TEST_FLAGS}")
77+
78+
add_subdirectory("test")
79+
80+
include_directories("test" "test/googletest/include")
81+
file (GLOB_RECURSE ASHLEY_TEST_SOURCES
82+
${PROJECT_SOURCE_DIR}/test/core/*.cpp
83+
${PROJECT_SOURCE_DIR}/test/signals/*.cpp
84+
${PROJECT_SOURCE_DIR}/test/systems/*.cpp)
85+
86+
add_executable(AshleyCPPTest ${ASHLEY_TEST_SOURCES})
87+
target_link_libraries(AshleyCPPTest ${ASHLEY_LIB_NAME} gtest_main gtest)
9088
endif (NOT EXCLUDE_TESTS)
9189

9290
install (TARGETS ${ASHLEY_LIB_NAME} DESTINATION lib)

README.md

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,47 +8,45 @@ AshleyCPP is a lightweight, cross-platform and easy to use Entity framework for
88
get started making a game using a pure, ECS-oriented style.
99

1010
It prioritises speed and simplicity and mirrors the public API of the original where possible to make it easy to learn,
11-
quick to run and simple to debug, doubly so for users of the Java original.
11+
quick to run and simple to debug - and doubly so for users of the Java original.
1212

13-
The original is inspired by the [Ash](http://www.ashframework.org/) and
14-
[Artemis](http://gamadu.com/artemis/) frameworks.
13+
The original is inspired by the [Ash](http://www.ashframework.org/) and [Artemis](http://gamadu.com/artemis/) frameworks.
1514

1615
AshleyCPP is a personal project and while there are no guarantees that it will compile and work, the master branch
17-
on GitHub should compile and function properly and should be usable for making projects right now.
16+
on GitHub should compile and function properly and should be usable for making projects right now. There is currently no
17+
guarantee of API stability between versions, or indeed any meaningful versioning.
1818

1919
### Building
20-
21-
AshleyCPP uses the CMake build system and comes with three build targets; the debug library, "AshleyCPP-d", the release library "AshleyCPP" and the imaginatively named executable "AshleyCPPTest". The test program has a hard dependency on Google Test.
20+
AshleyCPP uses the CMake build system and comes with three build targets; the debug library, "AshleyCPP-d", the release library "AshleyCPP" and the (imaginatively named) executable "AshleyCPPTest". The test program uses GTest, which is bundled.
2221

2322
To build the library from source, install a relatively recent version of CMake, navigate to a copy of the source and
2423
do the following:
2524

2625
mkdir build
2726
cd build
28-
cmake ..
27+
cmake -DCMAKE_BUILD_TYPE=<CHOOSE ONE: Debug/Release> ..
2928

30-
and proceed as normal for your environment. If you don't care about the tests, you can run `cmake -DEXCLUDE_TESTS=TRUE ..` and the dependency on GTest will be removed, just giving you the libraries.
29+
and proceed as normal for your environment. If you don't care about the tests, you can run `cmake -DEXCLUDE_TESTS=TRUE ..` leaving you with just the library.
3130

3231
### Usage Notes and API Changes
3332
While AshleyCPP strives to match the exported public API of the Java original, differences in the languages mean that
3433
some differences exist. Such changes are listed in detail in APICHANGES.md, but a quickstart is given below.
3534

36-
Note: In situations where you'd use `.class` to get the type of a Java class, in C++ you can `#include <typeinfo>` and:
35+
First in foremost: In situations where in Java you'd use `.class` to get a Java class, in C++ you can `#include <typeinfo>` and:
3736

3837
typeid(ComponentClass); // Equivalent to ComponentClass.class in Java.
3938

4039
// e.g. get a Family* that matches Entity having both ComponentA and ComponentB
4140
ashley::Family::getFor({typeid(ComponentA), typeid(ComponentB)});
4241
43-
- General
44-
- The whole library is enclosed in the `ashley` namespace. Use `using namespace ashley;` to save typing if you want.
45-
- You can `#include` individual headers (organised similarly to the Java packages) or `#include "Ashley/AshleyCore.hpp"`
46-
- Java generic functions that take vararg lists of `Class<? extends Component>` are replaced by
47-
`std::initializer_list<std::type_index>`. Some functions also provide template overloads which may be easier and
48-
faster to use; check the documentation for specific occurrences.
49-
- The library enforces ownership using std::unique_ptr; the engine owns all entities and systems that are passed into
50-
it and unless they're removed, all entities and systems die with the engine. Likewise, each Entity strictly owns
51-
its attached components. This minimises the risk of leaking memory.
42+
- The whole library is enclosed in the `ashley` namespace. Use `using namespace ashley;` to save typing if you want.
43+
- You can `#include` individual headers (organised similarly to the Java packages) or `#include "Ashley/Ashley.hpp"`
44+
- Java generic functions that take vararg lists of `Class<? extends Component>` are replaced by
45+
`std::initializer_list<std::type_index>`. Some functions also provide template overloads which may be easier and
46+
faster to use; check the documentation for specific occurrences.
47+
- The library enforces ownership using `std::unique_ptr`; the engine owns all entities and systems that are passed into
48+
it and unless they're removed, all entities and systems die with the engine. Likewise, each Entity strictly owns
49+
its attached components. This minimises the risk of leaking memory.
5250

5351
For more specific changes, see the [APICHANGES.md](https://github.com/SgtCoDFish/AshleyCPP/blob/master/APICHANGES.md) file.
5452

@@ -70,18 +68,18 @@ Ticked classes have both their implementation and tests complete.
7068
- [x] IteratingSystem
7169
- [x] IntervalSystem
7270
- [x] IntervalIteratingSystem
73-
- [ ] SortedIteratingSystem
71+
- [x] SortedIteratingSystem
7472
- Util
7573
- [x] ObjectPool
7674
- [x] Poolable
7775

7876
*NB:*
79-
- Bag and ImmutableArray will not be implemented, there are better native C++ choices without me reinventing the wheel.
77+
- `Bag` and `ImmutableArray` will probably not be implemented, there are better native C++ choices without reinventing the wheel.
8078
- Currently implements as far as Ashley commit [#a276fe45](https://github.com/libgdx/ashley/commit/a276fe45c81d450f305ce1b5b0bd0fe837207a70).
8179

82-
Features to be implemented:
80+
Nice to have features:
8381

84-
- Refactor entity ids, using a C++11 constexpr compile time hash and a templated Component class to prevent using a virtual method and vtable. Will lead to smaller components and better cache coherency.
82+
- Refactor/rewrite handling of entity ids, using a C++11 constexpr compile time hash and a templated Component class to prevent using a virtual method and vtable. Will lead to smaller components and better cache coherency.
8583

8684
### License
8785

src/Entity.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ std::unique_ptr<ashley::Component> ashley::Entity::removeImpl(std::type_index ty
8585

8686
std::unique_ptr<ashley::Component> ashley::Entity::removeInternal(std::type_index typeIndex) {
8787
const auto id = ashley::ComponentType::getIndexFor(typeIndex);
88-
assert(id >= 0 && id < componentBits.size() && "invalid component index; you might have too many component types");
88+
assert(id < componentBits.size() && "invalid component index; you might have too many component types");
8989

9090
std::unique_ptr<ashley::Component> ret { nullptr };
9191

test/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
cmake_minimum_required(VERSION 2.6.2)
2+
3+
project( googletest-distribution )
4+
5+
enable_testing()
6+
7+
option(BUILD_GTEST "Builds the googletest subproject" ON)
8+
9+
add_subdirectory( googletest )

test/core/ComponentTypeTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
// Ensures that we don't waste any memory by having a vtable on Components; that is, tests that a Component has a size of 1 (the minimum)
2626
TEST(ComponentTypeTest, MinSizeComponents) {
27-
ASSERT_EQ(sizeof(ashley::Component), 1);
27+
ASSERT_EQ(sizeof(ashley::Component), 1u);
2828
}
2929

3030
// Ensures a valid type is returned when a call is made to the various getFor() functions, and that this type is the same in the various functions.

test/core/EngineTests.cpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ class EntityListenerMock : public EntityListener {
6565

6666
class EntitySystemMock : public EntitySystem {
6767
public:
68-
uint64_t updateCalls = { 0 };
69-
uint64_t addedCalls = { 0 };
70-
uint64_t removedCalls = { 0 };
68+
int64_t updateCalls = { 0 };
69+
int64_t addedCalls = { 0 };
70+
int64_t removedCalls = { 0 };
7171

7272
EntitySystemMock() :
7373
EntitySystemMock(nullptr) {
@@ -142,22 +142,22 @@ class EngineTest : public ::testing::Test {
142142
TEST_F(EngineTest, AddAndRemoveEntities) {
143143
engine.addEntity();
144144

145-
ASSERT_EQ(1, listenerA.addedCount);
146-
ASSERT_EQ(1, listenerB.addedCount);
145+
ASSERT_EQ(1u, listenerA.addedCount);
146+
ASSERT_EQ(1u, listenerB.addedCount);
147147

148148
engine.removeEntityListener(&listenerB);
149149

150150
engine.addEntity();
151151

152-
ASSERT_EQ(2, listenerA.addedCount);
153-
ASSERT_EQ(1, listenerB.addedCount);
152+
ASSERT_EQ(2u, listenerA.addedCount);
153+
ASSERT_EQ(1u, listenerB.addedCount);
154154

155155
engine.addEntityListener(&listenerB);
156156

157157
engine.removeAllEntities(); // calls removeEntity(shared_ptr) on each added entity
158158

159-
ASSERT_EQ(2, listenerA.removedCount);
160-
ASSERT_EQ(2, listenerB.removedCount);
159+
ASSERT_EQ(2u, listenerA.removedCount);
160+
ASSERT_EQ(2u, listenerB.removedCount);
161161
}
162162

163163
// Test the addSystem(EntitySystem*) getSystem() and removeSystem(typeID) methods
@@ -173,8 +173,8 @@ TEST_F(EngineTest, AddGetAndRemoveSystem) {
173173

174174
ASSERT_FALSE(engine.getSystem(typeid(EntitySystemMockA)) == nullptr);
175175
ASSERT_FALSE(engine.getSystem(typeid(EntitySystemMockB)) == nullptr);
176-
ASSERT_EQ(1, sA->addedCalls);
177-
ASSERT_EQ(1, sB->addedCalls);
176+
ASSERT_EQ(1u, sA->addedCalls);
177+
ASSERT_EQ(1u, sB->addedCalls);
178178

179179
engine.removeSystem(typeid(EntitySystemMockA));
180180
engine.removeSystem(typeid(EntitySystemMockB));
@@ -275,7 +275,7 @@ TEST_F(EngineTest, EntitiesForFamily) {
275275
auto family = Family::getFor( { typeid(ComponentA), typeid(ComponentB) });
276276
auto familyEntities = engine.getEntitiesFor(family);
277277

278-
ASSERT_EQ(0, familyEntities->size());
278+
ASSERT_EQ(0u, familyEntities->size());
279279

280280
auto e1 = engine.addEntity();
281281
auto e2 = engine.addEntity();
@@ -287,7 +287,7 @@ TEST_F(EngineTest, EntitiesForFamily) {
287287
e3->add<ComponentA>().add<ComponentB>().add<ComponentC>();
288288
e4->add<ComponentA>().add<ComponentB>().add<ComponentC>();
289289

290-
ASSERT_EQ(3, familyEntities->size());
290+
ASSERT_EQ(3u, familyEntities->size());
291291

292292
bool e1Found = false, e2Found = false, e3Found = false, e4Found = false;
293293

@@ -308,14 +308,14 @@ TEST_F(EngineTest, EntityForFamilyWithRemoval) {
308308
e->add<ComponentA>();
309309
auto entities = engine.getEntitiesFor(Family::getFor( { typeid(ComponentA) }));
310310

311-
ASSERT_EQ(entities->size(), 1);
311+
ASSERT_EQ(1u, entities->size());
312312
ASSERT_TRUE(
313313
std::find_if(entities->begin(), entities->end(), [&](Entity *&found) {return found == e;})
314314
!= entities->end());
315315

316316
engine.removeEntity(e);
317317

318-
ASSERT_EQ(0, entities->size());
318+
ASSERT_EQ(0u, entities->size());
319319
ASSERT_FALSE(
320320
std::find_if(entities->begin(), entities->end(), [&](Entity *&found) {return found == e;})
321321
!= entities->end());
@@ -325,7 +325,7 @@ TEST_F(EngineTest, EntitiesForFamilyWithRemoval) {
325325
auto family = Family::getFor( { typeid(ComponentA), typeid(ComponentB) });
326326
auto familyEntities = engine.getEntitiesFor(family);
327327

328-
ASSERT_EQ(0, familyEntities->size());
328+
ASSERT_EQ(0u, familyEntities->size());
329329

330330
auto e1u = std::unique_ptr<Entity>(new Entity());
331331
auto e2u = std::unique_ptr<Entity>(new Entity());
@@ -342,7 +342,7 @@ TEST_F(EngineTest, EntitiesForFamilyWithRemoval) {
342342
auto e3 = engine.addEntity(std::move(e3u));
343343
auto e4 = engine.addEntity(std::move(e4u));
344344

345-
ASSERT_EQ(3, familyEntities->size());
345+
ASSERT_EQ(3u, familyEntities->size());
346346

347347
bool e1Found = false, e2Found = false, e3Found = false, e4Found = false;
348348

@@ -372,7 +372,7 @@ TEST_F(EngineTest, EntitiesForFamilyWithRemoval) {
372372
EXPECT_EQ(e2Found, false);
373373
EXPECT_EQ(e3Found, false);
374374
EXPECT_EQ(e4Found, true);
375-
ASSERT_EQ(1, familyEntities->size());
375+
ASSERT_EQ(1u, familyEntities->size());
376376
}
377377

378378
TEST_F(EngineTest, EntitiesForFamilyWithRemovalAndFiltering) {
@@ -393,24 +393,24 @@ TEST_F(EngineTest, EntitiesForFamilyWithRemovalAndFiltering) {
393393
e2->add<ComponentA>();
394394
e2->add<ComponentB>();
395395

396-
ASSERT_EQ(1, entsWithAOnly->size());
397-
ASSERT_EQ(1, entsWithB->size());
396+
ASSERT_EQ(1u, entsWithAOnly->size());
397+
ASSERT_EQ(1u, entsWithB->size());
398398

399399
e2->remove<ComponentB>();
400400

401-
ASSERT_EQ(2, entsWithAOnly->size());
402-
ASSERT_EQ(0, entsWithB->size());
401+
ASSERT_EQ(2u, entsWithAOnly->size());
402+
ASSERT_EQ(0u, entsWithB->size());
403403
}
404404

405405
TEST_F(EngineTest, GetSystems) {
406406
auto sys = engine.getSystems();
407407

408-
ASSERT_EQ(sys.size(), 0);
408+
ASSERT_EQ(sys.size(), 0u);
409409

410410
engine.addSystem(std::unique_ptr<EntitySystemMockA>(new EntitySystemMockA()));
411411
engine.addSystem(std::unique_ptr<EntitySystemMockB>(new EntitySystemMockB()));
412412

413413
sys = engine.getSystems();
414414

415-
ASSERT_EQ(sys.size(), 2);
415+
ASSERT_EQ(sys.size(), 2u);
416416
}

test/core/EntityTests.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -248,26 +248,26 @@ TEST_F(EntityTest, ComponentListener) {
248248
e.componentAdded.add(dynAdd);
249249
e.componentRemoved.add(dynRem);
250250

251-
ASSERT_EQ(0, dynAdd->counter);
252-
ASSERT_EQ(0, dynRem->counter);
251+
ASSERT_EQ(0u, dynAdd->counter);
252+
ASSERT_EQ(0u, dynRem->counter);
253253

254254
e.add<ashley::test::PositionComponent>(5, 2);
255255

256-
ASSERT_EQ(1, dynAdd->counter);
257-
ASSERT_EQ(0, dynRem->counter);
256+
ASSERT_EQ(1u, dynAdd->counter);
257+
ASSERT_EQ(0u, dynRem->counter);
258258

259259
e.remove<ashley::test::PositionComponent>();
260260

261-
ASSERT_EQ(1, dynAdd->counter);
262-
ASSERT_EQ(1, dynRem->counter);
261+
ASSERT_EQ(1u, dynAdd->counter);
262+
ASSERT_EQ(1u, dynRem->counter);
263263

264264
e.add<ashley::test::VelocityComponent>(5, 222);
265265

266-
ASSERT_EQ(2, dynAdd->counter);
267-
ASSERT_EQ(1, dynRem->counter);
266+
ASSERT_EQ(2u, dynAdd->counter);
267+
ASSERT_EQ(1u, dynRem->counter);
268268

269269
e.remove<ashley::test::VelocityComponent>();
270270

271-
ASSERT_EQ(2, dynAdd->counter);
272-
ASSERT_EQ(2, dynRem->counter);
271+
ASSERT_EQ(2u, dynAdd->counter);
272+
ASSERT_EQ(2u, dynRem->counter);
273273
}

test/googletest/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# python
2+
*.pyc

0 commit comments

Comments
 (0)