ref: 1928b9a1ba6f7c18ebc058835f308c3d7016a1da
parent: 5449a8a548129edb3561bcdedb54ca6deffcf879
parent: 8bb82769679bf274f4d53e0153099c5091274e09
author: Cullen Jennings <[email protected]>
date: Wed Dec 11 15:28:18 EST 2013
Merge pull request #15 from ekr/add_gtests Add gtests
--- a/Makefile
+++ b/Makefile
@@ -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 @@
#### 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 @@
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
@@ -61,6 +72,14 @@
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
+
+
+
--- /dev/null
+++ b/build/gtest-targets.mk
@@ -1,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)
--- a/build/mktargets.sh
+++ b/build/mktargets.sh
@@ -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)
+
--- a/codec/common/targets.mk
+++ b/codec/common/targets.mk
@@ -4,7 +4,7 @@
$(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)
--- /dev/null
+++ b/test/simple_test.cpp
@@ -1,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();
+}
--- /dev/null
+++ b/test/targets.mk
@@ -1,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