Created
February 26, 2014 05:16
-
-
Save mawenbao/9223908 to your computer and use it in GitHub Desktop.
googletest simple example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <gtest/gtest.h> | |
int main(int argc, char **argv) { | |
::testing::InitGoogleTest(&argc, argv); | |
return RUN_ALL_TESTS(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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