unit test for the FData
This commit is contained in:
parent
3d9f621258
commit
b15a665729
|
@ -1,5 +1,6 @@
|
|||
2020-09-25 Markus Gans <guru.mail@muenster.de>
|
||||
* std::clog now streams everything to the FLogger object
|
||||
* Added a unit test for the FData class
|
||||
|
||||
2020-09-23 Markus Gans <guru.mail@muenster.de>
|
||||
* Bugfix: empty FString() + wchar_t
|
||||
|
|
|
@ -24,7 +24,7 @@ endif
|
|||
# $@ = name of the targets
|
||||
# $^ = all dependency (without double entries)
|
||||
.cpp:
|
||||
$(CXX) $(CCXFLAGS) $(INCLUDES) $(LDFLAGS) -o $@ $^
|
||||
$(CXX) $^ -o $@ $(CCXFLAGS) $(INCLUDES) $(LDFLAGS)
|
||||
|
||||
all: $(OBJS)
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ endif
|
|||
# $@ = name of the targets
|
||||
# $^ = all dependency (without double entries)
|
||||
.cpp:
|
||||
$(CXX) $(CCXFLAGS) $(INCLUDES) $(LDFLAGS) -o $@ $^
|
||||
$(CXX) $^ -o $@ $(CCXFLAGS) $(INCLUDES) $(LDFLAGS)
|
||||
|
||||
all: $(OBJS)
|
||||
|
||||
|
|
|
@ -283,7 +283,10 @@ EventLog::EventLog (finalcut::FWidget* parent)
|
|||
|
||||
//----------------------------------------------------------------------
|
||||
EventLog::~EventLog() // destructor
|
||||
{ }
|
||||
{
|
||||
if ( event_dialog )
|
||||
delete event_dialog;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void EventLog::onTimer (finalcut::FTimerEvent*)
|
||||
|
|
|
@ -174,7 +174,7 @@ endif
|
|||
$(CXX) -c $(CCXFLAGS) $(INCLUDES) -fpic -o $@ $<
|
||||
|
||||
all: dep $(OBJS)
|
||||
$(CXX) $(CCXFLAGS) $(INCLUDES) $(LDFLAGS) -shared -Wl,-soname,$(LIB).$(MAJOR) -o $(LIB).$(VERSION) $(OBJS)
|
||||
$(CXX) $(OBJS) -o $(LIB).$(VERSION) $(CCXFLAGS) $(INCLUDES) $(LDFLAGS) -shared -Wl,-soname,$(LIB).$(MAJOR)
|
||||
ln -s -f $(LIB).$(VERSION) libfinal.so.$(MAJOR)
|
||||
ln -s -f $(LIB).$(MAJOR) libfinal.so
|
||||
|
||||
|
|
|
@ -174,7 +174,7 @@ endif
|
|||
$(CXX) -c $(CCXFLAGS) $(INCLUDES) -fpic -o $@ $<
|
||||
|
||||
all: dep $(OBJS)
|
||||
$(CXX) $(CCXFLAGS) $(INCLUDES) $(LDFLAGS) -shared -Wl,-soname,$(LIB).$(MAJOR) -o $(LIB).$(VERSION) $(OBJS)
|
||||
$(CXX) $(OBJS) -o $(LIB).$(VERSION) $(CCXFLAGS) $(INCLUDES) $(LDFLAGS) -shared -Wl,-soname,$(LIB).$(MAJOR)
|
||||
ln -s -f $(LIB).$(VERSION) libfinal.so.$(MAJOR)
|
||||
ln -s -f $(LIB).$(MAJOR) libfinal.so
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ namespace finalcut
|
|||
{
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// struct FDataAccess
|
||||
// class FDataAccess
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
template <typename T>
|
||||
|
@ -86,7 +86,7 @@ class FDataAccess
|
|||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
// struct FData
|
||||
// class FData
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
template <typename T>
|
||||
|
@ -103,6 +103,10 @@ class FData : public FDataAccess
|
|||
, value_ref{value}
|
||||
{ }
|
||||
|
||||
// Destructor
|
||||
~FData() override
|
||||
{ }
|
||||
|
||||
FData (const FData& d) // Copy constructor
|
||||
: value{d.value}
|
||||
, value_ref{value}
|
||||
|
@ -170,7 +174,7 @@ class FData : public FDataAccess
|
|||
// Inquiries
|
||||
bool isInitializedCopy()
|
||||
{
|
||||
return bool(value);
|
||||
return bool( &value == &value_ref );
|
||||
}
|
||||
|
||||
bool isInitializedReference()
|
||||
|
|
|
@ -9,6 +9,7 @@ AM_CPPFLAGS = -I$(top_srcdir)/src/include -Wall -Werror -std=c++11
|
|||
noinst_PROGRAMS = \
|
||||
fobject_test \
|
||||
fcallback_test \
|
||||
fdata_test \
|
||||
fmouse_test \
|
||||
fkeyboard_test \
|
||||
ftermdata_test \
|
||||
|
@ -30,6 +31,7 @@ noinst_PROGRAMS = \
|
|||
|
||||
fobject_test_SOURCES = fobject-test.cpp
|
||||
fcallback_test_SOURCES = fcallback-test.cpp
|
||||
fdata_test_SOURCES = fdata-test.cpp
|
||||
fmouse_test_SOURCES = fmouse-test.cpp
|
||||
fkeyboard_test_SOURCES = fkeyboard-test.cpp
|
||||
ftermdata_test_SOURCES = ftermdata-test.cpp
|
||||
|
@ -51,6 +53,7 @@ frect_test_SOURCES = frect-test.cpp
|
|||
|
||||
TESTS = fobject_test \
|
||||
fcallback_test \
|
||||
fdata_test \
|
||||
fmouse_test \
|
||||
fkeyboard_test \
|
||||
ftermdata_test \
|
||||
|
|
|
@ -26,7 +26,7 @@ endif
|
|||
# $@ = name of the targets
|
||||
# $^ = all dependency (without double entries)
|
||||
.cpp:
|
||||
$(CXX) $(CCXFLAGS) $(INCLUDES) $(LDFLAGS) -o $@ $^
|
||||
$(CXX) $^ -o $@ $(CCXFLAGS) $(INCLUDES) $(LDFLAGS)
|
||||
|
||||
all: $(OBJS)
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ endif
|
|||
# $@ = name of the targets
|
||||
# $^ = all dependency (without double entries)
|
||||
.cpp:
|
||||
$(CXX) $(CCXFLAGS) $(INCLUDES) $(LDFLAGS) -o $@ $^
|
||||
$(CXX) $^ -o $@ $(CCXFLAGS) $(INCLUDES) $(LDFLAGS)
|
||||
|
||||
all: $(OBJS)
|
||||
|
||||
|
|
|
@ -59,7 +59,8 @@ class FDataTest : public CPPUNIT_NS::TestFixture
|
|||
|
||||
protected:
|
||||
void classNameTest();
|
||||
void dataTest();
|
||||
void fdataTest();
|
||||
void makeFDataTest();
|
||||
|
||||
private:
|
||||
// Adds code needed to register the test suite
|
||||
|
@ -67,7 +68,8 @@ class FDataTest : public CPPUNIT_NS::TestFixture
|
|||
|
||||
// Add a methods to the test suite
|
||||
CPPUNIT_TEST (classNameTest);
|
||||
CPPUNIT_TEST (dataTest);
|
||||
CPPUNIT_TEST (fdataTest);
|
||||
CPPUNIT_TEST (makeFDataTest);
|
||||
|
||||
// End of test suite definition
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
@ -82,16 +84,154 @@ finalcut::FWidget FDataTest::root_widget{nullptr};
|
|||
//----------------------------------------------------------------------
|
||||
void FDataTest::classNameTest()
|
||||
{
|
||||
const finalcut::FCallback d;
|
||||
auto da = finalcut::FDataAccess();
|
||||
const finalcut::FString& classname2 = da.getClassName();
|
||||
CPPUNIT_ASSERT ( classname2 == "FDataAccess" );
|
||||
|
||||
auto d = finalcut::FData<void*>(nullptr);
|
||||
const finalcut::FString& classname = d.getClassName();
|
||||
CPPUNIT_ASSERT ( classname == "FData" );
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void FDataTest::dataTest()
|
||||
void FDataTest::fdataTest()
|
||||
{
|
||||
// nummber
|
||||
auto data1 = finalcut::FData<int>(5);
|
||||
CPPUNIT_ASSERT ( data1.isInitializedCopy() );
|
||||
CPPUNIT_ASSERT ( ! data1.isInitializedReference() );
|
||||
std::stringstream stream{};
|
||||
stream << data1;
|
||||
CPPUNIT_ASSERT ( stream.str() == "5" );
|
||||
int i1{data1};
|
||||
CPPUNIT_ASSERT ( i1 == 5 );
|
||||
CPPUNIT_ASSERT ( data1() == 5 );
|
||||
CPPUNIT_ASSERT ( data1.get() == 5 );
|
||||
data1.get()++;
|
||||
CPPUNIT_ASSERT ( data1.get() == 6 );
|
||||
data1.set(3);
|
||||
CPPUNIT_ASSERT ( data1.get() == 3 );
|
||||
data1 << 8;
|
||||
CPPUNIT_ASSERT ( data1.get() == 8 );
|
||||
|
||||
// int value
|
||||
int integer_value = 10;
|
||||
auto data2 = finalcut::FData<int>(integer_value);
|
||||
CPPUNIT_ASSERT ( ! data2.isInitializedCopy() );
|
||||
CPPUNIT_ASSERT ( data2.isInitializedReference() );
|
||||
stream.clear();
|
||||
stream.str("");
|
||||
stream << data2;
|
||||
CPPUNIT_ASSERT ( stream.str() == "10" );
|
||||
int i2{data2};
|
||||
CPPUNIT_ASSERT ( i2 == 10 );
|
||||
CPPUNIT_ASSERT ( data2() == 10 );
|
||||
CPPUNIT_ASSERT ( data2.get() == 10 );
|
||||
data2.get()--;
|
||||
CPPUNIT_ASSERT ( data2.get() == 9 );
|
||||
CPPUNIT_ASSERT ( integer_value == 9 );
|
||||
data2.set(7);
|
||||
CPPUNIT_ASSERT ( data2.get() == 7 );
|
||||
CPPUNIT_ASSERT ( integer_value == 7 );
|
||||
data2 << 15;
|
||||
CPPUNIT_ASSERT ( integer_value == 15 );
|
||||
|
||||
// const int value
|
||||
const int const_integer_value = 12;
|
||||
auto data3 = finalcut::FData<const int>(const_integer_value);
|
||||
CPPUNIT_ASSERT ( ! data3.isInitializedCopy() );
|
||||
CPPUNIT_ASSERT ( data3.isInitializedReference() );
|
||||
stream.clear();
|
||||
stream.str("");
|
||||
stream << data3;
|
||||
CPPUNIT_ASSERT ( stream.str() == "12" );
|
||||
int i3{data3};
|
||||
CPPUNIT_ASSERT ( i3 == 12 );
|
||||
CPPUNIT_ASSERT ( data3() == 12 );
|
||||
CPPUNIT_ASSERT ( data3.get() == 12 );
|
||||
|
||||
// Function via pointer
|
||||
auto data4 = finalcut::FData<std::function<float()>>(&my_function);
|
||||
CPPUNIT_ASSERT ( data4.isInitializedCopy() );
|
||||
CPPUNIT_ASSERT ( ! data4.isInitializedReference() );
|
||||
stream.clear();
|
||||
stream.str("");
|
||||
stream << data4()();
|
||||
CPPUNIT_ASSERT ( stream.str() == "13.45" );
|
||||
CPPUNIT_ASSERT ( data4()() == 13.45F );
|
||||
CPPUNIT_ASSERT ( data4.get()() == 13.45F );
|
||||
|
||||
// Function via reference -> remove reference + add pointer
|
||||
auto data5 = finalcut::FData<std::function<float()>>(my_function);
|
||||
CPPUNIT_ASSERT ( data5.isInitializedCopy() );
|
||||
CPPUNIT_ASSERT ( ! data5.isInitializedReference() );
|
||||
stream.clear();
|
||||
stream.str("");
|
||||
stream << data5()();
|
||||
CPPUNIT_ASSERT ( stream.str() == "13.45" );
|
||||
CPPUNIT_ASSERT ( data5()() == 13.45F );
|
||||
CPPUNIT_ASSERT ( data5.get()() == 13.45F );
|
||||
|
||||
// Function with parameter via pointer
|
||||
auto data6 = finalcut::FData<std::function<long int(long int)>>(&my_function2);
|
||||
CPPUNIT_ASSERT ( data6.isInitializedCopy() );
|
||||
CPPUNIT_ASSERT ( ! data6.isInitializedReference() );
|
||||
stream.clear();
|
||||
stream.str("");
|
||||
stream << data6()(4L);
|
||||
CPPUNIT_ASSERT ( stream.str() == "8" );
|
||||
CPPUNIT_ASSERT ( data6()(4) == 8L );
|
||||
CPPUNIT_ASSERT ( data6.get()(4) == 8L );
|
||||
|
||||
// std::string
|
||||
auto data7 = finalcut::FData<std::string>("123");
|
||||
CPPUNIT_ASSERT ( data7.isInitializedCopy() );
|
||||
CPPUNIT_ASSERT ( ! data7.isInitializedReference() );
|
||||
stream.clear();
|
||||
stream.str("");
|
||||
stream << data7;
|
||||
CPPUNIT_ASSERT ( stream.str() == "123" );
|
||||
std::string str{data7};
|
||||
CPPUNIT_ASSERT ( str == "123" );
|
||||
CPPUNIT_ASSERT ( data7() == "123" );
|
||||
CPPUNIT_ASSERT ( data7.get() == "123" );
|
||||
data7.get() += "4";
|
||||
CPPUNIT_ASSERT ( data7.get() == "1234" );
|
||||
data7.set("abc");
|
||||
CPPUNIT_ASSERT ( data7.get() == "abc" );
|
||||
data7 << "xyz";
|
||||
CPPUNIT_ASSERT ( data7.get() == "xyz" );
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
void FDataTest::makeFDataTest()
|
||||
{
|
||||
finalcut::FDataAccess* data_pointer{nullptr};
|
||||
|
||||
using ThreeInts = int[3];
|
||||
ThreeInts int_array{2, 1, 4};
|
||||
data_pointer = finalcut::makeFData(std::move(int_array));
|
||||
const auto& ints = static_cast<finalcut::FData<finalcut::clean_fdata_t<ThreeInts>>&>(*data_pointer).get();
|
||||
CPPUNIT_ASSERT ( ints[0] == 2 );
|
||||
CPPUNIT_ASSERT ( ints[1] == 1 );
|
||||
CPPUNIT_ASSERT ( ints[2] == 4 );
|
||||
|
||||
int n = 9;
|
||||
data_pointer = finalcut::makeFData(std::move(n));
|
||||
auto data = static_cast<finalcut::FData<int>&&>(*data_pointer);
|
||||
CPPUNIT_ASSERT ( data.isInitializedCopy() );
|
||||
CPPUNIT_ASSERT ( ! data.isInitializedReference() );
|
||||
auto& n2 = data.get();
|
||||
CPPUNIT_ASSERT ( n2 == 9 );
|
||||
n2++;
|
||||
CPPUNIT_ASSERT ( n2 == 10 );
|
||||
CPPUNIT_ASSERT ( data() == 10 );
|
||||
|
||||
data_pointer = finalcut::makeFData(std::move(my_function2));
|
||||
const auto& func = static_cast<finalcut::FData<finalcut::clean_fdata_t<long int (*) (long int)>>&>(*data_pointer).get();
|
||||
CPPUNIT_ASSERT ( func(128) == 256 );
|
||||
}
|
||||
|
||||
// Put the test suite in the registry
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION (FDataTest);
|
||||
|
||||
|
|
Loading…
Reference in New Issue