Created
June 22, 2013 19:08
-
-
Save daniel-kristjansson/5842178 to your computer and use it in GitHub Desktop.
Test of C++ array initialization
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 ( ../../../../settings.pro ) | |
QT += xml sql network | |
contains(QT_VERSION, ^4\\.[0-9]\\..*) { | |
CONFIG += qtestlib | |
} | |
contains(QT_VERSION, ^5\\.[0-9]\\..*) { | |
QT += testlib | |
} | |
TEMPLATE = app | |
TARGET = test_cpp_ctor_init | |
DEPENDPATH += . ../.. | |
INCLUDEPATH += . ../.. | |
LIBS += -L../.. -lmythbase-$$LIBVERSION | |
contains(QMAKE_CXX, "g++") { | |
QMAKE_CXXFLAGS += -O0 -fprofile-arcs -ftest-coverage | |
QMAKE_LFLAGS += -fprofile-arcs | |
} | |
QMAKE_LFLAGS += -Wl,$$_RPATH_$(PWD)/../../../../external/zeromq/src/.libs/ | |
QMAKE_LFLAGS += -Wl,$$_RPATH_$(PWD)/../../../../external/nzmqt/src/ | |
QMAKE_LFLAGS += -Wl,$$_RPATH_$(PWD)/../../../../external/qjson/lib/ | |
QMAKE_LFLAGS += -Wl,$$_RPATH_$(PWD)/../.. | |
# Input | |
HEADERS += test_cpp_ctor_init.h | |
SOURCES += test_cpp_ctor_init.cpp | |
QMAKE_CLEAN += $(TARGET) $(TARGETA) $(TARGETD) $(TARGET0) $(TARGET1) $(TARGET2) | |
QMAKE_CLEAN += ; rm -f *.gcov *.gcda *.gcno | |
LIBS += $$EXTRA_LIBS $$LATE_LIBS |
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 "test_cpp_ctor_init.h" | |
QTEST_APPLESS_MAIN(Testcpp_ctor_init) |
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 <iostream> | |
using namespace std; | |
#include <QtTest/QtTest> | |
class A | |
{ | |
public: | |
A() {} | |
A(float) : i(0x30) {} | |
unsigned char a[16]; | |
unsigned char i; | |
}; | |
class B | |
{ | |
public: | |
B() : i(0x30) {} | |
unsigned char a[16]; | |
unsigned char i; | |
}; | |
class Testcpp_ctor_init: public QObject | |
{ | |
Q_OBJECT | |
static const unsigned buffer_size = 8096; | |
char *buffer; | |
public: | |
Testcpp_ctor_init() | |
{ | |
buffer = new char[buffer_size]; | |
} | |
~Testcpp_ctor_init() | |
{ | |
delete [] buffer; | |
} | |
private slots: | |
// called at the beginning of these sets of tests | |
void initTestCase(void) | |
{ | |
} | |
// called at the end of these sets of tests | |
void cleanupTestCase(void) | |
{ | |
} | |
// called before each test case | |
void init(void) | |
{ | |
for (unsigned i = 0; i < buffer_size; i++) | |
buffer[i] = 99; | |
} | |
// called after each test case | |
void cleanup(void) | |
{ | |
} | |
void basic_value_is_not_initialized_with_empty_ctor(void) | |
{ | |
A *a = new (buffer) A(); | |
QVERIFY(a->i == 99); | |
} | |
void array_value_is_not_initialized_with_empty_ctor(void) | |
{ | |
A *a = new (buffer) A(); | |
QVERIFY(a->a[0] == 99); | |
} | |
void array_value_is_not_initialized_with_int_init_ctor(void) | |
{ | |
B *b = new (buffer) B(); | |
QVERIFY(b->a[0] == 99); | |
} | |
void array_value_is_not_initialized_with_int_init_ctor_with_param(void) | |
{ | |
A *a = new (buffer) A(5); | |
QVERIFY(a->a[0] == 99); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment