Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // required includes
- #include <cstdio> // printf and friends
- #include <cstdlib> // malloc, free, qsort
- #include <cstring> // strlen, strcpy, strtok
- #include <new> // placement new
- struct String
- {
- char* m_str;
- //__attribute__((noinline))
- void copy(const String& other) {
- if(m_str)
- free(m_str);
- m_str = 0;
- if(other.m_str) {
- m_str = static_cast<char*>(malloc(strlen(other.m_str) + 1));
- strcpy(m_str, other.m_str);
- }
- }
- //__attribute__((noinline))
- String(const char* in = 0)
- : m_str(0) {
- if(in == 0)
- return;
- m_str = static_cast<char*>(malloc(strlen(in) + 1));
- strcpy(m_str, in);
- }
- //__attribute__((noinline))
- String(const String& other)
- : m_str(0) {
- copy(other);
- }
- ~String() {
- if(m_str)
- free(m_str);
- }
- String& operator=(const String& other) {
- if(this != &other)
- copy(other);
- return *this;
- }
- };
- struct FunctionData
- {
- String m_suite;
- String m_name;
- const char* m_file;
- FunctionData(const char* suite, const char* name, const char* file)
- : m_suite(suite)
- , m_name(name)
- , m_file(file) {}
- FunctionData(const FunctionData& other)
- : m_suite(other.m_suite)
- , m_name(other.m_name)
- , m_file(other.m_file) {}
- };
- const char*& getCurrentTestSuite() {
- static const char* data = 0;
- return data;
- }
- int setTestSuiteName(const char* name) {
- getCurrentTestSuite() = name;
- return 0;
- }
- int regTest(const char* file, const char* name) {
- FunctionData temp(FunctionData(String(getCurrentTestSuite()).m_str, name, file));
- printf("hello! %s\n", temp.m_name);
- return 0;
- }
- __attribute__((unused)) static int a1 = setTestSuiteName("current testsuite");
- __attribute__((unused)) static int a2 = regTest("a.cpp", "zzz");
- int main(int, char**) { return 0; }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement