Permalink
Browse files

Initial import

  • Loading branch information...
0 parents commit bd35998f9c9a92c1ae78314a27c3fd9c1789eeda @afeinberg committed Sep 4, 2011
Showing with 116 additions and 0 deletions.
  1. +12 −0 CMakeLists.txt
  2. +1 −0 README
  3. +8 −0 clean_cmake.sh
  4. +22 −0 include/example.h
  5. +3 −0 src/CMakeLists.txt
  6. +20 −0 src/example.cc
  7. +10 −0 src_test/CMakeLists.txt
  8. +40 −0 src_test/example_test.cc
@@ -0,0 +1,12 @@
+cmake_minimum_required(VERSION 2.6)
+set(PROJECT_NAME_STR af_gtest_example)
+project(${PROJECT_NAME_STR})
+
+add_definitions(-Wall -pthread)
+
+set(COMMON_INCLUDES ${PROJECT_SOURCE_DIR}/include)
+
+enable_testing()
+
+add_subdirectory(src)
+add_subdirectory(src_test)
1 README
@@ -0,0 +1 @@
+Run GTEST_ROOT=/where/google/test/is/installed/ cmake . && make && make test
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+find . -name "CMakeFiles" | xargs rm -rfv
+find . -name "Makefile" | xargs rm -rfv
+find . -name "cmake_install.cmake" | xargs rm -rfv
+find . -name "CMakeCache.txt" | xargs rm -rfv
+find . -name "CTestTestfile.cmake" | xargs rm -rfv
+rm -vrf Testing
@@ -0,0 +1,22 @@
+#ifndef AF_GTEST_EXAMPLE_H_
+#define AF_GTEST_EXAMPLE_H_
+
+#include <string>
+
+namespace af {
+
+class Example {
+ public:
+
+ explicit Example(const char *name);
+ virtual ~Example();
+
+ std::string Greet() const;
+
+ private:
+ const char *name_;
+};
+
+}
+
+#endif // AF_GTEST_EXAMPLE_H_
@@ -0,0 +1,3 @@
+include_directories(${COMMON_INCLUDES})
+
+add_library(${PROJECT_NAME_STR} STATIC "example.cc")
@@ -0,0 +1,20 @@
+#include "example.h"
+
+namespace af {
+
+Example::Example(const char *name)
+ :name_(name) {
+}
+
+Example::~Example() {
+}
+
+std::string Example::Greet() const {
+ std::string ret;
+ ret.append("Hello, ");
+ ret.append(name_);
+ ret.push_back('!');
+ return ret;
+} // namespace
+
+}
@@ -0,0 +1,10 @@
+
+find_package(GTest REQUIRED)
+
+set(PROJECT_TEST_NAME "${PROJECT_NAME_STR}_test")
+include_directories(${GTEST_INCLUDE_DIRS} ${COMMON_INCLUDES})
+
+add_executable(${PROJECT_TEST_NAME} "example_test.cc")
+target_link_libraries(${PROJECT_TEST_NAME} ${PROJECT_NAME_STR} ${GTEST_BOTH_LIBRARIES} pthread)
+
+add_test(${PROJECT_TEST_NAME} ${PROJECT_TEST_NAME})
@@ -0,0 +1,40 @@
+#include "example.h"
+#include "gtest/gtest.h"
+
+using af::Example;
+
+namespace {
+
+class ExampleTest : public ::testing::Test {
+ protected:
+
+ ExampleTest()
+ :example_("world") {
+ // Class setup
+ }
+
+ virtual ~ExampleTest() {
+ // Class teardown
+ }
+
+ virtual void SetUp() {
+ // Setup before method
+ }
+
+ virtual void TearDown() {
+ // Teardown before method
+ }
+
+ Example example_;
+};
+
+} // namespace
+
+TEST_F(ExampleTest, Greet) {
+ EXPECT_EQ(example_.Greet(), "Hello, world!");
+}
+
+int main(int argc, char **argv) {
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}

0 comments on commit bd35998

Please sign in to comment.