Last active
September 3, 2016 04:46
-
-
Save KentaYamada/844a523b7de07ee723ad159644c837f2 to your computer and use it in GitHub Desktop.
ユニットテストかそうでないかでアクセシビリティを切り替える
This file contains hidden or 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 "hoge.h" | |
Hoge::Hoge() | |
{} | |
void Hoge::greeting(std::string name) | |
{ | |
std::cout << "Hello, " << name << std::endl; | |
} | |
void Hoge::hello_greeting(std::string name) | |
{ | |
this->greeting(name); | |
} |
This file contains hidden or 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
#ifndef __HOGE_H__ | |
#define __HOGE_H__ | |
#include <iostream> | |
#include <string> | |
class Hoge | |
{ | |
#ifdef TEST | |
public: | |
#else | |
private: | |
#endif // end of TEST | |
void greeting(std::string name); | |
public: | |
Hoge(); | |
void hello_greeting(std::string name); | |
}; | |
#endif // end of file | |
This file contains hidden or 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 "hoge.h" | |
int main(void) | |
{ | |
//MakefileでTESTを定義しないので、greeting関数を呼び出そうとするとコンパイルエラー | |
auto hoge = new Hoge(); | |
hoge->hello_greeting("hoge"); | |
delete hoge; | |
return 0; | |
} |
This file contains hidden or 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
CXX=g++ | |
CFLAGS=-Wall -O2 | |
main: main.o hoge.o | |
$(CXX) $(CFLAGS) main.o hoge.o -o main | |
test: test_main.o hoge.o | |
$(CXX) $(CFLAGS) test_main.o hoge.o -o test | |
test_main.o: test_main.cpp hoge.h | |
$(CXX) -D "TEST" -c test_main.cpp | |
main.o: main.o hoge.h | |
$(CXX) -c main.cpp | |
hoge.o: hoge.cpp hoge.h | |
$(CXX) -D "TEST" -c hoge.cpp | |
clean: | |
$(RM) *.o test_main main |
This file contains hidden or 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 "hoge.h" | |
int main(void) | |
{ | |
std::string name = "hoge"; | |
auto hoge = new Hoge(); | |
//MakfileでTESTを定義するから外部から見えるようになる | |
hoge->greeting(name); | |
hoge->hello_greeting(name); | |
delete hoge; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment