Merge pull request #15 from ekr/add_gtests

Add gtests
This commit is contained in:
Cullen Jennings 2013-12-11 20:28:18 -08:00
commit 1928b9a1ba
6 changed files with 105 additions and 3 deletions

View File

@ -1,8 +1,15 @@
UNAME=$(shell uname | tr A-Z a-z)
LIBPREFIX=lib
LIBSUFFIX=a
CP=cp
ROOTDIR=$(PWD)
ifeq (,wildcard ./gtest)
HAVE_GTEST=No
else
HAVE_GTEST=Yes
endif
# Configurations
ifeq ($(BUILDTYPE), Release)
CFLAGS += -O3
@ -24,7 +31,7 @@ ASMFLAGS += -DNO_DYNAMIC_VP -DNOPREFIX
#### No user-serviceable parts below this line
INCLUDES = -Icodec/api/svc -Icodec/common
INCLUDES = -Icodec/api/svc -Icodec/common -Igtest/include
ASM_INCLUDES = -Iprocessing/src/asm/
COMMON_INCLUDES = \
@ -49,11 +56,15 @@ H264DEC_LDFLAGS = -L. -ldecoder -lcommon
H264ENC_INCLUDES = $(ENCODER_INCLUDES) -Icodec/console/enc/inc
H264ENC_LDFLAGS = -L. -lencoder -lprocessing -lcommon
all: libraries binaries
CODEC_UNITTEST_LDFLAGS = -L. -lgtest -ldecoder -lcommon
all: $(GTEST_TARGETS) libraries binaries
clean:
rm -f $(OBJS) $(LIBRARIES) $(BINARIES)
gtest-bootstrap:
svn co https://googletest.googlecode.com/svn/trunk/ gtest
include codec/common/targets.mk
include codec/decoder/targets.mk
@ -62,5 +73,13 @@ include processing/targets.mk
include codec/console/dec/targets.mk
include codec/console/enc/targets.mk
ifeq ($(HAVE_GTEST),Yes)
include build/gtest-targets.mk
include test/targets.mk
endif

19
build/gtest-targets.mk Normal file
View File

@ -0,0 +1,19 @@
GTEST_PREFIX=GTEST
GTEST_SRCDIR=gtest
GTEST_CPP_SRCS=\
$(GTEST_SRCDIR)/src/gtest-all.cc
GTEST_OBJS += $(GTEST_CPP_SRCS:.cc=.o)
OBJS += $(GTEST_OBJS)
GTEST_INCLUDES += -Igtest
$(GTEST_SRCDIR)/src/gtest-all.o: $(GTEST_SRCDIR)/src/gtest-all.cc
$(CXX) $(CFLAGS) $(CXXFLAGS) $(INCLUDES) $(GTEST_CFLAGS) $(GTEST_INCLUDES) -c -o $(GTEST_SRCDIR)/src/gtest-all.o $(GTEST_SRCDIR)/src/gtest-all.cc
$(LIBPREFIX)gtest.$(LIBSUFFIX): $(GTEST_OBJS)
rm -f $(LIBPREFIX)gtest.$(LIBSUFFIX)
ar cr $@ $(GTEST_OBJS)
libraries: $(LIBPREFIX)gtest.$(LIBSUFFIX)
LIBRARIES += $(LIBPREFIX)gtest.$(LIBSUFFIX)

View File

@ -6,3 +6,5 @@
(cd codec/console/dec; python ../../../build/mktargets.py --directory codec/console/dec --binary h264dec --exclude dec_console.h --exclude load_bundle_functions.cpp)
(cd codec/console/enc; python ../../../build/mktargets.py --directory codec/console/enc --binary h264enc --exclude enc_console.h --exclude bundlewelsenc.cpp)
(cd test; python ../build/mktargets.py --directory test --binary codec_unittest)

View File

@ -4,7 +4,7 @@ COMMON_CPP_SRCS=\
$(COMMON_SRCDIR)/./logging.cpp\
COMMON_OBJS += $(COMMON_CPP_SRCS:.cpp=.o)
ifdef USE_ASM
ifeq ($(USE_ASM), Yes)
COMMON_ASM_SRCS=\
COMMON_OBJS += $(COMMON_ASM_SRCS:.asm=.o)

41
test/simple_test.cpp Normal file
View File

@ -0,0 +1,41 @@
#include <gtest/gtest.h>
#if defined (WIN32)
#include <windows.h>
#include <tchar.h>
#else
#include <string.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include "codec_def.h"
#include "codec_app_def.h"
#include "codec_api.h"
class CodecTest : public ::testing::Test {
public:
CodecTest() : decoder_(NULL) {}
~CodecTest() {
if (decoder_) DestroyDecoder(decoder_);
}
void SetUp() {
long rv = CreateDecoder(&decoder_);
ASSERT_EQ(0, rv);
ASSERT_TRUE(decoder_);
}
protected:
ISVCDecoder *decoder_;
};
TEST_F(CodecTest, JustInit) {
}
int main(int argc, char **argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

21
test/targets.mk Normal file
View File

@ -0,0 +1,21 @@
CODEC_UNITTEST_PREFIX=CODEC_UNITTEST
CODEC_UNITTEST_SRCDIR=test
CODEC_UNITTEST_CPP_SRCS=\
$(CODEC_UNITTEST_SRCDIR)/./simple_test.cpp\
CODEC_UNITTEST_OBJS += $(CODEC_UNITTEST_CPP_SRCS:.cpp=.o)
ifeq ($(USE_ASM), Yes)
CODEC_UNITTEST_ASM_SRCS=\
CODEC_UNITTEST_OBJS += $(CODEC_UNITTEST_ASM_SRCS:.asm=.o)
endif
OBJS += $(CODEC_UNITTEST_OBJS)
$(CODEC_UNITTEST_SRCDIR)/./simple_test.o: $(CODEC_UNITTEST_SRCDIR)/./simple_test.cpp
$(CXX) $(CFLAGS) $(CXXFLAGS) $(INCLUDES) $(CODEC_UNITTEST_CFLAGS) $(CODEC_UNITTEST_INCLUDES) -c -o $(CODEC_UNITTEST_SRCDIR)/./simple_test.o $(CODEC_UNITTEST_SRCDIR)/./simple_test.cpp
codec_unittest: $(CODEC_UNITTEST_OBJS) $(LIBS) $(CODEC_UNITTEST_LIBS)
$(CXX) -o $@ $(CODEC_UNITTEST_OBJS) $(CODEC_UNITTEST_LDFLAGS) $(CODEC_UNITTEST_LIBS) $(LDFLAGS) $(LIBS)
binaries: codec_unittest
BINARIES += codec_unittest