Add Google Test setup and one unit test

This commit is contained in:
Ben Visness
2016-08-25 16:04:42 -05:00
parent f8ff9972ee
commit 603dcc2f4a
7 changed files with 193 additions and 10 deletions

33
.gitignore vendored Normal file
View File

@@ -0,0 +1,33 @@
# Prerequisites
*.d
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app
hmm_test

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "externals/googletest"]
path = externals/googletest
url = https://github.com/google/googletest.git

View File

@@ -3,20 +3,20 @@
Single-file public domain game math library for C/C++ Single-file public domain game math library for C/C++
Version | Changes | Version | Changes |
----------------|----------------| ----------------|----------------|
**0.5** | Added scalar operations on vectors and matrices, added += and -= for hmm_mat4, reconciled headers and implementations, tidied up in general | **0.5** | Added scalar operations on vectors and matrices, added += and -= for hmm_mat4, reconciled headers and implementations, tidied up in general |
**0.4** | Added SSE Optimized HMM_SqrtF, HMM_RSqrtF, Removed use of CRT | **0.4** | Added SSE Optimized HMM_SqrtF, HMM_RSqrtF, Removed use of CRT |
**0.3** | Added +=,-=, *=, /= for hmm_vec2, hmm_vec3, hmm_vec4 | **0.3** | Added +=,-=, *=, /= for hmm_vec2, hmm_vec3, hmm_vec4 |
**0.2b** | Disabled warning C4201 on MSVC, Added 64bit percision on HMM_PI | **0.2b** | Disabled warning C4201 on MSVC, Added 64bit percision on HMM_PI |
**0.2a** | Prefixed Macros | **0.2a** | Prefixed Macros |
**0.2** | Updated Documentation, Fixed C Compliance, Prefixed all functions, and added better operator overloading | **0.2** | Updated Documentation, Fixed C Compliance, Prefixed all functions, and added better operator overloading |
**0.1** | Initial Version | **0.1** | Initial Version |
_ID: In Development_ _ID: In Development_
## FAQ
## FAQ
**What's the license?** **What's the license?**
@@ -24,4 +24,13 @@ This library is in the public domain. You can do whatever you want with them.
**Where can I contact you to ask questions?** **Where can I contact you to ask questions?**
You can email me at: Zak@Handmade.Network You can email me at: Zak@Handmade.Network
## Testing
```shell
cd test
make
./hmm_test
```

1
externals/googletest vendored Submodule

Submodule externals/googletest added at ed9d1e1ff9

5
test/HandmadeMath.cpp Normal file
View File

@@ -0,0 +1,5 @@
#define HANDMADE_MATH_IMPLEMENTATION
#define HANDMADE_MATH_CPP_MODE
#define HANDMADE_MATH_NO_INLINE
#include "../HandmadeMath.h"

81
test/Makefile Normal file
View File

@@ -0,0 +1,81 @@
# A sample Makefile for building Google Test and using it in user
# tests. Please tweak it to suit your environment and project. You
# may want to move it to your project's root directory.
#
# SYNOPSIS:
#
# make [all] - makes everything.
# make TARGET - makes the given target.
# make clean - removes all files generated by make.
# Please tweak the following variable definitions as needed by your
# project, except GTEST_HEADERS, which you can use in your own targets
# but shouldn't modify.
# Points to the root of Google Test, relative to where this file is.
# Remember to tweak this if you move this file.
GTEST_DIR = ../externals/googletest/googletest
# Where to find user code.
USER_DIR = ..
# Flags passed to the preprocessor.
# Set Google Test's header directory as a system directory, such that
# the compiler doesn't generate warnings in Google Test headers.
CPPFLAGS += -isystem $(GTEST_DIR)/include
# Flags passed to the C++ compiler.
CXXFLAGS += -g -Wall -Wextra -pthread -Wno-missing-braces -Wno-missing-field-initializers
# All tests produced by this Makefile. Remember to add new tests you
# created to the list.
TESTS = hmm_test
# All Google Test headers. Usually you shouldn't change this
# definition.
GTEST_HEADERS = $(GTEST_DIR)/include/gtest/*.h \
$(GTEST_DIR)/include/gtest/internal/*.h
# House-keeping build targets.
all : $(TESTS)
clean :
rm -f $(TESTS) gtest.a gtest_main.a *.o
# Builds gtest.a and gtest_main.a.
# Usually you shouldn't tweak such internal variables, indicated by a
# trailing _.
GTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h $(GTEST_HEADERS)
# For simplicity and to avoid depending on Google Test's
# implementation details, the dependencies specified below are
# conservative and not optimized. This is fine as Google Test
# compiles fast and for ordinary users its source rarely changes.
gtest-all.o : $(GTEST_SRCS_)
$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c \
$(GTEST_DIR)/src/gtest-all.cc
gtest_main.o : $(GTEST_SRCS_)
$(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c \
$(GTEST_DIR)/src/gtest_main.cc
gtest.a : gtest-all.o
$(AR) $(ARFLAGS) $@ $^
gtest_main.a : gtest-all.o gtest_main.o
$(AR) $(ARFLAGS) $@ $^
# Builds a sample test. A test should link with either gtest.a or
# gtest_main.a, depending on whether it defines its own main()
# function.
HandmadeMath.o : $(USER_DIR)/test/HandmadeMath.cpp $(USER_DIR)/HandmadeMath.h $(GTEST_HEADERS)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/test/HandmadeMath.cpp
hmm_test.o : $(USER_DIR)/test/hmm_test.cpp $(GTEST_HEADERS)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/test/hmm_test.cpp
hmm_test : HandmadeMath.o hmm_test.o gtest_main.a
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@

51
test/hmm_test.cpp Normal file
View File

@@ -0,0 +1,51 @@
#define HANDMADE_MATH_CPP_MODE
#include "../HandmadeMath.h"
#include "gtest/gtest.h"
TEST(Initialization, Vectors)
{
//
// Test vec2
//
hmm_vec2 v2 = HMM_Vec2(1.0f, 2.0f);
hmm_vec2 v2i = HMM_Vec2(1, 2);
EXPECT_FLOAT_EQ(v2.Elements[0], 1.0f);
EXPECT_FLOAT_EQ(v2.Elements[1], 2.0f);
EXPECT_FLOAT_EQ(v2i.Elements[0], 1.0f);
EXPECT_FLOAT_EQ(v2i.Elements[1], 2.0f);
//
// Test vec3
//
hmm_vec3 v3 = HMM_Vec3(1.0f, 2.0f, 3.0f);
hmm_vec3 v3i = HMM_Vec3i(1, 2, 3);
EXPECT_FLOAT_EQ(v3.Elements[0], 1.0f);
EXPECT_FLOAT_EQ(v3.Elements[1], 2.0f);
EXPECT_FLOAT_EQ(v3.Elements[2], 3.0f);
EXPECT_FLOAT_EQ(v3i.Elements[0], 1.0f);
EXPECT_FLOAT_EQ(v3i.Elements[1], 2.0f);
EXPECT_FLOAT_EQ(v3i.Elements[2], 3.0f);
//
// Test vec4
//
hmm_vec4 v4 = HMM_Vec4(1.0f, 2.0f, 3.0f, 4.0f);
hmm_vec4 v4i = HMM_Vec4i(1, 2, 3, 4);
EXPECT_FLOAT_EQ(v4.Elements[0], 1.0f);
EXPECT_FLOAT_EQ(v4.Elements[1], 2.0f);
EXPECT_FLOAT_EQ(v4.Elements[2], 3.0f);
EXPECT_FLOAT_EQ(v4.Elements[3], 4.0f);
EXPECT_FLOAT_EQ(v4i.Elements[0], 1.0f);
EXPECT_FLOAT_EQ(v4i.Elements[1], 2.0f);
EXPECT_FLOAT_EQ(v4i.Elements[2], 3.0f);
EXPECT_FLOAT_EQ(v4i.Elements[3], 4.0f);
}