C++ makefile 出力を実行する方法
以下は私の MakeFile です。unitTest.cpp を実行する方法をお尋ねしたいのですが、NetBean で MakeFile を使用する場合、下の MakeFile を使用すると、main.exe が実際には main.cpp の出力になるためです。
しかし、 unitTest.cpp の出力を実行したい
unitTest.cpp の実行方法
# ExampleTests Project
SRCS = main.cpp currencyConverter.cpp unitTest.cpp
HDRS = currencyConverter.h unitTest.h
PROJ = main
# Remaining lines shouldn't need changing
# Here's what they do:
# - rebuild if any header file or this Makefile changes
# - include CppUnit as dynamic library
# - search /opt/local for MacPorts
# - generate .exe files for Windows
# - add -enable-auto-import flag for Cygwin only
CC = g++
OBJS = $(SRCS:.cpp=.o)
APP = $(PROJ).exe
CFLAGS = -c -g -Wall -I/opt/local/include
ifeq (,$(findstring CYGWIN,$(shell uname)))
LDFLAGS = -L/opt/local/lib
else
LDFLAGS = -L/opt/local/lib -enable-auto-import
endif
LIBS = -lcppunit -ldl
all: $(APP)
$(APP): $(OBJS)
$(CC) $(LDFLAGS) $(OBJS) -o $(APP) $(LIBS)
%.o: %.cpp $(HDRS)
$(CC) $(CFLAGS) $< -o $@
clean:
rm -f *.o $(APP)
以下は私の unitTest.cpp です
#include "unitTest.h"
#include "currencyConverter.h"
CPPUNIT_TEST_SUITE_REGISTRATION(unitTest);
unitTest::unitTest() {
}
unitTest::~unitTest() {
}
void unitTest::setUp() {
}
void unitTest::tearDown() {
}
void stringToUpper(string&);
void unitTest::testStringLowerToUpper()
{
string str = "ILOVECPLUSPLUS";
string str2 = "IloveCplusplus";
cout << "\nChecking if string 1 '" << str << "' equals string 2 '" << str2 << "'";
CPPUNIT_ASSERT_EQUAL(str,str2);
//this part i will use my stringToUpperFunction to test.
currencyConverter c;
c.stringToUpper(str2);
cout << "\nChecking if string 1 '" << str << "' equals string 2 '" << str2 << "'";
CPPUNIT_ASSERT_EQUAL(str,str2);
}