Skip to content

Instantly share code, notes, and snippets.

@mawenbao
Created February 26, 2014 05:16
Show Gist options
  • Save mawenbao/9223908 to your computer and use it in GitHub Desktop.
Save mawenbao/9223908 to your computer and use it in GitHub Desktop.
googletest simple example
#include <gtest/gtest.h>
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
# Makefile for gtest examples
GOOGLE_TEST_LIB = gtest
GOOGLE_TEST_INCLUDE = /usr/local/include
G++ = g++
G++_FLAGS = -c -Wall -I $(GOOGLE_TEST_INCLUDE)
LD_FLAGS = -L /usr/local/lib -l $(GOOGLE_TEST_LIB) -l pthread
OBJECTS = main.o string-compare.o
TARGET = string-compare
all: $(TARGET)
$(TARGET): $(OBJECTS)
g++ -o $(TARGET) $(OBJECTS) $(LD_FLAGS)
%.o : %.cpp
$(G++) $(G++_FLAGS) $<
clean:
rm -f $(TARGET) $(OBJECTS)
.PHONY: all clean
#include <gtest/gtest.h> // googletest header file
#include <string>
using std::string;
const char *actualValTrue = "hello gtest";
const char *actualValFalse = "hello world";
const char *expectVal = "hello gtest";
TEST(StrCompare, CStrEqual) {
EXPECT_STREQ(expectVal, actualValTrue);
}
TEST(StrCompare, CStrNotEqual) {
EXPECT_STREQ(expectVal, actualValFalse);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment